summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromnom62 <omnom62@outlook.com>2026-06-03 21:47:02 +1000
committeromnom62 <omnom62@outlook.com>2026-06-03 21:47:02 +1000
commitba080f20749a7c79dc3033e5e022e3ccb00c65c5 (patch)
treef00d1d3603606b1bd55189d85be49a7024860a3b
parent197c021ddeb7bdd5cfa5155a09d6d253e1247a04 (diff)
downloadrest.vyos-ba080f20749a7c79dc3033e5e022e3ccb00c65c5.tar.gz
rest.vyos-ba080f20749a7c79dc3033e5e022e3ccb00c65c5.zip
vyos_configure tests
-rw-r--r--tests/integration/targets/vyos_configure/aliases1
-rw-r--r--tests/integration/targets/vyos_configure/defaults/main.yaml3
-rw-r--r--tests/integration/targets/vyos_configure/tasks/httpapi.yaml21
-rw-r--r--tests/integration/targets/vyos_configure/tasks/main.yaml5
-rw-r--r--tests/integration/targets/vyos_configure/tests/httpapi/configure.yaml52
-rw-r--r--tests/integration/targets/vyos_configure/vars/main.yaml2
-rw-r--r--tests/unit/modules/test_vyos_configure.py64
7 files changed, 148 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_configure/aliases b/tests/integration/targets/vyos_configure/aliases
new file mode 100644
index 0000000..cc0afef
--- /dev/null
+++ b/tests/integration/targets/vyos_configure/aliases
@@ -0,0 +1 @@
+network/vyos
diff --git a/tests/integration/targets/vyos_configure/defaults/main.yaml b/tests/integration/targets/vyos_configure/defaults/main.yaml
new file mode 100644
index 0000000..164afea
--- /dev/null
+++ b/tests/integration/targets/vyos_configure/defaults/main.yaml
@@ -0,0 +1,3 @@
+---
+testcase: "[^_].*"
+test_items: []
diff --git a/tests/integration/targets/vyos_configure/tasks/httpapi.yaml b/tests/integration/targets/vyos_configure/tasks/httpapi.yaml
new file mode 100644
index 0000000..4147e6d
--- /dev/null
+++ b/tests/integration/targets/vyos_configure/tasks/httpapi.yaml
@@ -0,0 +1,21 @@
+---
+- name: Collect all httpapi test cases
+ ansible.builtin.find:
+ paths: "{{ role_path }}/tests/httpapi"
+ patterns: "{{ testcase }}.yaml"
+ use_regex: true
+ register: test_cases
+ delegate_to: localhost
+
+- name: Set test_items
+ ansible.builtin.set_fact:
+ test_items: "{{ test_cases.files | map(attribute='path') | list }}"
+
+- name: Run test case (connection=httpapi)
+ ansible.builtin.include_tasks: "{{ test_case_to_run }}"
+ vars:
+ ansible_connection: ansible.netcommon.httpapi
+ ansible_network_os: vyos.rest.vyos
+ with_items: "{{ test_items }}"
+ loop_control:
+ loop_var: test_case_to_run
diff --git a/tests/integration/targets/vyos_configure/tasks/main.yaml b/tests/integration/targets/vyos_configure/tasks/main.yaml
new file mode 100644
index 0000000..b1f6193
--- /dev/null
+++ b/tests/integration/targets/vyos_configure/tasks/main.yaml
@@ -0,0 +1,5 @@
+---
+- name: Run httpapi tests
+ ansible.builtin.include_tasks: httpapi.yaml
+ tags:
+ - httpapi
diff --git a/tests/integration/targets/vyos_configure/tests/httpapi/configure.yaml b/tests/integration/targets/vyos_configure/tests/httpapi/configure.yaml
new file mode 100644
index 0000000..2f95df3
--- /dev/null
+++ b/tests/integration/targets/vyos_configure/tests/httpapi/configure.yaml
@@ -0,0 +1,52 @@
+---
+- debug:
+ msg: START vyos_configure integration tests on connection={{ ansible_connection }}
+
+- block:
+ - name: Set a loopback address via vyos_configure
+ register: result
+ vyos.rest.vyos_configure:
+ commands:
+ - set interfaces loopback lo address 192.0.2.100/32
+
+ - assert:
+ that:
+ - result.changed == true
+ - result.commands | length == 1
+ - result.commands[0][0] == "set"
+ - result.commands[0][1] == ["interfaces", "loopback", "lo", "address", "192.0.2.100/32"]
+
+ - name: Set multiple commands in one atomic commit
+ register: result
+ vyos.rest.vyos_configure:
+ commands:
+ - set interfaces loopback lo address 192.0.2.101/32
+ - set interfaces loopback lo address 192.0.2.102/32
+
+ - assert:
+ that:
+ - result.changed == true
+ - result.commands | length == 2
+
+ - name: Delete loopback addresses
+ register: result
+ vyos.rest.vyos_configure:
+ commands:
+ - delete interfaces loopback lo address 192.0.2.100/32
+ - delete interfaces loopback lo address 192.0.2.101/32
+ - delete interfaces loopback lo address 192.0.2.102/32
+
+ - assert:
+ that:
+ - result.changed == true
+ - result.commands | length == 3
+ - result.commands[0][0] == "delete"
+
+ always:
+ - name: Cleanup — remove test loopback addresses
+ vyos.rest.vyos_configure:
+ commands:
+ - delete interfaces loopback lo address 192.0.2.100/32
+ - delete interfaces loopback lo address 192.0.2.101/32
+ - delete interfaces loopback lo address 192.0.2.102/32
+ ignore_errors: true
diff --git a/tests/integration/targets/vyos_configure/vars/main.yaml b/tests/integration/targets/vyos_configure/vars/main.yaml
new file mode 100644
index 0000000..4303881
--- /dev/null
+++ b/tests/integration/targets/vyos_configure/vars/main.yaml
@@ -0,0 +1,2 @@
+---
+# only common vars here
diff --git a/tests/unit/modules/test_vyos_configure.py b/tests/unit/modules/test_vyos_configure.py
new file mode 100644
index 0000000..af1b325
--- /dev/null
+++ b/tests/unit/modules/test_vyos_configure.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+from __future__ import absolute_import, division, print_function
+
+
+__metaclass__ = type
+
+import unittest
+
+from ansible_collections.vyos.rest.plugins.modules.vyos_configure import (
+ _parse_command,
+)
+
+
+class TestVyOSConfigureParseCommand(unittest.TestCase):
+
+ def test_set_simple(self):
+ result = _parse_command("set system host-name vyos")
+ self.assertEqual(result, ("set", ["system", "host-name", "vyos"]))
+
+ def test_set_with_address(self):
+ result = _parse_command("set interfaces loopback lo address 20.1.1.1/32")
+ self.assertEqual(
+ result,
+ ("set", ["interfaces", "loopback", "lo", "address", "20.1.1.1/32"]),
+ )
+
+ def test_delete_simple(self):
+ result = _parse_command("delete service snmp")
+ self.assertEqual(result, ("delete", ["service", "snmp"]))
+
+ def test_delete_with_path(self):
+ result = _parse_command("delete interfaces loopback lo address 20.1.1.1/32")
+ self.assertEqual(
+ result,
+ ("delete", ["interfaces", "loopback", "lo", "address", "20.1.1.1/32"]),
+ )
+
+ def test_strips_leading_whitespace(self):
+ result = _parse_command(" set system host-name vyos")
+ self.assertEqual(result, ("set", ["system", "host-name", "vyos"]))
+
+ def test_invalid_command_returns_none(self):
+ result = _parse_command("commit")
+ self.assertIsNone(result)
+
+ def test_empty_string_returns_none(self):
+ result = _parse_command("")
+ self.assertIsNone(result)
+
+ def test_unknown_op_returns_none(self):
+ result = _parse_command("show interfaces")
+ self.assertIsNone(result)
+
+ def test_set_single_token_path(self):
+ result = _parse_command("set service")
+ self.assertEqual(result, ("set", ["service"]))
+
+ def test_delete_single_token_path(self):
+ result = _parse_command("delete service")
+ self.assertEqual(result, ("delete", ["service"]))
+
+
+if __name__ == "__main__":
+ unittest.main()