Skip to content

Commit 0cfa2ea

Browse files
committed
Introduce multi-version support for e2e tests
Fix issue with podman Remove exit(1)
1 parent c458b63 commit 0cfa2ea

File tree

9 files changed

+219
-61
lines changed

9 files changed

+219
-61
lines changed

.github/env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
golang-version=1.23
22
kind-version=v0.25.0
3-
kind-image=kindest/node:v1.31.2
3+
kind-image=kindest/node:v1.32.0

.github/workflows/e2e-tests.yaml

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ env:
1717
HTTPS_ENABLE: true
1818
NETBOX_RESTORATION_HASH_FIELD_NAME: netboxOperatorRestorationHash
1919
jobs:
20-
e2e-tests:
21-
name: E2E tests for netbox operator
20+
e2e-tests-3-7-8:
21+
name: Against netbox version 3.7.8
2222
runs-on: ubuntu-latest
2323
steps:
2424
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
@@ -28,7 +28,6 @@ jobs:
2828
- name: Import environment variables from file
2929
run: |
3030
cat ".github/env" >> "$GITHUB_ENV"
31-
echo "E2E_DIAGNOSTIC_DIRECTORY=$(mktemp -d)" >> "$GITHUB_ENV"
3231
- name: Start kind cluster
3332
uses: helm/kind-action@a1b0e391336a6ee6713a0583f8c6240d70863de3 # v1.12.0
3433
with:
@@ -47,27 +46,70 @@ jobs:
4746
kubectl get pods -A
4847
echo "Cluster information"
4948
kubectl cluster-info
50-
- name: Setup kind cluster with required software such as NetBox
49+
- name: Run e2e tests
5150
run: |
52-
make create-kind
53-
- name: Deploy NetBox operator to the kind cluster
51+
make test-e2e-3.7.8
52+
e2e-tests-4-0-11:
53+
name: Against netbox version 4.0.11
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
57+
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
58+
with:
59+
go-version: 1.23.4
60+
- name: Import environment variables from file
5461
run: |
55-
make deploy-kind
56-
- name: Run tests
57-
env:
58-
E2E_DIAGNOSTIC_DIRECTORY: ${{ env.E2E_DIAGNOSTIC_DIRECTORY }}
62+
cat ".github/env" >> "$GITHUB_ENV"
63+
- name: Start kind cluster
64+
uses: helm/kind-action@0025e74a8c7512023d06dc019c617aa3cf561fde # v1.10.0
65+
with:
66+
version: ${{ env.kind-version }}
67+
node_image: ${{ env.kind-image }}
68+
wait: 300s
69+
config: ./tests/e2e/kind-config.yaml
70+
cluster_name: e2e
71+
- name: Wait for cluster to finish bootstraping
72+
run: |
73+
echo "Waiting for all nodes to be ready..."
74+
kubectl wait --for=condition=Ready nodes --all --timeout=120s
75+
kubectl get nodes
76+
echo "Waiting for all pods to be ready..."
77+
kubectl wait --for=condition=Ready pods --all --all-namespaces --timeout=300s
78+
kubectl get pods -A
79+
echo "Cluster information"
80+
kubectl cluster-info
81+
- name: Run e2e tests
5982
run: |
60-
# # Very straight forward way of implementing a test and checking the result
61-
# kubectl apply -f config/samples/netbox_v1_prefixclaim.yaml
62-
# kubectl get prefixclaim,prefix,ipaddressclaim,ipaddress,iprange,iprangeclaim
63-
# kubectl wait --for=condition=ready --timeout=30s prefixclaim.netbox.dev/prefixclaim-sample
64-
65-
# Use Chainsaw
66-
make test-e2e
67-
- name: Upload diagnostics artifact
68-
if: ${{ failure() }}
69-
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
83+
make test-e2e-4.0.11
84+
e2e-tests-4-1-8:
85+
name: Against netbox version 4.1.8
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
89+
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
90+
with:
91+
go-version: 1.23.4
92+
- name: Import environment variables from file
93+
run: |
94+
cat ".github/env" >> "$GITHUB_ENV"
95+
- name: Start kind cluster
96+
uses: helm/kind-action@0025e74a8c7512023d06dc019c617aa3cf561fde # v1.10.0
7097
with:
71-
name: cluster-state
72-
path: ${{ env.E2E_DIAGNOSTIC_DIRECTORY }}
73-
retention-days: 15
98+
version: ${{ env.kind-version }}
99+
node_image: ${{ env.kind-image }}
100+
wait: 300s
101+
config: ./tests/e2e/kind-config.yaml
102+
cluster_name: e2e
103+
- name: Wait for cluster to finish bootstraping
104+
run: |
105+
echo "Waiting for all nodes to be ready..."
106+
kubectl wait --for=condition=Ready nodes --all --timeout=120s
107+
kubectl get nodes
108+
echo "Waiting for all pods to be ready..."
109+
kubectl wait --for=condition=Ready pods --all --all-namespaces --timeout=300s
110+
kubectl get pods -A
111+
echo "Cluster information"
112+
kubectl cluster-info
113+
- name: Run e2e tests
114+
run: |
115+
make test-e2e-4.1.8

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Dockerfile.cross
99

