diff options
| author | omnom62 <omnom62@outlook.com> | 2026-06-01 06:12:38 +1000 |
|---|---|---|
| committer | omnom62 <omnom62@outlook.com> | 2026-06-01 06:12:38 +1000 |
| commit | 3d5580b801812dbbeefb37cfb7059b7f2b4adcbb (patch) | |
| tree | 3566f36822e1ae4bae19efaaab63a06f4bb525b8 /tests | |
| parent | 967a8c581df46f3c01d642ed08ec0d7ec43d79f6 (diff) | |
| download | rest.vyos-3d5580b801812dbbeefb37cfb7059b7f2b4adcbb.tar.gz rest.vyos-3d5580b801812dbbeefb37cfb7059b7f2b4adcbb.zip | |
Preparing first cut of modules
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/integration/targets/vyos_prefix_lists.old/aliases | 1 | ||||
| -rw-r--r-- | tests/integration/targets/vyos_prefix_lists.old/tasks/main.yaml | 144 | ||||
| -rw-r--r-- | tests/unit/modules/test_vyos_ntp_global.py | 22 |
3 files changed, 12 insertions, 155 deletions
diff --git a/tests/integration/targets/vyos_prefix_lists.old/aliases b/tests/integration/targets/vyos_prefix_lists.old/aliases deleted file mode 100644 index cc0afef..0000000 --- a/tests/integration/targets/vyos_prefix_lists.old/aliases +++ /dev/null @@ -1 +0,0 @@ -network/vyos diff --git a/tests/integration/targets/vyos_prefix_lists.old/tasks/main.yaml b/tests/integration/targets/vyos_prefix_lists.old/tasks/main.yaml deleted file mode 100644 index e5c62cd..0000000 --- a/tests/integration/targets/vyos_prefix_lists.old/tasks/main.yaml +++ /dev/null @@ -1,144 +0,0 @@ ---- -# tests/integration/targets/vyos_prefix_lists/tasks/main.yaml - -- name: TEARDOWN — delete all prefix lists before tests - vyos.rest.vyos_prefix_lists: - state: deleted - -# ------------------------------------------------------------------ -# MERGED -# ------------------------------------------------------------------ - -- name: MERGED — create prefix lists - register: result - vyos.rest.vyos_prefix_lists: - config: - - afi: ipv4 - prefix_lists: - - name: AnsibleIPv4PrefixList - description: PL configured by ansible - entries: - - sequence: 2 - action: permit - prefix: 92.168.10.0/26 - le: 32 - - sequence: 3 - action: deny - prefix: 72.168.2.0/24 - ge: 26 - - afi: ipv6 - prefix_lists: - - name: AllowIPv6Prefix - description: Configured by ansible for allowing IPv6 networks - entries: - - sequence: 5 - action: permit - prefix: 2001:db8:8000::/35 - le: 37 - state: merged - -- name: ASSERT — merged changed - assert: - that: - - result.changed == true - -- name: MERGED — idempotency check - register: result - vyos.rest.vyos_prefix_lists: - config: - - afi: ipv4 - prefix_lists: - - name: AnsibleIPv4PrefixList - description: PL configured by ansible - entries: - - sequence: 2 - action: permit - prefix: 92.168.10.0/26 - le: 32 - - sequence: 3 - action: deny - prefix: 72.168.2.0/24 - ge: 26 - state: merged - -- name: ASSERT — merged idempotent - assert: - that: - - result.changed == false - - result.commands | length == 0 - -# ------------------------------------------------------------------ -# GATHERED -# ------------------------------------------------------------------ - -- name: GATHERED — read current prefix lists - register: result - vyos.rest.vyos_prefix_lists: - state: gathered - -- name: ASSERT — gathered has ipv4 entry - assert: - that: - - result.gathered | selectattr('afi','eq','ipv4') | list | length > 0 - -# ------------------------------------------------------------------ -# REPLACED -# ------------------------------------------------------------------ - -- name: REPLACED — replace AnsibleIPv4PrefixList - register: result - vyos.rest.vyos_prefix_lists: - config: - - afi: ipv4 - prefix_lists: - - name: AnsibleIPv4PrefixList - entries: - - sequence: 10 - action: permit - prefix: 10.0.0.0/8 - state: replaced - -- name: ASSERT — replaced changed - assert: - that: - - result.changed == true - -- name: REPLACED — idempotency check - register: result - vyos.rest.vyos_prefix_lists: - config: - - afi: ipv4 - prefix_lists: - - name: AnsibleIPv4PrefixList - entries: - - sequence: 10 - action: permit - prefix: 10.0.0.0/8 - state: replaced - -- name: ASSERT — replaced idempotent - assert: - that: - - result.changed == false - -# ------------------------------------------------------------------ -# DELETED -# ------------------------------------------------------------------ - -- name: DELETED — remove specific prefix list - register: result - vyos.rest.vyos_prefix_lists: - config: - - afi: ipv4 - prefix_lists: - - name: AnsibleIPv4PrefixList - state: deleted - -- name: ASSERT — deleted changed - assert: - that: - - result.changed == true - -- name: DELETED — remove all remaining - vyos.rest.vyos_prefix_lists: - state: deleted diff --git a/tests/unit/modules/test_vyos_ntp_global.py b/tests/unit/modules/test_vyos_ntp_global.py index d646b1a..9aac605 100644 --- a/tests/unit/modules/test_vyos_ntp_global.py +++ b/tests/unit/modules/test_vyos_ntp_global.py @@ -138,26 +138,28 @@ class TestVyOSNtpGlobalBuildCommands(unittest.TestCase): ) def test_deleted_removes_all(self): - want = self._want(servers={}, allow_clients=[], listen_addresses=[]) have = self._have( servers={"time1.vyos.net": []}, allow_clients=["10.0.0.0/24"], listen_addresses=["192.168.1.1"], ) - cmds = build_commands(want, have, "deleted") - paths = [c[1] for c in cmds] - self.assertIn(["service", "ntp", "server", "time1.vyos.net"], paths) - self.assertIn(["service", "ntp", "allow-client", "address", "10.0.0.0/24"], paths) + cmds = build_commands({}, have, "deleted") + self.assertEqual(len(cmds), 1) + self.assertEqual(cmds[0], ("delete", ["service", "ntp"])) + + def test_deleted_idempotent_when_empty(self): + have = self._have(servers={}, allow_clients=[], listen_addresses=[]) + cmds = build_commands({}, have, "deleted") + self.assertEqual(cmds, []) def test_overridden_deletes_then_merges(self): want = self._want(servers={"new.server.com": []}) have = self._have(servers={"old.server.com": []}) cmds = build_commands(want, have, "overridden") - paths = [c[1] for c in cmds] - # overridden deletes existing server subtree first - self.assertIn(["service", "ntp", "server"], paths) - # then adds new server - self.assertIn(["service", "ntp", "server", "new.server.com"], paths) + ops_paths = [(c[0], c[1]) for c in cmds] + self.assertIn(("delete", ["service", "ntp", "server", "old.server.com"]), ops_paths) + self.assertIn(("set", ["service", "ntp", "server", "new.server.com"]), ops_paths) + self.assertNotIn(("delete", ["service", "ntp", "server"]), ops_paths) def test_no_commands_when_already_correct(self): state = {"allow_clients": ["10.0.0.0/24"], "listen_addresses": [], "servers": {}} |
