Skip to content

Commit c52c6c3

Browse files
committed
Introduce multi-version support for e2e tests
1 parent 327b3a1 commit c52c6c3

File tree

9 files changed

+213
-55
lines changed

9 files changed

+213
-55
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@ae94020eaf628e9b9b9f341a10cc0cdcf5c018fb # v1.11.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@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class Site:
9494
# create custom fields and associate custom fields with IP/IPRange/Prefix
9595
@dataclass
9696
class CustomField:
97-
object_types: list[str]
97+
content_types: list[str] # for v3
98+
object_types: list[str] # for v4
9899
type: str
99100
name: str
100101
label: str
@@ -104,6 +105,7 @@ class CustomField:
104105

105106
custom_fields = [
106107
CustomField(
108+
content_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
107109
object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
108110
type="text",
109111
name="netboxOperatorRestorationHash",
@@ -113,6 +115,7 @@ class CustomField:
113115
filter_logic="exact"
114116
),
115117
CustomField(
118+
content_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
116119
object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
117120
type="text",
118121
name="example_field",
@@ -122,6 +125,7 @@ class CustomField:
122125
filter_logic="exact"
123126
),
124127
CustomField(
128+
content_types=["ipam.prefix"],
125129
object_types=["ipam.prefix"],
126130
type="text",
127131
name="environment",
@@ -131,6 +135,7 @@ class CustomField:
131135
filter_logic="exact"
132136
),
133137
CustomField(
138+
content_types=["ipam.prefix"],
134139
object_types=["ipam.prefix"],
135140
type="text",
136141
name="poolName",
@@ -140,6 +145,7 @@ class CustomField:
140145
filter_logic="exact"
141146
),
142147
CustomField(
148+
content_types=["ipam.prefix"],
143149
object_types=["ipam.prefix"],
144150
type="boolean",
145151
name="cfDataTypeBool",
@@ -149,6 +155,7 @@ class CustomField:
149155
filter_logic="exact"
150156
),
151157
CustomField(
158+
content_types=["ipam.prefix"],
152159
object_types=["ipam.prefix"],
153160
type="integer",
154161
name="cfDataTypeInteger",
@@ -162,6 +169,7 @@ class CustomField:
162169
for custom_field in custom_fields:
163170
try:
164171
nb.extras.custom_fields.create(
172+
content_types=custom_field.content_types,
165173
object_types=custom_field.object_types,
166174
type=custom_field.type,
167175
name=custom_field.name,

0 commit comments

Comments
 (0)