From 8547e63306ba4a513b166d775c4cd9d22f3eaea6 Mon Sep 17 00:00:00 2001 From: Julian Dehm Date: Thu, 6 Apr 2023 11:48:30 +0200 Subject: [PATCH] lxd: include devices in container tests --- .../integration/states/test_lxd_container.py | 57 +++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/tests/integration/states/test_lxd_container.py b/tests/integration/states/test_lxd_container.py index a7060562a90..8b2ea89eae6 100644 --- a/tests/integration/states/test_lxd_container.py +++ b/tests/integration/states/test_lxd_container.py @@ -31,10 +31,7 @@ class LxdContainerTestCase(ModuleCase, SaltReturnAssertsMixin): "lxd_image.absent", name="images:centos/7", ) - self.run_state( - "lxd_container.absent", - name="test-container", - ) + self.run_state("lxd_container.absent", name="test-container", stop=True) def test_02__create_container(self): ret = self.run_state( @@ -42,6 +39,14 @@ class LxdContainerTestCase(ModuleCase, SaltReturnAssertsMixin): name="test-container", running=True, source={"type": "image", "alias": "images:centos/7"}, + devices={ + "data1": {"type": "disk", "source": "/tmp", "path": "/mnt/data"}, + "port9000": { + "type": "proxy", + "listen": "tcp:127.0.0.1:9000", + "connect": "tcp:127.0.0.1:9000", + }, + }, ) name = "lxd_container_|-test-container_|-test-container_|-present" self.assertSaltTrueReturn(ret) @@ -56,12 +61,50 @@ class LxdContainerTestCase(ModuleCase, SaltReturnAssertsMixin): name="test-container", running=True, source={"type": "image", "alias": "images:centos/7"}, + devices={ + "data1": {"type": "disk", "source": "/tmp", "path": "/mnt/data"}, + "data2": {"type": "disk", "source": "/tmp", "path": "/mnt/data2"}, + "port9000": { + "type": "proxy", + "listen": "tcp:127.0.0.1:9000", + "connect": "tcp:127.0.0.1:9000", + }, + "port9001": { + "type": "proxy", + "listen": "tcp:127.0.0.1:9001", + "connect": "tcp:127.0.0.1:9001", + }, + "port9002": { + "type": "proxy", + "listen": "tcp:127.0.0.1:9002", + "connect": "tcp:127.0.0.1:9002", + }, + }, ) ret = self.run_state( "lxd_container.present", name="test-container", running=True, source={"type": "image", "alias": "images:centos/7"}, + devices={ + "data1": {"type": "disk", "source": "/tmp", "path": "/mnt/data"}, + "data2": {"type": "disk", "source": "/tmp", "path": "/mnt/data3"}, + "port9000": { + "type": "proxy", + "listen": "tcp:127.0.0.1:9000", + "connect": "tcp:127.0.0.1:9000", + }, + "port9001": { + "type": "proxy", + "listen": "tcp:127.0.0.1:9001", + "connect": "tcp:127.0.0.1:9009", + }, + "port9003": { + "type": "proxy", + "listen": "tcp:127.0.0.1:9003", + "connect": "tcp:127.0.0.1:9003", + }, + }, restart_on_change=True, config=[ {"key": "boot.autostart", "value": 1}, @@ -75,6 +118,12 @@ class LxdContainerTestCase(ModuleCase, SaltReturnAssertsMixin): "boot.autostart": 'Added config key "boot.autostart" = "1"', "security.privileged": 'Added config key "security.privileged" = "1"', } + assert ret[name]["changes"]["devices"] == { + "data2": 'Changed device "data2"', + "port9001": 'Changed device "port9001"', + "port9002": 'Removed device "port9002"', + "port9003": 'Added device "port9003"', + } def test_08__running_container(self): self.run_state(