Skip to content

Commit 3d4c27e

Browse files
authored
feat: support additional v4.3 types and fields (#122)
* feat: support additional v4.3 models and fields, compatibility updates * run tests with current and v4.2.3 NetBox
1 parent f7cc7f4 commit 3d4c27e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+12395
-531
lines changed

.github/workflows/lint-tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
strategy:
2727
matrix:
2828
python: [ "3.10" ]
29+
netbox: [ "", "v4.2.3" ]
2930
steps:
3031
- name: Checkout
3132
uses: actions/checkout@v4
@@ -47,7 +48,7 @@ jobs:
4748
- name: Test
4849
id: test
4950
run: |
50-
make docker-compose-netbox-plugin-test-cover
51+
make NETBOX_VERSION=${{ matrix.netbox }} docker-compose-netbox-plugin-test-cover
5152
continue-on-error: true
5253
- name: Check results
5354
if: always()
@@ -58,7 +59,7 @@ jobs:
5859
fi
5960
- name: Coverage comment
6061
uses: orgoro/coverage@3f13a558c5af7376496aa4848bf0224aead366ac # v3.2
61-
if: github.event.pull_request.head.repo.full_name == github.repository
62+
if: github.event.pull_request.head.repo.full_name == github.repository && matrix.netbox == ''
6263
with:
6364
coverageFile: ./docker/coverage/report.xml
6465
token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ dist/
2929
# Docker
3030
docker/coverage
3131
!docker/netbox/env
32+
!docker/*/netbox/env
3233
docker/oauth2/secrets/*
3334
!docker/oauth2/secrets/.gitkeep

Makefile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,42 @@ else
44
DOCKER_COMPOSE := docker-compose
55
endif
66

7+
NETBOX_VERSION ?=
8+
ifneq ($(NETBOX_VERSION),)
9+
DOCKER_PATH := docker/$(NETBOX_VERSION)
10+
TEST_SELECTOR := "/opt/netbox/netbox/netbox_diode_plugin/tests/$(NETBOX_VERSION)/tests/"
11+
else
12+
DOCKER_PATH := docker
13+
TEST_SELECTOR = netbox_diode_plugin
14+
endif
15+
716
.PHONY: docker-compose-netbox-plugin-up
817
docker-compose-netbox-plugin-up:
9-
@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml up -d --build
18+
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml up -d --build
1019

1120
.PHONY: docker-compose-netbox-plugin-down
1221
docker-compose-netbox-plugin-down:
13-
@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml down
22+
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml down
1423

1524
.PHONY: docker-compose-netbox-plugin-test
1625
docker-compose-netbox-plugin-test:
17-
-@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml -f docker/docker-compose.test.yaml run -u root --rm netbox ./manage.py test $(TEST_FLAGS) --keepdb netbox_diode_plugin
26+
-@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run -u root --rm netbox ./manage.py test $(TEST_FLAGS) --keepdb $(TEST_SELECTOR)
1827
@$(MAKE) docker-compose-netbox-plugin-down
1928

2029
.PHONY: docker-compose-netbox-plugin-test-lint
2130
docker-compose-netbox-plugin-test-lint:
22-
-@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml -f docker/docker-compose.test.yaml run -u root --rm netbox ruff check --output-format=github netbox_diode_plugin
31+
-@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run -u root --rm netbox ruff check --output-format=github netbox_diode_plugin
2332
@$(MAKE) docker-compose-netbox-plugin-down
2433

2534
.PHONY: docker-compose-netbox-plugin-test-cover
2635
docker-compose-netbox-plugin-test-cover:
27-
-@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml -f docker/docker-compose.test.yaml run --rm -u root -e COVERAGE_FILE=/opt/netbox/netbox/coverage/.coverage netbox sh -c "coverage run --source=netbox_diode_plugin --omit=*/migrations/* ./manage.py test --keepdb netbox_diode_plugin && coverage xml -o /opt/netbox/netbox/coverage/report.xml && coverage report -m | tee /opt/netbox/netbox/coverage/report.txt"
36+
-@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run --rm -u root -e COVERAGE_FILE=/opt/netbox/netbox/coverage/.coverage netbox sh -c "coverage run --source=netbox_diode_plugin --omit=*/migrations/* ./manage.py test --keepdb $(TEST_SELECTOR) && coverage xml -o /opt/netbox/netbox/coverage/report.xml && coverage report -m | tee /opt/netbox/netbox/coverage/report.txt"
2837
@$(MAKE) docker-compose-netbox-plugin-down
2938

3039
.PHONY: docker-compose-generate-matching-docs
3140
docker-compose-generate-matching-docs:
32-
@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml -f docker/docker-compose.test.yaml run --rm netbox python manage.py generate_matching_docs | awk '/Generating markdown documentation.../{p=1;next} p' > ./docs/matching-criteria-documentation.md
41+
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run --rm netbox python manage.py generate_matching_docs | awk '/Generating markdown documentation.../{p=1;next} p' > ./docs/matching-criteria-documentation.md
3342

3443
.PHONY: docker-compose-migrate
3544
docker-compose-migrate:
36-
@$(DOCKER_COMPOSE) -f docker/docker-compose.yaml -f docker/docker-compose.test.yaml run --rm netbox python manage.py migrate
45+
@$(DOCKER_COMPOSE) -f $(DOCKER_PATH)/docker-compose.yaml -f $(DOCKER_PATH)/docker-compose.test.yaml run --rm netbox python manage.py migrate

docker/Dockerfile-diode-netbox-plugin

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM netboxcommunity/netbox:v4.2.3-3.1.1
1+
FROM netboxcommunity/netbox:v4.3.3-3.3.0
22

33
COPY ./netbox/configuration/ /etc/netbox/config/
44
RUN chmod 755 /etc/netbox/config/* && \
@@ -9,4 +9,5 @@ RUN chmod 755 /opt/netbox/netbox/netbox/local_settings.py && \
99
chown unit:root /opt/netbox/netbox/netbox/local_settings.py
1010

1111
COPY ./requirements-diode-netbox-plugin.txt /opt/netbox/
12-
RUN /opt/netbox/venv/bin/pip install --no-warn-script-location -r /opt/netbox/requirements-diode-netbox-plugin.txt
12+
ENV VIRTUAL_ENV=/opt/netbox/venv
13+
RUN /usr/local/bin/uv pip install -r /opt/netbox/requirements-diode-netbox-plugin.txt

docker/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: diode-netbox-plugin
22
services:
33
netbox: &netbox
4-
image: netboxcommunity/netbox:v4.2.3-3.1.1-diode-netbox-plugin
4+
image: netboxcommunity/netbox:v4.3.3-3.3.0-diode-netbox-plugin
55
build:
66
context: .
77
dockerfile: Dockerfile-diode-netbox-plugin

docker/requirements-diode-netbox-plugin.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ coverage==7.6.0
44
grpcio==1.62.1
55
protobuf==5.29.5
66
pytest==8.0.2
7-
netboxlabs-netbox-branching==0.5.7
7+
netboxlabs-netbox-branching==0.6.0
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM netboxcommunity/netbox:v4.2.3-3.1.1
2+
3+
COPY ./netbox/configuration/ /etc/netbox/config/
4+
RUN chmod 755 /etc/netbox/config/* && \
5+
chown unit:root /etc/netbox/config/*
6+
7+
COPY ./netbox/local_settings.py /opt/netbox/netbox/netbox/local_settings.py
8+
RUN chmod 755 /opt/netbox/netbox/netbox/local_settings.py && \
9+
chown unit:root /opt/netbox/netbox/netbox/local_settings.py
10+
11+
COPY ./requirements-diode-netbox-plugin.txt /opt/netbox/
12+
RUN /opt/netbox/venv/bin/pip install --no-warn-script-location -r /opt/netbox/requirements-diode-netbox-plugin.txt
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: diode-netbox-plugin-4.2.3
2+
services:
3+
netbox:
4+
volumes:
5+
- ./netbox/plugins_test.py:/etc/netbox/config/plugins.py:z,ro

docker/v4.2.3/docker-compose.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: diode-netbox-plugin-4.2.3
2+
services:
3+
netbox: &netbox
4+
image: netboxcommunity/netbox:v4.2.3-3.1.1-diode-netbox-plugin
5+
build:
6+
context: .
7+
dockerfile: Dockerfile-diode-netbox-plugin
8+
pull: true
9+
depends_on:
10+
- netbox-postgres
11+
- netbox-redis
12+
- netbox-redis-cache
13+
env_file: netbox/env/netbox.env
14+
user: 'unit:root'
15+
healthcheck:
16+
start_period: 60s
17+
timeout: 3s
18+
interval: 15s
19+
test: "curl -f http://localhost:8080/netbox/api/ || exit 1"
20+
volumes:
21+
- ./netbox/docker-entrypoint.sh:/opt/netbox/docker-entrypoint.sh:z,ro
22+
- ./netbox/nginx-unit.json:/opt/netbox/nginx-unit.json:z,ro
23+
- ../../netbox_diode_plugin:/opt/netbox/netbox/netbox_diode_plugin:z,rw
24+
- ../oauth2/secrets:/run/secrets:z,ro
25+
- ./netbox/launch-netbox.sh:/opt/netbox/launch-netbox.sh:z,ro
26+
- ./netbox/plugins_dev.py:/etc/netbox/config/plugins.py:z,ro
27+
- ./coverage:/opt/netbox/netbox/coverage:z,rw
28+
- netbox-media-files:/opt/netbox/netbox/media:rw
29+
- netbox-reports-files:/opt/netbox/netbox/reports:rw
30+
- netbox-scripts-files:/opt/netbox/netbox/scripts:rw
31+
extra_hosts:
32+
- "host.docker.internal:host-gateway"
33+
ports:
34+
- "8000:8080"
35+
36+
netbox-worker:
37+
<<: *netbox
38+
depends_on:
39+
netbox:
40+
condition: service_healthy
41+
command:
42+
- /opt/netbox/venv/bin/python
43+
- /opt/netbox/netbox/manage.py
44+
- rqworker
45+
healthcheck:
46+
test: ps -aux | grep -v grep | grep -q rqworker || exit 1
47+
start_period: 20s
48+
timeout: 3s
49+
interval: 15s
50+
ports: []
51+
52+
# postgres
53+
netbox-postgres:
54+
image: docker.io/postgres:16-alpine
55+
env_file: netbox/env/postgres.env
56+
volumes:
57+
- netbox-postgres-data:/var/lib/postgresql/data
58+
59+
# redis
60+
netbox-redis:
61+
image: docker.io/redis:7-alpine
62+
command:
63+
- sh
64+
- -c # this is to evaluate the $REDIS_PASSWORD from the env
65+
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
66+
env_file: netbox/env/redis.env
67+
volumes:
68+
- netbox-redis-data:/data
69+
70+
netbox-redis-cache:
71+
image: docker.io/redis:7-alpine
72+
command:
73+
- sh
74+
- -c # this is to evaluate the $REDIS_PASSWORD from the env
75+
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
76+
env_file: netbox/env/redis-cache.env
77+
volumes:
78+
- netbox-redis-cache-data:/data
79+
80+
volumes:
81+
netbox-media-files:
82+
driver: local
83+
netbox-postgres-data:
84+
driver: local
85+
netbox-redis-cache-data:
86+
driver: local
87+
netbox-redis-data:
88+
driver: local
89+
netbox-reports-files:
90+
driver: local
91+
netbox-scripts-files:
92+
driver: local

0 commit comments

Comments
 (0)