summaryrefslogtreecommitdiff
path: root/tests/integration/targets
diff options
context:
space:
mode:
authoromnom62 <omnom62@outlook.com>2026-07-20 09:10:43 +1000
committeromnom62 <omnom62@outlook.com>2026-07-20 09:10:43 +1000
commitf6b57bacc92e59e3d17cb56b876bd4939bde3223 (patch)
tree414ba721690ce9cd5ddfaeb267bd12a98a964ce7 /tests/integration/targets
parent6d6052444be08ed9ff0525c1a3757d37cd0a5689 (diff)
downloadrest.vyos-T8989_wave4.tar.gz
rest.vyos-T8989_wave4.zip
T8989: vyos_nat module for REST API collectionT8989_wave4
Diffstat (limited to 'tests/integration/targets')
-rw-r--r--tests/integration/targets/vyos_nat/aliases1
-rw-r--r--tests/integration/targets/vyos_nat/defaults/main.yaml3
-rw-r--r--tests/integration/targets/vyos_nat/tasks/httpapi.yaml18
-rw-r--r--tests/integration/targets/vyos_nat/tasks/main.yaml2
-rw-r--r--tests/integration/targets/vyos_nat/tests/httpapi/_populate_config.yaml39
-rw-r--r--tests/integration/targets/vyos_nat/tests/httpapi/_remove_config.yaml5
-rw-r--r--tests/integration/targets/vyos_nat/tests/httpapi/deleted.yaml36
-rw-r--r--tests/integration/targets/vyos_nat/tests/httpapi/gathered.yaml30
-rw-r--r--tests/integration/targets/vyos_nat/tests/httpapi/merged.yaml49
-rw-r--r--tests/integration/targets/vyos_nat/tests/httpapi/overridden.yaml49
-rw-r--r--tests/integration/targets/vyos_nat/tests/httpapi/replaced.yaml49
-rw-r--r--tests/integration/targets/vyos_nat/vars/main.yaml2
12 files changed, 283 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_nat/aliases b/tests/integration/targets/vyos_nat/aliases
new file mode 100644
index 0000000..cc0afef
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/aliases
@@ -0,0 +1 @@
+network/vyos
diff --git a/tests/integration/targets/vyos_nat/defaults/main.yaml b/tests/integration/targets/vyos_nat/defaults/main.yaml
new file mode 100644
index 0000000..164afea
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/defaults/main.yaml
@@ -0,0 +1,3 @@
+---
+testcase: "[^_].*"
+test_items: []
diff --git a/tests/integration/targets/vyos_nat/tasks/httpapi.yaml b/tests/integration/targets/vyos_nat/tasks/httpapi.yaml
new file mode 100644
index 0000000..014aa9d
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/tasks/httpapi.yaml
@@ -0,0 +1,18 @@
+---
+- name: Collect all httpapi test cases
+ ansible.builtin.find:
+ paths: "{{ role_path }}/tests/httpapi"
+ patterns: "*.yaml"
+ excludes: "_*.yaml"
+ register: test_cases
+ delegate_to: localhost
+
+- name: Set test_items
+ ansible.builtin.set_fact:
+ test_items: "{{ test_cases.files | map(attribute='path') | list | sort }}"
+
+- name: Run test case (connection=httpapi)
+ ansible.builtin.include_tasks: "{{ test_case_to_run }}"
+ loop: "{{ test_items }}"
+ loop_control:
+ loop_var: test_case_to_run
diff --git a/tests/integration/targets/vyos_nat/tasks/main.yaml b/tests/integration/targets/vyos_nat/tasks/main.yaml
new file mode 100644
index 0000000..4f381a9
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/tasks/main.yaml
@@ -0,0 +1,2 @@
+---
+- include_tasks: httpapi.yaml
diff --git a/tests/integration/targets/vyos_nat/tests/httpapi/_populate_config.yaml b/tests/integration/targets/vyos_nat/tests/httpapi/_populate_config.yaml
new file mode 100644
index 0000000..fd543d5
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/tests/httpapi/_populate_config.yaml
@@ -0,0 +1,39 @@
+---
+- name: Populate NAT config for testing
+ vyos.rest.vyos_nat:
+ config:
+ nat:
+ source:
+ rule:
+ - id: 100
+ description: "Source rule 100"
+ outbound_interface:
+ name: eth0
+ translation:
+ address: masquerade
+ - id: 101
+ outbound_interface:
+ name: eth1
+ translation:
+ address: masquerade
+ destination:
+ rule:
+ - id: 200
+ protocol: tcp
+ inbound_interface:
+ name: eth0
+ destination:
+ address: 198.51.100.10
+ port: "80"
+ translation:
+ address: 192.168.1.10
+ port: "8080"
+ static:
+ rule:
+ - id: 300
+ inbound_interface: eth0
+ destination:
+ address: 198.51.100.20
+ translation:
+ address: 192.168.1.20
+ state: merged
diff --git a/tests/integration/targets/vyos_nat/tests/httpapi/_remove_config.yaml b/tests/integration/targets/vyos_nat/tests/httpapi/_remove_config.yaml
new file mode 100644
index 0000000..8ee616b
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/tests/httpapi/_remove_config.yaml
@@ -0,0 +1,5 @@
+---
+- name: Remove all NAT configuration
+ vyos.rest.vyos_nat:
+ state: deleted
+ ignore_errors: true
diff --git a/tests/integration/targets/vyos_nat/tests/httpapi/deleted.yaml b/tests/integration/targets/vyos_nat/tests/httpapi/deleted.yaml
new file mode 100644
index 0000000..96c4d07
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/tests/httpapi/deleted.yaml
@@ -0,0 +1,36 @@
+---
+- debug:
+ msg: START vyos_nat deleted integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: Delete all NAT configuration
+ vyos.rest.vyos_nat: &id001
+ state: deleted
+ register: result
+
+ - assert:
+ that:
+ - result.changed == true
+
+ - name: Gather after delete
+ vyos.rest.vyos_nat:
+ state: gathered
+ register: gathered
+
+ - assert:
+ that:
+ - gathered.gathered == {}
+
+ - name: Delete again (IDEMPOTENT)
+ vyos.rest.vyos_nat: *id001
+ register: result
+
+ - assert:
+ that:
+ - result.changed == false
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_nat/tests/httpapi/gathered.yaml b/tests/integration/targets/vyos_nat/tests/httpapi/gathered.yaml
new file mode 100644
index 0000000..4848b4f
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/tests/httpapi/gathered.yaml
@@ -0,0 +1,30 @@
+---
+- debug:
+ msg: START vyos_nat gathered integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: Gather NAT configuration
+ vyos.rest.vyos_nat:
+ state: gathered
+ register: result
+
+ - assert:
+ that:
+ - result.changed == false
+ - "'nat' in result.gathered"
+ - "'source' in result.gathered.nat"
+ - "'destination' in result.gathered.nat"
+ - "'static' in result.gathered.nat"
+ - result.gathered.nat.source.rule | length == 2
+ - result.gathered.nat.source.rule[0].id == 100
+ - result.gathered.nat.source.rule[1].id == 101
+ - result.gathered.nat.destination.rule[0].id == 200
+ - result.gathered.nat.destination.rule[0].protocol == "tcp"
+ - result.gathered.nat.static.rule[0].id == 300
+ - result.gathered.nat.static.rule[0].inbound_interface == "eth0"
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_nat/tests/httpapi/merged.yaml b/tests/integration/targets/vyos_nat/tests/httpapi/merged.yaml
new file mode 100644
index 0000000..c64fdb8
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/tests/httpapi/merged.yaml
@@ -0,0 +1,49 @@
+---
+- debug:
+ msg: START vyos_nat merged integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+
+- block:
+ - name: Merge NAT configuration
+ vyos.rest.vyos_nat: &id001
+ config:
+ nat:
+ source:
+ rule:
+ - id: 100
+ outbound_interface:
+ name: eth0
+ translation:
+ address: masquerade
+ destination:
+ rule:
+ - id: 200
+ protocol: tcp
+ inbound_interface:
+ name: eth0
+ destination:
+ address: 198.51.100.10
+ port: "80"
+ translation:
+ address: 192.168.1.10
+ port: "8080"
+ state: merged
+ register: result
+
+ - assert:
+ that:
+ - result.changed == true
+ - result.commands | length > 0
+
+ - name: Merge again (IDEMPOTENT)
+ vyos.rest.vyos_nat: *id001
+ register: result
+
+ - assert:
+ that:
+ - result.changed == false
+ - result.commands == []
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_nat/tests/httpapi/overridden.yaml b/tests/integration/targets/vyos_nat/tests/httpapi/overridden.yaml
new file mode 100644
index 0000000..8ccc671
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/tests/httpapi/overridden.yaml
@@ -0,0 +1,49 @@
+---
+- debug:
+ msg: START vyos_nat overridden integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: Override - replaces all NAT with only one rule
+ vyos.rest.vyos_nat: &id001
+ config:
+ nat:
+ source:
+ rule:
+ - id: 999
+ outbound_interface:
+ name: eth0
+ translation:
+ address: masquerade
+ state: overridden
+ register: result
+
+ - assert:
+ that:
+ - result.changed == true
+
+ - name: Gather after override
+ vyos.rest.vyos_nat:
+ state: gathered
+ register: gathered
+
+ - assert:
+ that:
+ - gathered.gathered.nat.source.rule | length == 1
+ - gathered.gathered.nat.source.rule[0].id == 999
+ - "'destination' not in gathered.gathered.nat"
+ - "'static' not in gathered.gathered.nat"
+
+ - name: Override again (IDEMPOTENT)
+ vyos.rest.vyos_nat: *id001
+ register: result
+
+ - assert:
+ that:
+ - result.changed == false
+ - result.commands == []
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_nat/tests/httpapi/replaced.yaml b/tests/integration/targets/vyos_nat/tests/httpapi/replaced.yaml
new file mode 100644
index 0000000..624a60a
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/tests/httpapi/replaced.yaml
@@ -0,0 +1,49 @@
+---
+- debug:
+ msg: START vyos_nat replaced integration tests on connection={{ ansible_connection }}
+
+- include_tasks: _remove_config.yaml
+- include_tasks: _populate_config.yaml
+
+- block:
+ - name: Replace source NAT - removes rule 101, keeps destination and static
+ vyos.rest.vyos_nat: &id001
+ config:
+ nat:
+ source:
+ rule:
+ - id: 100
+ outbound_interface:
+ name: eth0
+ translation:
+ address: masquerade
+ state: replaced
+ register: result
+
+ - assert:
+ that:
+ - result.changed == true
+
+ - name: Gather after replace
+ vyos.rest.vyos_nat:
+ state: gathered
+ register: gathered
+
+ - assert:
+ that:
+ - gathered.gathered.nat.source.rule | length == 1
+ - gathered.gathered.nat.source.rule[0].id == 100
+ - "'destination' in gathered.gathered.nat"
+ - "'static' in gathered.gathered.nat"
+
+ - name: Replace again (IDEMPOTENT)
+ vyos.rest.vyos_nat: *id001
+ register: result
+
+ - assert:
+ that:
+ - result.changed == false
+ - result.commands == []
+
+ always:
+ - include_tasks: _remove_config.yaml
diff --git a/tests/integration/targets/vyos_nat/vars/main.yaml b/tests/integration/targets/vyos_nat/vars/main.yaml
new file mode 100644
index 0000000..4303881
--- /dev/null
+++ b/tests/integration/targets/vyos_nat/vars/main.yaml
@@ -0,0 +1,2 @@
+---
+# only common vars here