Skip to content

Commit

Permalink
Introduce multi-version support for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybear327 committed Dec 19, 2024
1 parent 327b3a1 commit c52c6c3
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
golang-version=1.23
kind-version=v0.25.0
kind-image=kindest/node:v1.31.2
kind-image=kindest/node:v1.32.0
88 changes: 65 additions & 23 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ env:
HTTPS_ENABLE: true
NETBOX_RESTORATION_HASH_FIELD_NAME: netboxOperatorRestorationHash
jobs:
e2e-tests:
name: E2E tests for netbox operator
e2e-tests-3-7-8:
name: Against netbox version 3.7.8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
Expand All @@ -28,7 +28,6 @@ jobs:
- name: Import environment variables from file
run: |
cat ".github/env" >> "$GITHUB_ENV"
echo "E2E_DIAGNOSTIC_DIRECTORY=$(mktemp -d)" >> "$GITHUB_ENV"
- name: Start kind cluster
uses: helm/kind-action@ae94020eaf628e9b9b9f341a10cc0cdcf5c018fb # v1.11.0
with:
Expand All @@ -47,27 +46,70 @@ jobs:
kubectl get pods -A
echo "Cluster information"
kubectl cluster-info
- name: Setup kind cluster with required software such as NetBox
- name: Run e2e tests
run: |
make create-kind
- name: Deploy NetBox operator to the kind cluster
make test-e2e-3.7.8
e2e-tests-4-0-11:
name: Against netbox version 4.0.11
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version: 1.23.4
- name: Import environment variables from file
run: |
make deploy-kind
- name: Run tests
env:
E2E_DIAGNOSTIC_DIRECTORY: ${{ env.E2E_DIAGNOSTIC_DIRECTORY }}
cat ".github/env" >> "$GITHUB_ENV"
- name: Start kind cluster
uses: helm/kind-action@0025e74a8c7512023d06dc019c617aa3cf561fde # v1.10.0
with:
version: ${{ env.kind-version }}
node_image: ${{ env.kind-image }}
wait: 300s
config: ./tests/e2e/kind-config.yaml
cluster_name: e2e
- name: Wait for cluster to finish bootstraping
run: |
echo "Waiting for all nodes to be ready..."
kubectl wait --for=condition=Ready nodes --all --timeout=120s
kubectl get nodes
echo "Waiting for all pods to be ready..."
kubectl wait --for=condition=Ready pods --all --all-namespaces --timeout=300s
kubectl get pods -A
echo "Cluster information"
kubectl cluster-info
- name: Run e2e tests
run: |
# # Very straight forward way of implementing a test and checking the result
# kubectl apply -f config/samples/netbox_v1_prefixclaim.yaml
# kubectl get prefixclaim,prefix,ipaddressclaim,ipaddress,iprange,iprangeclaim
# kubectl wait --for=condition=ready --timeout=30s prefixclaim.netbox.dev/prefixclaim-sample
# Use Chainsaw
make test-e2e
- name: Upload diagnostics artifact
if: ${{ failure() }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
make test-e2e-4.0.11
e2e-tests-4-1-8:
name: Against netbox version 4.1.8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version: 1.23.4
- name: Import environment variables from file
run: |
cat ".github/env" >> "$GITHUB_ENV"
- name: Start kind cluster
uses: helm/kind-action@0025e74a8c7512023d06dc019c617aa3cf561fde # v1.10.0
with:
name: cluster-state
path: ${{ env.E2E_DIAGNOSTIC_DIRECTORY }}
retention-days: 15
version: ${{ env.kind-version }}
node_image: ${{ env.kind-image }}
wait: 300s
config: ./tests/e2e/kind-config.yaml
cluster_name: e2e
- name: Wait for cluster to finish bootstraping
run: |
echo "Waiting for all nodes to be ready..."
kubectl wait --for=condition=Ready nodes --all --timeout=120s
kubectl get nodes
echo "Waiting for all pods to be ready..."
kubectl wait --for=condition=Ready pods --all --all-namespaces --timeout=300s
kubectl get pods -A
echo "Cluster information"
kubectl cluster-info
- name: Run e2e tests
run: |
make test-e2e-4.1.8
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Dockerfile.cross

# Test binary, built with `go test -c`
*.test
database.sql

# Test/Intermediate files
kind/load-data-job/load-data.sh
kind/load-data-job/dockerfile

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
25 changes: 22 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ generate_mocks: ## TODO: auto install go install go.uber.org/mock/mockgen@latest
mkdir -p ${GEN_DIR}
mockgen -destination ${GEN_DIR}/${NETBOX_MOCKS_OUTPUT_FILE} -source=${INTERFACE_DEFITIONS_DIR}

.PHONY: test-e2e
test-e2e: install-$(GO_PACKAGE_NAME_CHAINSAW)
chainsaw test --namespace e2e
# e2e tests
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)
.PHONY: create-kind-3.7.8
create-kind-3.7.8:
./kind/local-env.sh --version 3.7.8
.PHONY: test-e2e-3.7.8
test-e2e-3.7.8: create-kind-3.7.8 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW)
chainsaw test $(E2E_PARAM)

