diff options
| author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2026-10-07 21:21:04 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-10-07 14:21:04 +0300 |
| commit | 41781e7a16e73fdca1f26c677ed3645ca2a8a3d0 (patch) | |
| tree | 61cf5e168e55ffd81c8d79d607b4ba3d9d91ad57 /tests/integration/targets | |
| parent | 7cfca28e5857b480920c22ae12557f55ca2a8a19 (diff) | |
| download | rest.vyos-41781e7a16e73fdca1f26c677ed3645ca2a8a3d0.tar.gz rest.vyos-41781e7a16e73fdca1f26c677ed3645ca2a8a3d0.zip | |
* T8989: vyos_interfaces dict_op refactor
---------
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Daniil Baturin <daniil@vyos.io>
Diffstat (limited to 'tests/integration/targets')
| -rw-r--r-- | tests/integration/targets/vyos_interfaces/tests/httpapi/overridden.yaml | 104 | ||||
| -rw-r--r-- | tests/integration/targets/vyos_interfaces/tests/httpapi/rtt.yaml | 107 |
2 files changed, 211 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_interfaces/tests/httpapi/overridden.yaml b/tests/integration/targets/vyos_interfaces/tests/httpapi/overridden.yaml new file mode 100644 index 0000000..650ce1b --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/httpapi/overridden.yaml @@ -0,0 +1,104 @@ +--- +- debug: + msg: START vyos_interfaces overridden integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Override interface configuration + register: result + vyos.rest.vyos_interfaces: &id001 + config: + - name: eth0 + description: Ansible overridden interface + mtu: 1300 + state: overridden + + - assert: + that: + - result.changed == true + + - name: Override interface configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_interfaces: *id001 + + - name: Assert idempotent + assert: + that: + - result.changed == false + - result.commands == [] + + always: + - include_tasks: _remove_config.yaml + +# Regression test (CodeRabbit, PR #33): overriding while an interface's +# VIF is left entirely unlisted (the interface itself isn't even named +# in config) must never delete the whole VIF node -- only this +# module's own managed leaves within it -- since vyos_l3_interfaces +# may have an address configured on that same VIF. +- block: + - name: Set up an interface with a VIF + vyos.rest.vyos_interfaces: + config: + - name: eth1 + description: mgmt + vifs: + - vlan_id: 200 + description: management vlan + state: merged + + - name: Set an address on that VIF via vyos_l3_interfaces + vyos.rest.vyos_l3_interfaces: + config: + - name: eth1 + vifs: + - vlan_id: 200 + ipv4: + - address: 192.0.2.1/24 + state: merged + + - name: Override with eth1 entirely unlisted + register: result + vyos.rest.vyos_interfaces: + config: + - name: eth0 + description: Ansible overridden interface + state: overridden + + - assert: + that: + - result.changed == true + - "'interfaces,ethernet,eth1,vif' not in (result.commands | map('join', ',') | list | join('|'))" + - "'interfaces,ethernet,eth1,vif,200' not in (result.commands | map('join', ',') | list | join('|'))" + + - name: Confirm the address survived, via vyos_l3_interfaces + register: l3_check + vyos.rest.vyos_l3_interfaces: + state: gathered + + - assert: + that: + - >- + l3_check.gathered + | selectattr('name', 'equalto', 'eth1') + | map(attribute='vifs') + | first + | selectattr('vlan_id', 'equalto', 200) + | map(attribute='ipv4') + | first + | map(attribute='address') + | list == ['192.0.2.1/24'] + + always: + - vyos.rest.vyos_interfaces: + config: + - name: eth1 + state: deleted + ignore_errors: true + - vyos.rest.vyos_l3_interfaces: + config: + - name: eth1 + state: deleted + ignore_errors: true + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_interfaces/tests/httpapi/rtt.yaml b/tests/integration/targets/vyos_interfaces/tests/httpapi/rtt.yaml new file mode 100644 index 0000000..e6783e3 --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/httpapi/rtt.yaml @@ -0,0 +1,107 @@ +--- +- debug: + msg: START vyos_interfaces round trip integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: RTT - Apply base configuration + vyos.rest.vyos_interfaces: + config: + - name: eth0 + description: Ansible test interface + mtu: 1450 + vifs: + - vlan_id: 200 + description: management vlan + state: merged + + - name: RTT - Gather + register: gathered + vyos.rest.vyos_interfaces: + state: gathered + + - assert: + that: + - >- + gathered.gathered + | selectattr('name', 'equalto', 'eth0') + | map(attribute='description') + | first == 'Ansible test interface' + - >- + gathered.gathered + | selectattr('name', 'equalto', 'eth0') + | map(attribute='mtu') + | first == 1450 + - >- + gathered.gathered + | selectattr('name', 'equalto', 'eth0') + | map(attribute='vifs') + | first + | selectattr('vlan_id', 'equalto', 200) + | map(attribute='description') + | first == 'management vlan' + + - name: RTT - Modify description and disable the VIF + vyos.rest.vyos_interfaces: + config: + - name: eth0 + description: Ansible test interface updated + mtu: 1450 + vifs: + - vlan_id: 200 + description: management vlan + enabled: false + state: replaced + + - name: RTT - Gather after modify + register: gathered2 + vyos.rest.vyos_interfaces: + state: gathered + + - assert: + that: + - >- + gathered2.gathered + | selectattr('name', 'equalto', 'eth0') + | map(attribute='description') + | first == 'Ansible test interface updated' + - >- + gathered2.gathered + | selectattr('name', 'equalto', 'eth0') + | map(attribute='vifs') + | first + | selectattr('vlan_id', 'equalto', 200) + | map(attribute='enabled', default=true) + | first == false + + - name: RTT - Re-enable the VIF + vyos.rest.vyos_interfaces: + config: + - name: eth0 + description: Ansible test interface updated + mtu: 1450 + vifs: + - vlan_id: 200 + description: management vlan + enabled: true + state: replaced + + - name: RTT - Gather after re-enable + register: gathered3 + vyos.rest.vyos_interfaces: + state: gathered + + - assert: + that: + - >- + gathered3.gathered + | selectattr('name', 'equalto', 'eth0') + | map(attribute='vifs') + | first + | selectattr('vlan_id', 'equalto', 200) + | map(attribute='enabled', default=true) + | first == true + + always: + - include_tasks: _remove_config.yaml |
