diff --git a/tests/integration/targets/vyos_command/tasks/main.yaml b/tests/integration/targets/vyos_command/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_command/tasks/main.yaml +++ b/tests/integration/targets/vyos_command/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_command/tasks/redirection.yaml b/tests/integration/targets/vyos_command/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_command/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_command/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_command/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..013d176 --- /dev/null +++ b/tests/integration/targets/vyos_command/tests/redirection/cli/shortname.yaml @@ -0,0 +1,41 @@ +--- +- debug: msg="START cli/shortname.yaml on connection={{ ansible_connection }}" + +- name: get output for single command + register: result + vyos.vyos.command: + commands: show version + +- assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: get output for multiple commands + register: result + vyos.vyos.command: + commands: + - show version + - show interfaces + +- assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout | length == 2 + +- name: Get output for multiple commands that call less explicitly + register: result + vyos.vyos.command: + commands: + - show hardware cpu detail + - show hardware mem + - show license +- assert: + that: + - result.changed == false + - result.stdout_lines is defined + - result.stdout_lines[2] | length >= 20 + +- debug: msg="END cli/shortname.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_config/tasks/main.yaml b/tests/integration/targets/vyos_config/tasks/main.yaml index 8d10ebb..684482c 100644 --- a/tests/integration/targets/vyos_config/tasks/main.yaml +++ b/tests/integration/targets/vyos_config/tasks/main.yaml @@ -1,8 +1,13 @@ --- - include: cli.yaml tags: - cli - include: cli_config.yaml tags: - cli_config + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_config/tasks/redirection.yaml b/tests/integration/targets/vyos_config/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_config/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..ac84154 --- /dev/null +++ b/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml @@ -0,0 +1,57 @@ +--- +- debug: msg="START cli/shortname.yaml on connection={{ ansible_connection }}" + +- name: setup- ensure interface is not present + vyos.vyos.config: + lines: delete interfaces loopback lo + +- name: setup- create interface + register: result + vyos.vyos.config: + lines: + - interfaces + - interfaces loopback lo + - interfaces loopback lo description test + +- name: Check that multiple duplicate lines collapse into a single commands + assert: + that: + - '{{ result.commands|length }} == 1' + +- name: Check that set is correctly prepended + assert: + that: + - result.commands[0] == 'set interfaces loopback lo description test' + +- name: configure config_check config command + register: result + vyos.vyos.config: + lines: delete interfaces loopback lo + +- assert: + that: + - result.changed == true + +- name: check config_check config command idempontent + register: result + vyos.vyos.config: + lines: delete interfaces loopback lo + +- assert: + that: + - result.changed == false + +- name: check multiple line config filter is working + register: result + vyos.vyos.config: + lines: + - set system login user esa level admin + - set system login user esa authentication encrypted-password '!abc!' + - set system login user vyos level admin + - set system login user vyos authentication encrypted-password 'abc' + +- assert: + that: + - '{{ result.filtered|length }} == 2' + +- debug: msg="END cli/shortname.yaml on connection={{ ansible_connection }}" diff --git a/tests/integration/targets/vyos_facts/tasks/main.yaml b/tests/integration/targets/vyos_facts/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_facts/tasks/main.yaml +++ b/tests/integration/targets/vyos_facts/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_facts/tasks/redirection.yaml b/tests/integration/targets/vyos_facts/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_facts/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_facts/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_facts/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..05399f1 --- /dev/null +++ b/tests/integration/targets/vyos_facts/tests/redirection/cli/shortname.yaml @@ -0,0 +1,42 @@ +--- +- name: get host name + register: vyos_host + vyos.vyos.command: + commands: + - show host name + +- name: get version info + register: vyos_version + vyos.vyos.command: + commands: + - show version + +- name: collect all facts from the device + register: result + vyos.vyos.facts: + gather_subset: all + +- name: check that hostname is present + assert: + that: + - result.ansible_facts.ansible_net_hostname == vyos_host.stdout[0] + +- name: check that subsets are present + assert: + that: + - "'neighbors' in result.ansible_facts.ansible_net_gather_subset" + - "'default' in result.ansible_facts.ansible_net_gather_subset" + - "'config' in result.ansible_facts.ansible_net_gather_subset" + +- name: check that version info is present + assert: + that: + - result.ansible_facts.ansible_net_version in vyos_version.stdout_lines[0][0] + - result.ansible_facts.ansible_net_model in vyos_version.stdout_lines[0][9] + - result.ansible_facts.ansible_net_serialnum in vyos_version.stdout_lines[0][10] + +- name: check that config info is present + assert: + that: + - result.ansible_facts.ansible_net_commits is defined + - result.ansible_facts.ansible_net_config is defined diff --git a/tests/integration/targets/vyos_firewall_global/tasks/main.yaml b/tests/integration/targets/vyos_firewall_global/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_firewall_global/tasks/main.yaml +++ b/tests/integration/targets/vyos_firewall_global/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_firewall_global/tasks/redirection.yaml b/tests/integration/targets/vyos_firewall_global/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_firewall_global/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_firewall_global/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..2a31413 --- /dev/null +++ b/tests/integration/targets/vyos_firewall_global/tests/redirection/cli/shortname.yaml @@ -0,0 +1,89 @@ +--- +- debug: + msg: START shortname integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.firewall_global: &id001 + config: + validation: strict + config_trap: true + log_martians: true + syn_cookies: true + twa_hazards_protection: true + ping: + all: true + broadcast: true + state_policy: + + - connection_type: established + action: accept + log: true + + - connection_type: invalid + action: reject + route_redirects: + + - afi: ipv4 + ip_src_route: true + icmp_redirects: + send: true + receive: false + group: + address_group: + + - name: MGMT-HOSTS + description: This group has the Management hosts address list + members: + + - address: 192.0.1.1 + + - address: 192.0.1.3 + + - address: 192.0.1.5 + network_group: + + - name: MGMT + description: This group has the Management network addresses + members: + + - address: 192.0.1.0/24 + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.firewall_global: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_interfaces/tasks/main.yaml b/tests/integration/targets/vyos_interfaces/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_interfaces/tasks/main.yaml +++ b/tests/integration/targets/vyos_interfaces/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_interfaces/tasks/redirection.yaml b/tests/integration/targets/vyos_interfaces/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_interfaces/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_interfaces/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..d2e501a --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/redirection/cli/shortname.yaml @@ -0,0 +1,67 @@ +--- +- debug: + msg: START shortname integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.interfaces: &id001 + config: + + - name: eth1 + description: Configured by Ansible - Interface 1 + mtu: 1500 + speed: auto + duplex: auto + vifs: + + - vlan_id: 100 + description: Eth1 - VIF 100 + mtu: 400 + + - vlan_id: 101 + description: Eth1 - VIF 101 + + - name: eth2 + description: Configured by Ansible - Interface 2 (ADMIN DOWN) + mtu: 600 + enabled: false + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/tasks/main.yaml b/tests/integration/targets/vyos_l3_interfaces/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_l3_interfaces/tasks/main.yaml +++ b/tests/integration/targets/vyos_l3_interfaces/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_l3_interfaces/tasks/redirection.yaml b/tests/integration/targets/vyos_l3_interfaces/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..33082d5 --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tests/redirection/cli/shortname.yaml @@ -0,0 +1,43 @@ +--- +- debug: + msg: START l3_interfaces rendered on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Structure provided configuration into device specific commands + register: result + vyos.vyos.l3_interfaces: &id001 + config: + - name: eth1 + ipv4: + - address: 192.0.2.14/24 + - name: eth2 + ipv4: + - address: 192.0.2.10/24 + - address: 192.0.2.11/24 + ipv6: + - address: 2001:db8::10/32 + - address: 2001:db8::12/32 + state: rendered + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\ + \ |length == 0 }}" + + - name: Structure provided configuration into device specific commands (IDEMPOTENT) + register: result + vyos.vyos.l3_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lag_interfaces/tasks/main.yaml b/tests/integration/targets/vyos_lag_interfaces/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_lag_interfaces/tasks/main.yaml +++ b/tests/integration/targets/vyos_lag_interfaces/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_lag_interfaces/tasks/redirection.yaml b/tests/integration/targets/vyos_lag_interfaces/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_lag_interfaces/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_lag_interfaces/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_lag_interfaces/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..be1cdc4 --- /dev/null +++ b/tests/integration/targets/vyos_lag_interfaces/tests/redirection/cli/shortname.yaml @@ -0,0 +1,69 @@ +--- +- debug: + msg: START lag_interfaces merged on connection={{ ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _remove_bond.yaml + +- include_tasks: _add_bond.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.lag_interfaces: &id001 + config: + + - name: bond0 + hash_policy: layer2 + mode: active-backup + members: + + - member: eth1 + primary: eth1 + + - name: bond1 + hash_policy: layer2+3 + mode: active-backup + members: + + - member: eth2 + primary: eth2 + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.lag_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tasks/main.yaml b/tests/integration/targets/vyos_lldp_interfaces/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tasks/main.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_lldp_interfaces/tasks/redirection.yaml b/tests/integration/targets/vyos_lldp_interfaces/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_lldp_interfaces/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..f43a8e8 --- /dev/null +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/redirection/cli/shortname.yaml @@ -0,0 +1,54 @@ +--- +- debug: + msg: START shortaname integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_intf.yaml + +- block: + - name: Overrides all device configuration with provided configuration + register: result + vyos.vyos.lldp_interfaces: &id001 + config: + + - name: eth2 + location: + elin: 0000000911 + state: overridden + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ populate_intf | symmetric_difference(result['before']) |length ==\ + \ 0 }}" + + - name: Assert that correct commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ |length == 0 }}" + + - name: Assert that after dicts were correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Overrides all device configuration with provided configurations (IDEMPOTENT) + register: result + vyos.vyos.lldp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/tasks/main.yaml b/tests/integration/targets/vyos_ospfv2/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_ospfv2/tasks/main.yaml +++ b/tests/integration/targets/vyos_ospfv2/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_ospfv2/tasks/redirection.yaml b/tests/integration/targets/vyos_ospfv2/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_ospfv2/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_ospfv2/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..ecaf4bd --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/redirection/cli/shortname.yaml @@ -0,0 +1,99 @@ +--- +- debug: + msg: START shortname integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.ospfv2: &id001 + config: + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + mpls_te: + enabled: true + router_address: '192.0.11.11' + auto_cost: + reference_bandwidth: 2 + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + redistribute: + - route_type: 'bgp' + metric: 10 + metric_type: 2 + passive_interface: + - 'eth1' + - 'eth2' + parameters: + router_id: '192.0.1.1' + opaque_lsa: true + rfc1583_compatibility: true + abr_type: 'cisco' + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '3' + area_type: + nssa: + set: true + - area_id: '4' + area_type: + stub: + default_cost: 20 + network: + - address: '192.0.2.0/24' + range: + - address: '192.0.3.0/24' + cost: 10 + - address: '192.0.4.0/24' + cost: 12 + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.ospfv2: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] == result['before'] }}" + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv3/tasks/main.yaml b/tests/integration/targets/vyos_ospfv3/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_ospfv3/tasks/main.yaml +++ b/tests/integration/targets/vyos_ospfv3/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_ospfv3/tasks/redirection.yaml b/tests/integration/targets/vyos_ospfv3/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_ospfv3/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_ospfv3/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_ospfv3/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..fdeeb89 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv3/tests/redirection/cli/shortname.yaml @@ -0,0 +1,61 @@ +--- +- debug: + msg: START shortname integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.ospfv3: &id001 + config: + areas: + - area_id: '2' + export_list: 'export1' + import_list: 'import1' + range: + - address: '2001:db10::/32' + - address: '2001:db20::/32' + - address: '2001:db30::/32' + - area_id: '3' + range: + - address: '2001:db40::/32' + parameters: + router_id: '192.0.2.10' + redistribute: + - route_type: 'bgp' + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.ospfv3: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] == result['before'] }}" + when: ansible_version.full is version('2.10.0', '>=') + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_static_routes/tasks/main.yaml b/tests/integration/targets/vyos_static_routes/tasks/main.yaml index a3db933..fb74fa1 100644 --- a/tests/integration/targets/vyos_static_routes/tasks/main.yaml +++ b/tests/integration/targets/vyos_static_routes/tasks/main.yaml @@ -1,4 +1,9 @@ --- - include: cli.yaml tags: - cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') + tags: + - redirection diff --git a/tests/integration/targets/vyos_static_routes/tasks/redirection.yaml b/tests/integration/targets/vyos_static_routes/tasks/redirection.yaml new file mode 100644 index 0000000..5564a3e --- /dev/null +++ b/tests/integration/targets/vyos_static_routes/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection/cli' + patterns: '{{ testcase }}.yaml' + register: shortname_test_cases + delegate_to: localhost + +- name: set test_items for redirection + set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_static_routes/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_static_routes/tests/redirection/cli/shortname.yaml new file mode 100644 index 0000000..08c22b9 --- /dev/null +++ b/tests/integration/targets/vyos_static_routes/tests/redirection/cli/shortname.yaml @@ -0,0 +1,76 @@ +--- +- debug: + msg: START shortname merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.static_routes: &id001 + config: + + - address_families: + + - afi: ipv4 + routes: + + - dest: 192.0.2.32/28 + blackhole_config: + type: blackhole + next_hops: + + - forward_router_address: 192.0.2.10 + + - forward_router_address: 192.0.2.9 + + - address_families: + + - afi: ipv6 + routes: + + - dest: 2001:db8:1000::/36 + blackhole_config: + distance: 2 + next_hops: + + - forward_router_address: 2001:db8:2000:2::1 + + - forward_router_address: 2001:db8:2000:2::2 + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.static_routes: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + - include_tasks: _remove_config.yaml