From 7a6b5e4f3a7a021cfa75faa7bf833741dfc09cff Mon Sep 17 00:00:00 2001 From: omnom62 <75066712+omnom62@users.noreply.github.com> Date: Sat, 22 Aug 2026 01:36:21 +1000 Subject: T8989: wave3 user, bgp_global, bgp_address_family, facts, firewall_global * T8989: vyos_user module * T8989: Wave 3 vyos_user module with integration and unit tests * T8989: Wave 3 vyos_bgp_global module with integration and unit tests * T8989: Wave 3 vyos_bgp_address_family module with integration and unit tests * T8989: Add overridden integration tests for vyos_bgp_global and vyos_bgp_address_family * T8989: vyos_facts * T8989: Add vyos_facts integration and unit tests with fixtures * T8989: vyos_firewall_global module * T8989: vyos_firewall_global module with integration and unit tests * T8989: vyos_firewall_rules module * T8989: vyos_firewall_rules module with integration and unit tests * T8989: vyos_firewall_interfaces module * T8989: vyos_firewall_interfaces module * T8989: vyos_firewall_interfaces UAT & SIT * T8989: vyos_firewall_interfaces UAT & SIT --- .../targets/vyos_bgp_address_family/aliases | 1 + .../vyos_bgp_address_family/defaults/main.yaml | 3 + .../vyos_bgp_address_family/tasks/httpapi.yaml | 21 +++++++ .../vyos_bgp_address_family/tasks/main.yaml | 5 ++ .../tests/httpapi/_populate_config.yaml | 32 +++++++++++ .../tests/httpapi/_remove_config.yaml | 5 ++ .../tests/httpapi/deleted.yaml | 33 +++++++++++ .../tests/httpapi/gathered.yaml | 21 +++++++ .../tests/httpapi/merged.yaml | 65 ++++++++++++++++++++++ .../tests/httpapi/overridden.yaml | 34 +++++++++++ .../tests/httpapi/replaced.yaml | 34 +++++++++++ .../vyos_bgp_address_family/tests/httpapi/rtt.yaml | 62 +++++++++++++++++++++ .../targets/vyos_bgp_address_family/vars/main.yaml | 2 + tests/integration/targets/vyos_bgp_global/aliases | 1 + .../targets/vyos_bgp_global/defaults/main.yaml | 3 + .../targets/vyos_bgp_global/tasks/httpapi.yaml | 21 +++++++ .../targets/vyos_bgp_global/tasks/main.yaml | 5 ++ .../tests/httpapi/_populate_config.yaml | 19 +++++++ .../tests/httpapi/_remove_config.yaml | 5 ++ .../vyos_bgp_global/tests/httpapi/deleted.yaml | 29 ++++++++++ .../vyos_bgp_global/tests/httpapi/gathered.yaml | 22 ++++++++ .../vyos_bgp_global/tests/httpapi/merged.yaml | 44 +++++++++++++++ .../vyos_bgp_global/tests/httpapi/overridden.yaml | 35 ++++++++++++ .../vyos_bgp_global/tests/httpapi/replaced.yaml | 35 ++++++++++++ .../targets/vyos_bgp_global/tests/httpapi/rtt.yaml | 50 +++++++++++++++++ .../targets/vyos_bgp_global/vars/main.yaml | 2 + tests/integration/targets/vyos_facts/aliases | 1 + .../targets/vyos_facts/defaults/main.yaml | 3 + .../targets/vyos_facts/tasks/httpapi.yaml | 21 +++++++ .../integration/targets/vyos_facts/tasks/main.yaml | 5 ++ .../targets/vyos_facts/tests/httpapi/all.yaml | 16 ++++++ .../targets/vyos_facts/tests/httpapi/default.yaml | 13 +++++ .../targets/vyos_facts/tests/httpapi/subsets.yaml | 33 +++++++++++ .../integration/targets/vyos_facts/vars/main.yaml | 2 + .../targets/vyos_firewall_global/aliases | 1 + .../vyos_firewall_global/defaults/main.yaml | 3 + .../vyos_firewall_global/tasks/httpapi.yaml | 21 +++++++ .../targets/vyos_firewall_global/tasks/main.yaml | 5 ++ .../tests/httpapi/_populate_config.yaml | 22 ++++++++ .../tests/httpapi/_remove_config.yaml | 5 ++ .../tests/httpapi/deleted.yaml | 29 ++++++++++ .../tests/httpapi/gathered.yaml | 21 +++++++ .../vyos_firewall_global/tests/httpapi/merged.yaml | 48 ++++++++++++++++ .../tests/httpapi/overridden.yaml | 34 +++++++++++ .../tests/httpapi/replaced.yaml | 34 +++++++++++ .../vyos_firewall_global/tests/httpapi/rtt.yaml | 55 ++++++++++++++++++ .../targets/vyos_firewall_global/vars/main.yaml | 2 + .../targets/vyos_firewall_interfaces/aliases | 1 + .../vyos_firewall_interfaces/defaults/main.yaml | 3 + .../vyos_firewall_interfaces/tasks/httpapi.yaml | 21 +++++++ .../vyos_firewall_interfaces/tasks/main.yaml | 5 ++ .../tests/httpapi/_populate_config.yaml | 23 ++++++++ .../tests/httpapi/_remove_config.yaml | 5 ++ .../tests/httpapi/deleted.yaml | 29 ++++++++++ .../tests/httpapi/gathered.yaml | 21 +++++++ .../tests/httpapi/merged.yaml | 46 +++++++++++++++ .../tests/httpapi/overridden.yaml | 33 +++++++++++ .../tests/httpapi/replaced.yaml | 37 ++++++++++++ .../tests/httpapi/rtt.yaml | 53 ++++++++++++++++++ .../vyos_firewall_interfaces/vars/main.yaml | 2 + .../targets/vyos_firewall_rules/aliases | 1 + .../targets/vyos_firewall_rules/defaults/main.yaml | 3 + .../targets/vyos_firewall_rules/tasks/httpapi.yaml | 21 +++++++ .../targets/vyos_firewall_rules/tasks/main.yaml | 5 ++ .../tests/httpapi/_populate_config.yaml | 28 ++++++++++ .../tests/httpapi/_remove_config.yaml | 5 ++ .../vyos_firewall_rules/tests/httpapi/deleted.yaml | 29 ++++++++++ .../tests/httpapi/gathered.yaml | 21 +++++++ .../vyos_firewall_rules/tests/httpapi/merged.yaml | 50 +++++++++++++++++ .../tests/httpapi/overridden.yaml | 36 ++++++++++++ .../tests/httpapi/replaced.yaml | 36 ++++++++++++ .../vyos_firewall_rules/tests/httpapi/rtt.yaml | 52 +++++++++++++++++ .../targets/vyos_firewall_rules/vars/main.yaml | 2 + tests/integration/targets/vyos_user/aliases | 1 + .../targets/vyos_user/defaults/main.yaml | 3 + .../targets/vyos_user/tasks/httpapi.yaml | 21 +++++++ .../integration/targets/vyos_user/tasks/main.yaml | 5 ++ .../vyos_user/tests/httpapi/_remove_config.yaml | 8 +++ .../targets/vyos_user/tests/httpapi/absent.yaml | 43 ++++++++++++++ .../targets/vyos_user/tests/httpapi/gathered.yaml | 28 ++++++++++ .../targets/vyos_user/tests/httpapi/present.yaml | 63 +++++++++++++++++++++ .../targets/vyos_user/tests/httpapi/rtt.yaml | 45 +++++++++++++++ tests/integration/targets/vyos_user/vars/main.yaml | 2 + 83 files changed, 1750 insertions(+) create mode 100644 tests/integration/targets/vyos_bgp_address_family/aliases create mode 100644 tests/integration/targets/vyos_bgp_address_family/defaults/main.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tasks/httpapi.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tasks/main.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tests/httpapi/_populate_config.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tests/httpapi/_remove_config.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tests/httpapi/deleted.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tests/httpapi/gathered.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tests/httpapi/merged.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tests/httpapi/overridden.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tests/httpapi/replaced.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/tests/httpapi/rtt.yaml create mode 100644 tests/integration/targets/vyos_bgp_address_family/vars/main.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/aliases create mode 100644 tests/integration/targets/vyos_bgp_global/defaults/main.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tasks/httpapi.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tasks/main.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tests/httpapi/_populate_config.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tests/httpapi/_remove_config.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tests/httpapi/deleted.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tests/httpapi/gathered.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tests/httpapi/merged.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tests/httpapi/overridden.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tests/httpapi/replaced.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/tests/httpapi/rtt.yaml create mode 100644 tests/integration/targets/vyos_bgp_global/vars/main.yaml create mode 100644 tests/integration/targets/vyos_facts/aliases create mode 100644 tests/integration/targets/vyos_facts/defaults/main.yaml create mode 100644 tests/integration/targets/vyos_facts/tasks/httpapi.yaml create mode 100644 tests/integration/targets/vyos_facts/tasks/main.yaml create mode 100644 tests/integration/targets/vyos_facts/tests/httpapi/all.yaml create mode 100644 tests/integration/targets/vyos_facts/tests/httpapi/default.yaml create mode 100644 tests/integration/targets/vyos_facts/tests/httpapi/subsets.yaml create mode 100644 tests/integration/targets/vyos_facts/vars/main.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/aliases create mode 100644 tests/integration/targets/vyos_firewall_global/defaults/main.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tasks/httpapi.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tasks/main.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tests/httpapi/_populate_config.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tests/httpapi/_remove_config.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tests/httpapi/deleted.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tests/httpapi/gathered.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tests/httpapi/merged.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tests/httpapi/overridden.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tests/httpapi/replaced.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/tests/httpapi/rtt.yaml create mode 100644 tests/integration/targets/vyos_firewall_global/vars/main.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/aliases create mode 100644 tests/integration/targets/vyos_firewall_interfaces/defaults/main.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tasks/httpapi.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tasks/main.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/_populate_config.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/_remove_config.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/deleted.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/gathered.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/merged.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/overridden.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/replaced.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/rtt.yaml create mode 100644 tests/integration/targets/vyos_firewall_interfaces/vars/main.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/aliases create mode 100644 tests/integration/targets/vyos_firewall_rules/defaults/main.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tasks/httpapi.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tasks/main.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tests/httpapi/_populate_config.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tests/httpapi/_remove_config.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tests/httpapi/deleted.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tests/httpapi/gathered.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tests/httpapi/merged.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tests/httpapi/overridden.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tests/httpapi/replaced.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/tests/httpapi/rtt.yaml create mode 100644 tests/integration/targets/vyos_firewall_rules/vars/main.yaml create mode 100644 tests/integration/targets/vyos_user/aliases create mode 100644 tests/integration/targets/vyos_user/defaults/main.yaml create mode 100644 tests/integration/targets/vyos_user/tasks/httpapi.yaml create mode 100644 tests/integration/targets/vyos_user/tasks/main.yaml create mode 100644 tests/integration/targets/vyos_user/tests/httpapi/_remove_config.yaml create mode 100644 tests/integration/targets/vyos_user/tests/httpapi/absent.yaml create mode 100644 tests/integration/targets/vyos_user/tests/httpapi/gathered.yaml create mode 100644 tests/integration/targets/vyos_user/tests/httpapi/present.yaml create mode 100644 tests/integration/targets/vyos_user/tests/httpapi/rtt.yaml create mode 100644 tests/integration/targets/vyos_user/vars/main.yaml (limited to 'tests/integration/targets') diff --git a/tests/integration/targets/vyos_bgp_address_family/aliases b/tests/integration/targets/vyos_bgp_address_family/aliases new file mode 100644 index 0000000..cc0afef --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/aliases @@ -0,0 +1 @@ +network/vyos diff --git a/tests/integration/targets/vyos_bgp_address_family/defaults/main.yaml b/tests/integration/targets/vyos_bgp_address_family/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/vyos_bgp_address_family/tasks/httpapi.yaml b/tests/integration/targets/vyos_bgp_address_family/tasks/httpapi.yaml new file mode 100644 index 0000000..4147e6d --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/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_bgp_address_family/tasks/main.yaml b/tests/integration/targets/vyos_bgp_address_family/tasks/main.yaml new file mode 100644 index 0000000..b1f6193 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/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_bgp_address_family/tests/httpapi/_populate_config.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/_populate_config.yaml new file mode 100644 index 0000000..e4487d9 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/_populate_config.yaml @@ -0,0 +1,32 @@ +--- +- name: Setup BGP global + vyos.rest.vyos_bgp_global: + config: + as_number: 65000 + parameters: + router_id: 192.0.1.1 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + state: merged + ignore_errors: true + +- name: Populate BGP address-family config + vyos.rest.vyos_bgp_address_family: + config: + as_number: 65000 + address_family: + - afi: ipv4 + networks: + - prefix: 192.0.2.0/24 + redistribute: + - protocol: connected + metric: 10 + neighbors: + - neighbor_address: 192.0.2.1 + address_family: + - afi: ipv4 + soft_reconfiguration: true + nexthop_self: true + state: merged + ignore_errors: true diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/_remove_config.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/_remove_config.yaml new file mode 100644 index 0000000..5272cb4 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/_remove_config.yaml @@ -0,0 +1,5 @@ +--- +- name: Remove BGP configuration + vyos.rest.vyos_bgp_global: + state: deleted + ignore_errors: true diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/deleted.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/deleted.yaml new file mode 100644 index 0000000..ce1ab70 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/deleted.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: START vyos_bgp_address_family deleted integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Delete BGP address-family configuration + register: result + vyos.rest.vyos_bgp_address_family: + config: + as_number: 65000 + state: deleted + + - assert: + that: + - result.changed == true + + - name: Delete BGP address-family configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_bgp_address_family: + config: + as_number: 65000 + state: deleted + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/gathered.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/gathered.yaml new file mode 100644 index 0000000..e686a32 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/gathered.yaml @@ -0,0 +1,21 @@ +--- +- debug: + msg: START vyos_bgp_address_family gathered integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Gather BGP address-family configuration + register: result + vyos.rest.vyos_bgp_address_family: + state: gathered + + - assert: + that: + - result.gathered.as_number == 65000 + - result.gathered.address_family | selectattr('afi', 'eq', 'ipv4') | list | length == 1 + - result.gathered.neighbors | selectattr('neighbor_address', 'eq', '192.0.2.1') | list | length == 1 + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/merged.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/merged.yaml new file mode 100644 index 0000000..69edb8c --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/merged.yaml @@ -0,0 +1,65 @@ +--- +- debug: + msg: START vyos_bgp_address_family merged integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Setup BGP global + vyos.rest.vyos_bgp_global: + config: + as_number: 65000 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + state: merged + + - name: Merge BGP address-family configuration + register: result + vyos.rest.vyos_bgp_address_family: + config: + as_number: 65000 + address_family: + - afi: ipv4 + networks: + - prefix: 192.0.2.0/24 + redistribute: + - protocol: connected + metric: 10 + neighbors: + - neighbor_address: 192.0.2.1 + address_family: + - afi: ipv4 + soft_reconfiguration: true + state: merged + + - assert: + that: + - result.changed == true + + - name: Merge BGP address-family configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_bgp_address_family: + config: + as_number: 65000 + address_family: + - afi: ipv4 + networks: + - prefix: 192.0.2.0/24 + redistribute: + - protocol: connected + metric: 10 + neighbors: + - neighbor_address: 192.0.2.1 + address_family: + - afi: ipv4 + soft_reconfiguration: true + state: merged + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/overridden.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/overridden.yaml new file mode 100644 index 0000000..9a497d2 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/overridden.yaml @@ -0,0 +1,34 @@ +--- +- debug: + msg: START vyos_bgp_address_family overridden integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Override BGP address-family configuration + register: result + vyos.rest.vyos_bgp_address_family: &id001 + config: + as_number: 65000 + address_family: + - afi: ipv4 + networks: + - prefix: 192.0.9.0/24 + state: replaced + + - assert: + that: + - result.changed == true + + - name: Override BGP address-family configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_bgp_address_family: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/replaced.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/replaced.yaml new file mode 100644 index 0000000..133ae39 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/replaced.yaml @@ -0,0 +1,34 @@ +--- +- debug: + msg: START vyos_bgp_address_family replaced integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Replace BGP address-family configuration + register: result + vyos.rest.vyos_bgp_address_family: &id001 + config: + as_number: 65000 + address_family: + - afi: ipv4 + networks: + - prefix: 192.0.3.0/24 + state: replaced + + - assert: + that: + - result.changed == true + + - name: Replace BGP address-family configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_bgp_address_family: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/rtt.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/rtt.yaml new file mode 100644 index 0000000..cea4611 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/tests/httpapi/rtt.yaml @@ -0,0 +1,62 @@ +--- +- debug: + msg: START vyos_bgp_address_family round trip integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: RTT - Setup BGP global + vyos.rest.vyos_bgp_global: + config: + as_number: 65000 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + state: merged + + - name: RTT - Apply base configuration + vyos.rest.vyos_bgp_address_family: + config: + as_number: 65000 + address_family: + - afi: ipv4 + networks: + - prefix: 192.0.2.0/24 + neighbors: + - neighbor_address: 192.0.2.1 + address_family: + - afi: ipv4 + soft_reconfiguration: true + state: merged + + - name: RTT - Gather + register: gathered + vyos.rest.vyos_bgp_address_family: + state: gathered + + - assert: + that: + - gathered.gathered.address_family | selectattr('afi', 'eq', 'ipv4') | list | length == 1 + - gathered.gathered.neighbors | selectattr('neighbor_address', 'eq', '192.0.2.1') | list | length == 1 + + - name: RTT - Modify configuration + vyos.rest.vyos_bgp_address_family: + config: + as_number: 65000 + address_family: + - afi: ipv4 + networks: + - prefix: 192.0.3.0/24 + state: replaced + + - name: RTT - Gather after modify + register: gathered2 + vyos.rest.vyos_bgp_address_family: + state: gathered + + - assert: + that: + - (gathered2.gathered.address_family | selectattr('afi', 'eq', 'ipv4') | first).networks[0].prefix == '192.0.3.0/24' + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/vars/main.yaml b/tests/integration/targets/vyos_bgp_address_family/vars/main.yaml new file mode 100644 index 0000000..4303881 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/vars/main.yaml @@ -0,0 +1,2 @@ +--- +# only common vars here diff --git a/tests/integration/targets/vyos_bgp_global/aliases b/tests/integration/targets/vyos_bgp_global/aliases new file mode 100644 index 0000000..cc0afef --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/aliases @@ -0,0 +1 @@ +network/vyos diff --git a/tests/integration/targets/vyos_bgp_global/defaults/main.yaml b/tests/integration/targets/vyos_bgp_global/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/vyos_bgp_global/tasks/httpapi.yaml b/tests/integration/targets/vyos_bgp_global/tasks/httpapi.yaml new file mode 100644 index 0000000..4147e6d --- /dev/null +++ b/tests/integration/targets/vyos_bgp_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_bgp_global/tasks/main.yaml b/tests/integration/targets/vyos_bgp_global/tasks/main.yaml new file mode 100644 index 0000000..b1f6193 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/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_bgp_global/tests/httpapi/_populate_config.yaml b/tests/integration/targets/vyos_bgp_global/tests/httpapi/_populate_config.yaml new file mode 100644 index 0000000..c8eb061 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/tests/httpapi/_populate_config.yaml @@ -0,0 +1,19 @@ +--- +- name: Populate BGP global config for testing + vyos.rest.vyos_bgp_global: + config: + as_number: 65000 + parameters: + router_id: 192.0.1.1 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + description: peer1 + timers: + holdtime: 30 + keepalive: 10 + peer_groups: + - peer_group: PG1 + remote_as: 65002 + state: merged + ignore_errors: true diff --git a/tests/integration/targets/vyos_bgp_global/tests/httpapi/_remove_config.yaml b/tests/integration/targets/vyos_bgp_global/tests/httpapi/_remove_config.yaml new file mode 100644 index 0000000..5272cb4 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/tests/httpapi/_remove_config.yaml @@ -0,0 +1,5 @@ +--- +- name: Remove BGP configuration + vyos.rest.vyos_bgp_global: + state: deleted + ignore_errors: true diff --git a/tests/integration/targets/vyos_bgp_global/tests/httpapi/deleted.yaml b/tests/integration/targets/vyos_bgp_global/tests/httpapi/deleted.yaml new file mode 100644 index 0000000..ed2c285 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/tests/httpapi/deleted.yaml @@ -0,0 +1,29 @@ +--- +- debug: + msg: START vyos_bgp_global deleted integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Delete BGP configuration + register: result + vyos.rest.vyos_bgp_global: + state: deleted + + - assert: + that: + - result.changed == true + + - name: Delete BGP configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_bgp_global: + state: deleted + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/httpapi/gathered.yaml b/tests/integration/targets/vyos_bgp_global/tests/httpapi/gathered.yaml new file mode 100644 index 0000000..b38dba0 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/tests/httpapi/gathered.yaml @@ -0,0 +1,22 @@ +--- +- debug: + msg: START vyos_bgp_global gathered integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Gather BGP global configuration + register: result + vyos.rest.vyos_bgp_global: + state: gathered + + - assert: + that: + - result.gathered.as_number == 65000 + - result.gathered.parameters.router_id == "192.0.1.1" + - result.gathered.neighbors | selectattr('neighbor_address', 'eq', '192.0.2.1') | list | length == 1 + - result.gathered.peer_groups | selectattr('peer_group', 'eq', 'PG1') | list | length == 1 + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/httpapi/merged.yaml b/tests/integration/targets/vyos_bgp_global/tests/httpapi/merged.yaml new file mode 100644 index 0000000..10ca4da --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/tests/httpapi/merged.yaml @@ -0,0 +1,44 @@ +--- +- debug: + msg: START vyos_bgp_global merged integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge BGP global configuration + register: result + vyos.rest.vyos_bgp_global: + config: + as_number: 65000 + parameters: + router_id: 192.0.1.1 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + description: peer1 + state: merged + + - assert: + that: + - result.changed == true + + - name: Merge BGP global configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_bgp_global: + config: + as_number: 65000 + parameters: + router_id: 192.0.1.1 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + description: peer1 + state: merged + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/httpapi/overridden.yaml b/tests/integration/targets/vyos_bgp_global/tests/httpapi/overridden.yaml new file mode 100644 index 0000000..603aff3 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/tests/httpapi/overridden.yaml @@ -0,0 +1,35 @@ +--- +- debug: + msg: START vyos_bgp_global overridden integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Override BGP global configuration + register: result + vyos.rest.vyos_bgp_global: &id001 + config: + as_number: 65000 + parameters: + router_id: 192.0.1.2 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + state: replaced + + - assert: + that: + - result.changed == true + + - name: Override BGP global configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_bgp_global: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/httpapi/replaced.yaml b/tests/integration/targets/vyos_bgp_global/tests/httpapi/replaced.yaml new file mode 100644 index 0000000..1a7d615 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/tests/httpapi/replaced.yaml @@ -0,0 +1,35 @@ +--- +- debug: + msg: START vyos_bgp_global replaced integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Replace BGP global configuration + register: result + vyos.rest.vyos_bgp_global: &id001 + config: + as_number: 65000 + parameters: + router_id: 192.0.1.2 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + state: replaced + + - assert: + that: + - result.changed == true + + - name: Replace BGP global configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_bgp_global: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/httpapi/rtt.yaml b/tests/integration/targets/vyos_bgp_global/tests/httpapi/rtt.yaml new file mode 100644 index 0000000..490ec1a --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/tests/httpapi/rtt.yaml @@ -0,0 +1,50 @@ +--- +- debug: + msg: START vyos_bgp_global round trip integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: RTT - Apply base configuration + vyos.rest.vyos_bgp_global: + config: + as_number: 65000 + parameters: + router_id: 192.0.1.1 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + state: merged + + - name: RTT - Gather + register: gathered + vyos.rest.vyos_bgp_global: + state: gathered + + - assert: + that: + - gathered.gathered.as_number == 65000 + - gathered.gathered.parameters.router_id == "192.0.1.1" + + - name: RTT - Modify configuration + vyos.rest.vyos_bgp_global: + config: + as_number: 65000 + parameters: + router_id: 192.0.1.2 + neighbors: + - neighbor_address: 192.0.2.1 + remote_as: 65001 + state: replaced + + - name: RTT - Gather after modify + register: gathered2 + vyos.rest.vyos_bgp_global: + state: gathered + + - assert: + that: + - gathered2.gathered.parameters.router_id == "192.0.1.2" + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/vars/main.yaml b/tests/integration/targets/vyos_bgp_global/vars/main.yaml new file mode 100644 index 0000000..4303881 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/vars/main.yaml @@ -0,0 +1,2 @@ +--- +# only common vars here diff --git a/tests/integration/targets/vyos_facts/aliases b/tests/integration/targets/vyos_facts/aliases new file mode 100644 index 0000000..cc0afef --- /dev/null +++ b/tests/integration/targets/vyos_facts/aliases @@ -0,0 +1 @@ +network/vyos diff --git a/tests/integration/targets/vyos_facts/defaults/main.yaml b/tests/integration/targets/vyos_facts/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/tests/integration/targets/vyos_facts/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/vyos_facts/tasks/httpapi.yaml b/tests/integration/targets/vyos_facts/tasks/httpapi.yaml new file mode 100644 index 0000000..4147e6d --- /dev/null +++ b/tests/integration/targets/vyos_facts/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_facts/tasks/main.yaml b/tests/integration/targets/vyos_facts/tasks/main.yaml new file mode 100644 index 0000000..b1f6193 --- /dev/null +++ b/tests/integration/targets/vyos_facts/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_facts/tests/httpapi/all.yaml b/tests/integration/targets/vyos_facts/tests/httpapi/all.yaml new file mode 100644 index 0000000..419634f --- /dev/null +++ b/tests/integration/targets/vyos_facts/tests/httpapi/all.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START vyos_facts all integration tests on connection={{ ansible_connection }} + +- block: + - name: Gather all facts + vyos.rest.vyos_facts: + gather_subset: all + + - assert: + that: + - ansible_facts.vyos_hostname is defined + - ansible_facts.vyos_interfaces is defined + - ansible_facts.vyos_users is defined + - ansible_facts.vyos_config is defined + - ansible_facts.vyos_logging is defined diff --git a/tests/integration/targets/vyos_facts/tests/httpapi/default.yaml b/tests/integration/targets/vyos_facts/tests/httpapi/default.yaml new file mode 100644 index 0000000..ff1caee --- /dev/null +++ b/tests/integration/targets/vyos_facts/tests/httpapi/default.yaml @@ -0,0 +1,13 @@ +--- +- debug: + msg: START vyos_facts default integration tests on connection={{ ansible_connection }} + +- block: + - name: Gather default facts + vyos.rest.vyos_facts: + + - assert: + that: + - ansible_facts.vyos_hostname is defined + - ansible_facts.vyos_interfaces is defined + - ansible_facts.vyos_hostname | length > 0 diff --git a/tests/integration/targets/vyos_facts/tests/httpapi/subsets.yaml b/tests/integration/targets/vyos_facts/tests/httpapi/subsets.yaml new file mode 100644 index 0000000..eb4ca4f --- /dev/null +++ b/tests/integration/targets/vyos_facts/tests/httpapi/subsets.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: START vyos_facts subsets integration tests on connection={{ ansible_connection }} + +- block: + - name: Gather hostname only + vyos.rest.vyos_facts: + gather_subset: + - hostname + + - assert: + that: + - ansible_facts.vyos_hostname is defined + + - name: Gather users + vyos.rest.vyos_facts: + gather_subset: + - users + + - assert: + that: + - ansible_facts.vyos_users is defined + - ansible_facts.vyos_users | selectattr('name', 'eq', 'vyos') | list | length == 1 + + - name: Gather config + vyos.rest.vyos_facts: + gather_subset: + - config + + - assert: + that: + - ansible_facts.vyos_config is defined + - ansible_facts.vyos_config.system is defined diff --git a/tests/integration/targets/vyos_facts/vars/main.yaml b/tests/integration/targets/vyos_facts/vars/main.yaml new file mode 100644 index 0000000..4303881 --- /dev/null +++ b/tests/integration/targets/vyos_facts/vars/main.yaml @@ -0,0 +1,2 @@ +--- +# only common vars here diff --git a/tests/integration/targets/vyos_firewall_global/aliases b/tests/integration/targets/vyos_firewall_global/aliases new file mode 100644 index 0000000..cc0afef --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/aliases @@ -0,0 +1 @@ +network/vyos diff --git a/tests/integration/targets/vyos_firewall_global/defaults/main.yaml b/tests/integration/targets/vyos_firewall_global/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/vyos_firewall_global/tasks/httpapi.yaml b/tests/integration/targets/vyos_firewall_global/tasks/httpapi.yaml new file mode 100644 index 0000000..4147e6d --- /dev/null +++ b/tests/integration/targets/vyos_firewall_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_firewall_global/tasks/main.yaml b/tests/integration/targets/vyos_firewall_global/tasks/main.yaml new file mode 100644 index 0000000..b1f6193 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/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_firewall_global/tests/httpapi/_populate_config.yaml b/tests/integration/targets/vyos_firewall_global/tests/httpapi/_populate_config.yaml new file mode 100644 index 0000000..c891369 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tests/httpapi/_populate_config.yaml @@ -0,0 +1,22 @@ +--- +- name: Populate firewall global config for testing + vyos.rest.vyos_firewall_global: + config: + group: + address_group: + - name: SERVERS + description: Web servers + address: + - 192.168.1.10 + - 192.168.1.11 + network_group: + - name: LAN + network: + - 192.168.0.0/16 + port_group: + - name: WEB-PORTS + port: + - "80" + - "443" + state: merged + ignore_errors: true diff --git a/tests/integration/targets/vyos_firewall_global/tests/httpapi/_remove_config.yaml b/tests/integration/targets/vyos_firewall_global/tests/httpapi/_remove_config.yaml new file mode 100644 index 0000000..eb0c596 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tests/httpapi/_remove_config.yaml @@ -0,0 +1,5 @@ +--- +- name: Remove firewall global configuration + vyos.rest.vyos_firewall_global: + state: deleted + ignore_errors: true diff --git a/tests/integration/targets/vyos_firewall_global/tests/httpapi/deleted.yaml b/tests/integration/targets/vyos_firewall_global/tests/httpapi/deleted.yaml new file mode 100644 index 0000000..ade5fe4 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tests/httpapi/deleted.yaml @@ -0,0 +1,29 @@ +--- +- debug: + msg: START vyos_firewall_global deleted integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Delete firewall global configuration + register: result + vyos.rest.vyos_firewall_global: + state: deleted + + - assert: + that: + - result.changed == true + + - name: Delete firewall global configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_global: + state: deleted + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/tests/httpapi/gathered.yaml b/tests/integration/targets/vyos_firewall_global/tests/httpapi/gathered.yaml new file mode 100644 index 0000000..6f470bd --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tests/httpapi/gathered.yaml @@ -0,0 +1,21 @@ +--- +- debug: + msg: START vyos_firewall_global gathered integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Gather firewall global configuration + register: result + vyos.rest.vyos_firewall_global: + state: gathered + + - assert: + that: + - result.gathered.group.address_group | selectattr('name', 'eq', 'SERVERS') | list | length == 1 + - result.gathered.group.network_group | selectattr('name', 'eq', 'LAN') | list | length == 1 + - result.gathered.group.port_group | selectattr('name', 'eq', 'WEB-PORTS') | list | length == 1 + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/tests/httpapi/merged.yaml b/tests/integration/targets/vyos_firewall_global/tests/httpapi/merged.yaml new file mode 100644 index 0000000..aaaa67a --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tests/httpapi/merged.yaml @@ -0,0 +1,48 @@ +--- +- debug: + msg: START vyos_firewall_global merged integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge firewall global configuration + register: result + vyos.rest.vyos_firewall_global: + config: + group: + address_group: + - name: SERVERS + address: + - 192.168.1.10 + network_group: + - name: LAN + network: + - 192.168.0.0/16 + state: merged + + - assert: + that: + - result.changed == true + + - name: Merge firewall global configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_global: + config: + group: + address_group: + - name: SERVERS + address: + - 192.168.1.10 + network_group: + - name: LAN + network: + - 192.168.0.0/16 + state: merged + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/tests/httpapi/overridden.yaml b/tests/integration/targets/vyos_firewall_global/tests/httpapi/overridden.yaml new file mode 100644 index 0000000..04d7c95 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tests/httpapi/overridden.yaml @@ -0,0 +1,34 @@ +--- +- debug: + msg: START vyos_firewall_global overridden integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Override firewall global configuration + register: result + vyos.rest.vyos_firewall_global: &id001 + config: + group: + network_group: + - name: DMZ + network: + - 10.0.0.0/8 + state: replaced + + - assert: + that: + - result.changed == true + + - name: Override firewall global configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_global: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/tests/httpapi/replaced.yaml b/tests/integration/targets/vyos_firewall_global/tests/httpapi/replaced.yaml new file mode 100644 index 0000000..b5af06f --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tests/httpapi/replaced.yaml @@ -0,0 +1,34 @@ +--- +- debug: + msg: START vyos_firewall_global replaced integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Replace firewall global configuration + register: result + vyos.rest.vyos_firewall_global: &id001 + config: + group: + network_group: + - name: DMZ + network: + - 10.0.0.0/8 + state: replaced + + - assert: + that: + - result.changed == true + + - name: Replace firewall global configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_global: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/tests/httpapi/rtt.yaml b/tests/integration/targets/vyos_firewall_global/tests/httpapi/rtt.yaml new file mode 100644 index 0000000..56ce94d --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tests/httpapi/rtt.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START vyos_firewall_global round trip integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: RTT - Apply base configuration + vyos.rest.vyos_firewall_global: + config: + group: + address_group: + - name: SERVERS + address: + - 192.168.1.10 + network_group: + - name: LAN + network: + - 192.168.0.0/16 + state: merged + + - name: RTT - Gather + register: gathered + vyos.rest.vyos_firewall_global: + state: gathered + + - assert: + that: + - gathered.gathered.group.address_group | selectattr('name', 'eq', 'SERVERS') | list | length == 1 + - gathered.gathered.group.network_group | selectattr('name', 'eq', 'LAN') | list | length == 1 + + - name: RTT - Modify configuration + vyos.rest.vyos_firewall_global: + config: + group: + network_group: + - name: LAN + network: + - 192.168.0.0/16 + - name: DMZ + network: + - 10.0.0.0/8 + state: merged + + - name: RTT - Gather after modify + register: gathered2 + vyos.rest.vyos_firewall_global: + state: gathered + + - assert: + that: + - gathered2.gathered.group.network_group | selectattr('name', 'eq', 'DMZ') | list | length == 1 + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_global/vars/main.yaml b/tests/integration/targets/vyos_firewall_global/vars/main.yaml new file mode 100644 index 0000000..4303881 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/vars/main.yaml @@ -0,0 +1,2 @@ +--- +# only common vars here diff --git a/tests/integration/targets/vyos_firewall_interfaces/aliases b/tests/integration/targets/vyos_firewall_interfaces/aliases new file mode 100644 index 0000000..cc0afef --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/aliases @@ -0,0 +1 @@ +network/vyos diff --git a/tests/integration/targets/vyos_firewall_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_firewall_interfaces/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/vyos_firewall_interfaces/tasks/httpapi.yaml b/tests/integration/targets/vyos_firewall_interfaces/tasks/httpapi.yaml new file mode 100644 index 0000000..4147e6d --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/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_firewall_interfaces/tasks/main.yaml b/tests/integration/targets/vyos_firewall_interfaces/tasks/main.yaml new file mode 100644 index 0000000..b1f6193 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/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_firewall_interfaces/tests/httpapi/_populate_config.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/_populate_config.yaml new file mode 100644 index 0000000..d2dddc7 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/_populate_config.yaml @@ -0,0 +1,23 @@ +--- +- name: Populate firewall interfaces config for testing + vyos.rest.vyos_firewall_interfaces: + config: + - afi: ipv4 + hooks: + - hook: input + default_action: accept + rules: + - number: 10 + action: accept + state: established + - number: 20 + action: drop + state: invalid + - hook: forward + default_action: accept + - afi: ipv6 + hooks: + - hook: input + default_action: accept + state: merged + ignore_errors: true diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/_remove_config.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/_remove_config.yaml new file mode 100644 index 0000000..14b0216 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/_remove_config.yaml @@ -0,0 +1,5 @@ +--- +- name: Remove firewall interfaces configuration + vyos.rest.vyos_firewall_interfaces: + state: deleted + ignore_errors: true diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/deleted.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/deleted.yaml new file mode 100644 index 0000000..00025f7 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/deleted.yaml @@ -0,0 +1,29 @@ +--- +- debug: + msg: START vyos_firewall_interfaces deleted integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Delete all firewall interfaces configuration + register: result + vyos.rest.vyos_firewall_interfaces: + state: deleted + + - assert: + that: + - result.changed == true + + - name: Delete all firewall interfaces configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_interfaces: + state: deleted + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/gathered.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/gathered.yaml new file mode 100644 index 0000000..27ad537 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/gathered.yaml @@ -0,0 +1,21 @@ +--- +- debug: + msg: START vyos_firewall_interfaces gathered integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Gather firewall interfaces configuration + register: result + vyos.rest.vyos_firewall_interfaces: + state: gathered + + - assert: + that: + - result.gathered | selectattr('afi', 'eq', 'ipv4') | list | length == 1 + - result.gathered | selectattr('afi', 'eq', 'ipv6') | list | length == 1 + - (result.gathered | selectattr('afi', 'eq', 'ipv4') | first).hooks | selectattr('hook', 'eq', 'input') | list | length == 1 + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/merged.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/merged.yaml new file mode 100644 index 0000000..d89530d --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/merged.yaml @@ -0,0 +1,46 @@ +--- +- debug: + msg: START vyos_firewall_interfaces merged integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge firewall interfaces configuration + register: result + vyos.rest.vyos_firewall_interfaces: + config: + - afi: ipv4 + hooks: + - hook: input + default_action: accept + rules: + - number: 10 + action: accept + state: established + state: merged + + - assert: + that: + - result.changed == true + + - name: Merge firewall interfaces configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_interfaces: + config: + - afi: ipv4 + hooks: + - hook: input + default_action: accept + rules: + - number: 10 + action: accept + state: established + state: merged + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/overridden.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/overridden.yaml new file mode 100644 index 0000000..8a20a48 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/overridden.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: START vyos_firewall_interfaces overridden integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Override firewall interfaces configuration + register: result + vyos.rest.vyos_firewall_interfaces: &id001 + config: + - afi: ipv4 + hooks: + - hook: forward + default_action: accept + state: overridden + + - assert: + that: + - result.changed == true + + - name: Override firewall interfaces configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_interfaces: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/replaced.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/replaced.yaml new file mode 100644 index 0000000..f782fc6 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/replaced.yaml @@ -0,0 +1,37 @@ +--- +- debug: + msg: START vyos_firewall_interfaces replaced integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Replace firewall interfaces configuration + register: result + vyos.rest.vyos_firewall_interfaces: &id001 + config: + - afi: ipv4 + hooks: + - hook: input + default_action: accept + rules: + - number: 10 + action: accept + state: established + state: replaced + + - assert: + that: + - result.changed == true + + - name: Replace firewall interfaces configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_interfaces: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/rtt.yaml b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/rtt.yaml new file mode 100644 index 0000000..229bc7f --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/tests/httpapi/rtt.yaml @@ -0,0 +1,53 @@ +--- +- debug: + msg: START vyos_firewall_interfaces round trip integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: RTT - Apply base configuration + vyos.rest.vyos_firewall_interfaces: + config: + - afi: ipv4 + hooks: + - hook: input + default_action: accept + rules: + - number: 10 + action: accept + state: established + state: merged + + - name: RTT - Gather + register: gathered + vyos.rest.vyos_firewall_interfaces: + state: gathered + + - assert: + that: + - gathered.gathered | selectattr('afi', 'eq', 'ipv4') | list | length == 1 + + - name: RTT - Modify configuration + vyos.rest.vyos_firewall_interfaces: + config: + - afi: ipv4 + hooks: + - hook: input + default_action: accept + rules: + - number: 10 + action: accept + state: established + state: replaced + + - name: RTT - Gather after modify + register: gathered2 + vyos.rest.vyos_firewall_interfaces: + state: gathered + + - assert: + that: + - (gathered2.gathered | selectattr('afi', 'eq', 'ipv4') | first).hooks[0].default_action == 'accept' + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_interfaces/vars/main.yaml b/tests/integration/targets/vyos_firewall_interfaces/vars/main.yaml new file mode 100644 index 0000000..4303881 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_interfaces/vars/main.yaml @@ -0,0 +1,2 @@ +--- +# only common vars here diff --git a/tests/integration/targets/vyos_firewall_rules/aliases b/tests/integration/targets/vyos_firewall_rules/aliases new file mode 100644 index 0000000..cc0afef --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/aliases @@ -0,0 +1 @@ +network/vyos diff --git a/tests/integration/targets/vyos_firewall_rules/defaults/main.yaml b/tests/integration/targets/vyos_firewall_rules/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/vyos_firewall_rules/tasks/httpapi.yaml b/tests/integration/targets/vyos_firewall_rules/tasks/httpapi.yaml new file mode 100644 index 0000000..4147e6d --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/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_firewall_rules/tasks/main.yaml b/tests/integration/targets/vyos_firewall_rules/tasks/main.yaml new file mode 100644 index 0000000..b1f6193 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/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_firewall_rules/tests/httpapi/_populate_config.yaml b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/_populate_config.yaml new file mode 100644 index 0000000..7654625 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/_populate_config.yaml @@ -0,0 +1,28 @@ +--- +- name: Populate firewall rules config for testing + vyos.rest.vyos_firewall_rules: + config: + - afi: ipv4 + rule_sets: + - name: RULE-SET1 + default_action: drop + rules: + - number: 10 + action: accept + protocol: tcp + source: + address: 192.168.1.0/24 + destination: + port: "80" + - number: 20 + action: drop + state: invalid + - afi: ipv6 + rule_sets: + - name: RULE-SET6 + default_action: accept + rules: + - number: 10 + action: accept + state: merged + ignore_errors: true diff --git a/tests/integration/targets/vyos_firewall_rules/tests/httpapi/_remove_config.yaml b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/_remove_config.yaml new file mode 100644 index 0000000..52866df --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/_remove_config.yaml @@ -0,0 +1,5 @@ +--- +- name: Remove firewall rules configuration + vyos.rest.vyos_firewall_rules: + state: deleted + ignore_errors: true diff --git a/tests/integration/targets/vyos_firewall_rules/tests/httpapi/deleted.yaml b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/deleted.yaml new file mode 100644 index 0000000..db4cbf0 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/deleted.yaml @@ -0,0 +1,29 @@ +--- +- debug: + msg: START vyos_firewall_rules deleted integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Delete all firewall rules configuration + register: result + vyos.rest.vyos_firewall_rules: + state: deleted + + - assert: + that: + - result.changed == true + + - name: Delete all firewall rules configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_rules: + state: deleted + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/httpapi/gathered.yaml b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/gathered.yaml new file mode 100644 index 0000000..6729976 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/gathered.yaml @@ -0,0 +1,21 @@ +--- +- debug: + msg: START vyos_firewall_rules gathered integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Gather firewall rules configuration + register: result + vyos.rest.vyos_firewall_rules: + state: gathered + + - assert: + that: + - result.gathered | selectattr('afi', 'eq', 'ipv4') | list | length == 1 + - result.gathered | selectattr('afi', 'eq', 'ipv6') | list | length == 1 + - (result.gathered | selectattr('afi', 'eq', 'ipv4') | first).rule_sets | selectattr('name', 'eq', 'RULE-SET1') | list | length == 1 + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/httpapi/merged.yaml b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/merged.yaml new file mode 100644 index 0000000..4dc02ca --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/merged.yaml @@ -0,0 +1,50 @@ +--- +- debug: + msg: START vyos_firewall_rules merged integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge firewall rules configuration + register: result + vyos.rest.vyos_firewall_rules: + config: + - afi: ipv4 + rule_sets: + - name: RULE-SET1 + default_action: drop + rules: + - number: 10 + action: accept + protocol: tcp + source: + address: 192.168.1.0/24 + state: merged + + - assert: + that: + - result.changed == true + + - name: Merge firewall rules configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_rules: + config: + - afi: ipv4 + rule_sets: + - name: RULE-SET1 + default_action: drop + rules: + - number: 10 + action: accept + protocol: tcp + source: + address: 192.168.1.0/24 + state: merged + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/httpapi/overridden.yaml b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/overridden.yaml new file mode 100644 index 0000000..d5db4b9 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/overridden.yaml @@ -0,0 +1,36 @@ +--- +- debug: + msg: START vyos_firewall_rules overridden integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Override firewall rules configuration + register: result + vyos.rest.vyos_firewall_rules: &id001 + config: + - afi: ipv4 + rule_sets: + - name: NEW-SET + default_action: accept + rules: + - number: 10 + action: accept + state: overridden + + - assert: + that: + - result.changed == true + + - name: Override firewall rules configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_rules: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/httpapi/replaced.yaml b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/replaced.yaml new file mode 100644 index 0000000..92033c4 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/replaced.yaml @@ -0,0 +1,36 @@ +--- +- debug: + msg: START vyos_firewall_rules replaced integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Replace firewall rules configuration + register: result + vyos.rest.vyos_firewall_rules: &id001 + config: + - afi: ipv4 + rule_sets: + - name: RULE-SET1 + default_action: accept + rules: + - number: 10 + action: accept + state: replaced + + - assert: + that: + - result.changed == true + + - name: Replace firewall rules configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_firewall_rules: *id001 + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/tests/httpapi/rtt.yaml b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/rtt.yaml new file mode 100644 index 0000000..193f03e --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/tests/httpapi/rtt.yaml @@ -0,0 +1,52 @@ +--- +- debug: + msg: START vyos_firewall_rules round trip integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: RTT - Apply base configuration + vyos.rest.vyos_firewall_rules: + config: + - afi: ipv4 + rule_sets: + - name: RULE-SET1 + default_action: drop + rules: + - number: 10 + action: accept + protocol: tcp + state: merged + + - name: RTT - Gather + register: gathered + vyos.rest.vyos_firewall_rules: + state: gathered + + - assert: + that: + - gathered.gathered | selectattr('afi', 'eq', 'ipv4') | list | length == 1 + + - name: RTT - Modify configuration + vyos.rest.vyos_firewall_rules: + config: + - afi: ipv4 + rule_sets: + - name: RULE-SET1 + default_action: accept + rules: + - number: 10 + action: accept + state: replaced + + - name: RTT - Gather after modify + register: gathered2 + vyos.rest.vyos_firewall_rules: + state: gathered + + - assert: + that: + - (gathered2.gathered | selectattr('afi', 'eq', 'ipv4') | first).rule_sets[0].default_action == 'accept' + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_firewall_rules/vars/main.yaml b/tests/integration/targets/vyos_firewall_rules/vars/main.yaml new file mode 100644 index 0000000..4303881 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_rules/vars/main.yaml @@ -0,0 +1,2 @@ +--- +# only common vars here diff --git a/tests/integration/targets/vyos_user/aliases b/tests/integration/targets/vyos_user/aliases new file mode 100644 index 0000000..cc0afef --- /dev/null +++ b/tests/integration/targets/vyos_user/aliases @@ -0,0 +1 @@ +network/vyos diff --git a/tests/integration/targets/vyos_user/defaults/main.yaml b/tests/integration/targets/vyos_user/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/tests/integration/targets/vyos_user/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/vyos_user/tasks/httpapi.yaml b/tests/integration/targets/vyos_user/tasks/httpapi.yaml new file mode 100644 index 0000000..4147e6d --- /dev/null +++ b/tests/integration/targets/vyos_user/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_user/tasks/main.yaml b/tests/integration/targets/vyos_user/tasks/main.yaml new file mode 100644 index 0000000..b1f6193 --- /dev/null +++ b/tests/integration/targets/vyos_user/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_user/tests/httpapi/_remove_config.yaml b/tests/integration/targets/vyos_user/tests/httpapi/_remove_config.yaml new file mode 100644 index 0000000..54cf0f9 --- /dev/null +++ b/tests/integration/targets/vyos_user/tests/httpapi/_remove_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Remove test users + vyos.rest.vyos_user: + users: + - name: testuser + - name: testuser2 + state: absent + ignore_errors: true diff --git a/tests/integration/targets/vyos_user/tests/httpapi/absent.yaml b/tests/integration/targets/vyos_user/tests/httpapi/absent.yaml new file mode 100644 index 0000000..c89da2e --- /dev/null +++ b/tests/integration/targets/vyos_user/tests/httpapi/absent.yaml @@ -0,0 +1,43 @@ +--- +- debug: + msg: START vyos_user absent integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Create users for deletion test + vyos.rest.vyos_user: + users: + - name: testuser + full_name: Test User + password: S3cur3P@ss! + - name: testuser2 + full_name: Test User 2 + password: S3cur3P@ss! + state: present + + - name: Delete specific user + register: result + vyos.rest.vyos_user: + users: + - name: testuser + state: absent + + - assert: + that: + - result.changed == true + + - name: Delete specific user (IDEMPOTENT) + register: result + vyos.rest.vyos_user: + users: + - name: testuser + state: absent + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_user/tests/httpapi/gathered.yaml b/tests/integration/targets/vyos_user/tests/httpapi/gathered.yaml new file mode 100644 index 0000000..0f651e7 --- /dev/null +++ b/tests/integration/targets/vyos_user/tests/httpapi/gathered.yaml @@ -0,0 +1,28 @@ +--- +- debug: + msg: START vyos_user gathered integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Create user for gathering + vyos.rest.vyos_user: + users: + - name: testuser + full_name: Test User + password: S3cur3P@ss! + state: present + + - name: Gather users + register: result + vyos.rest.vyos_user: + state: gathered + + - assert: + that: + - result.gathered | selectattr('name', 'eq', 'testuser') | list | length == 1 + - result.gathered | selectattr('name', 'eq', 'vyos') | list | length == 1 + - (result.gathered | selectattr('name', 'eq', 'testuser') | first).full_name == 'Test User' + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_user/tests/httpapi/present.yaml b/tests/integration/targets/vyos_user/tests/httpapi/present.yaml new file mode 100644 index 0000000..1797772 --- /dev/null +++ b/tests/integration/targets/vyos_user/tests/httpapi/present.yaml @@ -0,0 +1,63 @@ +--- +- debug: + msg: START vyos_user present integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Create user + register: result + vyos.rest.vyos_user: + users: + - name: testuser + full_name: Test User + password: S3cur3P@ss! + update_password: on_create + state: present + + - assert: + that: + - result.changed == true + + - name: Create user (IDEMPOTENT) + register: result + vyos.rest.vyos_user: + users: + - name: testuser + full_name: Test User + password: S3cur3P@ss! + update_password: on_create + state: present + + - assert: + that: + - result.changed == false + - result.commands == [] + + - name: Update full_name + register: result + vyos.rest.vyos_user: + users: + - name: testuser + full_name: Test User Updated + state: present + + - assert: + that: + - result.changed == true + + - name: Update full_name (IDEMPOTENT) + register: result + vyos.rest.vyos_user: + users: + - name: testuser + full_name: Test User Updated + state: present + + - assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_user/tests/httpapi/rtt.yaml b/tests/integration/targets/vyos_user/tests/httpapi/rtt.yaml new file mode 100644 index 0000000..6f35676 --- /dev/null +++ b/tests/integration/targets/vyos_user/tests/httpapi/rtt.yaml @@ -0,0 +1,45 @@ +--- +- debug: + msg: START vyos_user round trip integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: RTT - Create user + vyos.rest.vyos_user: + users: + - name: testuser + full_name: Test User + password: S3cur3P@ss! + update_password: on_create + state: present + + - name: RTT - Gather + register: gathered + vyos.rest.vyos_user: + state: gathered + + - name: RTT - Assert user exists + assert: + that: + - gathered.gathered | selectattr('name', 'eq', 'testuser') | list | length == 1 + + - name: RTT - Update full_name + vyos.rest.vyos_user: + users: + - name: testuser + full_name: Test User Modified + state: present + + - name: RTT - Gather after update + register: gathered2 + vyos.rest.vyos_user: + state: gathered + + - name: RTT - Assert update applied + assert: + that: + - (gathered2.gathered | selectattr('name', 'eq', 'testuser') | first).full_name == 'Test User Modified' + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_user/vars/main.yaml b/tests/integration/targets/vyos_user/vars/main.yaml new file mode 100644 index 0000000..4303881 --- /dev/null +++ b/tests/integration/targets/vyos_user/vars/main.yaml @@ -0,0 +1,2 @@ +--- +# only common vars here -- cgit v1.2.3