1010
# Test binary, built with `go test -c`
1111
*.test
12-
database.sql
12+
13+
# Test/Intermediate files
14+
kind/load-data-job/load-data.sh
15+
kind/load-data-job/dockerfile
1316

1417
# Output of the go coverage tool, specifically when used with LiteIDE
1518
*.out

Makefile

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,25 @@ generate_mocks: ## TODO: auto install go install go.uber.org/mock/mockgen@latest
237237
mkdir -p ${GEN_DIR}
238238
mockgen -destination ${GEN_DIR}/${NETBOX_MOCKS_OUTPUT_FILE} -source=${INTERFACE_DEFITIONS_DIR}
239239

240-
.PHONY: test-e2e
241-
test-e2e: install-$(GO_PACKAGE_NAME_CHAINSAW)
242-
chainsaw test --namespace e2e
240+
# e2e tests
241+
E2E_PARAM := --namespace e2e --parallel 3 --apply-timeout 3m --assert-timeout 3m --delete-timeout 3m --error-timeout 3m --exec-timeout 3m # --skip-delete (add this argument for local debugging)
242+
.PHONY: create-kind-3.7.8
243+
create-kind-3.7.8:
244+
./kind/local-env.sh --version 3.7.8
245+
.PHONY: test-e2e-3.7.8
246+
test-e2e-3.7.8: create-kind-3.7.8 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW)
247+
chainsaw test $(E2E_PARAM)
248+
249+
.PHONY: create-kind-4.0.11
250+
create-kind-4.0.11:
251+
./kind/local-env.sh --version 4.0.11
252+
.PHONY: test-e2e-4.0.11
253+
test-e2e-4.0.11: create-kind-4.0.11 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW)
254+
chainsaw test $(E2E_PARAM)
255+
256+
.PHONY: create-kind-4.1.8
257+
create-kind-4.1.8:
258+
./kind/local-env.sh --version 4.1.8
259+
.PHONY: test-e2e-4.1.8
260+
test-e2e-4.1.8: create-kind-4.1.8 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW)
261+
chainsaw test $(E2E_PARAM)

kind/load-data-job/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# load-data-job
2+
3+
Due to database schema changes cross major/minor NetBox versions, we have to `patch` the SQL files and demo data link on-the-fly.
4+
5+
The default values stems from the NetBox 4.1.x version. So the patching will only happen for 3.7.x and 4.0.x versions.
6+
7+
Please see `../local-env.sh`, that's where all the patching happen.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM python:3.12
22
ADD main.py .
3-
RUN pip install pynetbox
3+
RUN pip install -Iv pynetbox==7.4.1
44
CMD ["python", "./main.py"]

