From a895f8a468d3c97aa513fdc9830a5cac5d914f85 Mon Sep 17 00:00:00 2001 From: Frederico Sequeira Date: Mon, 21 Sep 2026 16:36:02 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A7=20Add=20new=20Add=20Container?= =?UTF-8?q?=20Choice=20and=20agent=20compatibility=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main_ci.yml | 2 +- .github/workflows/pr_ci.yml | 2 +- netbox_docker_plugin/models/container.py | 9 +- .../container/test_agent_compatibility.py | 96 +++++++++++++++++++ 4 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 netbox_docker_plugin/tests/container/test_agent_compatibility.py diff --git a/.github/workflows/main_ci.yml b/.github/workflows/main_ci.yml index b2db6eb..5f62f1d 100644 --- a/.github/workflows/main_ci.yml +++ b/.github/workflows/main_ci.yml @@ -3,7 +3,7 @@ name: main branch CI on: push: branches: - - "main" + - "main_v4" jobs: testing: diff --git a/.github/workflows/pr_ci.yml b/.github/workflows/pr_ci.yml index 6585d3f..8f00ee6 100644 --- a/.github/workflows/pr_ci.yml +++ b/.github/workflows/pr_ci.yml @@ -3,7 +3,7 @@ name: Pull Request CI on: pull_request: branches: - - "main" + - "main_v4" jobs: testing: diff --git a/netbox_docker_plugin/models/container.py b/netbox_docker_plugin/models/container.py index 761fd68..9d6b223 100644 --- a/netbox_docker_plugin/models/container.py +++ b/netbox_docker_plugin/models/container.py @@ -94,22 +94,27 @@ class ContainerCapAddChoices(ChoiceSet): key = "Container.cap_add" CHOICES = [ - ("NET_ADMIN", "NET_ADMIN"), + ("AUDIT_WRITE", "AUDIT_WRITE"), ("CHOWN", "CHOWN"), ("DAC_OVERRIDE", "DAC_OVERRIDE"), ("DAC_READ_SEARCH", "DAC_READ_SEARCH"), ("FOWNER", "FOWNER"), ("FSETID", "FSETID"), ("KILL", "KILL"), + ("MKNOD", "MKNOD"), + ("NET_ADMIN", "NET_ADMIN"), + ("NET_BIND_SERVICE", "NET_BIND_SERVICE"), ("NET_RAW", "NET_RAW"), ("SETFCAP", "SETFCAP"), ("SETGID", "SETGID"), + ("SETPCAP", "SETPCAP"), ("SETUID", "SETUID"), ("SYS_ADMIN", "SYS_ADMIN"), ("SYS_CHROOT", "SYS_CHROOT"), + ("SYS_NICE", "SYS_NICE"), ("SYS_PTRACE", "SYS_PTRACE"), ("SYS_RESOURCE", "SYS_RESOURCE"), - ("SYS_NICE", "SYS_NICE"), + ("ALL", "ALL"), ] diff --git a/netbox_docker_plugin/tests/container/test_agent_compatibility.py b/netbox_docker_plugin/tests/container/test_agent_compatibility.py new file mode 100644 index 0000000..01382f1 --- /dev/null +++ b/netbox_docker_plugin/tests/container/test_agent_compatibility.py @@ -0,0 +1,96 @@ +"""Agent compatibility regression tests. + +Each test pins one payload shape that netbox-docker-agent >= 1.25 sends back to +NetBox and that plugin 3.3.0 rejected. See the migrations 0036 to 0038. +""" + +from django.test import TestCase +from netbox_docker_plugin.models.container import Container, Env, Port +from netbox_docker_plugin.models.host import Host +from netbox_docker_plugin.models.image import Image +from netbox_docker_plugin.models.registry import Registry + + +class AgentCompatibilityTestCase(TestCase): + """Agent Compatibility Test Case Class""" + + objects = {} + + @classmethod + def setUpTestData(cls) -> None: + cls.objects["host1"] = Host.objects.create( + endpoint="http://localhost:8080", name="host1" + ) + cls.objects["registry1"] = Registry.objects.create( + host=cls.objects["host1"], + name="registry1", + serveraddress="http://localhost:8080", + ) + cls.objects["image1"] = Image.objects.create( + host=cls.objects["host1"], + name="image1", + registry=cls.objects["registry1"], + ) + + def _container(self, name, **kwargs): + """Create a container on the shared fixture host""" + + container = Container.objects.create( + host=self.objects["host1"], + image=self.objects["image1"], + name=name, + operation="none", + state="created", + **kwargs, + ) + container.full_clean() + return container + + def test_docker_log_drivers_are_accepted(self): + """The agent reports LogConfig.Type verbatim from the Docker daemon""" + + for index, driver in enumerate( + ["json-file", "syslog", "journald", "local", "none"] + ): + container = self._container(f"container-log-{index}", log_driver=driver) + self.assertEqual(container.log_driver, driver) + + def test_log_driver_may_be_empty(self): + """A container created before any refresh has no log driver yet""" + + container = self._container("container-log-null") + self.assertIsNone(container.log_driver) + + def test_unpublished_port_is_accepted(self): + """The agent uses -1 for exposed but unpublished ports""" + + container = self._container("container-port") + port = Port.objects.create( + container=container, + private_port=8080, + public_port=-1, + type="tcp", + ) + port.full_clean() + self.assertEqual(port.public_port, -1) + + def test_docker_capabilities_are_accepted(self): + """The agent reports the container capabilities with CAP_ stripped""" + + container = self._container( + "container-caps", + cap_add=["CHOWN", "SETUID", "SYS_ADMIN", "MKNOD"], + ) + self.assertEqual(len(container.cap_add), 4) + + def test_long_environment_value_is_accepted(self): + """Inline configuration and certificates exceed the old 4096 ceiling""" + + container = self._container("container-env") + env = Env.objects.create( + container=container, + var_name="BIG_VALUE", + value="x" * 20000, + ) + env.full_clean() + self.assertEqual(len(env.value), 20000) \ No newline at end of file From 2a2c8944fb77c7a86ebd2ae302b3ad4e36fd469e Mon Sep 17 00:00:00 2001 From: Frederico Sequeira Date: Mon, 21 Sep 2026 16:43:41 +0100 Subject: [PATCH 2/3] Increase plugin version --- netbox_docker_plugin/__init__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox_docker_plugin/__init__.py b/netbox_docker_plugin/__init__.py index 9620380..ee744ae 100644 --- a/netbox_docker_plugin/__init__.py +++ b/netbox_docker_plugin/__init__.py @@ -11,7 +11,7 @@ class NetBoxDockerConfig(PluginConfig): name = "netbox_docker_plugin" verbose_name = " NetBox Docker Plugin" description = "Manage Docker" - version = "4.12.1" + version = "4.12.2" base_url = "docker" min_version = "4.3.7" author = "Vincent Simonin , David Delassus " diff --git a/pyproject.toml b/pyproject.toml index af09e2f..9997f3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "netbox-docker-plugin" -version = "4.12.1" +version = "4.12.2" authors = [ { name="Vincent Simonin", email="vincent@saashup.com" }, { name="David Delassus", email="david.jose.delassus@gmail.com" } From a973cc8d40b75ee769c6e70c6bea819406c5ef87 Mon Sep 17 00:00:00 2001 From: Frederico Sequeira Date: Mon, 21 Sep 2026 16:53:02 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=9A=A8=20=20Fix=20lint=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/container/test_agent_compatibility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_docker_plugin/tests/container/test_agent_compatibility.py b/netbox_docker_plugin/tests/container/test_agent_compatibility.py index 01382f1..f7efaac 100644 --- a/netbox_docker_plugin/tests/container/test_agent_compatibility.py +++ b/netbox_docker_plugin/tests/container/test_agent_compatibility.py @@ -93,4 +93,4 @@ def test_long_environment_value_is_accepted(self): value="x" * 20000, ) env.full_clean() - self.assertEqual(len(env.value), 20000) \ No newline at end of file + self.assertEqual(len(env.value), 20000)