From 88248610065245ea8ee5bbc299b116a37da584f3 Mon Sep 17 00:00:00 2001 From: omnom62 Date: Fri, 19 Jun 2026 17:37:25 +1000 Subject: T8989: vyos_interfaces --- tests/integration/targets/vyos_interfaces/aliases | 1 + .../targets/vyos_interfaces/defaults/main.yaml | 3 ++ .../targets/vyos_interfaces/tasks/httpapi.yaml | 21 ++++++++++++++ .../targets/vyos_interfaces/tasks/main.yaml | 5 ++++ .../tests/httpapi/_populate_config.yaml | 9 ++++++ .../tests/httpapi/_remove_config.yaml | 7 +++++ .../vyos_interfaces/tests/httpapi/deleted.yaml | 30 ++++++++++++++++++++ .../vyos_interfaces/tests/httpapi/gathered.yaml | 21 ++++++++++++++ .../vyos_interfaces/tests/httpapi/merged.yaml | 32 +++++++++++++++++++++ .../vyos_interfaces/tests/httpapi/replaced.yaml | 33 ++++++++++++++++++++++ .../targets/vyos_interfaces/vars/main.yaml | 2 ++ 11 files changed, 164 insertions(+) create mode 100644 tests/integration/targets/vyos_interfaces/aliases create mode 100644 tests/integration/targets/vyos_interfaces/defaults/main.yaml create mode 100644 tests/integration/targets/vyos_interfaces/tasks/httpapi.yaml create mode 100644 tests/integration/targets/vyos_interfaces/tasks/main.yaml create mode 100644 tests/integration/targets/vyos_interfaces/tests/httpapi/_populate_config.yaml create mode 100644 tests/integration/targets/vyos_interfaces/tests/httpapi/_remove_config.yaml create mode 100644 tests/integration/targets/vyos_interfaces/tests/httpapi/deleted.yaml create mode 100644 tests/integration/targets/vyos_interfaces/tests/httpapi/gathered.yaml create mode 100644 tests/integration/targets/vyos_interfaces/tests/httpapi/merged.yaml create mode 100644 tests/integration/targets/vyos_interfaces/tests/httpapi/replaced.yaml create mode 100644 tests/integration/targets/vyos_interfaces/vars/main.yaml (limited to 'tests/integration') diff --git a/tests/integration/targets/vyos_interfaces/aliases b/tests/integration/targets/vyos_interfaces/aliases new file mode 100644 index 0000000..cc0afef --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/aliases @@ -0,0 +1 @@ +network/vyos diff --git a/tests/integration/targets/vyos_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_interfaces/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/vyos_interfaces/tasks/httpapi.yaml b/tests/integration/targets/vyos_interfaces/tasks/httpapi.yaml new file mode 100644 index 0000000..4147e6d --- /dev/null +++ b/tests/integration/targets/vyos_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_interfaces/tasks/main.yaml b/tests/integration/targets/vyos_interfaces/tasks/main.yaml new file mode 100644 index 0000000..b1f6193 --- /dev/null +++ b/tests/integration/targets/vyos_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_interfaces/tests/httpapi/_populate_config.yaml b/tests/integration/targets/vyos_interfaces/tests/httpapi/_populate_config.yaml new file mode 100644 index 0000000..9562fce --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/httpapi/_populate_config.yaml @@ -0,0 +1,9 @@ +--- +- name: Populate interface config for testing + vyos.rest.vyos_interfaces: + config: + - name: eth0 + description: Ansible test interface + mtu: 1450 + state: merged + ignore_errors: true diff --git a/tests/integration/targets/vyos_interfaces/tests/httpapi/_remove_config.yaml b/tests/integration/targets/vyos_interfaces/tests/httpapi/_remove_config.yaml new file mode 100644 index 0000000..4014e56 --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/httpapi/_remove_config.yaml @@ -0,0 +1,7 @@ +--- +- name: Remove interface L2 config + vyos.rest.vyos_interfaces: + config: + - name: eth0 + state: deleted + ignore_errors: true diff --git a/tests/integration/targets/vyos_interfaces/tests/httpapi/deleted.yaml b/tests/integration/targets/vyos_interfaces/tests/httpapi/deleted.yaml new file mode 100644 index 0000000..e8dfd06 --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/httpapi/deleted.yaml @@ -0,0 +1,30 @@ +--- +- debug: + msg: START vyos_interfaces deleted integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Delete interface configuration + register: result + vyos.rest.vyos_interfaces: &id001 + config: + - name: eth0 + state: deleted + + - assert: + that: + - result.changed == true + + - name: Delete interface configuration (IDEMPOTENT) + register: result + vyos.rest.vyos_interfaces: *id001 + + - name: Assert idempotent + assert: + that: + - result.changed == false + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_interfaces/tests/httpapi/gathered.yaml b/tests/integration/targets/vyos_interfaces/tests/httpapi/gathered.yaml new file mode 100644 index 0000000..022e21e --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/httpapi/gathered.yaml @@ -0,0 +1,21 @@ +--- +- debug: + msg: START vyos_interfaces gathered integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Gather interface configuration + register: result + vyos.rest.vyos_interfaces: + state: gathered + + - assert: + that: + - result.changed == false + - result.gathered | selectattr('name', 'eq', 'eth0') | list | length == 1 + - result.gathered | selectattr('name', 'eq', 'eth0') | map(attribute='description') | first == 'Ansible test interface' + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_interfaces/tests/httpapi/merged.yaml b/tests/integration/targets/vyos_interfaces/tests/httpapi/merged.yaml new file mode 100644 index 0000000..b5a82ef --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/httpapi/merged.yaml @@ -0,0 +1,32 @@ +--- +- debug: + msg: START vyos_interfaces merged integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge interface configuration + register: result + vyos.rest.vyos_interfaces: &id001 + config: + - name: eth0 + description: Ansible test interface + mtu: 1450 + state: merged + + - assert: + that: + - result.changed == true + + - name: Merge 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 diff --git a/tests/integration/targets/vyos_interfaces/tests/httpapi/replaced.yaml b/tests/integration/targets/vyos_interfaces/tests/httpapi/replaced.yaml new file mode 100644 index 0000000..430b441 --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/httpapi/replaced.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: START vyos_interfaces replaced integration tests on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + - name: Replace interface configuration + register: result + vyos.rest.vyos_interfaces: &id001 + config: + - name: eth0 + description: Ansible replaced interface + mtu: 1400 + state: replaced + + - assert: + that: + - result.changed == true + + - name: Replace 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 diff --git a/tests/integration/targets/vyos_interfaces/vars/main.yaml b/tests/integration/targets/vyos_interfaces/vars/main.yaml new file mode 100644 index 0000000..4303881 --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/vars/main.yaml @@ -0,0 +1,2 @@ +--- +# only common vars here -- cgit v1.2.3