kind/load-data-job/load-data.sh renamed to kind/load-data-job/load-data.orig.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
set -o errexit
23

34
TMP_SQL_FILE=$(mktemp /tmp/netbox-data-dump.XXXXXXX.sql) || exit 1
45
curl -k https://raw.githubusercontent.com/netbox-community/netbox-demo-data/master/sql/netbox-demo-v4.1.sql > "${TMP_SQL_FILE}"

kind/load-data-job/main.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pynetbox
22
from pprint import pprint
33
from dataclasses import dataclass
4-
import sys
54

65
print("Starting to load data onto NetBox through API")
76
try:
@@ -11,7 +10,7 @@
1110
)
1211
except pynetbox.RequestError as e:
1312
pprint(e.error)
14-
sys.exit(1)
13+
1514
print("Connected to NetBoxAPI")
1615

1716
# insert Tenants
@@ -47,7 +46,7 @@ class Tenant:
4746
)
4847
except pynetbox.RequestError as e:
4948
pprint(e.error)
50-
sys.exit(1)
49+
5150
print("Tenants loaded")
5251

5352
# insert Sites
@@ -88,13 +87,14 @@ class Site:
8887
)
8988
except pynetbox.RequestError as e:
9089
pprint(e.error)
91-
sys.exit(1)
90+
9291
print("Sites loaded")
9392

9493
# create custom fields and associate custom fields with IP/IPRange/Prefix
9594
@dataclass
9695
class CustomField:
97-
object_types: list[str]
96+
content_types: list[str] # for v3
97+
object_types: list[str] # for v4
9898
type: str
9999
name: str
100100
label: str
@@ -104,6 +104,7 @@ class CustomField:
104104

105105
custom_fields = [
106106
CustomField(
107+
content_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
107108
object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
108109
type="text",
109110
name="netboxOperatorRestorationHash",
@@ -113,6 +114,7 @@ class CustomField:
113114
filter_logic="exact"
114115
),
115116
CustomField(
117+
content_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
116118
object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
117119
type="text",
118120
name="example_field",
@@ -122,6 +124,7 @@ class CustomField:
122124
filter_logic="exact"
123125
),
124126
CustomField(
127+
content_types=["ipam.prefix"],
125128
object_types=["ipam.prefix"],
126129
type="text",
127130
name="environment",
@@ -131,6 +134,7 @@ class CustomField:
131134
filter_logic="exact"
132135
),
133136
CustomField(
137+
content_types=["ipam.prefix"],
134138
object_types=["ipam.prefix"],
135139
type="text",
136140
name="poolName",
@@ -140,6 +144,7 @@ class CustomField:
140144
filter_logic="exact"
141145
),
142146
CustomField(
147+
content_types=["ipam.prefix"],
143148
object_types=["ipam.prefix"],
144149
type="boolean",
145150
name="cfDataTypeBool",
@@ -149,6 +154,7 @@ class CustomField:
149154
filter_logic="exact"
150155
),
151156
CustomField(
157+
content_types=["ipam.prefix"],
152158
object_types=["ipam.prefix"],
153159
type="integer",
154160
name="cfDataTypeInteger",
@@ -162,6 +168,7 @@ class CustomField:
162168
for custom_field in custom_fields:
163169
try:
164170
nb.extras.custom_fields.create(
171+
content_types=custom_field.content_types,
165172
object_types=custom_field.object_types,
166173
type=custom_field.type,
167174
name=custom_field.name,
@@ -173,7 +180,7 @@ class CustomField:
173180
)
174181
except pynetbox.RequestError as e:
175182
pprint(e.error)
176-
sys.exit(1)
183+
177184
print("Custom fields loaded")
178185

179186
# for debugging
@@ -461,5 +468,5 @@ class Prefix:
461468
)
462469
except pynetbox.RequestError as e:
463470
pprint(e.error)
464-
sys.exit(1)
471+
465472
print("Prefixes loaded")

0 commit comments

Comments
 (0)