summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromnom62 <omnom62@outlook.com>2026-05-28 09:04:37 +1000
committeromnom62 <omnom62@outlook.com>2026-05-28 09:04:37 +1000
commitf37d4e313154ea7ea40250849549065196fab722 (patch)
tree48965ab4b5a234a3c1cddbd7ff4470b47faf5d13
parent015e83683bb84ce565177a8ebae825635c755580 (diff)
downloadrest.vyos-f37d4e313154ea7ea40250849549065196fab722.tar.gz
rest.vyos-f37d4e313154ea7ea40250849549065196fab722.zip
WIP test framework
-rw-r--r--tests/integration/targets/vyos_ntp_global/defaults/main.yaml3
-rw-r--r--tests/integration/targets/vyos_ntp_global/tasks/httpapi.yaml21
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/httpapi/_populate_config.yaml21
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/httpapi/_remove_config.yaml5
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/httpapi/deleted.yaml35
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/httpapi/gathered.yaml23
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/httpapi/merged.yaml38
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/httpapi/overridden.yaml41
-rw-r--r--tests/integration/targets/vyos_ntp_global/tests/httpapi/replaced.yaml48
-rw-r--r--tests/integration/targets/vyos_ntp_global/vars/main.yaml2
10 files changed, 237 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_ntp_global/defaults/main.yaml b/tests/integration/targets/vyos_ntp_global/defaults/main.yaml
new file mode 100644
index 0000000..164afea
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/defaults/main.yaml
@@ -0,0 +1,3 @@
+---
+testcase: "[^_].*"
+test_items: []
diff --git a/tests/integration/targets/vyos_ntp_global/tasks/httpapi.yaml b/tests/integration/targets/vyos_ntp_global/tasks/httpapi.yaml
new file mode 100644
index 0000000..4147e6d
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/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_ntp_global/tests/httpapi/_populate_config.yaml b/tests/integration/targets/vyos_ntp_global/tests/httpapi/_populate_config.yaml
new file mode 100644
index 0000000..aac01d9
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/httpapi/_populate_config.yaml
@@ -0,0 +1,21 @@
+---
+- name: Populate NTP config for testing
+ vyos.rest.vyos_ntp_global:
+ config:
+ allow_clients:
+ - 10.4.9.0/24
+ - 10.4.7.0/24
+ listen_addresses:
+ - 10.1.9.16
+ servers:
+ - server: 10.3.6.5
+ options:
+ - noselect
+ - prefer
+ - server: server4.example.com
+ options:
+ - pool
+ - noselect
+ - server: server5.example.com
+ state: merged
+ ignore_errors: true
diff --git a/tests/integration/targets/vyos_ntp_global/tests/httpapi/_remove_config.yaml b/tests/integration/targets/vyos_ntp_global/tests/httpapi/_remove_config.yaml
new file mode 100644
index 0000000..4355886
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/httpapi/_remove_config.yaml
@@ -0,0 +1,5 @@
+---
+- name: Remove pre-existing ntp_global config
+ vyos.rest.vyos_ntp_global:
+ state: deleted
+ ignore_errors: true
diff --git a/tests/integration/targets/vyos_ntp_global/tests/httpapi/deleted.yaml b/tests/integration/targets/vyos_ntp_global/tests/httpapi/deleted.yaml
new file mode 100644
index 0000000..957e119
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/httpapi/deleted.yaml
@@ -0,0 +1,35 @@
+---
+- debug:
+ msg: START vyos_ntp_global deleted integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: Delete all NTP configuration
+ register: result
+ vyos.rest.vyos_ntp_global: &id001
+ state: deleted
+
+ - assert:
+ that:
+ - result.changed == true
+
+ - name: Assert after is empty
+ assert:
+ that:
+ - result.after.allow_clients == []
+ - result.after.listen_addresses == []
+ - result.after.servers == {}
+
+ - name: Delete the existing configuration (IDEMPOTENT)
+ register: result
+ vyos.rest.vyos_ntp_global: *id001
+
+ - name: Assert idempotent
+ assert:
+ that:
+ - result.changed == false
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ntp_global/tests/httpapi/gathered.yaml b/tests/integration/targets/vyos_ntp_global/tests/httpapi/gathered.yaml
new file mode 100644
index 0000000..73ee1ff
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/httpapi/gathered.yaml
@@ -0,0 +1,23 @@
+---
+- debug:
+ msg: START vyos_ntp_global gathered integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: Gather NTP configuration
+ register: result
+ vyos.rest.vyos_ntp_global:
+ state: gathered
+
+ - assert:
+ that:
+ - result.changed == false
+ - "'10.4.9.0/24' in result.gathered.allow_clients"
+ - "'10.1.9.16' in result.gathered.listen_addresses"
+ - "'10.3.6.5' in result.gathered.servers"
+ - "'server4.example.com' in result.gathered.servers"
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ntp_global/tests/httpapi/merged.yaml b/tests/integration/targets/vyos_ntp_global/tests/httpapi/merged.yaml
new file mode 100644
index 0000000..613704a
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/httpapi/merged.yaml
@@ -0,0 +1,38 @@
+---
+- debug:
+ msg: START vyos_ntp_global merged integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+ - name: Merge the provided configuration with the existing running configuration
+ register: result
+ vyos.rest.vyos_ntp_global: &id001
+ config:
+ allow_clients:
+ - 10.6.6.0/24
+ listen_addresses:
+ - 10.1.3.1
+ servers:
+ - server: 203.0.113.0
+ options:
+ - prefer
+ state: merged
+
+ - assert:
+ that:
+ - result.changed == true
+ - result.commands | length > 0
+
+ - name: Merge the provided configuration (IDEMPOTENT)
+ register: result
+ vyos.rest.vyos_ntp_global: *id001
+
+ - name: Assert idempotent
+ assert:
+ that:
+ - result.changed == false
+ - result.commands == []
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ntp_global/tests/httpapi/overridden.yaml b/tests/integration/targets/vyos_ntp_global/tests/httpapi/overridden.yaml
new file mode 100644
index 0000000..deee2c0
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/httpapi/overridden.yaml
@@ -0,0 +1,41 @@
+---
+- debug:
+ msg: START vyos_ntp_global overridden integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: Override the existing configuration with the provided configuration
+ register: result
+ vyos.rest.vyos_ntp_global: &id001
+ config:
+ allow_clients:
+ - 10.3.3.0/24
+ listen_addresses:
+ - 10.7.8.1
+ servers:
+ - server: server1
+ options:
+ - prefer
+ - server: server2
+ options:
+ - noselect
+ state: overridden
+
+ - assert:
+ that:
+ - result.changed == true
+
+ - name: Override the provided configuration (IDEMPOTENT)
+ register: result
+ vyos.rest.vyos_ntp_global: *id001
+
+ - name: Assert idempotent
+ assert:
+ that:
+ - result.changed == false
+ - result.commands == []
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ntp_global/tests/httpapi/replaced.yaml b/tests/integration/targets/vyos_ntp_global/tests/httpapi/replaced.yaml
new file mode 100644
index 0000000..77136fc
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/tests/httpapi/replaced.yaml
@@ -0,0 +1,48 @@
+---
+- debug:
+ msg: START vyos_ntp_global replaced integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: Replace the existing configuration with the provided configuration
+ register: result
+ vyos.rest.vyos_ntp_global: &id001
+ config:
+ allow_clients:
+ - 10.99.99.0/24
+ servers:
+ - server: server-new.example.com
+ options:
+ - prefer
+ state: replaced
+
+ - assert:
+ that:
+ - result.changed == true
+
+ - name: Verify old entries removed
+ vyos.rest.vyos_ntp_global:
+ state: gathered
+ register: gathered
+
+ - assert:
+ that:
+ - "'10.4.9.0/24' not in gathered.gathered.allow_clients"
+ - "'10.99.99.0/24' in gathered.gathered.allow_clients"
+ - "'server-new.example.com' in gathered.gathered.servers"
+ - "'10.3.6.5' not in gathered.gathered.servers"
+
+ - name: Replace the provided configuration (IDEMPOTENT)
+ register: result
+ vyos.rest.vyos_ntp_global: *id001
+
+ - name: Assert idempotent
+ assert:
+ that:
+ - result.changed == false
+ - result.commands == []
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_ntp_global/vars/main.yaml b/tests/integration/targets/vyos_ntp_global/vars/main.yaml
new file mode 100644
index 0000000..4303881
--- /dev/null
+++ b/tests/integration/targets/vyos_ntp_global/vars/main.yaml
@@ -0,0 +1,2 @@
+---
+# only common vars here