diff options
author | Sumit Jaiswal <sjaiswal@redhat.com> | 2020-02-28 18:29:17 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 18:29:17 +0530 |
commit | 4c0eb4396b5665cb940d85f9557fc128e2b953bb (patch) | |
tree | f601157b4acedac237b9e529a42118d782839964 /test/integration | |
parent | 6629b9feefddd0c289f508fe7cc915ca26dc483b (diff) | |
download | ansible-4c0eb4396b5665cb940d85f9557fc128e2b953bb.tar.gz |
Resource module for IOS static routes (#64632)
* ios_static_routes
Diffstat (limited to 'test/integration')
16 files changed, 613 insertions, 0 deletions
diff --git a/test/integration/targets/ios_static_routes/defaults/main.yaml b/test/integration/targets/ios_static_routes/defaults/main.yaml new file mode 100644 index 0000000000..164afead28 --- /dev/null +++ b/test/integration/targets/ios_static_routes/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/test/integration/targets/ios_static_routes/meta/main.yaml b/test/integration/targets/ios_static_routes/meta/main.yaml new file mode 100644 index 0000000000..32cf5dda7e --- /dev/null +++ b/test/integration/targets/ios_static_routes/meta/main.yaml @@ -0,0 +1 @@ +dependencies: [] diff --git a/test/integration/targets/ios_static_routes/tasks/cli.yaml b/test/integration/targets/ios_static_routes/tasks/cli.yaml new file mode 100644 index 0000000000..337e34133b --- /dev/null +++ b/test/integration/targets/ios_static_routes/tasks/cli.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + delegate_to: localhost + +- name: Run test case (connection=network_cli) + include: "{{ test_case_to_run }}" + vars: + ansible_connection: network_cli + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/ios_static_routes/tasks/main.yaml b/test/integration/targets/ios_static_routes/tasks/main.yaml new file mode 100644 index 0000000000..415c99d8b1 --- /dev/null +++ b/test/integration/targets/ios_static_routes/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/test/integration/targets/ios_static_routes/tests/cli/_intial_setup_config.yaml b/test/integration/targets/ios_static_routes/tests/cli/_intial_setup_config.yaml new file mode 100644 index 0000000000..a6b390ad04 --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/_intial_setup_config.yaml @@ -0,0 +1,13 @@ +--- +- name: Intitial Setup Config + cli_config: + config: "{{ lines }}" + vars: + lines: | + vrf definition ansible_temp_vrf + address-family ipv4 + ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150 + ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3 + ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2 + ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast + ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6 diff --git a/test/integration/targets/ios_static_routes/tests/cli/_populate_config.yaml b/test/integration/targets/ios_static_routes/tests/cli/_populate_config.yaml new file mode 100644 index 0000000000..e6275cc7e2 --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/_populate_config.yaml @@ -0,0 +1,11 @@ +--- +- name: Populate Config + cli_config: + config: "{{ lines }}" + vars: + lines: | + ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150 + ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3 + ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2 + ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast + ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6 diff --git a/test/integration/targets/ios_static_routes/tests/cli/_remove_config.yaml b/test/integration/targets/ios_static_routes/tests/cli/_remove_config.yaml new file mode 100644 index 0000000000..acfd6cc8e5 --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/_remove_config.yaml @@ -0,0 +1,12 @@ +--- +- name: Remove Config + cli_config: + config: "{{ lines }}" + vars: + lines: | + no ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150 + no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3 + no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2 + no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast + no ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6 + no vrf definition ansible_temp_vrf diff --git a/test/integration/targets/ios_static_routes/tests/cli/deleted.yaml b/test/integration/targets/ios_static_routes/tests/cli/deleted.yaml new file mode 100644 index 0000000000..2d3967b129 --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/deleted.yaml @@ -0,0 +1,66 @@ +--- +- debug: + msg: "Start Deleted integration state for ios_static_routes ansible_connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _intial_setup_config.yaml + +- block: + - name: Delete attributes of provided configured interfaces + ios_static_routes: &deleted + config: + - vrf: ansible_temp_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.0/24 + next_hops: + - forward_router_address: 192.0.2.1 + name: test_vrf + tag: 50 + track: 150 + - address_families: + - afi: ipv4 + routes: + - dest: 198.51.100.0/24 + next_hops: + - forward_router_address: 198.51.101.1 + name: route_1 + distance_metric: 110 + tag: 40 + multicast: True + - forward_router_address: 198.51.101.2 + name: route_2 + distance_metric: 30 + - forward_router_address: 198.51.101.3 + name: route_3 + - afi: ipv6 + routes: + - dest: 2001:DB8:0:3::/64 + next_hops: + - forward_router_address: 2001:DB8:0:3::2 + name: test_v6 + tag: 105 + state: deleted + register: result + + - assert: + that: + - "result.commands|length == 5" + - "result.changed == true" + - "result.commands|symmetric_difference(deleted.commands) == []" + + - name: Delete attributes of all configured interfaces (IDEMPOTENT) + ios_static_routes: *deleted + register: result + + - name: Assert that the previous task was idempotent + assert: + that: + - "result.commands|length == 0" + - "result.changed == false" + + always: + - include_tasks: _populate_config.yaml + - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/ios_static_routes/tests/cli/empty_config.yaml b/test/integration/targets/ios_static_routes/tests/cli/empty_config.yaml new file mode 100644 index 0000000000..0cf39e734a --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/empty_config.yaml @@ -0,0 +1,58 @@ +--- +- debug: + msg: "START ios_static_routes empty_config.yaml integration tests on connection={{ ansible_connection }}" + +- name: Merged with empty config should give appropriate error message + ios_static_routes: + config: + state: merged + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty config should give appropriate error message + ios_static_routes: + config: + state: replaced + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty config should give appropriate error message + ios_static_routes: + config: + state: overridden + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Rendered with empty config should give appropriate error message + ios_static_routes: + config: + state: rendered + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' + +- name: Parsed with empty config should give appropriate error message + ios_static_routes: + running_config: + state: parsed + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' diff --git a/test/integration/targets/ios_static_routes/tests/cli/gathered.yaml b/test/integration/targets/ios_static_routes/tests/cli/gathered.yaml new file mode 100644 index 0000000000..4377f544d0 --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/gathered.yaml @@ -0,0 +1,22 @@ +--- +- debug: + msg: "START ios_static_routes gathered integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _intial_setup_config.yaml + +- block: + - name: Gather the provided configuration with the exisiting running configuration + ios_static_routes: &gathered + config: + state: gathered + register: result + + - name: Assert that gathered dicts was correctly generated + assert: + that: + - "result['changed'] == false" + + always: + - include_tasks: _remove_config.yaml
\ No newline at end of file diff --git a/test/integration/targets/ios_static_routes/tests/cli/merged.yaml b/test/integration/targets/ios_static_routes/tests/cli/merged.yaml new file mode 100644 index 0000000000..26825412ca --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/merged.yaml @@ -0,0 +1,66 @@ +--- +- debug: + msg: "START Merged ios_static_routes state for integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _intial_setup_config.yaml + +- block: + - name: Merge provided configuration with device configuration + ios_static_routes: &merged + config: + - vrf: ansible_temp_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.0/24 + next_hops: + - forward_router_address: 192.0.2.1 + name: merged_vrf + tag: 50 + track: 150 + - address_families: + - afi: ipv4 + routes: + - dest: 198.51.100.0/24 + next_hops: + - forward_router_address: 198.51.101.1 + name: merged_route_1 + distance_metric: 110 + tag: 40 + multicast: True + - forward_router_address: 198.51.101.2 + name: merged_route_2 + distance_metric: 30 + - forward_router_address: 198.51.101.3 + name: merged_route_3 + - afi: ipv6 + routes: + - dest: 2001:DB8:0:3::/64 + next_hops: + - forward_router_address: 2001:DB8:0:3::2 + name: merged_v6 + tag: 105 + state: merged + register: result + + - assert: + that: + - "result.commands|length == 5" + - "result.changed == true" + - "result.commands|symmetric_difference(merged.commands) == []" + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + ios_static_routes: *merged + register: result + + - name: Assert that the previous task was idempotent + assert: + that: + - "result.commands|length == 0" + - "result['changed'] == false" + + always: + - include_tasks: _populate_config.yaml + - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/ios_static_routes/tests/cli/overridden.yaml b/test/integration/targets/ios_static_routes/tests/cli/overridden.yaml new file mode 100644 index 0000000000..02b6acb6a8 --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/overridden.yaml @@ -0,0 +1,58 @@ +--- +- debug: + msg: "START Overridden ios_static_routes state for integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _intial_setup_config.yaml + +- block: + - name: Override device configuration of all interfaces with provided configuration + ios_static_routes: &overridden + config: + - vrf: ansible_temp_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.0/24 + next_hops: + - forward_router_address: 192.0.2.1 + name: override_vrf + tag: 50 + track: 150 + - address_families: + - afi: ipv4 + routes: + - dest: 198.51.100.0/24 + next_hops: + - forward_router_address: 198.51.101.3 + name: override_route + - afi: ipv6 + routes: + - dest: 2001:DB8:0:3::/64 + next_hops: + - forward_router_address: 2001:DB8:0:3::2 + name: override_v6 + tag: 175 + state: overridden + register: result + + - assert: + that: + - "result.commands|length == 8" + - "result.changed == true" + - "result.commands|symmetric_difference(overridden.commands) == []" + + - name: Override device configuration of all interfaces with provided configuration (IDEMPOTENT) + ios_static_routes: *overridden + register: result + + - name: Assert that task was idempotent + assert: + that: + - "result.commands|length == 0" + - "result['changed'] == false" + + always: + - include_tasks: _populate_config.yaml + - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/ios_static_routes/tests/cli/rendered.yaml b/test/integration/targets/ios_static_routes/tests/cli/rendered.yaml new file mode 100644 index 0000000000..9805efebaf --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/rendered.yaml @@ -0,0 +1,54 @@ +--- +- debug: + msg: "START ios_static_routes rendered integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _intial_setup_config.yaml + +- block: + - name: Rendered the provided configuration with the exisiting running configuration + ios_static_routes: &rendered + config: + - vrf: ansible_temp_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.0/24 + next_hops: + - forward_router_address: 192.0.2.1 + name: test_vrf + tag: 50 + track: 150 + - address_families: + - afi: ipv4 + routes: + - dest: 198.51.100.0/24 + next_hops: + - forward_router_address: 198.51.101.1 + name: route_1 + distance_metric: 110 + tag: 40 + multicast: True + - forward_router_address: 198.51.101.2 + name: route_2 + distance_metric: 30 + - forward_router_address: 198.51.101.3 + name: route_3 + - afi: ipv6 + routes: + - dest: 2001:DB8:0:3::/64 + next_hops: + - forward_router_address: 2001:DB8:0:3::2 + name: test_v6 + tag: 105 + state: rendered + register: result + + - assert: + that: + - "result.changed == false" + - "result.rendered|symmetric_difference(rendered.commands) == []" + + always: + - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/ios_static_routes/tests/cli/replaced.yaml b/test/integration/targets/ios_static_routes/tests/cli/replaced.yaml new file mode 100644 index 0000000000..b7e7badfed --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/replaced.yaml @@ -0,0 +1,61 @@ +--- +- debug: + msg: "START Replaced ios_static_routes state for integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _intial_setup_config.yaml + +- block: + - name: Replaces device configuration of listed interfaces with provided configuration + ios_static_routes: &replaced + config: + - vrf: ansible_temp_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.0/24 + next_hops: + - forward_router_address: 192.0.2.1 + name: replaced_vrf + tag: 75 + track: 155 + - address_families: + - afi: ipv4 + routes: + - dest: 198.51.100.0/24 + next_hops: + - forward_router_address: 198.51.101.1 + name: replaced_route + distance_metric: 175 + tag: 70 + multicast: True + - afi: ipv6 + routes: + - dest: 2001:DB8:0:3::/64 + next_hops: + - forward_router_address: 2001:DB8:0:3::2 + name: replaced_v6 + tag: 110 + state: replaced + register: result + + - assert: + that: + - "result.commands|length == 7" + - "result.changed == true" + - "result.commands|symmetric_difference(replaced.commands) == []" + + - name: Replaces device configuration of listed interfaces with provided configuration (IDEMPOTENT) + ios_static_routes: *replaced + register: result + + - name: Assert that task was idempotent + assert: + that: + - "result.commands|length == 0" + - "result['changed'] == false" + + always: + - include_tasks: _populate_config.yaml + - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/ios_static_routes/tests/cli/rtt.yaml b/test/integration/targets/ios_static_routes/tests/cli/rtt.yaml new file mode 100644 index 0000000000..e8a5c6b151 --- /dev/null +++ b/test/integration/targets/ios_static_routes/tests/cli/rtt.yaml @@ -0,0 +1,78 @@ +--- +- debug: + msg: "START ios_static_routes round trip integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- block: + - name: Apply the provided configuration (base config) + ios_static_routes: + config: + - vrf: ansible_temp_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.0/24 + next_hops: + - forward_router_address: 192.0.2.1 + name: rtt_vrf + tag: 50 + track: 150 + - address_families: + - afi: ipv4 + routes: + - dest: 198.51.100.0/24 + next_hops: + - forward_router_address: 198.51.101.1 + name: rtt_route_1 + distance_metric: 110 + tag: 40 + multicast: True + state: merged + register: base_config + + - name: Gather static routes facts + ios_facts: + gather_subset: + - "!all" + - "!min" + gather_network_resources: + - static_routes + + - name: Apply the configuration which need to be reverted + ios_static_routes: + config: + - vrf: ansible_temp_vrf + address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.0/24 + next_hops: + - forward_router_address: 192.0.2.12 + name: new_rtt_vrf + tag: 10 + track: 150 + state: overridden + register: result + + - assert: + that: + - "result.commands|length == 2" + - "result.changed == true" + - "result.commands|symmetric_difference(rtt.override_commands) == []" + + - name: Revert back to base config using facts round trip + ios_static_routes: + config: "{{ ansible_facts['network_resources']['static_routes'] }}" + state: overridden + register: revert + + - assert: + that: + - "revert.commands|length == 1" + - "revert.changed == true" + - "revert.commands|symmetric_difference(rtt.override_revert_commands) == []" + + always: + - include_tasks: _populate_config.yaml + - include_tasks: _remove_config.yaml
\ No newline at end of file diff --git a/test/integration/targets/ios_static_routes/vars/main.yaml b/test/integration/targets/ios_static_routes/vars/main.yaml new file mode 100644 index 0000000000..30c67c56e9 --- /dev/null +++ b/test/integration/targets/ios_static_routes/vars/main.yaml @@ -0,0 +1,88 @@ +--- +deleted: + commands: + - "no ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name test_vrf track 150 tag 50" + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name route_1 tag 40" + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2" + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3" + - "no ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 name test_v6 tag 105" + +merged: + commands: + - "ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name merged_vrf track 150 tag 50" + - "ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name merged_route_1 tag 40" + - "ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name merged_route_2" + - "ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3" + - "ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 name merged_v6 tag 105" + +replaced: + commands: + - "no ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name test_vrf track 150 tag 50" + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name route_1 tag 40" + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2" + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3" + - "ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name replaced_vrf track 155 tag 75" + - "ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 multicast name replaced_route tag 70" + - "ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 name replaced_v6 tag 110" + +overridden: + commands: + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name route_1 tag 40" + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2" + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3" + - "no ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name test_vrf track 150 tag 50" + - "no ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 name test_v6 tag 105" + - "ip route 198.51.100.0 255.255.255.0 198.51.101.3 name override_route" + - "ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name override_vrf track 150 tag 50" + - "ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 name override_v6 tag 175" + +rendered: + commands: + - "ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name test_vrf track 150 tag 50" + - "ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name route_1 tag 40" + - "ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2" + - "ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3" + - "ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 name test_v6 tag 105" + +gathered: + config: + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.0/24 + next_hops: + - forward_router_address: 192.0.2.1 + name: test_vrf + tag: 50 + track: 150 + vrf: ansible_temp_vrf + - address_families: + - afi: ipv6 + routes: + - dest: 2001:DB8:0:3::/64 + next_hops: + - forward_router_address: 2001:DB8:0:3::2 + name: test_v6 + tag: 105 + - afi: ipv4 + routes: + - dest: 198.51.100.0/24 + next_hops: + - distance_metric: 110 + forward_router_address: 198.51.101.1 + multicast: true + name: route_1 + tag: 40 + - distance_metric: 30 + forward_router_address: 198.51.101.2 + name: route_2 + - forward_router_address: 198.51.101.3 + name: route_3 + +rtt: + override_commands: + - "no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name rtt_route_1 tag 40" + - "ip route vrf ansible_temp_vrf 192.0.2.0 255.255.255.0 192.0.2.12 name new_rtt_vrf track 150 tag 10" + + override_revert_commands: + - "ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name rtt_route_1 tag 40" |