.PHONY: create-kind-4.0.11
create-kind-4.0.11:
./kind/local-env.sh --version 4.0.11
.PHONY: test-e2e-4.0.11
test-e2e-4.0.11: create-kind-4.0.11 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW)
chainsaw test $(E2E_PARAM)

.PHONY: create-kind-4.1.8
create-kind-4.1.8:
./kind/local-env.sh --version 4.1.8
.PHONY: test-e2e-4.1.8
test-e2e-4.1.8: create-kind-4.1.8 deploy-kind install-$(GO_PACKAGE_NAME_CHAINSAW)
chainsaw test $(E2E_PARAM)
7 changes: 7 additions & 0 deletions kind/load-data-job/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# load-data-job

Due to database schema changes cross major/minor NetBox versions, we have to `patch` the SQL files and demo data link on-the-fly.

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.

Please see `../local-env.sh`, that's where all the patching happen.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12
ADD main.py .
RUN pip install pynetbox
RUN pip install -Iv pynetbox==7.4.1
CMD ["python", "./main.py"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
set -o errexit

TMP_SQL_FILE=$(mktemp /tmp/netbox-data-dump.XXXXXXX.sql) || exit 1
curl -k https://raw.githubusercontent.com/netbox-community/netbox-demo-data/master/sql/netbox-demo-v4.1.sql > "${TMP_SQL_FILE}"
Expand Down
10 changes: 9 additions & 1 deletion kind/load-data-job/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class Site:
# create custom fields and associate custom fields with IP/IPRange/Prefix
@dataclass
class CustomField:
object_types: list[str]
content_types: list[str] # for v3
object_types: list[str] # for v4
type: str
name: str
label: str
Expand All @@ -104,6 +105,7 @@ class CustomField:

custom_fields = [
CustomField(
content_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
type="text",
name="netboxOperatorRestorationHash",
Expand All @@ -113,6 +115,7 @@ class CustomField:
filter_logic="exact"
),
CustomField(
content_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
object_types=["ipam.ipaddress", "ipam.iprange", "ipam.prefix"],
type="text",
name="example_field",
Expand All @@ -122,6 +125,7 @@ class CustomField:
filter_logic="exact"
),
CustomField(
content_types=["ipam.prefix"],
object_types=["ipam.prefix"],
type="text",
name="environment",
Expand All @@ -131,6 +135,7 @@ class CustomField:
filter_logic="exact"
),
CustomField(
content_types=["ipam.prefix"],
object_types=["ipam.prefix"],
type="text",
name="poolName",
Expand All @@ -140,6 +145,7 @@ class CustomField:
filter_logic="exact"
),
CustomField(
content_types=["ipam.prefix"],
object_types=["ipam.prefix"],
type="boolean",
name="cfDataTypeBool",
Expand All @@ -149,6 +155,7 @@ class CustomField:
filter_logic="exact"
),
CustomField(
content_types=["ipam.prefix"],
object_types=["ipam.prefix"],
type="integer",
name="cfDataTypeInteger",
Expand All @@ -162,6 +169,7 @@ class CustomField:
for custom_field in custom_fields:
try:
nb.extras.custom_fields.create(
content_types=custom_field.content_types,
object_types=custom_field.object_types,
type=custom_field.type,
name=custom_field.name,
Expand Down
Loading

0 comments on commit c52c6c3

Please sign in to comment.