diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
commit | a453ac31f3428614cceb99027f8efbdb9258a40b (patch) | |
tree | f61f87408f32a8511cbd91799f9cececb53e0374 /collections-debian-merged/ansible_collections/cisco/ios/tests | |
parent | Initial commit. (diff) | |
download | ansible-a453ac31f3428614cceb99027f8efbdb9258a40b.tar.xz ansible-a453ac31f3428614cceb99027f8efbdb9258a40b.zip |
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collections-debian-merged/ansible_collections/cisco/ios/tests')
528 files changed, 26857 insertions, 0 deletions
diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/.gitignore b/collections-debian-merged/ansible_collections/cisco/ios/tests/.gitignore new file mode 100644 index 00000000..ea1472ec --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/.gitignore @@ -0,0 +1 @@ +output/ diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/network-integration.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/network-integration.cfg new file mode 100644 index 00000000..d12c1efe --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/network-integration.cfg @@ -0,0 +1,4 @@ +[persistent_connection] +command_timeout = 100 +connect_timeout = 100 +connect_retry_timeout = 100 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/target-prefixes.network b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/target-prefixes.network new file mode 100644 index 00000000..d99afd61 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/target-prefixes.network @@ -0,0 +1 @@ +ios
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/_parsed.cfg new file mode 100644 index 00000000..1462c135 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/_parsed.cfg @@ -0,0 +1,8 @@ +interface GigabitEthernet0/1 +ip access-group 110 in +ip access-group 123 out +ipv6 traffic-filter temp_v6 in +ipv6 traffic-filter test_v6 out +interface GigabitEthernet0/2 +ip access-group 110 in +ip access-group 123 out diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..ad7ca4ac --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,9 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/1\nip access-group 110 in\nip access-group\ + \ 123 out\nipv6 traffic-filter temp_v6 in\nipv6 traffic-filter test_v6 out\n\ + interface GigabitEthernet 0/2\nip access-group 110 in\nip access-group 123\ + \ out\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..b5c69165 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,9 @@ +--- +- name: Remove Config + vars: + lines: "interface GigabitEthernet 0/1\nno ip access-group 110 in\nno ip access-group\ + \ 100 out\nno ip access-group 123 out\nno ipv6 traffic-filter temp_v6 in\n\ + no ipv6 traffic-filter test_v6 out\ninterface GigabitEthernet 0/2\nno ip access-group\ + \ 110 in\nno ip access-group 123 out\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..caa03991 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,39 @@ +--- +- debug: + msg: Start ios_acl_interfaces deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete module attributes of given Interface. + register: result + cisco.ios.ios_acl_interfaces: + config: + + - name: GigabitEthernet0/1 + state: deleted + + - assert: + that: + - result.commands|length == 5 + - result.changed == true + - result.commands|symmetric_difference(deleted.commands) == [] + + - name: Delete module attributes of given Interface (IDEMPOTENT) + register: result + cisco.ios.ios_acl_interfaces: + config: + + - name: GigabitEthernet0/1 + state: deleted + + - assert: + that: + - result.changed == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..1a931456 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START ios_acl_interfaces empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_acl_interfaces: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_acl_interfaces: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_acl_interfaces: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_acl_interfaces: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_acl_interfaces: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..56de45dd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,23 @@ +--- +- debug: + msg: START ios_acl_interfaces gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_acl_interfaces: + config: + state: gathered + + - name: Assert + assert: + that: + - gathered['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..93c8e409 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/merged.yaml @@ -0,0 +1,66 @@ +--- +- debug: + msg: Start ios_acl_interfaces merged integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_acl_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: 110 + direction: in + + - name: 123 + direction: out + + - afi: ipv6 + acls: + + - name: temp_v6 + direction: in + + - name: test_v6 + direction: out + + - name: GigabitEthernet0/2 + access_groups: + + - afi: ipv4 + acls: + + - name: 110 + direction: in + + - name: 123 + direction: out + state: merged + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(merged.commands) == [] + + - name: Merge the provided configuration with the exisiting running configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_acl_interfaces: *id001 + + - assert: + that: + - result.commands|length == 0 + - result.changed == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..7ccf928f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,47 @@ +--- +- debug: + msg: Start ios_acl_interfaces overridden integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _populate_config.yaml + +- block: + + - name: Override device configuration of all acl_interfaces with provided configuration + become: true + register: result + cisco.ios.ios_acl_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: 100 + direction: out + + - name: 110 + direction: in + state: overridden + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Override device configuration of all acl_interfaces with provided configuration + (IDEMPOTENT) + become: true + register: result + cisco.ios.ios_acl_interfaces: *id001 + + - assert: + that: + - result.commands|length == 0 + - result.changed == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..ded11455 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START ios_acl_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_acl_interfaces: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - parsed['config']|symmetric_difference(result.parsed) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..13c626eb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,51 @@ +--- +- debug: + msg: Start ios_acl_interfaces rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_acl_interfaces: + config: + + - name: GigabitEthernet0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: 110 + direction: in + + - name: 123 + direction: out + + - afi: ipv6 + acls: + + - name: test_v6 + direction: out + + - name: temp_v6 + direction: in + + - name: GigabitEthernet0/2 + access_groups: + + - afi: ipv4 + acls: + + - name: 110 + direction: in + + - name: 123 + direction: out + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..53c8cad7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,48 @@ +--- +- debug: + msg: Start ios_acl_interfaces replced integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces device configuration of listed acl_interfaces with provided + configuration + become: true + register: result + cisco.ios.ios_acl_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: 100 + direction: out + + - name: 110 + direction: in + state: replaced + + - assert: + that: + - result.commands|length == 5 + - result.changed == true + - result.commands|symmetric_difference(replaced.commands) == [] + + - name: Replaces device configuration of listed acl_interfaces with provided + configuration (IDEMPOTENT) + become: true + register: result + cisco.ios.ios_acl_interfaces: *id001 + + - assert: + that: + - result.commands|length == 0 + - result.changed == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..868600a2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,94 @@ +--- +- debug: + msg: START ios_acl_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: base_config + cisco.ios.ios_acl_interfaces: + config: + + - name: GigabitEthernet0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: 110 + direction: in + + - name: 123 + direction: out + + - afi: ipv6 + acls: + + - name: temp_v6 + direction: in + + - name: test_v6 + direction: out + + - name: GigabitEthernet0/2 + access_groups: + + - afi: ipv4 + acls: + + - name: 110 + direction: in + + - name: 123 + direction: out + state: merged + + - name: Gather acl interfaces facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - acl_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_acl_interfaces: + config: + + - name: GigabitEthernet0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: 100 + direction: out + + - name: 110 + direction: in + state: overridden + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_acl_interfaces: + config: "{{ ansible_facts['network_resources']['acl_interfaces'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 8 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/vars/main.yaml new file mode 100644 index 00000000..3ed2a0a1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acl_interfaces/vars/main.yaml @@ -0,0 +1,97 @@ +--- +interfaces: + int1: GigabitEthernet0/1 + int2: GigabitEthernet0/2 +merged: + commands: + - interface GigabitEthernet0/1 + - ip access-group 110 in + - ip access-group 123 out + - ipv6 traffic-filter temp_v6 in + - ipv6 traffic-filter test_v6 out + - interface GigabitEthernet0/2 + - ip access-group 110 in + - ip access-group 123 out +replaced: + commands: + - interface GigabitEthernet0/1 + - no ip access-group 123 out + - no ipv6 traffic-filter temp_v6 in + - no ipv6 traffic-filter test_v6 out + - ip access-group 100 out +overridden: + commands: + - interface GigabitEthernet0/1 + - no ip access-group 123 out + - no ipv6 traffic-filter test_v6 out + - no ipv6 traffic-filter temp_v6 in + - ip access-group 100 out + - interface GigabitEthernet0/2 + - no ip access-group 110 in + - no ip access-group 123 out +deleted: + commands: + - interface GigabitEthernet0/1 + - no ip access-group 110 in + - no ip access-group 123 out + - no ipv6 traffic-filter temp_v6 in + - no ipv6 traffic-filter test_v6 out +gathered: + config: + - name: GigabitEthernet0/0 + - access_groups: + - acls: + - direction: in + name: '110' + - direction: out + name: '123' + afi: ipv4 + - acls: + - direction: in + name: temp_v6 + - direction: out + name: test_v6 + afi: ipv6 + name: GigabitEthernet0/1 + - access_groups: + - acls: + - direction: in + name: '110' + - direction: out + name: '123' + afi: ipv4 + name: GigabitEthernet0/2 +parsed: + config: + - access_groups: + - acls: + - direction: in + name: '110' + - direction: out + name: '123' + afi: ipv4 + - acls: + - direction: in + name: temp_v6 + - direction: out + name: test_v6 + afi: ipv6 + name: GigabitEthernet0/1 + - access_groups: + - acls: + - direction: in + name: '110' + - direction: out + name: '123' + afi: ipv4 + name: GigabitEthernet0/2 +rtt: + commands: + - interface GigabitEthernet0/1 + - no ip access-group 100 out + - ip access-group 123 out + - ipv6 traffic-filter temp_v6 in + - ipv6 traffic-filter test_v6 out + - interface GigabitEthernet0/2 + - ip access-group 110 in + - ip access-group 123 out diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_parsed.cfg new file mode 100644 index 00000000..08a88445 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_parsed.cfg @@ -0,0 +1,9 @@ +Extended IP access list 110 + 10 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 +Extended IP access list 123 + 10 deny tcp 198.51.100.0 0.0.0.255 198.51.101.0 0.0.0.255 eq telnet ack tos 12 + 20 deny tcp 192.0.3.0 0.0.0.255 192.0.4.0 0.0.0.255 eq www ack dscp ef ttl lt 20 +Extended IP access list test_acl + 10 deny tcp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 eq www fin option traceroute ttl eq 10 +IPv6 access list R1_TRAFFIC + deny tcp any eq www any eq telnet ack dscp af11 sequence 10
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..6bc193c3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_populate_config.yaml @@ -0,0 +1,12 @@ +--- +- name: Populate Config + vars: + lines: "ip access-list extended test_acl\ndeny tcp 192.0.2.0 0.0.0.255 192.0.3.0\ + \ 0.0.0.255 eq www fin option traceroute ttl eq 10\nip access-list extended\ + \ 110\ndeny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl\ + \ eq 10\nip access-list extended 123\ndeny tcp 198.51.100.0 0.0.0.255 198.51.101.0\ + \ 0.0.0.255 eq telnet ack tos 12\ndeny tcp 192.0.3.0 0.0.0.255 192.0.4.0 0.0.0.255\ + \ eq www ack dscp ef ttl lt 20\nipv6 access-list R1_TRAFFIC\ndeny tcp any\ + \ eq www any eq telnet ack dscp af11\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..1a9240db --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_remove_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Remove Config + vars: + lines: "no ip access-list standard std_acl\nno ip access-list extended test_acl\n\ + no ip access-list extended 110\nno ip access-list extended 123\nno ip access-list\ + \ extended 150\nno ipv6 access-list R1_TRAFFIC\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/deleted.yaml new file mode 100644 index 00000000..556f33ea --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/deleted.yaml @@ -0,0 +1,97 @@ +--- +- debug: + msg: Start Deleted integration state for ios_acls ansible_connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete attributes of provided configured ACLs + register: result + cisco.ios.ios_acls: &id001 + config: + - afi: ipv4 + acls: + - name: test_acl + - name: 110 + - afi: ipv6 + acls: + - name: R1_TRAFFIC + state: deleted + + - assert: + that: + - result.commands|length == 3 + - result.changed == true + - result.commands|symmetric_difference(deleted.commands) == [] + + - name: Delete configured ACLs (IDEMPOTENT) + register: result + cisco.ios.ios_acls: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.commands|length == 0 + - result.changed == false + + - include_tasks: _remove_config.yaml + + - include_tasks: _populate_config.yaml + + - name: Delete ACL attributes based on AFI + register: result + cisco.ios.ios_acls: &id002 + config: + + - afi: ipv4 + state: deleted + + - assert: + that: + - result.commands|length == 3 + - result.changed == true + - result.commands|symmetric_difference(deleted_afi.commands) == [] + + - name: Delete ACL attributes based on AFI + (IDEMPOTENT) + register: result + cisco.ios.ios_acls: *id002 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.commands|length == 0 + - result.changed == false + + - include_tasks: _remove_config.yaml + + - include_tasks: _populate_config.yaml + + - name: Delete ALL configured ACLs + register: result + cisco.ios.ios_acls: &id003 + state: deleted + + - assert: + that: + - result.commands|length == 4 + - result.changed == true + - result.commands|symmetric_difference(deleted_all.commands) == [] + + - name: Delete ALL configured ACLs + (IDEMPOTENT) + register: result + cisco.ios.ios_acls: *id003 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.commands|length == 0 + - result.changed == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/empty_config.yaml new file mode 100644 index 00000000..141e382f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START ios_acls empty_config.yaml integration tests on connection={{ ansible_connection + }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_acls: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_acls: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_acls: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_acls: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_acls: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/gathered.yaml new file mode 100644 index 00000000..bc7a5a32 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START ios_acls gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_acls: + config: + state: gathered + + - assert: + that: + - gathered['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/merged.yaml new file mode 100644 index 00000000..38f05d39 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/merged.yaml @@ -0,0 +1,142 @@ +--- +- debug: + msg: START Merged ios_acls state for integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge initial config with device configuration + cisco.ios.ios_acls: + config: + - afi: ipv4 + acls: + - name: test_acl + acl_type: extended + aces: + - grant: deny + protocol_options: + tcp: + fin: true + source: + address: 192.0.2.0 + wildcard_bits: 0.0.0.255 + destination: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: www + option: + traceroute: true + ttl: + eq: 10 + state: merged + + - name: Merge new configuration with existing device configuration + register: result + cisco.ios.ios_acls: &id001 + config: + - afi: ipv4 + acls: + - name: std_acl + acl_type: standard + aces: + - grant: deny + source: + address: 192.0.2.0 + wildcard_bits: 0.0.0.255 + - name: test_acl + acl_type: extended + aces: + - sequence: 10 + source: + address: 192.0.4.0 + wildcard_bits: 0.0.0.255 + destination: + address: 192.0.5.0 + wildcard_bits: 0.0.0.255 + - name: 110 + aces: + - grant: deny + sequence: 10 + protocol_options: + icmp: + echo: true + source: + address: 192.0.2.0 + wildcard_bits: 0.0.0.255 + destination: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + dscp: ef + ttl: + eq: 10 + - name: 123 + aces: + - grant: deny + protocol_options: + tcp: + ack: true + source: + address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + destination: + address: 198.51.101.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + tos: + service_value: 12 + - grant: deny + protocol_options: + tcp: + ack: true + source: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + destination: + address: 192.0.4.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: www + dscp: ef + ttl: + lt: 20 + - afi: ipv6 + acls: + - name: R1_TRAFFIC + aces: + + - grant: deny + protocol_options: + tcp: + ack: true + source: + any: true + port_protocol: + eq: www + destination: + any: true + port_protocol: + eq: telnet + dscp: af11 + state: merged + + - assert: + that: + - result.commands|length == 12 + - result.changed == true + - result.commands|symmetric_difference(merged.commands) == [] + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_acls: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.commands|length == 0 + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/overridden.yaml new file mode 100644 index 00000000..988aff8d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/overridden.yaml @@ -0,0 +1,82 @@ +--- +- debug: + msg: START Overridden ios_acls state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Override device configuration of all interfaces with provided configuration + register: result + cisco.ios.ios_acls: &id001 + config: + + - afi: ipv4 + acls: + + - name: 110 + aces: + + - grant: deny + protocol_options: + tcp: + ack: true + sequence: 10 + source: + address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + destination: + address: 198.51.110.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: www + dscp: ef + ttl: + eq: 10 + + - name: 150 + aces: + + - grant: deny + protocol_options: + tcp: + syn: true + source: + address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + destination: + address: 198.51.110.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + dscp: ef + ttl: + eq: 10 + state: overridden + + - 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) + register: result + cisco.ios.ios_acls: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result.commands|length == 0 + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/parsed.yaml new file mode 100644 index 00000000..a1b1d9d8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START ios_acls parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_acls: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - gathered['config']|symmetric_difference(result.parsed) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/rendered.yaml new file mode 100644 index 00000000..2c03bf73 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/rendered.yaml @@ -0,0 +1,61 @@ +--- +- debug: + msg: Start ios_acls rendered integration tests ansible_connection={{ ansible_connection + }} + +- block: + + - name: Rendered the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_acls: + config: + + - afi: ipv4 + acls: + + - name: 110 + aces: + + - grant: deny + sequence: 10 + protocol_options: + tcp: + syn: true + source: + address: 192.0.2.0 + wildcard_bits: 0.0.0.255 + destination: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: www + dscp: ef + ttl: + eq: 10 + + - name: 150 + aces: + + - grant: deny + protocol_options: + tcp: + syn: true + source: + address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + destination: + address: 198.51.110.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + dscp: ef + ttl: + eq: 10 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(rendered.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/replaced.yaml new file mode 100644 index 00000000..7150f90f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/replaced.yaml @@ -0,0 +1,81 @@ +--- +- debug: + msg: START Replaced ios_acls state for integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces device configuration of listed interfaces with provided configuration + register: result + cisco.ios.ios_acls: &id001 + config: + + - afi: ipv4 + acls: + + - name: 110 + aces: + + - grant: deny + protocol_options: + tcp: + syn: true + sequence: 10 + source: + address: 192.0.2.0 + wildcard_bits: 0.0.0.255 + destination: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: www + dscp: ef + ttl: + eq: 10 + + - name: 150 + aces: + + - grant: deny + sequence: 20 + protocol_options: + tcp: + syn: true + source: + address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + destination: + address: 198.51.110.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + dscp: ef + ttl: + eq: 10 + state: replaced + + - assert: + that: + - result.commands|length == 5 + - result.changed == true + - result.commands|symmetric_difference(replaced.commands) == [] + + - name: Replaces device configuration of listed interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_acls: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result.commands|length == 0 + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/rtt.yaml new file mode 100644 index 00000000..b2fdd39a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/rtt.yaml @@ -0,0 +1,192 @@ +--- +- debug: + msg: START ios_acls round trip integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Apply the provided configuration (base config) + register: base_config + cisco.ios.ios_acls: + config: + + - afi: ipv4 + acls: + + - name: test_acl + acl_type: extended + aces: + + - grant: deny + protocol_options: + tcp: + fin: true + source: + address: 192.0.2.0 + wildcard_bits: 0.0.0.255 + destination: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: www + option: + traceroute: true + ttl: + eq: 10 + + - name: 110 + aces: + + - grant: deny + protocol_options: + icmp: + echo: true + source: + address: 192.0.2.0 + wildcard_bits: 0.0.0.255 + destination: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + dscp: ef + ttl: + eq: 10 + + - name: 123 + aces: + + - grant: deny + protocol_options: + tcp: + ack: true + source: + address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + destination: + address: 198.51.101.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + tos: + service_value: 12 + + - grant: deny + protocol_options: + tcp: + ack: true + source: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + destination: + address: 192.0.4.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: www + dscp: ef + ttl: + lt: 20 + + - afi: ipv6 + acls: + + - name: R1_TRAFFIC + aces: + + - grant: deny + protocol_options: + tcp: + ack: true + source: + any: true + port_protocol: + eq: www + destination: + any: true + port_protocol: + eq: telnet + dscp: af11 + state: merged + + - name: Gather ACLs facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - acls + + - name: Apply the configuration which need to be reverted + register: result + cisco.ios.ios_acls: + config: + + - afi: ipv4 + acls: + + - name: 110 + aces: + + - grant: deny + protocol_options: + tcp: + ack: true + sequence: 10 + source: + address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + destination: + address: 198.51.110.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: www + dscp: ef + ttl: + eq: 10 + + - name: 150 + aces: + + - grant: deny + protocol_options: + tcp: + syn: true + source: + address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + destination: + address: 198.51.110.0 + wildcard_bits: 0.0.0.255 + port_protocol: + eq: telnet + dscp: ef + ttl: + eq: 10 + state: overridden + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_acls: + config: "{{ ansible_facts['network_resources']['acls'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 11 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/vars/main.yaml new file mode 100644 index 00000000..7503cd82 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/vars/main.yaml @@ -0,0 +1,174 @@ +--- +deleted: + commands: + - no ip access-list extended test_acl + - no ip access-list extended 110 + - no ipv6 access-list R1_TRAFFIC +deleted_afi: + commands: + - no ip access-list extended 110 + - no ip access-list extended 123 + - no ip access-list extended test_acl +deleted_all: + commands: + - no ip access-list extended test_acl + - no ip access-list extended 110 + - no ip access-list extended 123 + - no ipv6 access-list R1_TRAFFIC +merged: + commands: + - ip access-list standard std_acl + - deny 192.0.2.0 0.0.0.255 + - ip access-list extended test_acl + - no 10 deny tcp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 eq www fin option traceroute ttl eq 10 + - 10 deny tcp 192.0.4.0 0.0.0.255 192.0.5.0 0.0.0.255 eq www fin option traceroute + ttl eq 10 + - ip access-list extended 110 + - 10 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 + - ip access-list extended 123 + - deny tcp 198.51.100.0 0.0.0.255 198.51.101.0 0.0.0.255 eq telnet ack tos 12 + - deny tcp 192.0.3.0 0.0.0.255 192.0.4.0 0.0.0.255 eq www ack dscp ef ttl lt 20 + - ipv6 access-list R1_TRAFFIC + - deny tcp any eq www any eq telnet ack dscp af11 +replaced: + commands: + - ip access-list extended 110 + - no 10 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 + - 10 deny tcp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 eq www syn dscp ef ttl eq 10 + - ip access-list extended 150 + - 20 deny tcp 198.51.100.0 0.0.0.255 eq telnet 198.51.110.0 0.0.0.255 eq telnet + syn dscp ef ttl eq 10 +overridden: + commands: + - no ip access-list extended 123 + - no ip access-list extended test_acl + - no ipv6 access-list R1_TRAFFIC + - ip access-list extended 110 + - no 10 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 + - 10 deny tcp 198.51.100.0 0.0.0.255 eq telnet 198.51.110.0 0.0.0.255 eq www ack + dscp ef ttl eq 10 + - ip access-list extended 150 + - deny tcp 198.51.100.0 0.0.0.255 eq telnet 198.51.110.0 0.0.0.255 eq telnet syn + dscp ef ttl eq 10 +gathered: + config: + - acls: + - aces: + - destination: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + dscp: ef + grant: deny + protocol: icmp + protocol_options: + icmp: + echo: true + sequence: 10 + source: + address: 192.0.2.0 + wildcard_bits: 0.0.0.255 + ttl: + eq: 10 + acl_type: extended + name: '110' + - aces: + - destination: + address: 198.51.101.0 + port_protocol: + eq: telnet + wildcard_bits: 0.0.0.255 + grant: deny + protocol: tcp + protocol_options: + tcp: + ack: true + sequence: 10 + source: + address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + tos: + service_value: 12 + - destination: + address: 192.0.4.0 + port_protocol: + eq: www + wildcard_bits: 0.0.0.255 + dscp: ef + grant: deny + protocol: tcp + protocol_options: + tcp: + ack: true + sequence: 20 + source: + address: 192.0.3.0 + wildcard_bits: 0.0.0.255 + ttl: + lt: 20 + acl_type: extended + name: '123' + - aces: + - destination: + address: 192.0.3.0 + port_protocol: + eq: www + wildcard_bits: 0.0.0.255 + grant: deny + option: + traceroute: true + protocol: tcp + protocol_options: + tcp: + fin: true + sequence: 10 + source: + address: 192.0.2.0 + wildcard_bits: 0.0.0.255 + ttl: + eq: 10 + acl_type: extended + name: test_acl + afi: ipv4 + - acls: + - aces: + - destination: + any: true + port_protocol: + eq: telnet + dscp: af11 + grant: deny + protocol: tcp + protocol_options: + tcp: + ack: true + sequence: 10 + source: + any: true + port_protocol: + eq: www + name: R1_TRAFFIC + afi: ipv6 +rendered: + commands: + - ip access-list extended 110 + - 10 deny tcp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 eq www syn dscp ef ttl eq + 10 + - ip access-list extended 150 + - deny tcp 198.51.100.0 0.0.0.255 eq telnet 198.51.110.0 0.0.0.255 eq telnet syn + dscp ef ttl eq 10 +rtt: + commands: + - no ip access-list extended 150 + - ip access-list extended 123 + - 10 deny tcp 198.51.100.0 0.0.0.255 198.51.101.0 0.0.0.255 eq telnet ack tos + 12 + - 20 deny tcp 192.0.3.0 0.0.0.255 192.0.4.0 0.0.0.255 eq www ack dscp ef ttl lt + 20 + - ip access-list extended test_acl + - 10 deny tcp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 eq www fin option traceroute + ttl eq 10 + - ip access-list extended 110 + - no 10 deny tcp 198.51.100.0 0.0.0.255 eq telnet 198.51.110.0 0.0.0.255 eq www ack dscp ef ttl eq 10 + - 10 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 + - ipv6 access-list R1_TRAFFIC + - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/meta/main.yml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/basic-login.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/basic-login.yaml new file mode 100644 index 00000000..c4cdc36f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/basic-login.yaml @@ -0,0 +1,36 @@ +--- +- name: setup - remove login + cisco.ios.ios_banner: + banner: login + state: absent + provider: '{{ cli }}' + +- name: Set login + register: result + cisco.ios.ios_banner: + banner: login + text: "this is my login banner\nthat has a multiline\nstring\n" + state: present + provider: '{{ cli }}' + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + - "'banner login @\nthis is my login banner\nthat has a multiline\nstring\n\ + @' in result.commands" + +- name: Set login again (idempotent) + register: result + cisco.ios.ios_banner: + banner: login + text: "this is my login banner\nthat has a multiline\nstring\n" + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/basic-motd.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/basic-motd.yaml new file mode 100644 index 00000000..c33c9cde --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/basic-motd.yaml @@ -0,0 +1,36 @@ +--- +- name: setup - remove motd + cisco.ios.ios_banner: + banner: motd + state: absent + provider: '{{ cli }}' + +- name: Set motd + register: result + cisco.ios.ios_banner: + banner: motd + text: "this is my motd banner\nthat has a multiline\nstring\n" + state: present + provider: '{{ cli }}' + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + - "'banner motd @\nthis is my motd banner\nthat has a multiline\nstring\n\ + @' in result.commands" + +- name: Set motd again (idempotent) + register: result + cisco.ios.ios_banner: + banner: motd + text: "this is my motd banner\nthat has a multiline\nstring\n" + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/basic-no-login.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/basic-no-login.yaml new file mode 100644 index 00000000..ef490cfd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/basic-no-login.yaml @@ -0,0 +1,34 @@ +--- +- name: Setup + cisco.ios.ios_banner: + banner: login + text: "Junk login banner\nover multiple lines\n" + state: present + provider: '{{ cli }}' + +- name: remove login + register: result + cisco.ios.ios_banner: + banner: login + state: absent + provider: '{{ cli }}' + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + - "'no banner login' in result.commands" + +- name: remove login (idempotent) + register: result + cisco.ios.ios_banner: + banner: login + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/multiple-login-exec.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/multiple-login-exec.yaml new file mode 100644 index 00000000..63441ebd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/multiple-login-exec.yaml @@ -0,0 +1,42 @@ +--- +- name: Setup - set login and exec + loop: + - login + - exec + cisco.ios.ios_banner: + banner: '{{ item }}' + text: "this is my login banner\nthat as a multiline\nstring\n" + state: present + provider: '{{ cli }}' + +- name: Set login + register: result + cisco.ios.ios_banner: + banner: login + text: "this is my login banner\nthat as a multiline\nstring\n" + state: present + provider: '{{ cli }}' + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 + +- name: Set exec + register: result + cisco.ios.ios_banner: + banner: exec + text: "this is my login banner\nthat as a multiline\nstring\n" + state: present + provider: '{{ cli }}' + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/net_banner.yml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/net_banner.yml new file mode 100644 index 00000000..a4345bba --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_banner/tests/cli/net_banner.yml @@ -0,0 +1,31 @@ +--- +- debug: msg="START ios cli/net_banner.yaml on connection={{ ansible_connection + }}" + +- name: setup - remove login + ansible.netcommon.net_banner: + banner: login + state: absent + authorize: true + +- name: Set login + register: result + ansible.netcommon.net_banner: + banner: login + text: this is my login banner confgiured by net_banner + state: present + authorize: true + +- assert: + that: + - result.changed == true + - "'banner login @\nthis is my login banner confgiured by net_banner\n@' in\ + \ result.commands" + +- name: teardown - remove login + ansible.netcommon.net_banner: + banner: login + state: absent + authorize: true + +- debug: msg="END ios cli/net_banner.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/tasks/cli.yaml new file mode 100644 index 00000000..a3aae347 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/tasks/cli.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/tests/cli/basic.yaml new file mode 100644 index 00000000..ea53f186 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp/tests/cli/basic.yaml @@ -0,0 +1,526 @@ +--- +- debug: msg="START ios cli/ios_bgp.yaml on connection={{ ansible_connection }}" + +- name: Clear existing BGP config + ignore_errors: true + cisco.ios.ios_bgp: + operation: delete + +- block: + + - name: Add fake config with 'bgp' string + cisco.ios.ios_config: + match: none + replace: block + lines: + - no ip access-list extended BGP_ACL + - ip access-list extended BGP_ACL + - permit tcp any any eq bgp + + - name: Try delete fake bgp config + register: result + cisco.ios.ios_bgp: + operation: delete + + - assert: + that: + - result.changed == false + + - name: Clean fake config with 'bgp' string + cisco.ios.ios_config: + match: none + replace: block + lines: + - no ip access-list extended BGP_ACL + + - name: Add fake bgp-like config + cisco.ios.ios_config: + match: none + replace: block + lines: + - no ip access-list extended BGP_ACL_2 + - ip access-list extended BGP_ACL_2 + - remark router bgp 64496 + - remark neighbor 192.0.2.10 remote-as 64496 + - remark neighbor 192.0.2.10 shutdown + - remark address-family ipv4 + - remark neighbor 192.0.2.10 activate + - remark exit-address-family + - permit tcp any any eq bgp + + - name: Try delete fake bgp-like config + register: result + cisco.ios.ios_bgp: + operation: delete + + - assert: + that: + - result.changed == false + + - name: Clean fake bgp-like config + cisco.ios.ios_config: + match: none + replace: block + lines: + - no ip access-list extended BGP_ACL_2 + + - name: Configure BGP with AS 64496 and a router-id + register: result + cisco.ios.ios_bgp: &id001 + operation: merge + config: + bgp_as: 64496 + router_id: 192.0.2.2 + + - assert: + that: + - result.changed == true + - "'router bgp 64496' in result.commands" + - "'bgp router-id 192.0.2.2' in result.commands" + + - name: Configure BGP with AS 64496 and a router-id (idempotent) + register: result + cisco.ios.ios_bgp: *id001 + + - assert: + that: + - result.changed == false + + - name: Configure BGP neighbors + register: result + cisco.ios.ios_bgp: &id002 + operation: merge + config: + bgp_as: 64496 + neighbors: + + - neighbor: 192.0.2.10 + remote_as: 64496 + password: ansible + description: IBGP_NBR_1 + ebgp_multihop: 100 + timers: + keepalive: 300 + holdtime: 360 + min_neighbor_holdtime: 360 + + - neighbor: 192.0.2.15 + remote_as: 64496 + description: IBGP_NBR_2 + ebgp_multihop: 150 + + - assert: + that: + - result.changed == true + - "'router bgp 64496' in result.commands" + - "'neighbor 192.0.2.10 remote-as 64496' in result.commands" + - "'neighbor 192.0.2.10 description IBGP_NBR_1' in result.commands" + - "'neighbor 192.0.2.10 ebgp-multihop 100' in result.commands" + - "'neighbor 192.0.2.10 timers 300 360 360' in result.commands" + - "'neighbor 192.0.2.15 remote-as 64496' in result.commands" + - "'neighbor 192.0.2.15 description IBGP_NBR_2' in result.commands" + - "'neighbor 192.0.2.15 ebgp-multihop 150' in result.commands" + + - name: Configure BGP neighbors (idempotent) + register: result + cisco.ios.ios_bgp: *id002 + + - assert: + that: + - result.changed == false + + - name: Configure BGP neighbors with operation replace + register: result + cisco.ios.ios_bgp: &id003 + operation: replace + config: + bgp_as: 64496 + neighbors: + + - neighbor: 192.0.2.15 + remote_as: 64496 + description: IBGP_NBR_2 + ebgp_multihop: 150 + + - neighbor: 203.0.113.10 + remote_as: 64511 + description: EBGP_NBR_1 + local_as: 64497 + + - neighbor: 10.10.20.20 + remote_as: 65012 + description: BGP_NBR_2 + ebgp_multihop: 100 + + - assert: + that: + - result.changed == true + - "'neighbor 203.0.113.10 remote-as 64511' in result.commands" + - "'neighbor 203.0.113.10 description EBGP_NBR_1' in result.commands" + - "'neighbor 203.0.113.10 local-as 64497' in result.commands" + - "'neighbor 10.10.20.20 remote-as 65012' in result.commands" + - "'neighbor 10.10.20.20 description BGP_NBR_2' in result.commands" + - "'no neighbor 192.0.2.10' in result.commands" + + - name: Configure BGP neighbors with operation replace (idempotent) + register: result + cisco.ios.ios_bgp: *id003 + + - assert: + that: + - result.changed == false + + - name: Configure root-level networks for BGP + register: result + cisco.ios.ios_bgp: &id004 + operation: merge + config: + bgp_as: 64496 + networks: + + - prefix: 203.0.113.0 + masklen: 27 + route_map: RMAP_1 + + - prefix: 203.0.113.32 + masklen: 27 + route_map: RMAP_2 + + - assert: + that: + - result.changed == True + - "'router bgp 64496' in result.commands" + - "'network 203.0.113.0 mask 255.255.255.224 route-map RMAP_1' in result.commands" + - "'network 203.0.113.32 mask 255.255.255.224 route-map RMAP_2' in result.commands" + + - name: Configure root-level networks for BGP (idempotent) + register: result + cisco.ios.ios_bgp: *id004 + + - assert: + that: + - result.changed == false + + - name: Configure root-level networks for BGP with operation replace + register: result + cisco.ios.ios_bgp: &id005 + operation: replace + config: + bgp_as: 64496 + networks: + + - prefix: 203.0.113.0 + masklen: 27 + route_map: RMAP_1 + + - prefix: 198.51.100.16 + masklen: 28 + + - assert: + that: + - result.changed == True + - "'router bgp 64496' in result.commands" + - "'network 198.51.100.16 mask 255.255.255.240' in result.commands" + - "'no network 203.0.113.32 mask 255.255.255.224 route-map RMAP_2' in\ + \ result.commands" + + - name: Configure root-level networks for BGP with operation replace (idempotent) + register: result + cisco.ios.ios_bgp: *id005 + + - assert: + that: + - result.changed == false + + - name: Configure BGP neighbors under address family mode + register: result + cisco.ios.ios_bgp: &id006 + operation: merge + config: + bgp_as: 64496 + address_family: + + - afi: ipv4 + safi: unicast + neighbors: + + - neighbor: 203.0.113.10 + activate: true + maximum_prefix: 250 + advertisement_interval: 120 + + - neighbor: 192.0.2.15 + activate: true + route_reflector_client: true + + - neighbor: 10.10.20.20 + activate: true + prefix_list_in: incoming-prefixes + prefix_list_out: outgoing-prefixes + + - assert: + that: + - result.changed == true + - "'router bgp 64496' in result.commands" + - "'address-family ipv4' in result.commands" + - "'neighbor 203.0.113.10 activate' in result.commands" + - "'neighbor 203.0.113.10 maximum-prefix 250' in result.commands" + - "'neighbor 203.0.113.10 advertisement-interval 120' in result.commands" + - "'neighbor 192.0.2.15 activate' in result.commands" + - "'neighbor 192.0.2.15 route-reflector-client' in result.commands" + - "'neighbor 10.10.20.20 activate' in result.commands" + - "'neighbor 10.10.20.20 prefix-list incoming-prefixes in' in result.commands" + - "'neighbor 10.10.20.20 prefix-list outgoing-prefixes out' in result.commands" + + - name: Configure BGP neighbors under address family mode (idempotent) + register: result + cisco.ios.ios_bgp: *id006 + + - assert: + that: + - result.changed == false + + - name: Configure networks under address family + register: result + cisco.ios.ios_bgp: &id007 + operation: merge + config: + bgp_as: 64496 + address_family: + + - afi: ipv4 + safi: multicast + networks: + + - prefix: 198.51.100.48 + masklen: 28 + route_map: RMAP_1 + + - prefix: 192.0.2.64 + masklen: 27 + + - prefix: 203.0.113.160 + masklen: 27 + route_map: RMAP_2 + + - afi: ipv4 + safi: unicast + networks: + + - prefix: 198.51.100.64 + masklen: 28 + + - assert: + that: + - result.changed == true + - "'router bgp 64496' in result.commands" + - "'address-family ipv4 multicast' in result.commands" + - "'network 198.51.100.48 mask 255.255.255.240 route-map RMAP_1' in result.commands" + - "'network 192.0.2.64 mask 255.255.255.224' in result.commands" + - "'network 203.0.113.160 mask 255.255.255.224 route-map RMAP_2' in result.commands" + - "'exit-address-family' in result.commands" + - "'address-family ipv4' in result.commands" + - "'network 198.51.100.64 mask 255.255.255.240' in result.commands" + - "'exit-address-family' in result.commands" + + - name: Configure networks under address family (idempotent) + register: result + cisco.ios.ios_bgp: *id007 + + - assert: + that: + - result.changed == false + + - name: Configure networks under address family with operation replace + register: result + cisco.ios.ios_bgp: &id008 + operation: replace + config: + bgp_as: 64496 + address_family: + + - afi: ipv4 + safi: multicast + networks: + + - prefix: 198.51.100.80 + masklen: 28 + + - prefix: 192.0.2.64 + masklen: 27 + + - prefix: 203.0.113.192 + masklen: 27 + + - afi: ipv4 + safi: unicast + networks: + + - prefix: 198.51.100.64 + masklen: 28 + + - assert: + that: + - result.changed == true + - '"router bgp 64496" in result.commands' + - '"address-family ipv4 multicast" in result.commands' + - '"network 198.51.100.80 mask 255.255.255.240" in result.commands' + - '"network 203.0.113.192 mask 255.255.255.224" in result.commands' + - '"no network 198.51.100.48 mask 255.255.255.240 route-map RMAP_1" in + result.commands' + - '"no network 203.0.113.160 mask 255.255.255.224 route-map RMAP_2" in + result.commands' + - '"exit-address-family" in result.commands' + + - name: Configure networks under address family with operation replace (idempotent) + register: result + cisco.ios.ios_bgp: *id008 + + - assert: + that: + - result.changed == false + + - name: Configure redistribute information under address family mode + register: result + cisco.ios.ios_bgp: &id009 + operation: merge + config: + bgp_as: 64496 + address_family: + + - afi: ipv4 + safi: multicast + redistribute: + + - protocol: ospf + id: 112 + metric: 64 + + - protocol: eigrp + id: 233 + metric: 256 + + - assert: + that: + - result.changed == true + - "'router bgp 64496' in result.commands" + - "'address-family ipv4 multicast' in result.commands" + - "'redistribute ospf 112 metric 64' in result.commands" + - "'redistribute eigrp 233 metric 256' in result.commands" + - "'exit-address-family' in result.commands" + + - name: Configure redistribute information under address family mode (idempotent) + register: result + cisco.ios.ios_bgp: *id009 + + - assert: + that: + - result.changed == false + + - name: Get the IOS version + cisco.ios.ios_facts: + gather_subset: all + + - name: Configure redistribute information under address family mode with operation + replace + register: result + cisco.ios.ios_bgp: &id010 + operation: replace + config: + bgp_as: 64496 + address_family: + + - afi: ipv4 + safi: multicast + redistribute: + + - protocol: ospf + id: 112 + metric: 64 + + - assert: + that: + - result.changed == true + - "'router bgp 64496' in result.commands" + - "'address-family ipv4 multicast' in result.commands" + - "'no redistribute eigrp 233' in result.commands" + - "'exit-address-family' in result.commands" + + - name: Configure redistribute information under address family mode with operation + replace (idempotent) + register: result + when: ansible_net_version != "15.6(2)T" + cisco.ios.ios_bgp: *id010 + + - assert: + that: + - result.changed == false + when: ansible_net_version != "15.6(2)T" + + - name: Override all the exisiting BGP config + register: result + cisco.ios.ios_bgp: + operation: override + config: + bgp_as: 64497 + router_id: 192.0.2.10 + log_neighbor_changes: true + + - assert: + that: + - result.changed == true + - "'no router bgp 64496' in result.commands" + - "'router bgp 64497' in result.commands" + - "'bgp router-id 192.0.2.10' in result.commands" + - "'bgp log-neighbor-changes' in result.commands" + + - name: Configure BGP neighbors with classful boundary + register: result + cisco.ios.ios_bgp: &id011 + config: + bgp_as: 64497 + log_neighbor_changes: true + networks: + + - prefix: 198.51.100.0 + masklen: 23 + + - prefix: 201.0.113.32 + masklen: 24 + operation: merge + + - assert: + that: + - result.changed == true + - "'router bgp 64497' in result.commands" + - "'network 198.51.100.0 mask 255.255.254.0' in result.commands" + - "'network 201.0.113.32' in result.commands" + + - name: Configure BGP neighbors with classful boundary (idempotent) + register: result + cisco.ios.ios_bgp: *id011 + + - assert: + that: + - result.changed == false + always: + + - name: Teardown + register: result + cisco.ios.ios_bgp: &id012 + operation: delete + + - assert: + that: + - result.changed == true + - "'no router bgp 64497' in result.commands" + + - name: Teardown again (idempotent) + register: result + cisco.ios.ios_bgp: *id012 + + - assert: + that: + - result.changed == false + +- debug: msg="END ios cli/ios_bgp.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/_parsed.cfg new file mode 100644 index 00000000..6be7fad0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/_parsed.cfg @@ -0,0 +1,13 @@ +router bgp 65000 + bgp nopeerup-delay post-boot 10 + bgp graceful-shutdown all neighbors 50 local-preference 100 community 100 + bgp bestpath compare-routerid + bgp dampening 1 1 1 1 + bgp advertise-best-external + bgp log-neighbor-changes + timers bgp 100 200 150 + redistribute connected metric 10 + neighbor 198.51.100.1 remote-as 100 + neighbor 198.51.100.1 description merge neighbor + neighbor 198.51.100.1 aigp send cost-community 100 poi igp-cost transitive + neighbor 198.51.100.1 route-map test-route out
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..bb50abd6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/_populate_config.yaml @@ -0,0 +1,44 @@ +--- +- name: Populate BGP Global Configuration + cisco.ios.ios_bgp_global: + config: + as_number: 65000 + bgp: + advertise_best_external: true + bestpath: + - compare_routerid: true + dampening: + penalty_half_time: 1 + reuse_route_val: 1 + suppress_route_val: 1 + max_suppress: 1 + graceful_shutdown: + neighbors: + time: 50 + community: 100 + local_preference: 100 + log_neighbor_changes: true + nopeerup_delay: + - post_boot: 10 + neighbor: + - address: 198.51.100.1 + description: merge neighbor + remote_as: 100 + aigp: + send: + cost_community: + id: 100 + poi: + igp_cost: true + transitive: true + route_map: + name: test-route + out: true + redistribute: + - connected: + metric: 10 + timers: + keepalive: 100 + holdtime: 200 + min_holdtime: 150 + state: merged diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..d857052b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/_remove_config.yaml @@ -0,0 +1,4 @@ +--- +- name: Remove BGP Global Config + cisco.ios.ios_bgp_global: + state: purged diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/deleted.yaml new file mode 100644 index 00000000..c1273f59 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/deleted.yaml @@ -0,0 +1,40 @@ +--- +- debug: + msg: Start Deleted integration state for ios_bgp_global ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete provided BGP Global + register: result + cisco.ios.ios_bgp_global: &id001 + config: + as_number: 65000 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that after dicts are correctly generated + assert: + that: + - deleted['after'] == result['after'] + + - name: Delete provided BGP Global (IDEMPOTENT) + register: result + cisco.ios.ios_bgp_global: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/empty_config.yaml new file mode 100644 index 00000000..fea162f1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START ios_bgp_global empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_bgp_global: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_bgp_global: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_bgp_global: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_bgp_global: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_bgp_global: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/gathered.yaml new file mode 100644 index 00000000..bbf39bc9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/gathered.yaml @@ -0,0 +1,25 @@ +--- +- debug: + msg: START ios_bgp_global gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_bgp_global: + config: + state: gathered + + - name: Assert + assert: + that: + - result.changed == false + - merged['after'] == result['gathered'] + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/merged.yaml new file mode 100644 index 00000000..23dae8c6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/merged.yaml @@ -0,0 +1,81 @@ +--- +- debug: + msg: START Merged ios_bgp_global state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_bgp_global: &id001 + config: + as_number: 65000 + bgp: + advertise_best_external: true + bestpath: + - compare_routerid: true + dampening: + penalty_half_time: 1 + reuse_route_val: 1 + suppress_route_val: 1 + max_suppress: 1 + graceful_shutdown: + neighbors: + time: 50 + community: 100 + local_preference: 100 + log_neighbor_changes: true + nopeerup_delay: + - post_boot: 10 + neighbor: + - address: 198.51.100.1 + description: merge neighbor + remote_as: 100 + aigp: + send: + cost_community: + id: 100 + poi: + igp_cost: true + transitive: true + route_map: + name: test-route + out: true + redistribute: + - connected: + metric: 10 + timers: + keepalive: 100 + holdtime: 200 + min_holdtime: 150 + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - merged['before'] == {} + + - name: Assert that after dict is correctly generated + assert: + that: + - merged['after'] == result['after'] + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_bgp_global: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/parsed.yaml new file mode 100644 index 00000000..5bf1d33c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/parsed.yaml @@ -0,0 +1,15 @@ +--- +- debug: + msg: START ios_bgp_global parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse the commands for provided configuration + register: result + cisco.ios.ios_bgp_global: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - merged['after'] == result['parsed'] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/purged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/purged.yaml new file mode 100644 index 00000000..7b676011 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/purged.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: Start Deleted integration state for ios_bgp_global ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Purge provided BGP Global + register: result + cisco.ios.ios_bgp_global: &id001 + state: purged + + - name: Assert that correct set of commands were generated + assert: + that: + - "'no router bgp 65000' in result.commands" + - result.commands|length == 1 + + - name: Purge provided BGP Global (IDEMPOTENT) + register: result + cisco.ios.ios_bgp_global: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/rendered.yaml new file mode 100644 index 00000000..5ae909f2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/rendered.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: Start ios_bgp_global rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + - name: Render the commands for provided configuration + register: result + cisco.ios.ios_bgp_global: &id001 + config: + as_number: 65000 + bgp: + advertise_best_external: true + bestpath: + - compare_routerid: true + dampening: + penalty_half_time: 1 + reuse_route_val: 1 + suppress_route_val: 1 + max_suppress: 1 + graceful_shutdown: + neighbors: + time: 50 + community: 100 + local_preference: 100 + log_neighbor_changes: true + nopeerup_delay: + - post_boot: 10 + neighbor: + - address: 198.51.100.1 + description: merge neighbor + remote_as: 100 + aigp: + send: + cost_community: + id: 100 + poi: + igp_cost: true + transitive: true + route_map: + name: test-route + out: true + redistribute: + - connected: + metric: 10 + timers: + keepalive: 100 + holdtime: 200 + min_holdtime: 150 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/replaced.yaml new file mode 100644 index 00000000..5881158e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/tests/cli/replaced.yaml @@ -0,0 +1,59 @@ +--- +- debug: + msg: START Replaced ios_bgp_global state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaced provided BGP Global configuration + register: result + cisco.ios.ios_bgp_global: &id001 + config: + as_number: 65000 + bgp: + advertise_best_external: true + bestpath: + - med: + confed: true + log_neighbor_changes: true + nopeerup_delay: + - post_boot: 10 + cold_boot: 20 + neighbor: + - address: 192.0.2.1 + description: replace neighbor + remote_as: 100 + slow_peer: + detection: + disable: true + redistribute: + - connected: + metric: 10 + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - replaced['after'] == result['after'] + + - name: Replaced provided BGP Global configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_bgp_global: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/vars/main.yaml new file mode 100644 index 00000000..fb80663f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_global/vars/main.yaml @@ -0,0 +1,117 @@ +--- +merged: + before: {} + + commands: + - router bgp 65000 + - bgp bestpath compare-routerid + - bgp nopeerup-delay post-boot 10 + - bgp dampening 1 1 1 1 + - timers bgp 100 200 150 + - bgp advertise-best-external + - neighbor 198.51.100.1 remote-as 100 + - bgp graceful-shutdown all neighbors 50 local-preference 100 community 100 + - bgp log-neighbor-changes + - neighbor 198.51.100.1 route-map test-route out + - neighbor 198.51.100.1 aigp send cost-community 100 poi igp-cost transitive + - neighbor 198.51.100.1 description merge neighbor + - redistribute connected metric 10 + + after: + as_number: "65000" + bgp: + advertise_best_external: true + bestpath: + - compare_routerid: true + dampening: + max_suppress: 1 + penalty_half_time: 1 + reuse_route_val: 1 + suppress_route_val: 1 + graceful_shutdown: + community: "100" + local_preference: 100 + neighbors: + time: 50 + log_neighbor_changes: true + nopeerup_delay: + - post_boot: 10 + neighbor: + - address: "198.51.100.1" + aigp: + send: + cost_community: + id: 100 + poi: + igp_cost: true + transitive: true + description: merge neighbor + remote_as: 100 + route_map: + name: test-route + out: true + redistribute: + - connected: + metric: 10 + timers: + holdtime: 200 + keepalive: 100 + min_holdtime: 150 + +replaced: + commands: + - router bgp 65000 + - no bgp dampening 1 1 1 1 + - no timers bgp 100 200 150 + - no bgp bestpath compare-routerid + - bgp bestpath med confed + - bgp nopeerup-delay cold-boot 20 + - no neighbor 198.51.100.1 remote-as 100 + - neighbor 192.0.2.1 remote-as 100 + - no bgp graceful-shutdown all neighbors 50 local-preference 100 community 100 + - no neighbor 198.51.100.1 route-map test-route out + - no neighbor 198.51.100.1 aigp send cost-community 100 poi igp-cost transitive + - no neighbor 198.51.100.1 description merge neighbor + - neighbor 192.0.2.1 slow-peer detection disable + - neighbor 192.0.2.1 description replace neighbor + + after: + as_number: "65000" + bgp: + advertise_best_external: true + bestpath: + - med: + confed: true + log_neighbor_changes: true + nopeerup_delay: + - cold_boot: 20 + - post_boot: 10 + neighbor: + - address: "192.0.2.1" + description: "replace neighbor" + remote_as: 100 + slow_peer: + detection: + disable: true + redistribute: + - connected: + metric: 10 + +deleted: + commands: + - router bgp 65000 + - no bgp bestpath compare-routerid + - no bgp nopeerup-delay post-boot 10 + - no bgp dampening 1 1 1 1 + - no timers bgp 100 200 150 + - no bgp advertise-best-external + - no neighbor 198.51.100.1 remote-as 100 + - no bgp graceful-shutdown all neighbors 50 local-preference 100 community 100 + - no bgp log-neighbor-changes + - no neighbor 198.51.100.1 route-map test-route out + - no neighbor 198.51.100.1 aigp send cost-community 100 poi igp-cost transitive + - no neighbor 198.51.100.1 description merge neighbor + - no redistribute connected metric 10 + + after: + as_number: "65000" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/meta/main.yml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/bad_operator.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/bad_operator.yaml new file mode 100644 index 00000000..7f98f1ff --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/bad_operator.yaml @@ -0,0 +1,21 @@ +--- +- debug: msg="START cli/bad_operator.yaml on connection={{ ansible_connection }}" + +- name: test bad operator + register: result + ignore_errors: true + cisco.ios.ios_command: + commands: + - show version + - show interfaces GigabitEthernet 0/0 + provider: '{{ cli }}' + wait_for: + + - "result[0] contains 'Description: Foo'" + +- assert: + that: + - result.failed == true + - result.msg is defined + +- debug: msg="END cli/bad_operator.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/cli_command.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/cli_command.yaml new file mode 100644 index 00000000..306128e2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/cli_command.yaml @@ -0,0 +1,29 @@ +--- +- debug: + msg: START cli/cli_command.yaml on connection={{ ansible_connection }} + +- block: + + - name: get output for single command + register: result + ansible.netcommon.cli_command: + command: show version + + - assert: + that: + - result.changed == false + - result.stdout is defined + + - name: send invalid command + register: result + ignore_errors: true + ansible.netcommon.cli_command: + command: show foo + + - assert: + that: + - result.failed == true + - result.msg is defined + when: ansible_connection == 'ansible.netcommon.network_cli' + +- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/contains.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/contains.yaml new file mode 100644 index 00000000..e0c01a51 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/contains.yaml @@ -0,0 +1,20 @@ +--- +- debug: msg="START cli/contains.yaml on connection={{ ansible_connection }}" + +- name: test contains operator + register: result + cisco.ios.ios_command: + commands: + - show version + - show interface loopback 888 + provider: '{{ cli }}' + wait_for: + - result[0] contains Cisco + - result[1] contains Loopback888 + +- assert: + that: + - result.changed == false + - result.stdout is defined + +- debug: msg="END cli/contains.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/error_regex.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/error_regex.yaml new file mode 100644 index 00000000..167e19bd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/error_regex.yaml @@ -0,0 +1,69 @@ +--- +- debug: msg="START cli/error_regex.yaml on connection={{ ansible_connection }}" + +- block: + + - name: clear logs 1 + ignore_errors: true + ansible.netcommon.cli_command: &id001 + command: clear logging + prompt: + - Clear logging buffer + answer: + - "\r" + + - name: increase log buffer size + ansible.netcommon.cli_config: + config: logging buffered 9600000 + + - name: send log with error regex match 1 + ignore_errors: true + ansible.netcommon.cli_command: &id002 + command: "send log 'IPSEC-3-REPLAY_ERROR: test log_1'\n" + + - name: pause to avoid rate limiting-1 + pause: + seconds: 20 + + - name: fetch logs without command specific error regex + register: result + ignore_errors: true + cisco.ios.ios_command: + commands: + - show logging + + - name: ensure task fails due to mismatched regex + assert: + that: + - result.failed == true + + - name: pause to avoid rate limiting-2 + pause: + seconds: 20 + + - name: clear logs 2 + ignore_errors: true + ansible.netcommon.cli_command: *id001 + + - name: send log with error regex match 2 + ignore_errors: true + ansible.netcommon.cli_command: *id002 + + - name: fetch logs with command specific error regex + register: result + vars: + ansible_terminal_stderr_re: + + - pattern: connection timed out + flags: re.I + cisco.ios.ios_command: + commands: + - show logging + + - name: ensure task with modified error regex is success + assert: + that: + - result.failed == false + when: ansible_connection == 'ansible.netcommon.network_cli' + +- debug: msg="END cli/error_regex.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/invalid.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/invalid.yaml new file mode 100644 index 00000000..d3f34b78 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/invalid.yaml @@ -0,0 +1,28 @@ +--- +- debug: msg="START cli/invalid.yaml on connection={{ ansible_connection }}" + +- name: run invalid command + register: result + ignore_errors: true + cisco.ios.ios_command: + commands: show foo + provider: '{{ cli }}' + +- assert: + that: + - result.failed + +- name: run commands that include invalid command + register: result + ignore_errors: true + cisco.ios.ios_command: + commands: + - show version + - show foo + provider: '{{ cli }}' + +- assert: + that: + - result.failed + +- debug: msg="END cli/invalid.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/output.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/output.yaml new file mode 100644 index 00000000..adfcca95 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/output.yaml @@ -0,0 +1,30 @@ +--- +- debug: msg="START cli/output.yaml on connection={{ ansible_connection }}" + +- name: get output for single command + register: result + cisco.ios.ios_command: + commands: + - show version + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.stdout is defined + +- name: get output for multiple commands + register: result + cisco.ios.ios_command: + commands: + - show version + - show interfaces + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout | length == 2 + +- debug: msg="END cli/output.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/timeout.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/timeout.yaml new file mode 100644 index 00000000..d1097de3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/timeout.yaml @@ -0,0 +1,19 @@ +--- +- debug: msg="START cli/timeout.yaml on connection={{ ansible_connection }}" + +- name: test bad condition + register: result + ignore_errors: true + cisco.ios.ios_command: + commands: + - show version + provider: '{{ cli }}' + wait_for: + - result[0] contains bad_value_string + +- assert: + that: + - result.failed == true + - result.msg is defined + +- debug: msg="END cli/timeout.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/meta/main.yml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/cli.yaml new file mode 100644 index 00000000..ce5fdc46 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/cli.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (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/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/cli_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/cli_config.yaml new file mode 100644 index 00000000..2feb4468 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/cli_config.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all cli_config test cases + find: + paths: '{{ role_path }}/tests/cli_config' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (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/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/main.yaml new file mode 100644 index 00000000..49d8d06f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/main.yaml @@ -0,0 +1,11 @@ +--- +- include: cli.yaml + tags: + - network_cli + +- include: cli_config.yaml + tags: + - network_cli + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/redirection.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/redirection.yaml new file mode 100644 index 00000000..6282ad40 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tasks/redirection.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all redirection cli test cases + find: + paths: '{{ role_path }}/tests/redirection' + 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/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/base_running_config b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/base_running_config new file mode 100644 index 00000000..37254dc9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/base_running_config @@ -0,0 +1,9 @@ +version 15.6 +service timestamps debug datetime msec +service timestamps log datetime msec +no service password-encryption +! +hostname an-ios-01.ansible.com +! +boot-start-marker +boot-end-marker diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/config.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/config.j2 new file mode 100644 index 00000000..06f98488 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/config.j2 @@ -0,0 +1,4 @@ +interface Loopback999 + description this is a test + shutdown + diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configblock.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configblock.j2 new file mode 100644 index 00000000..46150c4d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configblock.j2 @@ -0,0 +1,5 @@ +ip access-list extended test + permit ip host 192.0.2.1 any log + permit ip host 192.0.2.2 any log + permit ip host 192.0.2.3 any log + permit ip host 192.0.2.4 any log diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configexact1.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configexact1.j2 new file mode 100644 index 00000000..82ad080c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configexact1.j2 @@ -0,0 +1,6 @@ +no ip access-list extended test +ip access-list extended test + permit ip host 192.0.2.1 any log + permit ip host 192.0.2.2 any log + permit ip host 192.0.2.3 any log + permit ip host 192.0.2.4 any log diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configexact2.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configexact2.j2 new file mode 100644 index 00000000..46150c4d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configexact2.j2 @@ -0,0 +1,5 @@ +ip access-list extended test + permit ip host 192.0.2.1 any log + permit ip host 192.0.2.2 any log + permit ip host 192.0.2.3 any log + permit ip host 192.0.2.4 any log diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configstrict1.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configstrict1.j2 new file mode 100644 index 00000000..46150c4d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/configstrict1.j2 @@ -0,0 +1,5 @@ +ip access-list extended test + permit ip host 192.0.2.1 any log + permit ip host 192.0.2.2 any log + permit ip host 192.0.2.3 any log + permit ip host 192.0.2.4 any log diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/intended_running_config b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/intended_running_config new file mode 100644 index 00000000..bdad8d3d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/intended_running_config @@ -0,0 +1,9 @@ +version 15.6 +service timestamps debug datetime msec +service timestamps log datetime msec +no service password-encryption +! +hostname an-ios-02.ansible.com +! +boot-start-marker +boot-end-marker diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/macro.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/macro.j2 new file mode 100644 index 00000000..44a7a9bd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/macro.j2 @@ -0,0 +1,8 @@ + A12345678 123456789 123456789 123456789 123456789 123456789 123456789 + B12345678 123456789 123456789 123456789 123456789 123456789 123456789 + C12345678 123456789 123456789 123456789 123456789 123456789 123456789 + D12345678 123456789 123456789 123456789 123456789 123456789 123456789 + E12345678 123456789 123456789 123456789 123456789 123456789 123456789 + F12345678 123456789 123456789 123456789 123456789 123456789 123456789 + G12345678 123456789 123456789 123456789 123456789 123456789 123456789 + H12345678 123456789 123456789 123456789 123456789 123456789 123456789 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/setupblock.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/setupblock.j2 new file mode 100644 index 00000000..f57aa49b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/setupblock.j2 @@ -0,0 +1,5 @@ +no ip access-list extended test +ip access-list extended test + permit ip host 192.0.2.1 any log + permit ip host 192.0.2.2 any log + permit ip host 192.0.2.3 any log diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/setupexact.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/setupexact.j2 new file mode 100644 index 00000000..e8791e27 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/setupexact.j2 @@ -0,0 +1,7 @@ +no ip access-list extended test +ip access-list extended test + permit ip host 192.0.2.1 any log + permit ip host 192.0.2.2 any log + permit ip host 192.0.2.3 any log + permit ip host 192.0.2.4 any log + permit ip host 192.0.2.5 any log diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/setupstrict.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/setupstrict.j2 new file mode 100644 index 00000000..e8791e27 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/setupstrict.j2 @@ -0,0 +1,7 @@ +no ip access-list extended test +ip access-list extended test + permit ip host 192.0.2.1 any log + permit ip host 192.0.2.2 any log + permit ip host 192.0.2.3 any log + permit ip host 192.0.2.4 any log + permit ip host 192.0.2.5 any log diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/defaults/config.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/defaults/config.j2 new file mode 100644 index 00000000..1d4d9da8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/defaults/config.j2 @@ -0,0 +1,4 @@ +interface Loopback999 + description this is a test + no shutdown + diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/backup.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/backup.yaml new file mode 100644 index 00000000..3088ab9a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/backup.yaml @@ -0,0 +1,123 @@ +--- +- debug: msg="START cli/cli_backup.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.ios.ios_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: collect any backup files + find: + paths: '{{ role_path }}/backup' + pattern: '{{ inventory_hostname_short }}_config*' + register: backup_files + connection: local + +- name: delete backup files + file: + path: '{{ item.path }}' + state: absent + with_items: '{{backup_files.files|default([])}}' + +- name: configure device with config + register: result + cisco.ios.ios_config: + src: basic/config.j2 + backup: true + +- assert: + that: + - result.changed == true + +- name: collect any backup files + find: + paths: '{{ role_path }}/backup' + pattern: '{{ inventory_hostname_short }}_config*' + register: backup_files + connection: local + +- assert: + that: + - backup_files.files is defined + +- name: delete configurable backup file path + file: + path: '{{ item }}' + state: absent + with_items: + - '{{ role_path }}/backup_test_dir/' + - '{{ role_path }}/backup/backup.cfg' + +- name: take configuration backup in custom filename and directory path + become: true + register: result + cisco.ios.ios_config: + backup: true + backup_options: + filename: backup.cfg + dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + +- assert: + that: + - result.changed == true + +- name: check if the backup file-1 exist + find: + paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg' + register: backup_file + connection: local + +- assert: + that: + - backup_file.files is defined + +- name: take configuration backup in custom filename + become: true + register: result + cisco.ios.ios_config: + backup: true + backup_options: + filename: backup.cfg + +- assert: + that: + - result.changed == true + +- name: check if the backup file-2 exist + find: + paths: '{{ role_path }}/backup/backup.cfg' + register: backup_file + connection: local + +- assert: + that: + - backup_file.files is defined + +- name: take configuration backup in custom path and default filename + become: true + register: result + cisco.ios.ios_config: + backup: true + backup_options: + dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + +- assert: + that: + - result.changed == true + +- name: check if the backup file-3 exist + find: + paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + pattern: '{{ inventory_hostname_short }}_config*' + register: backup_file + connection: local + +- assert: + that: + - backup_file.files is defined + +- debug: msg="END cli/cli_backup.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/defaults.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/defaults.yaml new file mode 100644 index 00000000..09beebb3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/defaults.yaml @@ -0,0 +1,67 @@ +--- +- debug: msg="START cli/defaults.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.ios.ios_config: + commands: + - no description + - shutdown + parents: + - interface Loopback999 + match: none + +- name: configure device with defaults included + register: result + cisco.ios.ios_config: + src: defaults/config.j2 + defaults: true + +- debug: var=result + +- assert: + that: + - result.changed == true + +- name: check device with defaults included + register: result + cisco.ios.ios_config: + src: defaults/config.j2 + defaults: true + +- debug: var=result + +- assert: + that: + - result.changed == false + - result.updates is not defined + +- name: Check device is in proper prompt after error + ignore_errors: true + cisco.ios.ios_config: + lines: + - mac-address-table notification mac-move + +- name: show interfaces brief to ensure deivce goes to valid prompt + register: result + cisco.ios.ios_command: + commands: + - show interfaces + +- assert: + that: + - result.changed == false + - result.stdout is defined + +- name: Validate Terminal Error Regex + ios_config: + lines: + - switchport private-vlan mapping 10 6000 + parents: interface GigabitEthernet0/1 + register: result + ignore_errors: true + +- assert: + that: + - result.failed == True + +- debug: msg="END cli/defaults.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/diff.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/diff.yaml new file mode 100644 index 00000000..548bb3e4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/diff.yaml @@ -0,0 +1,36 @@ +--- +- debug: msg="START cli/diff.yaml on connection={{ ansible_connection }}" + +- name: Ensure hostname is preset + cisco.ios.ios_system: + hostname: '{{ shorter_hostname }}' + +- name: ios_config diff against retrieved config + diff: true + register: result + cisco.ios.ios_config: + diff_against: intended + intended_config: "{{ lookup('file', '{{ role_path }}/templates/basic/intended_running_config')\ + \ }}" + +- assert: + that: + - "'hostname an-ios-02.ansible.com' in result['diff']['after']" + - "'hostname {{ shorter_hostname }}' in result['diff']['before']" + +- name: ios_config diff against provided running_config + diff: true + register: result + cisco.ios.ios_config: + diff_against: intended + intended_config: "{{ lookup('file', '{{ role_path }}/templates/basic/intended_running_config')\ + \ }}" + running_config: "{{ lookup('file', '{{ role_path }}/templates/basic/base_running_config')\ + \ }}" + +- assert: + that: + - "'hostname an-ios-02.ansible.com' in result['diff']['after']" + - "'hostname an-ios-01.ansible.com' in result['diff']['before']" + +- debug: msg="END cli/diff.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/macro.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/macro.yaml new file mode 100644 index 00000000..dcb1bd29 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/macro.yaml @@ -0,0 +1,64 @@ +--- +- debug: msg="START cli/cli_macro.yaml on connection={{ ansible_connection }}" + +- name: Check for macro support + register: supports_macro + ignore_errors: true + cisco.ios.ios_command: + commands: + - show parser macro brief + +- name: ios_config macro integration tests + when: supports_macro is succeeded + block: + + - name: Define macro name + set_fact: + macro_name: MACRO_ANSIBLE_TEST + + - name: setup - remove configuration + cisco.ios.ios_config: + lines: + - no macro name {{ macro_name }} + - do show clock + match: none + + - name: configure macro + register: result + cisco.ios.ios_config: + parents: macro name {{ macro_name }} + multiline_delimiter: '@' + after: '@' + match: line + replace: block + lines: "{{ lookup('template', 'basic/macro.j2') }}" + + - name: Check if macro has been added + assert: + that: + - result.changed == true + + - name: configure macro again - idempotent check + register: result + cisco.ios.ios_config: + parents: macro name {{ macro_name }} + multiline_delimiter: '@' + after: '@' + match: line + replace: block + lines: "{{ lookup('template', 'basic/macro.j2') }}" + + - name: macro already/correctly configured ? + assert: + that: + - result.changed == false + always: + + - name: teardown + cisco.ios.ios_config: + lines: + - no macro name {{ macro_name }} + - do show clock + match: none + +- debug: msg="END cli/cli_macro.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/save.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/save.yaml new file mode 100644 index 00000000..4f7d3241 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/save.yaml @@ -0,0 +1,49 @@ +--- +- debug: msg="START cli/save.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.ios.ios_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + save_when: modified + +- name: save should always run + register: result + cisco.ios.ios_config: + save_when: always + +- assert: + that: + - result.changed == true + +- name: delete config (setup) + register: result + cisco.ios.ios_config: + replace: line + lines: + - no ip http server + save_when: modified + +- name: save should run when changed + register: result + cisco.ios.ios_config: + replace: line + lines: + - ip http server + save_when: modified + +- assert: + that: + - result.changed == true + +- name: teardown + register: result + cisco.ios.ios_config: + lines: + - no ip http server + +- debug: msg="END cli/save.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/src_basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/src_basic.yaml new file mode 100644 index 00000000..c2f41123 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/src_basic.yaml @@ -0,0 +1,64 @@ +--- +- debug: msg="START cli/src_basic.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.ios.ios_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: configure device with config + register: result + cisco.ios.ios_config: + src: basic/config.j2 + +- name: debug, remove me + debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + +- name: check device with config + register: result + cisco.ios.ios_config: + src: basic/config.j2 + +- assert: + that: + - result.changed == false + +- name: check for empty diff + check_mode: true + register: result + cisco.ios.ios_config: + running_config: "service timestamps debug datetime msec\nservice timestamps\ + \ log datetime msec\n" + lines: + - service timestamps debug datetime msec + - service timestamps log datetime msec + +- assert: + that: + - result.updates is undefined + +- name: check for diff with ignore lines for running config + check_mode: true + register: result + cisco.ios.ios_config: + running_config: "service timestamps debug datetime msec\nservice timestamps\ + \ log datetime msec\n" + lines: + - service timestamps debug datetime msec + - service timestamps log datetime msec + diff_ignore_lines: service timestamps log datetime msec + +- assert: + that: + - "'service timestamps log datetime msec' in result.updates" + +- debug: msg="END cli/src_basic.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/src_invalid.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/src_invalid.yaml new file mode 100644 index 00000000..852a3d45 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/src_invalid.yaml @@ -0,0 +1,16 @@ +--- +- debug: msg="START cli/src_invalid.yaml on connection={{ ansible_connection }}" + +- name: configure with invalid src + register: result + ignore_errors: true + cisco.ios.ios_config: + src: basic/foobar.j2 + +- assert: + that: + - result.changed == false + - result.failed == true + - result.msg == 'path specified in src not found' + +- debug: msg="END cli/src_invalid.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/src_match_none.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/src_match_none.yaml new file mode 100644 index 00000000..5a8cf448 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/src_match_none.yaml @@ -0,0 +1,34 @@ +--- +- debug: msg="START cli/src_match_none.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: configure device with config + register: result + cisco.ios.ios_config: + src: basic/config.j2 + match: none + +- assert: + that: + - result.changed == true + +- name: check device with config + register: result + cisco.ios.ios_config: + src: basic/config.j2 + +- assert: + that: + - result.changed == false + - result.updates is not defined + +- debug: msg="END cli/src_match_none.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel.yaml new file mode 100644 index 00000000..59f0c8b5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel.yaml @@ -0,0 +1,43 @@ +--- +- debug: msg="START cli/sublevel.yaml on connection={{ ansible_connection }}" + +- name: setup test + cisco.ios.ios_config: + lines: + - no ip access-list extended test + - no ip access-list standard test + match: none + +- name: configure sub level command + register: result + cisco.ios.ios_config: + lines: + - permit ip any any log + parents: + - ip access-list extended test + +- assert: + that: + - result.changed == true + - "'ip access-list extended test' in result.updates" + - "'permit ip any any log' in result.updates" + +- name: configure sub level command idempotent check + register: result + cisco.ios.ios_config: + lines: + - permit ip any any log + parents: + - ip access-list extended test + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: + - no ip access-list extended test + match: none + +- debug: msg="END cli/sublevel.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_block.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_block.yaml new file mode 100644 index 00000000..ded1fccc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_block.yaml @@ -0,0 +1,66 @@ +--- +- debug: msg="START cli/sublevel_block.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + parents: + - ip access-list extended test + before: + - no ip access-list extended test + after: + - exit + match: none + +- name: configure sub level command using block resplace + register: result + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + - permit ip host 192.0.2.4 any log + parents: + - ip access-list extended test + replace: block + after: + - exit + +- assert: + that: + - result.changed == true + - "'ip access-list extended test' in result.updates" + - "'permit ip host 192.0.2.1 any log' in result.updates" + - "'permit ip host 192.0.2.2 any log' in result.updates" + - "'permit ip host 192.0.2.3 any log' in result.updates" + - "'permit ip host 192.0.2.4 any log' in result.updates" + +- name: check sub level command using block replace + register: result + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + - permit ip host 192.0.2.4 any log + parents: + - ip access-list extended test + replace: block + after: + - exit + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: + - no ip access-list extended test + match: none + +- debug: msg="END cli/sublevel_block.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_exact.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_exact.yaml new file mode 100644 index 00000000..d340184a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_exact.yaml @@ -0,0 +1,62 @@ +--- +- debug: msg="START cli/sublevel_exact.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + - permit ip host 192.0.2.4 any log + - permit ip host 192.0.2.5 any log + parents: ip access-list extended test + before: no ip access-list extended test + after: exit + match: none + +- name: configure sub level command using exact match + register: result + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + - permit ip host 192.0.2.4 any log + parents: ip access-list extended test + before: no ip access-list extended test + after: exit + match: exact + +- assert: + that: + - result.changed == true + - "'ip access-list extended test' in result.updates" + - "'permit ip host 192.0.2.1 any log' in result.updates" + - "'permit ip host 192.0.2.2 any log' in result.updates" + - "'permit ip host 192.0.2.3 any log' in result.updates" + - "'permit ip host 192.0.2.4 any log' in result.updates" + - "'permit ip host 192.0.2.5 any log' not in result.updates" + +- name: check sub level command using exact match + register: result + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + - permit ip host 192.0.2.4 any log + parents: ip access-list extended test + match: exact + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: + - no ip access-list extended test + match: none + +- debug: msg="END cli/sublevel_exact.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_strict.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_strict.yaml new file mode 100644 index 00000000..81d0e772 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_strict.yaml @@ -0,0 +1,58 @@ +--- +- debug: msg="START cli/sublevel_strict.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + - permit ip host 192.0.2.4 any log + - permit ip host 192.0.2.5 any log + parents: ip access-list extended test + before: no ip access-list extended test + match: none + +- name: configure sub level command using strict match + register: result + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + - permit ip host 192.0.2.4 any log + parents: ip access-list extended test + match: strict + +- assert: + that: + - result.changed == false + +- name: check sub level command using strict match + register: result + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.3 any log + - permit ip host 192.0.2.2 any log + parents: ip access-list extended test + after: exit + match: strict + +- assert: + that: + - result.changed == true + - "'ip access-list extended test' in result.updates" + - "'permit ip host 192.0.2.1 any log' not in result.updates" + - "'permit ip host 192.0.2.2 any log' in result.updates" + - "'permit ip host 192.0.2.3 any log' in result.updates" + - "'permit ip host 192.0.2.4 any log' not in result.updates" + - "'permit ip host 192.0.2.5 any log' not in result.updates" + +- name: teardown + cisco.ios.ios_config: + lines: no ip access-list extended test + match: none + +- debug: msg="END cli/sublevel_strict.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_strict_mul_parents.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_strict_mul_parents.yaml new file mode 100644 index 00000000..9419dc3d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/sublevel_strict_mul_parents.yaml @@ -0,0 +1,74 @@ +--- +- debug: msg="START cli/sublevel_strict_mul_parents.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - class-map c1 + - match precedence 7 + - policy-map p1 + - class c1 + before: + - no policy-map p1 + - no class-map c1 + match: none + +- name: configure sub level command using strict match + register: result + cisco.ios.ios_config: + lines: + - set ip precedence 5 + - police cir percent 10 + parents: + - policy-map p1 + - class c1 + match: strict + +- assert: + that: + - result.changed == true + - "'set ip precedence 5' in result.updates" + - "'police cir percent 10' in result.updates" + +- name: change sub level command order and config with strict match + register: result + cisco.ios.ios_config: + lines: + - police cir percent 10 + - set ip precedence 5 + parents: + - policy-map p1 + - class c1 + match: strict + +- assert: + that: + - result.changed == true + - "'set ip precedence 5' in result.updates" + - "'police cir percent 10' in result.updates" + +- name: Config sub level command with strict match (Idempotency) + register: result + cisco.ios.ios_config: + lines: + - set ip precedence 5 + - police cir percent 10 + parents: + - policy-map p1 + - class c1 + match: strict + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: + - no policy-map p1 + - no class-map c1 + match: none + +- debug: msg="END cli/sublevel_strict_mul_parents.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel.yaml new file mode 100644 index 00000000..6b951870 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel.yaml @@ -0,0 +1,37 @@ +--- +- debug: msg="START cli/toplevel.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.ios.ios_config: + lines: + - hostname {{ shorter_hostname }} + match: none + +- name: configure top level command + register: result + cisco.ios.ios_config: + lines: + - hostname foo + +- assert: + that: + - result.changed == true + - "'hostname foo' in result.updates" + +- name: configure top level command idempotent check + register: result + cisco.ios.ios_config: + lines: + - hostname foo + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: + - hostname {{ shorter_hostname }} + match: none + +- debug: msg="END cli/toplevel.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel_after.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel_after.yaml new file mode 100644 index 00000000..1e139f68 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel_after.yaml @@ -0,0 +1,45 @@ +--- +- debug: msg="START cli/toplevel_after.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - snmp-server contact ansible + - hostname {{ shorter_hostname }} + match: none + +- name: configure top level command with before + register: result + cisco.ios.ios_config: + lines: + - hostname foo + after: + - snmp-server contact bar + +- assert: + that: + - result.changed == true + - "'hostname foo' in result.updates" + - "'snmp-server contact bar' in result.updates" + +- name: configure top level command with before idempotent check + register: result + cisco.ios.ios_config: + lines: + - hostname foo + after: + - snmp-server contact foo + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: + - no snmp-server contact + - hostname {{ shorter_hostname }} + match: none + +- debug: msg="END cli/toplevel_after.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel_before.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel_before.yaml new file mode 100644 index 00000000..f90d629e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel_before.yaml @@ -0,0 +1,45 @@ +--- +- debug: msg="START cli/toplevel_before.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - snmp-server contact ansible + - hostname {{ shorter_hostname }} + match: none + +- name: configure top level command with before + register: result + cisco.ios.ios_config: + lines: + - hostname foo + before: + - snmp-server contact bar + +- assert: + that: + - result.changed == true + - "'hostname foo' in result.updates" + - "'snmp-server contact bar' in result.updates" + +- name: configure top level command with before idempotent check + register: result + cisco.ios.ios_config: + lines: + - hostname foo + before: + - snmp-server contact foo + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: + - no snmp-server contact + - hostname {{ shorter_hostname }} + match: none + +- debug: msg="END cli/toplevel_before.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel_nonidempotent.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel_nonidempotent.yaml new file mode 100644 index 00000000..e958eef3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/toplevel_nonidempotent.yaml @@ -0,0 +1,41 @@ +--- +- debug: msg="START cli/toplevel_nonidempotent.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - hostname {{ shorter_hostname }} + match: none + +- name: configure top level command + register: result + cisco.ios.ios_config: + lines: + - hostname foo + match: strict + +- assert: + that: + - result.changed == true + - "'hostname foo' in result.updates" + +- name: configure top level command idempotent check + register: result + cisco.ios.ios_config: + lines: + - hostname foo + match: strict + +- assert: + that: + - result.changed == true + +- name: teardown + cisco.ios.ios_config: + lines: + - hostname {{ shorter_hostname }} + match: none + +- debug: msg="END cli/toplevel_nonidempotent.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_backup.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_backup.yaml new file mode 100644 index 00000000..3880a040 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_backup.yaml @@ -0,0 +1,114 @@ +--- +- debug: msg="END cli_config/backup.yaml on connection={{ ansible_connection }}" + +- name: delete configurable backup file path + file: + path: '{{ item }}' + state: absent + with_items: + - '{{ role_path }}/backup_test_dir/' + - '{{ role_path }}/backup/backup.cfg' + +- name: collect any backup files + find: + paths: '{{ role_path }}/backup' + pattern: '{{ inventory_hostname_short }}_config*' + register: backup_files + connection: local + +- name: delete backup files + file: + path: '{{ item.path }}' + state: absent + with_items: '{{backup_files.files|default([])}}' + +- name: take config backup + become: true + register: result + ansible.netcommon.cli_config: + backup: true + +- assert: + that: + - result.changed == true + +- name: collect any backup files + find: + paths: '{{ role_path }}/backup' + pattern: '{{ inventory_hostname_short }}_config*' + register: backup_files + connection: local + +- assert: + that: + - backup_files.files is defined + +- name: take configuration backup in custom filename and directory path + become: true + register: result + ansible.netcommon.cli_config: + backup: true + backup_options: + filename: backup.cfg + dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + +- assert: + that: + - result.changed == true + +- name: check if the backup file-1 exist + find: + paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg' + register: backup_file + connection: local + +- assert: + that: + - backup_file.files is defined + +- name: take configuration backup in custom filename + become: true + register: result + ansible.netcommon.cli_config: + backup: true + backup_options: + filename: backup.cfg + +- assert: + that: + - result.changed == true + +- name: check if the backup file-2 exist + find: + paths: '{{ role_path }}/backup/backup.cfg' + register: backup_file + connection: local + +- assert: + that: + - backup_file.files is defined + +- name: take configuration backup in custom path and default filename + become: true + register: result + ansible.netcommon.cli_config: + backup: true + backup_options: + dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + +- assert: + that: + - result.changed == true + +- name: check if the backup file-3 exist + find: + paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + pattern: '{{ inventory_hostname_short }}_config*' + register: backup_file + connection: local + +- assert: + that: + - backup_file.files is defined + +- debug: msg="END cli_config/backup.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_basic.yaml new file mode 100644 index 00000000..2285fe3a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_basic.yaml @@ -0,0 +1,44 @@ +--- +- debug: msg="START cli_config/cli_basic.yaml on connection={{ ansible_connection + }}" + +- name: setup + ansible.netcommon.cli_config: &id002 + config: "interface loopback999\nno description\nshutdown\n" + diff_match: none + +- name: configure device with config + register: result + ansible.netcommon.cli_config: &id001 + config: "{{ lookup('template', 'basic/config.j2') }}" + +- assert: + that: + - result.changed == true + +- name: Idempotence + register: result + ansible.netcommon.cli_config: *id001 + +- assert: + that: + - result.changed == false + +- name: remove config + ansible.netcommon.cli_config: *id002 + +- name: configure device with config + register: result + ansible.netcommon.cli_config: + config: "{{ lookup('template', 'basic/config.j2') }}" + defaults: true + +- assert: + that: + - result.changed == true + +- name: teardown + ansible.netcommon.cli_config: *id002 + +- debug: msg="END cli_config/cli_basic.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_block_replace.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_block_replace.yaml new file mode 100644 index 00000000..d5505579 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_block_replace.yaml @@ -0,0 +1,34 @@ +--- +- debug: msg="START cli_config/cli_block_replace.yaml on connection={{ ansible_connection + }}" + +- name: setup - remove configuration + ansible.netcommon.cli_config: + config: "{{ lookup('template', 'basic/setupblock.j2') }}" + diff_match: none + +- name: block replace + register: result + ansible.netcommon.cli_config: &id001 + config: "{{ lookup('template', 'basic/configblock.j2') }}" + diff_replace: block + +- assert: + that: + - result.changed == true + +- name: block replace (Idempotence) + register: result + ansible.netcommon.cli_config: *id001 + +- assert: + that: + - result.changed == false + +- name: teardown + ansible.netcommon.cli_config: + config: no ip access-list extended test + diff_match: none + +- debug: msg="END cli_config/cli_block_replace.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_exact_match.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_exact_match.yaml new file mode 100644 index 00000000..4d5d95dd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_exact_match.yaml @@ -0,0 +1,35 @@ +--- +- debug: msg="START cli_config/cli_exact_match.yaml on connection={{ ansible_connection + }}" + +- name: setup - remove configuration + ansible.netcommon.cli_config: + config: "{{ lookup('template', 'basic/setupexact.j2') }}" + diff_match: none + +- name: configure using exact match + register: result + ansible.netcommon.cli_config: + config: "{{ lookup('template', 'basic/configexact1.j2') }}" + diff_match: exact + +- assert: + that: + - result.changed == true + +- name: check using exact match + register: result + ansible.netcommon.cli_config: + config: "{{ lookup('template', 'basic/configexact2.j2') }}" + +- assert: + that: + - result.changed == false + +- name: teardown + ansible.netcommon.cli_config: + config: no ip access-list extended test + diff_match: none + +- debug: msg="END cli_config/cli_exact_match.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_strict_match.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_strict_match.yaml new file mode 100644 index 00000000..bf86cf58 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli_config/cli_strict_match.yaml @@ -0,0 +1,26 @@ +--- +- debug: msg="START cli_config/cli_strict_match.yaml on connection={{ ansible_connection + }}" + +- name: setup - remove configuration + ansible.netcommon.cli_config: + config: "{{ lookup('template', 'basic/setupstrict.j2') }}" + diff_match: none + +- name: configure using strict match + register: result + ansible.netcommon.cli_config: + config: "{{ lookup('template', 'basic/configstrict1.j2') }}" + diff_match: strict + +- assert: + that: + - result.changed == true + +- name: teardown + ansible.netcommon.cli_config: + config: no ip access-list extended test + diff_match: none + +- debug: msg="END cli_config/cli_strict_match.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/redirection/shortname.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/redirection/shortname.yaml new file mode 100644 index 00000000..7248eca0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/redirection/shortname.yaml @@ -0,0 +1,37 @@ +--- +- debug: msg="START cli/shortname.yaml on connection={{ ansible_connection }}" + +- name: Use src with module alias + register: result + cisco.ios.config: + src: basic/config.j2 + +- assert: + that: + # make sure that the template content was read and not the path + - result.changed == true + - result.updates is defined + +- name: use module alias to take configuration backup + register: result + cisco.ios.config: + backup: true + backup_options: + filename: backup_with_alias.cfg + dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}' + +- assert: + that: + - result.changed == true + +- name: check if the backup file-4 exist + find: + paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup_with_alias.cfg' + register: backup_file + connection: local + +- assert: + that: + - backup_file.files is defined + +- debug: msg="END cli/shortname.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/meta/main.yml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml new file mode 100644 index 00000000..beaa956f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml @@ -0,0 +1,27 @@ +--- +- debug: msg="START cli/all_facts.yaml on connection={{ ansible_connection }}" + +- name: test getting all facts + register: result + cisco.ios.ios_facts: + gather_subset: + - all + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - "'config' in result.ansible_facts.ansible_net_gather_subset" + - "'hardware' in result.ansible_facts.ansible_net_gather_subset" + - "'default' in result.ansible_facts.ansible_net_gather_subset" + - "'interfaces' in result.ansible_facts.ansible_net_gather_subset" + - result.ansible_facts.ansible_net_filesystems is defined + - result.ansible_facts.ansible_net_memfree_mb > 1 + - result.ansible_facts.ansible_net_memtotal_mb > 1 + +- assert: + that: '{{ item.value.spacetotal_kb }} > {{ item.value.spacefree_kb }}' + loop: "{{ lookup('dict', result.ansible_facts.ansible_net_filesystems_info, wantlist=True)\ + \ }}" + +- debug: msg="END cli/all_facts.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/default_facts.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/default_facts.yaml new file mode 100644 index 00000000..3499b0fc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/default_facts.yaml @@ -0,0 +1,27 @@ +--- +- debug: msg="START cli/default_facts.yaml on connection={{ ansible_connection }}" + +- name: test getting default facts + register: result + cisco.ios.ios_facts: + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - "'hardware' in result.ansible_facts.ansible_net_gather_subset" + - "'default' in result.ansible_facts.ansible_net_gather_subset" + - "'interfaces' in result.ansible_facts.ansible_net_gather_subset" + - result.ansible_facts.ansible_net_filesystems is defined + - "'config' not in result.ansible_facts.ansible_net_gather_subset" + - result.ansible_facts.ansible_net_filesystems is defined + - result.ansible_facts.ansible_net_memtotal_mb > 10 + - result.ansible_facts.ansible_net_interfaces | length > 1 + - result.ansible_facts.ansible_net_config is not defined + +- assert: + that: '{{ item.value.spacetotal_kb }} > {{ item.value.spacefree_kb }}' + loop: "{{ lookup('dict', result.ansible_facts.ansible_net_filesystems_info, wantlist=True)\ + \ }}" + +- debug: msg="END cli/default.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/invalid_subset.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/invalid_subset.yaml new file mode 100644 index 00000000..fd483430 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/invalid_subset.yaml @@ -0,0 +1,36 @@ +--- +- debug: msg="START cli/invalid_subset.yaml on connection={{ ansible_connection + }}" + +- name: test invalid subset (foobar) + register: result + ignore_errors: true + cisco.ios.ios_facts: + gather_subset: + - foobar + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.failed == true + - result.msg == 'Subset must be one of [config, default, hardware, interfaces], + got foobar' + +- name: test subset specified multiple times + register: result + ignore_errors: true + cisco.ios.ios_facts: + gather_subset: + - '!hardware' + - hardware + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.failed == true + - result.msg == 'Bad subset' + ignore_errors: true + +- debug: msg="END cli/invalid_subset.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/not_hardware.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/not_hardware.yaml new file mode 100644 index 00000000..671c4c99 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/not_hardware.yaml @@ -0,0 +1,24 @@ +--- +- debug: msg="START cli/not_hardware_facts.yaml on connection={{ ansible_connection + }}" + +- name: test not hardware + register: result + cisco.ios.ios_facts: + gather_subset: + - '!hardware' + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - "'config' in result.ansible_facts.ansible_net_gather_subset" + - "'default' in result.ansible_facts.ansible_net_gather_subset" + - "'interfaces' in result.ansible_facts.ansible_net_gather_subset" + - "'hardware' not in result.ansible_facts.ansible_net_gather_subset" + - result.ansible_facts.ansible_net_interfaces | length > 1 + - result.ansible_facts.ansible_net_filesystems is not defined + - result.ansible_facts.ansible_net_filesystems_info is not defined + +- debug: msg="END cli/not_hardware_facts.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tests/cli/basic.yaml new file mode 100644 index 00000000..1fdf50e7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tests/cli/basic.yaml @@ -0,0 +1,254 @@ +--- +- debug: msg="START ios_interface cli/basic.yaml on connection={{ ansible_connection + }}" + +- name: Configure interface (setup) + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + description: test-interface-1 + speed: 1000 + mtu: 1800 + state: present + provider: '{{ cli }}' + +- name: Configure interface + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + description: test-interface-initial + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"description test-interface-initial" in result.commands' + +- name: Confgure interface (idempotent) + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + description: test-interface-initial + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: Confgure interface parameters + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + description: test-interface + mtu: 2000 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"description test-interface" in result.commands' + - '"mtu 2000" in result.commands' + +- name: Change interface parameters + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + description: test-interface-1 + mtu: 1800 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"description test-interface-1" in result.commands' + - '"mtu 1800" in result.commands' + +- name: Disable interface + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + enabled: false + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"shutdown" in result.commands' + +- name: Enable interface + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + enabled: true + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"no shutdown" in result.commands' + +- name: Confgure second interface (setup) + register: result + cisco.ios.ios_interface: + name: '{{ test_interface2 }}' + description: test-interface-initial + speed: 1000 + mtu: 1800 + state: present + provider: '{{ cli }}' + +- name: Add interface aggregate + register: result + cisco.ios.ios_interface: + aggregate: + + - name: '{{ test_interface }}' + mtu: 2000 + description: test-interface-1 + + - name: '{{ test_interface2 }}' + mtu: 2000 + description: test-interface-2 + speed: 1000 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"mtu 2000" in result.commands' + - '"interface {{ test_interface2 }}" in result.commands' + - '"description test-interface-2" in result.commands' + - '"mtu 2000" in result.commands' + +- name: Add interface aggregate (idempotent) + register: result + cisco.ios.ios_interface: + aggregate: + + - name: '{{ test_interface }}' + mtu: 2000 + description: test-interface-1 + + - name: '{{ test_interface2 }}' + mtu: 2000 + description: test-interface-2 + speed: 1000 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: Disable interface aggregate + register: result + cisco.ios.ios_interface: + aggregate: + + - name: '{{ test_interface }}' + + - name: '{{ test_interface2 }}' + enabled: false + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"shutdown" in result.commands' + - '"interface {{ test_interface2 }}" in result.commands' + - '"shutdown" in result.commands' + +- name: Enable interface aggregate + register: result + cisco.ios.ios_interface: + aggregate: + + - name: '{{ test_interface }}' + + - name: '{{ test_interface2 }}' + enabled: true + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"no shutdown" in result.commands' + - '"interface {{ test_interface2 }}" in result.commands' + - '"no shutdown" in result.commands' + +- name: loopback interface setup + cisco.ios.ios_interface: + aggregate: + + - name: Loopback9 + + - name: Loopback10 + state: absent + provider: '{{ cli }}' + +- name: Create loopback interface aggregate + register: result + cisco.ios.ios_interface: + aggregate: + + - name: Loopback9 + + - name: Loopback10 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface Loopback9" in result.commands' + - '"interface Loopback10" in result.commands' + +- name: Delete loopback interface aggregate + register: result + cisco.ios.ios_interface: + aggregate: + + - name: Loopback9 + + - name: Loopback10 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"no interface Loopback9" in result.commands' + - '"no interface Loopback10" in result.commands' + +- name: Delete loopback interface aggregate (idempotent) + register: result + cisco.ios.ios_interface: + aggregate: + + - name: Loopback9 + + - name: Loopback10 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- debug: msg="END ios_interface cli/basic.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tests/cli/intent.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tests/cli/intent.yaml new file mode 100644 index 00000000..0665e111 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tests/cli/intent.yaml @@ -0,0 +1,151 @@ +--- +- debug: msg="START ios_interface cli/intent.yaml on connection={{ ansible_connection + }}" + +- name: Check intent arguments + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + state: up + provider: '{{ cli }}' + +- assert: + that: + - result.failed == false + +- name: Check intent arguments (failed condition) + ignore_errors: true + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + state: down + provider: '{{ cli }}' + +- assert: + that: + - result.failed == true + - "'state eq(down)' in result.failed_conditions" + +- name: Config + intent + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + enabled: false + state: down + provider: '{{ cli }}' + +- assert: + that: + - result.failed == false + +- name: Config + intent (fail) + ignore_errors: true + register: result + cisco.ios.ios_interface: + name: '{{ test_interface }}' + enabled: false + provider: '{{ cli }}' + state: up + +- assert: + that: + - result.failed == true + - "'state eq(up)' in result.failed_conditions" + +- name: Register show neighbors detail + register: show_lldp_neighbors_result + cisco.ios.ios_command: + commands: + - show lldp neighbors + provider: '{{ cli }}' + +- block: + + - name: Check neighbors intent arguments + register: result + cisco.ios.ios_interface: + name: Gi0/0 + neighbors: + + - port: eth0 + host: netdev + provider: '{{ cli }}' + + - assert: + that: + - result.failed == false + + - name: Check neighbors intent arguments (failed condition) + ignore_errors: true + register: result + cisco.ios.ios_interface: + name: Gi0/0 + neighbors: + + - port: dummy_port + host: dummy_host + provider: '{{ cli }}' + + - assert: + that: + - result.failed == true + - "'host dummy_host' in result.failed_conditions" + - "'port dummy_port' in result.failed_conditions" + when: '"netdev" in show_lldp_neighbors_result.stdout[0]' + +- name: Aggregate config + intent (pass) + ignore_errors: true + register: result + cisco.ios.ios_interface: + aggregate: + + - name: '{{ test_interface }}' + enabled: true + state: up + provider: '{{ cli }}' + +- assert: + that: + - result.failed == false + +- block: + + - name: Aggregate neighbors intent (pass) + ignore_errors: true + register: result + cisco.ios.ios_interface: + aggregate: + + - name: Gi0/0 + neighbors: + + - port: eth0 + host: netdev + provider: '{{ cli }}' + + - assert: + that: + - result.failed == false + + - name: Aggregate neighbors intent (fail) + ignore_errors: true + register: result + cisco.ios.ios_interface: + aggregate: + + - name: Gi0/0 + neighbors: + + - port: eth0 + host: netdev + + - port: dummy_port + host: dummy_host + provider: '{{ cli }}' + + - assert: + that: + - result.failed == true + - "'host dummy_host' in result.failed_conditions" + - "'port dummy_port' in result.failed_conditions" + when: "'netdev' in show_lldp_neighbors_result.stdout[0]" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tests/cli/net_interface.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tests/cli/net_interface.yaml new file mode 100644 index 00000000..5309775c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interface/tests/cli/net_interface.yaml @@ -0,0 +1,46 @@ +--- +- debug: msg="START ios cli/net_interface.yaml on connection={{ ansible_connection + }}" + +- name: Configure interface (setup) + register: result + ansible.netcommon.net_interface: + name: '{{ test_interface }}' + description: test-interface-1 + speed: 1000 + mtu: 1800 + state: present + provider: '{{ cli }}' + +- name: Configure interface using platform agnostic module + register: result + ansible.netcommon.net_interface: + name: '{{ test_interface }}' + description: test-interface-initial + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"description test-interface-initial" in result.commands' + +- name: Confgure interface parameters using platform agnostic module + register: result + ansible.netcommon.net_interface: + name: '{{ test_interface }}' + description: test-interface + mtu: 2000 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"description test-interface" in result.commands' + - '"mtu 2000" in result.commands' + +- debug: msg="START ios cli/net_interface.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/_parsed.cfg new file mode 100644 index 00000000..7effa5c6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/_parsed.cfg @@ -0,0 +1,11 @@ +interface GigabitEthernet0/1 +description interfaces 0/1 +mtu 110 +duplex half +no shutdown +interface GigabitEthernet0/2 +description interfaces 0/2 +mtu 2800 +speed 100 +duplex full +shutdown
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..00c30911 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/1\ndescription this is interface1\nmtu 65\n\ + speed 10\nno shutdown\ninterface GigabitEthernet 0/2\ndescription this is interface\ + \ for testing\nmtu 110\nduplex auto\nspeed 100\nshutdown\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..2c5d64a8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,9 @@ +--- +- name: Remove Config + vars: + lines: "interface loopback888\nno description\nno shutdown\ninterface loopback999\n\ + no description\nno shutdown\ninterface GigabitEthernet 0/1\nno description\n\ + no mtu\nno duplex\nno speed\nno shutdown\ninterface GigabitEthernet 0/2\n\ + no description\nno mtu\nno duplex\nno speed\nno shutdown\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..3ada7a2d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,51 @@ +--- +- debug: + msg: Start Deleted integration state for ios_interfaces ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete attributes of all configured interfaces + register: result + cisco.ios.ios_interfaces: &id001 + state: deleted + + - debug: + msg: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) }}" + - "{{ deleted['before'] | symmetric_difference(result['before']) }}" + - "{{ deleted['after'] | symmetric_difference(result['after']) }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ deleted['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Delete attributes of all configured interfaces (IDEMPOTENT) + register: result + cisco.ios.ios_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..2e8cd156 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START ios_interfaces empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_interfaces: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_interfaces: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_interfaces: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_interfaces: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_interfaces: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..bb09af37 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START ios_interfaces gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_interfaces: + config: + state: gathered + + - name: Assert + assert: + that: + - gathered['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..3c87c2a6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/merged.yaml @@ -0,0 +1,57 @@ +--- +- debug: + msg: START Merged ios_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + description: Configured and Merged by Ansible-Network + mtu: 110 + enabled: true + duplex: half + + - name: GigabitEthernet0/2 + description: Configured and Merged by Ansible-Network + mtu: 2800 + enabled: false + speed: 100 + duplex: full + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..d08482fb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,53 @@ +--- +- debug: + msg: START Overridden ios_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Override device configuration of all interfaces with provided configuration + register: result + cisco.ios.ios_interfaces: &id001 + config: + + - name: GigabitEthernet0/2 + description: Configured and Overridden by Ansible-Network + enabled: false + duplex: full + mtu: 2000 + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ overridden['before'] | symmetric_difference(result['before']) |\ + \ length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Override device configuration of all interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..ac58283a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START ios_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_interfaces: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - parsed['config']|symmetric_difference(result.parsed) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..dc9e8344 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,29 @@ +--- +- debug: + msg: Start ios_interfaces rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_interfaces: + config: + - name: GigabitEthernet0/1 + description: Configured by Ansible-Network + mtu: 110 + enabled: true + duplex: half + - name: GigabitEthernet0/2 + description: Configured by Ansible-Network + mtu: 2800 + enabled: false + speed: 100 + duplex: full + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(rendered.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..f3003344 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START Replaced ios_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces device configuration of listed interfaces with provided configuration + register: result + cisco.ios.ios_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + description: Configured and Replaced by Ansible-Network + mtu: 110 + + - name: GigabitEthernet0/2 + description: Configured and Replaced by Ansible-Network + speed: 10 + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ replaced['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Replaces device configuration of listed interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/vars/main.yaml new file mode 100644 index 00000000..0ae1cead --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_interfaces/vars/main.yaml @@ -0,0 +1,251 @@ +--- +merged: + before: + - enabled: true + name: loopback888 + - enabled: true + name: loopback999 + - duplex: auto + enabled: true + name: GigabitEthernet0/0 + speed: auto + - duplex: auto + enabled: true + name: GigabitEthernet0/1 + speed: auto + - duplex: auto + enabled: true + name: GigabitEthernet0/2 + speed: auto + commands: + - interface GigabitEthernet0/1 + - description Configured and Merged by Ansible-Network + - mtu 110 + - duplex half + - interface GigabitEthernet0/2 + - description Configured and Merged by Ansible-Network + - mtu 2800 + - speed 100 + - duplex full + - shutdown + after: + - enabled: true + name: loopback888 + - enabled: true + name: loopback999 + - duplex: auto + enabled: true + name: GigabitEthernet0/0 + speed: auto + - description: Configured and Merged by Ansible-Network + duplex: half + enabled: true + mtu: 110 + name: GigabitEthernet0/1 + speed: auto + - description: Configured and Merged by Ansible-Network + duplex: full + enabled: false + mtu: 2800 + name: GigabitEthernet0/2 + speed: '100' +replaced: + before: + - enabled: true + name: loopback888 + - enabled: true + name: loopback999 + - duplex: auto + enabled: true + name: GigabitEthernet0/0 + speed: auto + - description: this is interface1 + duplex: auto + enabled: true + mtu: 65 + name: GigabitEthernet0/1 + speed: '10' + - description: this is interface for testing + duplex: auto + enabled: false + mtu: 110 + name: GigabitEthernet0/2 + speed: '100' + commands: + - interface GigabitEthernet0/1 + - no speed + - description Configured and Replaced by Ansible-Network + - mtu 110 + - interface GigabitEthernet0/2 + - no shutdown + - no mtu + - description Configured and Replaced by Ansible-Network + - speed 10 + after: + - enabled: true + name: loopback888 + - enabled: true + name: loopback999 + - duplex: auto + enabled: true + name: GigabitEthernet0/0 + speed: auto + - description: Configured and Replaced by Ansible-Network + duplex: auto + enabled: true + mtu: 110 + name: GigabitEthernet0/1 + speed: auto + - description: Configured and Replaced by Ansible-Network + duplex: auto + enabled: true + name: GigabitEthernet0/2 + speed: '10' +overridden: + before: + - enabled: true + name: loopback888 + - enabled: true + name: loopback999 + - duplex: auto + enabled: true + name: GigabitEthernet0/0 + speed: auto + - description: this is interface1 + duplex: auto + enabled: true + mtu: 65 + name: GigabitEthernet0/1 + speed: '10' + - description: this is interface for testing + duplex: auto + enabled: false + mtu: 110 + name: GigabitEthernet0/2 + speed: '100' + commands: + - interface GigabitEthernet0/1 + - no description + - no speed + - no mtu + - interface GigabitEthernet0/2 + - no speed + - description Configured and Overridden by Ansible-Network + - mtu 2000 + - duplex full + after: + - enabled: true + name: loopback888 + - enabled: true + name: loopback999 + - duplex: auto + enabled: true + name: GigabitEthernet0/0 + speed: auto + - duplex: auto + enabled: true + name: GigabitEthernet0/1 + speed: auto + - description: Configured and Overridden by Ansible-Network + duplex: full + enabled: false + mtu: 2000 + name: GigabitEthernet0/2 + speed: auto +deleted: + before: + - enabled: true + name: loopback888 + - enabled: true + name: loopback999 + - duplex: auto + enabled: true + name: GigabitEthernet0/0 + speed: auto + - description: this is interface1 + duplex: auto + enabled: true + mtu: 65 + name: GigabitEthernet0/1 + speed: '10' + - description: this is interface for testing + duplex: auto + enabled: false + mtu: 110 + name: GigabitEthernet0/2 + speed: '100' + commands: + - interface GigabitEthernet0/1 + - no description + - no speed + - no mtu + - interface GigabitEthernet0/2 + - no description + - no shutdown + - no speed + - no mtu + after: + - enabled: true + name: loopback888 + - enabled: true + name: loopback999 + - duplex: auto + enabled: true + name: GigabitEthernet0/0 + speed: auto + - duplex: auto + enabled: true + name: GigabitEthernet0/1 + speed: auto + - duplex: auto + enabled: true + name: GigabitEthernet0/2 + speed: auto +gathered: + config: + - enabled: true + name: loopback888 + - enabled: true + name: loopback999 + - duplex: auto + enabled: true + name: GigabitEthernet0/0 + speed: auto + - description: this is interface1 + duplex: auto + enabled: true + mtu: 65 + name: GigabitEthernet0/1 + speed: "10" + - description: this is interface for testing + duplex: auto + enabled: false + mtu: 110 + name: GigabitEthernet0/2 + speed: "100" +parsed: + config: + - description: interfaces 0/1 + duplex: half + enabled: true + mtu: 110 + name: GigabitEthernet0/1 + - description: interfaces 0/2 + duplex: full + enabled: true + mtu: 2800 + name: GigabitEthernet0/2 + speed: "100" +rendered: + commands: + - interface GigabitEthernet0/1 + - description Configured by Ansible-Network + - mtu 110 + - duplex half + - no shutdown + - interface GigabitEthernet0/2 + - description Configured by Ansible-Network + - mtu 2800 + - speed 100 + - duplex full + - shutdown diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/meta/main.yml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tasks/cli.yaml new file mode 100644 index 00000000..c00ee31e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tasks/cli.yaml @@ -0,0 +1,27 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: + + - files: '{{ test_items|default([]) }}' + skip: true + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tasks/main.yaml new file mode 100644 index 00000000..f4c48370 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tasks/main.yaml @@ -0,0 +1,6 @@ +--- +- block: + - include: cli.yaml + tags: + - network_cli + when: switch_type == "L2" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tests/cli/agg.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tests/cli/agg.yaml new file mode 100644 index 00000000..ed2a05c1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tests/cli/agg.yaml @@ -0,0 +1,106 @@ +--- +- debug: msg="START connection={{ ansible_connection }} ios_l2_interface aggregate + test" + +- name: Setup - Ensure interfaces are switchport + loop: + - '{{ test_interface }}' + - '{{ test_interface2 }}' + cisco.ios.ios_config: + lines: + - switchport + parents: + - interface {{ item }} + +- name: Setup vlans + cisco.ios.ios_vlan: + aggregate: + + - vlan_id: 6 + + - vlan_id: 15 + provider: '{{ cli }}' + +- name: Setup - Remove interface aggregate before testing + cisco.ios.ios_l2_interface: + aggregate: + + - name: '{{ test_interface }}' + mode: access + access_vlan: 6 + + - name: '{{ test_interface2 }}' + mode: access + access_vlan: 15 + state: absent + provider: '{{ cli }}' + +- block: + + - name: Configure interface for access_vlan aggregate + register: result + cisco.ios.ios_l2_interface: &id001 + aggregate: + + - name: '{{ test_interface }}' + mode: access + access_vlan: 6 + + - name: '{{ test_interface2 }}' + mode: access + access_vlan: 15 + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + + - name: Configure interface for access_vlan aggregate(Idempotence) + register: result + cisco.ios.ios_l2_interface: *id001 + + - assert: + that: + - result.changed == false + + - name: Remove interface aggregate + register: result + cisco.ios.ios_l2_interface: &id002 + aggregate: + + - name: '{{ test_interface }}' + mode: access + access_vlan: 6 + + - name: '{{ test_interface2 }}' + mode: access + access_vlan: 15 + provider: '{{ cli }}' + state: absent + + - assert: + that: + - result.changed == true + + - name: Remove interface aggregate(Idempotence) + register: result + cisco.ios.ios_l2_interface: *id002 + + - assert: + that: + - result.changed == false + always: + + - name: remove vlans + ignore_errors: true + cisco.ios.ios_vlan: + aggregate: + + - vlan_id: 6 + + - vlan_id: 15 + state: absent + provider: '{{ cli }}' + +- debug: msg="END connection={{ ansible_connection }} ios_l2_interface aggregate + test" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tests/cli/sanity.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tests/cli/sanity.yaml new file mode 100644 index 00000000..15a8a237 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interface/tests/cli/sanity.yaml @@ -0,0 +1,186 @@ +--- +- debug: msg="START connection={{ ansible_connection }} ios_l2_interface sanity + test" + +- name: Setup interface + cisco.ios.ios_config: &id009 + lines: + - default interface {{ test_interface }} + provider: '{{ cli }}' + +- name: set trunk encapsulation type + cisco.ios.ios_config: + lines: + - switchport trunk encapsulation dot1q + parents: + - interface {{ test_interface }} + provider: '{{ cli }}' + +- name: Setup vlans + cisco.ios.ios_vlan: + aggregate: + + - vlan_id: 5 + + - vlan_id: 6 + + - vlan_id: 7 + + - vlan_id: 8 + + - vlan_id: 9 + + - vlan_id: 10 + + - vlan_id: 20 + provider: '{{ cli }}' + +- block: + + - name: Ensure interface is in its default switchport state + cisco.ios.ios_l2_interface: &id008 + name: '{{ test_interface }}' + state: unconfigured + provider: '{{ cli }}' + + - name: Ensure interface is configured for access vlan 20 + register: result + cisco.ios.ios_l2_interface: &id001 + name: '{{ test_interface }}' + mode: access + access_vlan: 20 + provider: '{{ cli }}' + + - assert: &id002 + that: + - result.changed == true + + - name: access vlan Idempotence + register: result + cisco.ios.ios_l2_interface: *id001 + + - assert: &id004 + that: + - result.changed == false + + - name: Ensure interface only has vlans 5-10 as trunk vlans + register: result + cisco.ios.ios_l2_interface: &id003 + name: '{{ test_interface }}' + mode: trunk + native_vlan: 10 + trunk_allowed_vlans: 5-10 + provider: '{{ cli }}' + + - assert: *id002 + + - name: trunk vlan Idempotence + register: result + cisco.ios.ios_l2_interface: *id003 + + - assert: *id004 + + - name: Ensure interface is a trunk port and ensure 2-50 are being tagged (doesn't + mean others aren't also being tagged) + register: result + cisco.ios.ios_l2_interface: &id005 + name: '{{ test_interface }}' + mode: trunk + native_vlan: 10 + trunk_vlans: 2-50 + provider: '{{ cli }}' + + - assert: *id002 + + - name: tag vlan Idempotence + register: result + cisco.ios.ios_l2_interface: *id005 + + - assert: *id004 + + - name: Remove full trunk vlan range 2-50 + register: result + cisco.ios.ios_l2_interface: &id006 + name: '{{ test_interface }}' + mode: trunk + trunk_vlans: 2-50 + state: absent + provider: '{{ cli }}' + + - assert: *id002 + + - name: Check Idempotence Remove full trunk vlan range 2-50 + register: result + cisco.ios.ios_l2_interface: *id006 + + - assert: *id004 + + - name: Reconfigure interface trunk port and ensure 2-50 are being tagged + register: result + cisco.ios.ios_l2_interface: *id005 + + - assert: *id002 + + - name: Check Idempotence Reconfigure interface trunk port and ensure 2-50 are + being tagged + register: result + cisco.ios.ios_l2_interface: *id005 + + - assert: *id004 + + - name: Remove partial trunk vlan range 30-4094 are removed + register: result + cisco.ios.ios_l2_interface: &id007 + name: '{{ test_interface }}' + mode: trunk + trunk_vlans: 30-4094 + state: absent + provider: '{{ cli }}' + + - assert: *id002 + + - name: Check Idempotence Remove partial trunk vlan range 30-4094 are removed + register: result + cisco.ios.ios_l2_interface: *id007 + + - assert: *id004 + + - name: put interface default state + register: result + cisco.ios.ios_l2_interface: *id008 + + - assert: *id002 + + - name: default state idempotence + register: result + cisco.ios.ios_l2_interface: *id008 + + - assert: *id004 + always: + + - name: remove vlans + ignore_errors: true + cisco.ios.ios_vlan: + aggregate: + + - vlan_id: 5 + + - vlan_id: 6 + + - vlan_id: 7 + + - vlan_id: 8 + + - vlan_id: 9 + + - vlan_id: 10 + + - vlan_id: 20 + state: absent + provider: '{{ cli }}' + + - name: default interface + ignore_errors: true + cisco.ios.ios_config: *id009 + +- debug: msg="END connection={{ ansible_connection }} ios_l2_interface sanity test" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..b14576a6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- 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: Get the IOS version + cisco.ios.ios_facts: + gather_subset: all + +- name: Run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_parsed.cfg new file mode 100644 index 00000000..a0ffc5f9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_parsed.cfg @@ -0,0 +1,8 @@ +interface GigabitEthernet0/1 + switchport mode access + switchport access vlan 30 +interface GigabitEthernet0/2 + switchport trunk allowed vlan 15-20,40 + switchport trunk encapsulation dot1q + switchport trunk native vlan 20 + switchport trunk pruning vlan 10,20
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..71449eae --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,10 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/1\nswitchport access vlan 10\ninterface\ + \ GigabitEthernet 0/2\nswitchport trunk encapsulation dot1q\nswitchport trunk\ + \ native vlan 10\nswitchport trunk allowed vlan 10-20,40\nswitchport trunk\ + \ pruning vlan 10,20\nswitchport mode trunk\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..339e37d6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,12 @@ +--- +- name: Remove Config + vars: + lines: "interface GigabitEthernet 0/1\nno switchport access vlan\nno switchport\ + \ trunk encapsulation\nno switchport trunk native vlan\nno switchport trunk\ + \ allowed vlan\nno switchport trunk pruning vlan\nno switchport mode\nno switchport voice vlan\ninterface\ + \ GigabitEthernet 0/2\nno switchport access vlan\nno switchport trunk encapsulation\n\ + no switchport trunk native vlan\nno switchport trunk allowed vlan\nno switchport\ + \ trunk pruning vlan\nno switchport mode\nno switchport voice vlan\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_remove_vlan_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_remove_vlan_config.yaml new file mode 100644 index 00000000..15e3eb58 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/_remove_vlan_config.yaml @@ -0,0 +1,5 @@ +--- +- name: Remove ALL VLAN Config + cisco.ios.ios_vlans: + state: deleted + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..c80c7609 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,47 @@ +--- +- debug: + msg: Start Deleted integration state for ios_l2_interfaces ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete L2 attributes from all configured interfaces + register: result + cisco.ios.ios_l2_interfaces: &id001 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ deleted['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Delete attributes of all configured interfaces (IDEMPOTENT) + register: result + cisco.ios.ios_l2_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml + - include_tasks: _remove_vlan_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..ce93edb3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START ios_l2_interfaces empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_l2_interfaces: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_l2_interfaces: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_l2_interfaces: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_l2_interfaces: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_l2_interfaces: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..852d586b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START ios_l2_interfaces gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_l2_interfaces: + config: + state: gathered + + - name: Assert + assert: + that: + - gathered['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..03fbf9e7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/merged.yaml @@ -0,0 +1,97 @@ +--- +- debug: + msg: START Merged ios_l2_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_l2_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + access: + vlan: 30 + voice: + vlan: 40 + - name: GigabitEthernet0/2 + trunk: + allowed_vlans: 15-20,40 + native_vlan: 20 + pruning_vlans: 10,20 + encapsulation: dot1q + mode: trunk + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_l2_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Merge new configuration with already merged configuration + register: result + cisco.ios.ios_l2_interfaces: &id002 + config: + - name: GigabitEthernet0/2 + trunk: + allowed_vlans: 200 + pruning_vlans: 40-60 + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged_again['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged_again['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge new configuration with already merged configuration (IDEMPOTENT) + register: result + cisco.ios.ios_l2_interfaces: *id002 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml + - include_tasks: _remove_vlan_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..36370507 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START Overridden ios_l2_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Override device L2 configuration from all interfaces with provided configuration + register: result + cisco.ios.ios_l2_interfaces: &id001 + config: + + - name: GigabitEthernet0/2 + trunk: + allowed_vlans: 30-35,40 + native_vlan: 30 + encapsulation: isl + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ overridden['before'] | symmetric_difference(result['before']) |\ + \ length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Override device L2 configuration from all interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_l2_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml + - include_tasks: _remove_vlan_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..29dfe300 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,18 @@ +--- +- debug: + msg: START ios_l2_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- block: + - name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_l2_interfaces: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + + - assert: + that: + - result.changed == false + - parsed['config']|symmetric_difference(result.parsed) == [] + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..e1e02ed4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,30 @@ +--- +- debug: + msg: Start ios_l2_interfaces rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_l2_interfaces: + config: + + - name: GigabitEthernet0/1 + access: + vlan: 30 + + - name: GigabitEthernet0/2 + trunk: + allowed_vlans: 10-20,40 + native_vlan: 20 + pruning_vlans: 10,20 + encapsulation: dot1q + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(rendered.commands) == [] + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..fe8e7d62 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,61 @@ +--- +- debug: + msg: START Replaced ios_l2_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces device L2 configuration from listed interfaces with provided + configuration + register: result + cisco.ios.ios_l2_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + access: + vlan: 40 + voice: + vlan: 20 + - name: GigabitEthernet0/2 + trunk: + native_vlan: 20 + pruning_vlans: 10-20,30 + encapsulation: dot1q + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ replaced['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Replaces device L2 configuration from listed interfaces with provided + configuration (IDEMPOTENT) + register: result + cisco.ios.ios_l2_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml + - include_tasks: _remove_vlan_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..6243c860 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,65 @@ +--- +- debug: + msg: START ios_l2_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: base_config + cisco.ios.ios_l2_interfaces: + config: + - name: GigabitEthernet0/1 + access: + vlan: 30 + - mode: trunk + name: GigabitEthernet0/2 + trunk: + allowed_vlans: 15-20,40 + native_vlan: 20 + pruning_vlans: 10,20 + encapsulation: dot1q + state: merged + + - name: Gather L2 interfaces facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - l2_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_l2_interfaces: + config: + - name: GigabitEthernet0/2 + trunk: + allowed_vlans: 30-35,40 + native_vlan: 30 + encapsulation: isl + state: overridden + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_l2_interfaces: + config: "{{ ansible_facts['network_resources']['l2_interfaces'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 7 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/vars/main.yaml new file mode 100644 index 00000000..251b5585 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l2_interfaces/vars/main.yaml @@ -0,0 +1,213 @@ +--- +merged: + before: + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 + commands: + - interface GigabitEthernet0/1 + - switchport access vlan 30 + - switchport voice vlan 40 + - interface GigabitEthernet0/2 + - switchport trunk encapsulation dot1q + - switchport trunk native vlan 20 + - switchport trunk allowed vlan 15-20,40 + - switchport trunk pruning vlan 10,20 + - switchport mode trunk + after: + - name: GigabitEthernet0/0 + - access: + vlan: 30 + voice: + vlan: 40 + name: GigabitEthernet0/1 + - mode: trunk + name: GigabitEthernet0/2 + trunk: + allowed_vlans: + - 15-20 + - '40' + encapsulation: dot1q + native_vlan: 20 + pruning_vlans: + - '10' + - '20' +merged_again: + commands: + - interface GigabitEthernet0/2 + - switchport trunk allowed vlan 200,15-20,40 + - switchport trunk pruning vlan 40-60,10,20 + after: + - name: GigabitEthernet0/0 + - access: + vlan: 30 + name: GigabitEthernet0/1 + - mode: trunk + name: GigabitEthernet0/2 + trunk: + allowed_vlans: + - 15-20 + - '40' + - '200' + encapsulation: dot1q + native_vlan: 20 + pruning_vlans: + - '10' + - '20' + - 40-60 +replaced: + before: + - name: GigabitEthernet0/0 + - access: + vlan: 10 + name: GigabitEthernet0/1 + - mode: trunk + name: GigabitEthernet0/2 + trunk: + allowed_vlans: + - 10-20 + - '40' + encapsulation: dot1q + native_vlan: 10 + pruning_vlans: + - '10' + - '20' + commands: + - interface GigabitEthernet0/1 + - switchport access vlan 40 + - switchport voice vlan 20 + - interface GigabitEthernet0/2 + - no switchport mode + - no switchport trunk allowed vlan + - switchport trunk native vlan 20 + - switchport trunk pruning vlan 10-20,30 + after: + - name: GigabitEthernet0/0 + - access: + vlan: 40 + name: GigabitEthernet0/1 + voice: + vlan: 20 + - name: GigabitEthernet0/2 + trunk: + encapsulation: dot1q + native_vlan: 20 + pruning_vlans: + - 10-20 + - '30' +overridden: + before: + - name: GigabitEthernet0/0 + - access: + vlan: 10 + name: GigabitEthernet0/1 + - mode: trunk + name: GigabitEthernet0/2 + trunk: + allowed_vlans: + - 10-20 + - '40' + encapsulation: dot1q + native_vlan: 10 + pruning_vlans: + - '10' + - '20' + commands: + - interface GigabitEthernet0/1 + - no switchport access vlan + - interface GigabitEthernet0/2 + - no switchport mode + - no switchport trunk pruning vlan + - switchport trunk encapsulation isl + - switchport trunk native vlan 30 + - switchport trunk allowed vlan 30-35,40 + after: + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 + trunk: + allowed_vlans: + - 30-35 + - '40' + encapsulation: isl + native_vlan: 30 +deleted: + before: + - name: GigabitEthernet0/0 + - access: + vlan: 10 + name: GigabitEthernet0/1 + - mode: trunk + name: GigabitEthernet0/2 + trunk: + allowed_vlans: + - 10-20 + - '40' + encapsulation: dot1q + native_vlan: 10 + pruning_vlans: + - '10' + - '20' + commands: + - interface GigabitEthernet0/1 + - no switchport access vlan + - interface GigabitEthernet0/2 + - no switchport mode + - no switchport trunk encapsulation + - no switchport trunk native vlan + - no switchport trunk allowed vlan + - no switchport trunk pruning vlan + after: + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 +gathered: + config: + - access: + vlan: 30 + name: GigabitEthernet0/1 + - mode: trunk + name: GigabitEthernet0/2 + trunk: + allowed_vlans: + - "10-20" + - "40" + encapsulation: dot1q + native_vlan: 10 + pruning_vlans: + - "10" + - "20" +parsed: + config: + - access: + vlan: 30 + mode: access + name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 + trunk: + allowed_vlans: + - "15-20" + - "40" + encapsulation: dot1q + native_vlan: 20 + pruning_vlans: + - "10" + - "20" +rendered: + commands: + - interface GigabitEthernet0/1 + - switchport access vlan 30 + - interface GigabitEthernet0/2 + - switchport trunk encapsulation dot1q + - switchport trunk native vlan 20 + - switchport trunk allowed vlan 10-20,40 + - switchport trunk pruning vlan 10,20 +rtt: + commands: + - interface GigabitEthernet0/1 + - switchport access vlan 30 + - interface GigabitEthernet0/2 + - switchport trunk encapsulation dot1q + - switchport trunk native vlan 20 + - switchport trunk allowed vlan 15-20,40 + - switchport trunk pruning vlan 10,20 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/tests/cli/basic.yaml new file mode 100644 index 00000000..3b02731b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interface/tests/cli/basic.yaml @@ -0,0 +1,280 @@ +--- +- debug: msg="START ios_l3_interface cli/basic.yaml on connection={{ ansible_connection + }}" + +- name: Delete interface ipv4 and ipv6 address(setup) + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface }}' + state: absent + provider: '{{ cli }}' + +- name: Setup - Ensure interfaces are switchport + loop: + - '{{ test_interface }}' + - '{{ test_interface2 }}' + cisco.ios.ios_config: + lines: + - no shutdown + parents: + - interface {{ item }} + provider: '{{ cli }}' + +- name: Configure interface ipv4 address + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface }}' + ipv4: 192.168.20.1/24 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"ip address 192.168.20.1 255.255.255.0" in result.commands' + +- name: Configure interface ipv4 address (idempotent) + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface }}' + ipv4: 192.168.20.1/24 + state: present + provider: '{{ cli }}' + +- assert: &id002 + that: + - result.changed == false + +- name: Assign same ipv4 address to other interface (fail) + ignore_errors: true + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface2 }}' + ipv4: 192.168.20.1/24 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.failed == true + - result.msg is defined + +- name: Change interface ipv4 address + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface }}' + ipv4: dhcp + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"ip address dhcp" in result.commands' + +- name: Configure interface ipv6 address + register: result + cisco.ios.ios_l3_interface: &id001 + name: '{{ test_interface }}' + ipv6: fd5d:12c9:2201:1::1/64 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"ipv6 address fd5d:12c9:2201:1::1/64" in result.commands' + +- name: Configure interface ipv6 address (idempotent) + register: result + cisco.ios.ios_l3_interface: *id001 + +- assert: *id002 + +- name: Configure second ipv6 address on interface + register: result + cisco.ios.ios_l3_interface: &id003 + name: '{{ test_interface }}' + ipv6: fd5d:12c9:2291:1::1/64 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"ipv6 address fd5d:12c9:2291:1::1/64" in result.commands' + +- name: Ensure first ipv6 address still associated with interface + register: result + cisco.ios.ios_l3_interface: *id001 + +- assert: *id002 + +- name: Ensure second ipv6 address still associated with interface + register: result + cisco.ios.ios_l3_interface: *id003 + +- assert: *id002 + +- name: Assign same ipv6 address to other interface (fail) + ignore_errors: true + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface2 }}' + ipv6: fd5d:12c9:2201:1::1/64 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.failed == true + - result.msg is defined + +- name: Change interface ipv6 address + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface }}' + ipv6: dhcp + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"ipv6 address dhcp" in result.commands' + +- name: Delete interface ipv4 and ipv6 address + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface }}' + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"no ip address" in result.commands' + - '"no ipv6 address" in result.commands' + +- name: Delete interface ipv4 and ipv6 address (idempotent) + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface }}' + state: absent + provider: '{{ cli }}' + +- assert: *id002 + +- name: Delete second interface ipv4 and ipv6 address (setup) + register: result + cisco.ios.ios_l3_interface: + name: '{{ test_interface2 }}' + state: absent + provider: '{{ cli }}' + +- name: Configure ipv4 and ipv6 address using aggregate + register: result + cisco.ios.ios_l3_interface: + aggregate: + + - name: '{{ test_interface }}' + ipv4: 192.161.0.1/24 + ipv6: fd5d:12c9:2201:2::2/64 + + - name: '{{ test_interface2 }}' + ipv4: 192.162.0.2/16 + ipv6: fd5e:12c9:2201:3::3/32 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"ip address 192.161.0.1 255.255.255.0" in result.commands' + - '"ipv6 address fd5d:12c9:2201:2::2/64" in result.commands' + - '"interface {{ test_interface2 }}" in result.commands' + - '"ip address 192.162.0.2 255.255.0.0" in result.commands' + - '"ipv6 address fd5e:12c9:2201:3::3/32" in result.commands' + +- name: Configure ipv4 and ipv6 address using aggregate (idempotent) + register: result + cisco.ios.ios_l3_interface: + aggregate: + + - name: '{{ test_interface }}' + ipv4: 192.161.0.1/24 + ipv6: fd5d:12c9:2201:2::2/64 + + - name: '{{ test_interface2 }}' + ipv4: 192.162.0.2/16 + ipv6: fd5e:12c9:2201:3::3/32 + provider: '{{ cli }}' + +- assert: *id002 + +- name: Change ipv4 and ipv6 address using aggregate + register: result + cisco.ios.ios_l3_interface: + aggregate: + + - name: '{{ test_interface }}' + ipv4: 193.167.1.1/8 + ipv6: fd5a:12c9:2201:4::4/32 + + - name: '{{ test_interface2 }}' + ipv4: 192.169.2.2/24 + ipv6: fd5b:12c9:2201:5::5/90 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"ip address 193.167.1.1 255.0.0.0" in result.commands' + - '"ipv6 address fd5a:12c9:2201:4::4/32" in result.commands' + - '"interface {{ test_interface2 }}" in result.commands' + - '"ip address 192.169.2.2 255.255.255.0" in result.commands' + - '"ipv6 address fd5b:12c9:2201:5::5/90" in result.commands' + +- name: Delete ipv4 and ipv6 address using aggregate + register: result + cisco.ios.ios_l3_interface: + aggregate: + + - name: '{{ test_interface }}' + + - name: '{{ test_interface2 }}' + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface {{ test_interface }}" in result.commands' + - '"no ip address" in result.commands' + - '"no ipv6 address" in result.commands' + - '"interface {{ test_interface2 }}" in result.commands' + - '"no ip address" in result.commands' + - '"no ipv6 address" in result.commands' + +- name: Delete ipv4 and ipv6 address using aggregate (idempotent) + register: result + cisco.ios.ios_l3_interface: + aggregate: + + - name: '{{ test_interface }}' + + - name: '{{ test_interface2 }}' + state: absent + provider: '{{ cli }}' + +- assert: *id002 + +- debug: msg="END ios_l3_interface cli/basic.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/_parsed.cfg new file mode 100644 index 00000000..dc22f5fc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/_parsed.cfg @@ -0,0 +1,6 @@ +interface GigabitEthernet0/1 + ip address dhcp client-id GigabitEthernet 0/0 hostname test.com +interface GigabitEthernet0/2 + ip address 198.51.100.1 255.255.255.0 secondary + ip address 198.51.100.2 255.255.255.0 + ipv6 address 2001:db8:0:3::/64
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..9d3861d3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/1\nip address 203.0.113.27 255.255.255.0\n\ + interface GigabitEthernet 0/2\nip address 192.0.2.1 255.255.255.0 secondary\n\ + ip address 192.0.2.2 255.255.255.0\nipv6 address 2001:db8:0:3::/64\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..14b8fbdf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,7 @@ +--- +- name: Remove Config + vars: + lines: "interface Loopback 999\nno ip address\ninterface GigabitEthernet 0/1\nno ip address\nno ipv6 address\ninterface\ + \ GigabitEthernet 0/2\nno ip address\nno ipv6 address\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..c2929490 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,50 @@ +--- +- debug: + msg: Start Deleted integration state for ios_l3_interfaces ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete attributes of provided configured interfaces + register: result + cisco.ios.ios_l3_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + + - name: GigabitEthernet0/2 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ deleted['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Delete attributes of all configured interfaces (IDEMPOTENT) + register: result + cisco.ios.ios_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/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..e86ecbf7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START ios_l3_interfaces empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_l3_interfaces: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_l3_interfaces: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_l3_interfaces: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_l3_interfaces: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_l3_interfaces: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..7748b8c3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,23 @@ +--- +- debug: + msg: START ios_l3_interfaces gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_l3_interfaces: + config: + state: gathered + + - name: Assert + assert: + that: + - gathered['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..6aed7ca1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/merged.yaml @@ -0,0 +1,59 @@ +--- +- debug: + msg: START Merged ios_l3_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_l3_interfaces: &id001 + config: + - name: Loopback999 + ipv4: + - address: 192.0.2.1/24 + - name: GigabitEthernet0/1 + ipv4: + - address: dhcp + dhcp_client: 0 + dhcp_hostname: test.com + - name: GigabitEthernet0/2 + ipv4: + - address: 198.51.100.1/24 + secondary: true + - address: 198.51.100.2/24 + ipv6: + - address: 2001:db8:0:3::/64 + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_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/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..e1f9c021 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START Overridden ios_l3_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Override device configuration of all interfaces with provided configuration + register: result + cisco.ios.ios_l3_interfaces: &id001 + config: + + - name: GigabitEthernet0/0 + ipv4: + + - address: dhcp + + - name: GigabitEthernet0/2 + ipv4: + + - address: 198.51.100.1/24 + + - address: 198.51.100.2/24 + secondary: true + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ overridden['before'] | symmetric_difference(result['before']) |\ + \ length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Override device configuration of all interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_l3_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..9abf5cf9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START ios_l3_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_l3_interfaces: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - parsed['config']|symmetric_difference(result.parsed) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..399409b2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: Start ios_l3_interfaces rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_l3_interfaces: + config: + - name: Loopback999 + ipv4: + - address: 192.0.2.1/24 + - name: GigabitEthernet0/1 + ipv4: + - address: dhcp + dhcp_client: 0 + dhcp_hostname: test.com + - name: GigabitEthernet0/2 + ipv4: + - address: 198.51.100.1/24 + secondary: true + - address: 198.51.100.2/24 + ipv6: + - address: 2001:db8:0:3::/64 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..826f7fb2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,63 @@ +--- +- debug: + msg: START Replaced ios_l3_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces device configuration of listed interfaces with provided configuration + register: result + cisco.ios.ios_l3_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + ipv4: + + - address: 203.0.114.1/24 + + - name: GigabitEthernet0/2 + ipv4: + + - address: 198.51.100.1/24 + secondary: true + + - address: 198.51.100.2/24 + ipv6: + + - address: 2001:db8:1:1::/64 + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ replaced['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Replaces device configuration of listed interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_l3_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..e123ac1f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,79 @@ +--- +- debug: + msg: START ios_l3_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: result + cisco.ios.ios_l3_interfaces: + config: + - name: Loopback999 + ipv4: + - address: 192.0.2.1/24 + - name: GigabitEthernet0/0 + ipv4: + - address: dhcp + - name: GigabitEthernet0/1 + ipv4: + - address: dhcp + dhcp_client: 0 + dhcp_hostname: test.com + - name: GigabitEthernet0/2 + ipv4: + - address: 198.51.100.1/24 + secondary: true + - address: 198.51.100.2/24 + ipv6: + - address: 2001:db8:0:3::/64 + state: merged + + - name: Gather L3 interfaces facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - l3_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_l3_interfaces: + config: + - name: Loopback999 + ipv4: + - address: 192.0.2.1/24 + - name: GigabitEthernet0/0 + ipv4: + - address: dhcp + - name: GigabitEthernet0/2 + ipv4: + - address: 198.51.100.1/24 + - address: 198.51.100.2/24 + secondary: true + state: overridden + + - assert: + that: + - result.commands|length == 7 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_l3_interfaces: + config: "{{ ansible_facts['network_resources']['l3_interfaces'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 6 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/vars/main.yaml new file mode 100644 index 00000000..cc5614f6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_l3_interfaces/vars/main.yaml @@ -0,0 +1,188 @@ +--- +merged: + before: + - name: loopback888 + - name: loopback999 + - ipv4: + - address: dhcp + name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 + commands: + - interface loopback999 + - ip address 192.0.2.1 255.255.255.0 + - interface GigabitEthernet0/1 + - ip address dhcp client-id GigabitEthernet0/0 hostname test.com + - interface GigabitEthernet0/2 + - ip address 198.51.100.1 255.255.255.0 secondary + - ip address 198.51.100.2 255.255.255.0 + - ipv6 address 2001:db8:0:3::/64 + after: + - name: loopback888 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + name: loopback999 + - ipv4: + - address: dhcp + name: GigabitEthernet0/0 + - ipv4: + - address: dhcp + dhcp_client: 0 + dhcp_hostname: test.com + name: GigabitEthernet0/1 + - ipv4: + - address: 198.51.100.1 255.255.255.0 + secondary: true + - address: 198.51.100.2 255.255.255.0 + ipv6: + - address: 2001:db8:0:3::/64 + name: GigabitEthernet0/2 +replaced: + before: + - name: loopback888 + - name: loopback999 + - ipv4: + - address: dhcp + name: GigabitEthernet0/0 + - ipv4: + - address: 203.0.113.27 255.255.255.0 + name: GigabitEthernet0/1 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + secondary: true + - address: 192.0.2.2 255.255.255.0 + ipv6: + - address: 2001:db8:0:3::/64 + name: GigabitEthernet0/2 + commands: + - interface GigabitEthernet0/1 + - ip address 203.0.114.1 255.255.255.0 + - interface GigabitEthernet0/2 + - no ip address + - no ipv6 address + - ip address 198.51.100.1 255.255.255.0 secondary + - ip address 198.51.100.2 255.255.255.0 + - ipv6 address 2001:db8:1:1::/64 + after: + - name: loopback888 + - name: loopback999 + - ipv4: + - address: dhcp + name: GigabitEthernet0/0 + - ipv4: + - address: 203.0.114.1 255.255.255.0 + name: GigabitEthernet0/1 + - ipv4: + - address: 198.51.100.1 255.255.255.0 + secondary: true + - address: 198.51.100.2 255.255.255.0 + ipv6: + - address: 2001:db8:1:1::/64 + name: GigabitEthernet0/2 +overridden: + before: + - name: loopback888 + - name: loopback999 + - ipv4: + - address: dhcp + name: GigabitEthernet0/0 + - ipv4: + - address: 203.0.113.27 255.255.255.0 + name: GigabitEthernet0/1 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + secondary: true + - address: 192.0.2.2 255.255.255.0 + ipv6: + - address: 2001:db8:0:3::/64 + name: GigabitEthernet0/2 + commands: + - interface GigabitEthernet0/1 + - no ip address + - interface GigabitEthernet0/2 + - no ip address + - no ipv6 address + - ip address 198.51.100.1 255.255.255.0 + - ip address 198.51.100.2 255.255.255.0 secondary + after: + - name: loopback888 + - name: loopback999 + - ipv4: + - address: dhcp + name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - ipv4: + - address: 198.51.100.2 255.255.255.0 + secondary: true + - address: 198.51.100.1 255.255.255.0 + name: GigabitEthernet0/2 +deleted: + before: + - name: loopback888 + - name: loopback999 + - ipv4: + - address: dhcp + name: GigabitEthernet0/0 + - ipv4: + - address: 203.0.113.27 255.255.255.0 + name: GigabitEthernet0/1 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + secondary: true + - address: 192.0.2.2 255.255.255.0 + ipv6: + - address: 2001:db8:0:3::/64 + name: GigabitEthernet0/2 + commands: + - interface GigabitEthernet0/1 + - no ip address + - interface GigabitEthernet0/2 + - no ip address + - no ipv6 address + after: + - name: loopback888 + - name: loopback999 + - ipv4: + - address: dhcp + name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 +gathered: + config: + - name: loopback888 + - name: loopback999 + - ipv4: + - address: dhcp + name: GigabitEthernet0/0 + - ipv4: + - address: 203.0.113.27 255.255.255.0 + name: GigabitEthernet0/1 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + secondary: true + - address: 192.0.2.2 255.255.255.0 + ipv6: + - address: 2001:db8:0:3::/64 + name: GigabitEthernet0/2 +parsed: + config: + - ipv4: + - address: dhcp + dhcp_client: 0 + dhcp_hostname: test.com + name: GigabitEthernet0/1 + - ipv4: + - address: 198.51.100.1 255.255.255.0 + secondary: true + - address: 198.51.100.2 255.255.255.0 + ipv6: + - address: 2001:db8:0:3::/64 + name: GigabitEthernet0/2 +rtt: + commands: + - interface GigabitEthernet0/1 + - ip address dhcp client-id GigabitEthernet0/0 hostname test.com + - interface GigabitEthernet0/2 + - ip address 198.51.100.1 255.255.255.0 secondary + - ip address 198.51.100.2 255.255.255.0 + - ipv6 address 2001:db8:0:3::/64 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/aliases b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/aliases new file mode 100644 index 00000000..6bb69158 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/aliases @@ -0,0 +1 @@ +shippable/ios/group1 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tasks/cli.yaml new file mode 100644 index 00000000..b14576a6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- 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: Get the IOS version + cisco.ios.ios_facts: + gather_subset: all + +- name: Run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/_parsed.cfg new file mode 100644 index 00000000..c2bbb7a5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/_parsed.cfg @@ -0,0 +1 @@ +123, 5e00.0000.8000
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..52b5b9b2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/_populate_config.yaml @@ -0,0 +1,7 @@ +--- +- name: Populate Config + vars: + lines: "lacp system-priority 500\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..d418aad3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/_remove_config.yaml @@ -0,0 +1,7 @@ +--- +- name: Remove Config + vars: + lines: "no lacp system-priority\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/deleted.yaml new file mode 100644 index 00000000..df55dfb6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/deleted.yaml @@ -0,0 +1,44 @@ +--- +- debug: + msg: Start Deleted integration state for ios_lacp ansible_connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete configured System LACP + register: result + cisco.ios.ios_lacp: &id001 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ deleted['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ deleted['before'] == result['before'] }}" + + - name: Delete configured System LACP (IDEMPOTENT) + register: result + cisco.ios.ios_lacp: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/empty_config.yaml new file mode 100644 index 00000000..7a6991df --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/empty_config.yaml @@ -0,0 +1,54 @@ +--- +- debug: + msg: START ios_lacp empty_config.yaml integration tests on connection={{ ansible_connection + }} + +- block: + + - name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_lacp: + config: + state: merged + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lacp: + config: + state: replaced + + - assert: + that: + - result.msg == 'value of config parameter must not be empty for state + replaced' + + - name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_lacp: + config: + state: rendered + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lacp: + running_config: + state: parsed + + - assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/gathered.yaml new file mode 100644 index 00000000..d84a0232 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START ios_lacp gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_lacp: + config: + state: gathered + + - name: Assert + assert: + that: + - "{{result['gathered'] == gathered['config'] }}" + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/merged.yaml new file mode 100644 index 00000000..40f12640 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/merged.yaml @@ -0,0 +1,45 @@ +--- +- debug: + msg: START Merged ios_lacp state for integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge provided configuration system LACP + register: result + cisco.ios.ios_lacp: &id001 + config: + system: + priority: 10 + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['before'] == result['before'] }}" + + - name: Merge provided configuration system LACP (IDEMPOTENT) + register: result + cisco.ios.ios_lacp: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/parsed.yaml new file mode 100644 index 00000000..bb2b8b2f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/parsed.yaml @@ -0,0 +1,18 @@ +--- +- debug: + msg: START ios_lacp parsed integration tests on connection={{ ansible_connection + }} + +- block: + - name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_lacp: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + + - assert: + that: + - result.changed == false + - "{{result['parsed'] == parsed['config'] }}" + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/rendered.yaml new file mode 100644 index 00000000..943b783c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/rendered.yaml @@ -0,0 +1,21 @@ +--- +- debug: + msg: Start ios_lacp rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_lacp: + config: + system: + priority: 10 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/replaced.yaml new file mode 100644 index 00000000..9a9f5b83 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/tests/cli/replaced.yaml @@ -0,0 +1,47 @@ +--- +- debug: + msg: START Replaced ios_lacp state for integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces system LACP configuration provided LACP configuration + register: result + cisco.ios.ios_lacp: &id001 + config: + system: + priority: 20 + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ replaced['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['before'] == result['before'] }}" + + - name: Replaces system LACP configuration provided LACP configuration (IDEMPOTENT) + register: result + cisco.ios.ios_lacp: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/vars/main.yaml new file mode 100644 index 00000000..5c3611f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp/vars/main.yaml @@ -0,0 +1,38 @@ +--- +merged: + before: + system: + priority: 32768 + commands: + - lacp system-priority 10 + after: + - system: + priority: 10 +replaced: + before: + system: + priority: 500 + commands: + - lacp system-priority 20 + after: + system: + priority: 20 +deleted: + before: + system: + priority: 500 + commands: + - no lacp system-priority + after: + system: + priority: 32768 + +gathered: + config: + system: + priority: 500 + +parsed: + config: + system: + priority: 123 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..b14576a6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- 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: Get the IOS version + cisco.ios.ios_facts: + gather_subset: all + +- name: Run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/_parsed.cfg new file mode 100644 index 00000000..792196c8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/_parsed.cfg @@ -0,0 +1,7 @@ +interface GigabitEthernet0/1 + lacp port-priority 10 +interface GigabitEthernet0/2 + lacp port-priority 20 +interface Port-channel10 + lacp max-bundle 2 + lacp fast-switchover diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..5739706d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,9 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/1\nlacp port-priority 30\ninterface GigabitEthernet\ + \ 0/2\nlacp port-priority 20\ninterface Port-channel 10\nlacp fast-switchover\n\ + lacp max-bundle 2\ninterface Port-channel 40\nlacp max-bundle 5\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..334a22b1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,10 @@ +--- +- name: Remove Config + vars: + lines: "interface GigabitEthernet 0/1\nno lacp port-priority\ninterface GigabitEthernet\ + \ 0/2\nno lacp port-priority\ninterface Port-channel 10\nno lacp fast-switchover\n\ + no lacp max-bundle\ninterface Port-channel 40\nno lacp fast-switchover\nno\ + \ lacp max-bundle\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..c08115c4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,46 @@ +--- +- debug: + msg: Start Deleted integration state for ios_lacp_interfaces ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete LACP attributes for all configured interfaces + register: result + cisco.ios.ios_lacp_interfaces: &id001 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ deleted['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Delete LACP attributes for all configured interfaces (IDEMPOTENT) + register: result + cisco.ios.ios_lacp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..f022d2cd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,66 @@ +--- +- debug: + msg: START ios_lacp_interfaces empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- block: + + - name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_lacp_interfaces: + config: + state: merged + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lacp_interfaces: + config: + state: replaced + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lacp_interfaces: + config: + state: overridden + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lacp_interfaces: + config: + state: rendered + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lacp_interfaces: + running_config: + state: parsed + + - assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..212482dd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START ios_lacp_interfaces gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_lacp_interfaces: + config: + state: gathered + + - name: Assert + assert: + that: + - gathered['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..9244fbd6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/merged.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: START Merged ios_lacp_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_lacp_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + port_priority: 30 + + - name: GigabitEthernet0/2 + port_priority: 20 + + - name: Port-channel10 + fast_switchover: true + max_bundle: 2 + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge the provided configuration with the exisiting running configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_lacp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..a925578e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START Overridden ios_lacp_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Override device configuration of all lacp_interfaces with provided configuration + register: result + cisco.ios.ios_lacp_interfaces: &id001 + config: + + - name: GigabitEthernet0/2 + port_priority: 40 + + - name: Port-channel40 + fast_switchover: true + max_bundle: 2 + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ overridden['before'] | symmetric_difference(result['before']) |\ + \ length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Override device configuration of all lacp_interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_lacp_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..fac0c714 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,18 @@ +--- +- debug: + msg: START ios_lacp_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- block: + - name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_lacp_interfaces: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + + - assert: + that: + - result.changed == false + - parsed['config']|symmetric_difference(result.parsed) == [] + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..5fbb6601 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,26 @@ +--- +- debug: + msg: Start ios_lacp_interfaces rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_lacp_interfaces: + config: + - name: GigabitEthernet0/1 + port_priority: 30 + - name: GigabitEthernet0/2 + port_priority: 20 + - name: Port-channel10 + fast_switchover: true + max_bundle: 2 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..bfcfe4fe --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START Replaced ios_lacp_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces device configuration of listed lacp_interfaces with provided + configuration + register: result + cisco.ios.ios_lacp_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + port_priority: 10 + + - name: Port-channel40 + fast_switchover: true + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ replaced['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Replaces device configuration of listed lacp_interfaces with provided + configuration (IDEMPOTENT) + register: result + cisco.ios.ios_lacp_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..83f5af6b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,62 @@ +--- +- debug: + msg: START ios_lacp_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: base_config + cisco.ios.ios_lacp_interfaces: + config: + - name: GigabitEthernet0/1 + port_priority: 30 + - name: GigabitEthernet0/2 + port_priority: 20 + - name: Port-channel10 + fast_switchover: true + max_bundle: 2 + state: merged + + - name: Gather lacp interfaces facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - lacp_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_lacp_interfaces: + config: + - name: GigabitEthernet0/2 + port_priority: 40 + - name: Port-channel40 + fast_switchover: true + max_bundle: 2 + state: overridden + + - assert: + that: + - result.commands|length == 10 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_lacp_interfaces: + config: "{{ ansible_facts['network_resources']['lacp_interfaces'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 10 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/vars/main.yaml new file mode 100644 index 00000000..d9d55b5e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lacp_interfaces/vars/main.yaml @@ -0,0 +1,148 @@ +--- +merged: + before: + - name: Port-channel10 + - name: Port-channel40 + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 + commands: + - interface GigabitEthernet0/1 + - lacp port-priority 30 + - interface GigabitEthernet0/2 + - lacp port-priority 20 + - interface Port-channel10 + - lacp max-bundle 2 + - lacp fast-switchover + after: + - fast_switchover: true + max_bundle: 2 + name: Port-channel10 + - name: Port-channel40 + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + port_priority: 30 + - name: GigabitEthernet0/2 + port_priority: 20 +replaced: + before: + - fast_switchover: true + max_bundle: 2 + name: Port-channel10 + - max_bundle: 5 + name: Port-channel40 + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + port_priority: 30 + - name: GigabitEthernet0/2 + port_priority: 20 + commands: + - interface GigabitEthernet0/1 + - lacp port-priority 10 + - interface Port-channel40 + - no lacp max-bundle + - lacp fast-switchover + after: + - fast_switchover: true + max_bundle: 2 + name: Port-channel10 + - fast_switchover: true + name: Port-channel40 + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + port_priority: 10 + - name: GigabitEthernet0/2 + port_priority: 20 +overridden: + before: + - fast_switchover: true + max_bundle: 2 + name: Port-channel10 + - max_bundle: 5 + name: Port-channel40 + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + port_priority: 30 + - name: GigabitEthernet0/2 + port_priority: 20 + commands: + - interface GigabitEthernet0/1 + - no lacp port-priority + - interface GigabitEthernet0/2 + - lacp port-priority 40 + - interface Port-channel10 + - no lacp fast-switchover + - no lacp max-bundle + - interface Port-channel40 + - lacp fast-switchover + - lacp max-bundle 2 + after: + - name: Port-channel10 + - fast_switchover: true + max_bundle: 2 + name: Port-channel40 + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 + port_priority: 40 +deleted: + before: + - fast_switchover: true + max_bundle: 2 + name: Port-channel10 + - max_bundle: 5 + name: Port-channel40 + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + port_priority: 30 + - name: GigabitEthernet0/2 + port_priority: 20 + commands: + - interface GigabitEthernet0/1 + - no lacp port-priority + - interface GigabitEthernet0/2 + - no lacp port-priority + - interface Port-channel10 + - no lacp fast-switchover + - no lacp max-bundle + - interface Port-channel40 + - no lacp max-bundle + after: + - name: Port-channel10 + - name: Port-channel40 + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 +gathered: + config: + - fast_switchover: true + max_bundle: 2 + name: Port-channel10 + - max_bundle: 5 + name: Port-channel40 + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + port_priority: 30 + - name: GigabitEthernet0/2 + port_priority: 20 +parsed: + config: + - name: GigabitEthernet0/1 + port_priority: 10 + - name: GigabitEthernet0/2 + port_priority: 20 + - fast_switchover: true + max_bundle: 2 + name: Port-channel10 +rtt: + commands: + - interface Port-channel10 + - lacp max-bundle 2 + - lacp fast-switchover + - interface Port-channel40 + - no lacp max-bundle + - no lacp fast-switchover + - interface GigabitEthernet0/1 + - lacp port-priority 30 + - interface GigabitEthernet0/2 + - lacp port-priority 20 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..b14576a6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- 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: Get the IOS version + cisco.ios.ios_facts: + gather_subset: all + +- name: Run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_parsed.cfg new file mode 100644 index 00000000..5d2a5826 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_parsed.cfg @@ -0,0 +1,4 @@ +interface GigabitEthernet0/1 +channel-group 11 mode active +interface GigabitEthernet0/2 +channel-group 22 mode passive diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..57404ef7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/1\nchannel-group 11 mode active\ninterface\ + \ GigabitEthernet 0/2\nchannel-group 22 mode active\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_populate_port_channel.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_populate_port_channel.yaml new file mode 100644 index 00000000..83034823 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_populate_port_channel.yaml @@ -0,0 +1,7 @@ +--- +- name: Populate Port-Channel Config + vars: + lines: "interface Port-channel11\ninterface Port-channel22\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..3273e4da --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Remove Config + vars: + lines: "interface GigabitEthernet 0/1\nno channel-group\ninterface GigabitEthernet\ + \ 0/2\nno channel-group\nno interface Port-channel11\nno interface Port-channel22" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..ec06444d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,47 @@ +--- +- debug: + msg: Start Deleted integration state for ios_lag_interfaces ansible_connection={{ + ansible_connection }} + +- include_tasks: _populate_port_channel.yaml +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete attributes of all configured interfaces + register: result + cisco.ios.ios_lag_interfaces: &id001 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ deleted['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Delete attributes of all configured interfaces (IDEMPOTENT) + register: result + cisco.ios.ios_lag_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..3160561f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,67 @@ +--- +- debug: + msg: START ios_lag_interfaces empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- block: + + - name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_lag_interfaces: + config: + state: merged + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lag_interfaces: + config: + state: replaced + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lag_interfaces: + config: + state: overridden + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lag_interfaces: + config: + state: rendered + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_lag_interfaces: + running_config: + state: parsed + + - assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..b06af796 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,26 @@ +--- +- debug: + msg: START ios_lag_interfaces gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _populate_port_channel.yaml +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_lag_interfaces: + config: + state: gathered + + - name: Assert + assert: + that: + - gathered['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..2492ff95 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/merged.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START Merged ios_lag_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _populate_port_channel.yaml +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_lag_interfaces: &id001 + config: + + - name: Port-channel11 + members: + - member: GigabitEthernet0/1 + mode: active + - name: Port-channel22 + members: + - member: GigabitEthernet0/2 + mode: passive + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_lag_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..30aaa7bd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,54 @@ +--- +- debug: + msg: START Overridden ios_lag_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _populate_port_channel.yaml +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Override device configuration of all interfaces with provided configuration + register: result + cisco.ios.ios_lag_interfaces: &id001 + config: + + - name: Port-channel22 + members: + - member: GigabitEthernet0/2 + mode: passive + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ overridden['before'] | symmetric_difference(result['before']) |\ + \ length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Override device configuration of all interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_lag_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..21ba2ca8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,18 @@ +--- +- debug: + msg: START ios_lag_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- block: + - name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_lag_interfaces: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + + - assert: + that: + - result.changed == false + - parsed['config']|symmetric_difference(result.parsed) == [] + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..07cce311 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,26 @@ +--- +- debug: + msg: Start ios_lag_interfaces rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_lag_interfaces: + config: + - name: Port-channel11 + members: + - member: GigabitEthernet0/1 + mode: active + - name: Port-channel22 + members: + - member: GigabitEthernet0/2 + mode: passive + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..3eabb6a6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START Replaced ios_lag_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _populate_port_channel.yaml +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces device configuration of listed interfaces with provided configuration + register: result + cisco.ios.ios_lag_interfaces: &id001 + config: + + - name: Port-channel11 + members: + + - member: GigabitEthernet0/1 + mode: passive + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ replaced['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Replaces device configuration of listed interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_lag_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..04e1ea2f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,63 @@ +--- +- debug: + msg: START ios_lag_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _populate_port_channel.yaml +- include_tasks: _remove_config.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: base_config + cisco.ios.ios_lag_interfaces: + config: + - name: Port-channel11 + members: + - member: GigabitEthernet0/1 + mode: active + - name: Port-channel22 + members: + - member: GigabitEthernet0/2 + mode: active + state: merged + + - name: Gather LAG interfaces facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - lag_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_lag_interfaces: + config: + - name: Port-channel22 + members: + - member: GigabitEthernet0/2 + mode: passive + state: overridden + + - assert: + that: + - result.commands|length == 4 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_lag_interfaces: + config: "{{ ansible_facts['network_resources']['lag_interfaces'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 4 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/vars/main.yaml new file mode 100644 index 00000000..34c3712e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lag_interfaces/vars/main.yaml @@ -0,0 +1,115 @@ +--- +merged: + before: + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 + commands: + - interface GigabitEthernet0/1 + - channel-group 11 mode active + - interface GigabitEthernet0/2 + - channel-group 22 mode passive + after: + - name: GigabitEthernet0/0 + - members: + - member: GigabitEthernet0/1 + mode: active + name: Port-channel11 + - members: + - member: GigabitEthernet0/2 + mode: passive + name: Port-channel22 +replaced: + before: + - name: GigabitEthernet0/0 + - members: + - member: GigabitEthernet0/1 + mode: active + name: Port-channel11 + - members: + - member: GigabitEthernet0/2 + mode: active + name: Port-channel22 + commands: + - interface GigabitEthernet0/1 + - channel-group 11 mode passive + after: + - name: GigabitEthernet0/0 + - members: + - member: GigabitEthernet0/1 + mode: passive + name: Port-channel11 + - members: + - member: GigabitEthernet0/2 + mode: active + name: Port-channel22 +overridden: + before: + - name: GigabitEthernet0/0 + - members: + - member: GigabitEthernet0/1 + mode: active + name: Port-channel11 + - members: + - member: GigabitEthernet0/2 + mode: active + name: Port-channel22 + commands: + - interface GigabitEthernet0/1 + - no channel-group + - interface GigabitEthernet0/2 + - channel-group 22 mode passive + after: + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - members: + - member: GigabitEthernet0/2 + mode: passive + name: Port-channel22 +deleted: + before: + - name: GigabitEthernet0/0 + - members: + - member: GigabitEthernet0/1 + mode: active + name: Port-channel11 + - members: + - member: GigabitEthernet0/2 + mode: active + name: Port-channel22 + commands: + - interface GigabitEthernet0/1 + - no channel-group + - interface GigabitEthernet0/2 + - no channel-group + after: + - name: GigabitEthernet0/0 + - name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 +gathered: + config: + - name: GigabitEthernet0/0 + - members: + - member: GigabitEthernet0/1 + mode: active + name: Port-channel11 + - members: + - member: GigabitEthernet0/2 + mode: active + name: Port-channel22 +parsed: + config: + - members: + - member: GigabitEthernet0/1 + mode: active + name: Port-channel11 + - members: + - member: GigabitEthernet0/2 + mode: passive + name: Port-channel22 +rtt: + commands: + - interface GigabitEthernet0/1 + - channel-group 11 mode active + - interface GigabitEthernet0/2 + - channel-group 22 mode active diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/tests/cli/basic.yaml new file mode 100644 index 00000000..9e4fb400 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_linkagg/tests/cli/basic.yaml @@ -0,0 +1,175 @@ +--- +- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" + +- set_fact: switch_type="{{ switch_type }}" + +- block: + + - name: setup - remove config used in test(part1) + ignore_errors: true + cisco.ios.ios_config: + lines: + - no interface port-channel 20 + provider: '{{ cli }}' + + - name: setup - remove config used in test(part2) + ignore_errors: true + cisco.ios.ios_config: + lines: + - no interface port-channel 5 + provider: '{{ cli }}' + + - name: setup - remove config used in test(part3) + loop: + - interface GigabitEthernet0/1 + - interface GigabitEthernet0/2 + cisco.ios.ios_config: + lines: + - no channel-group 20 mode active + provider: '{{ cli }}' + parents: '{{ item }}' + + - name: create linkagg + register: result + cisco.ios.ios_linkagg: &id001 + group: 20 + state: present + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'interface port-channel 20' in result.commands" + + - name: create linkagg(Idempotence) + register: result + cisco.ios.ios_linkagg: *id001 + + - assert: + that: + - result.changed == false + + - name: set link aggregation group to members + register: result + cisco.ios.ios_linkagg: &id002 + group: 20 + mode: active + members: + - GigabitEthernet0/1 + - GigabitEthernet0/2 + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'interface GigabitEthernet0/1' in result.commands" + - "'channel-group 20 mode active' in result.commands" + - "'interface GigabitEthernet0/2' in result.commands" + - "'channel-group 20 mode active' in result.commands" + + - name: set link aggregation group to members(Idempotence) + register: result + cisco.ios.ios_linkagg: *id002 + + - assert: + that: + - result.changed == false + + - name: remove link aggregation group from member + register: result + cisco.ios.ios_linkagg: &id003 + group: 20 + mode: active + members: + - GigabitEthernet0/2 + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'interface GigabitEthernet0/1' in result.commands" + - "'no channel-group 20 mode active' in result.commands" + + - name: remove link aggregation group from member(Idempotence) + register: result + cisco.ios.ios_linkagg: *id003 + + - assert: + that: + - result.changed == false + + - name: remove linkagg + register: result + cisco.ios.ios_linkagg: &id004 + group: 20 + state: absent + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'no interface port-channel 20' in result.commands" + + - name: remove linkagg(Idempotence) + register: result + cisco.ios.ios_linkagg: *id004 + + - assert: + that: + - result.changed == false + + - name: create aggregate of linkagg definitions + register: result + cisco.ios.ios_linkagg: &id005 + aggregate: + + - group: 5 + + - group: 20 + mode: active + members: + - GigabitEthernet0/1 + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'interface port-channel 5' in result.commands" + - "'interface port-channel 20' in result.commands" + - "'interface GigabitEthernet0/1' in result.commands" + - "'channel-group 20 mode active' in result.commands" + + - name: create aggregate of linkagg definitions(Idempotence) + register: result + cisco.ios.ios_linkagg: *id005 + + - assert: + that: + - result.changed == false + + - name: teardown(part1) + ignore_errors: true + cisco.ios.ios_config: + lines: + - no interface port-channel 20 + provider: '{{ cli }}' + + - name: teardown(part2) + ignore_errors: true + cisco.ios.ios_config: + lines: + - no interface port-channel 5 + provider: '{{ cli }}' + + - name: teardown(part3) + loop: + - interface GigabitEthernet0/1 + - interface GigabitEthernet0/2 + cisco.ios.ios_config: + lines: + - no channel-group 20 mode active + provider: '{{ cli }}' + parents: '{{ item }}' + when: switch_type == 'L2' + +- debug: msg="END cli/basic.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/tests/cli/basic.yaml new file mode 100644 index 00000000..44ad2e97 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp/tests/cli/basic.yaml @@ -0,0 +1,52 @@ +--- +- debug: msg="START ios_lldp cli/basic.yaml on connection={{ ansible_connection + }}" + +- name: Make sure LLDP is not running before tests + cisco.ios.ios_config: + lines: no lldp run + provider: '{{ cli }}' + +- name: Enable LLDP service + register: result + cisco.ios.ios_lldp: + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"lldp run" in result.commands' + +- name: Enable LLDP service again (idempotent) + register: result + cisco.ios.ios_lldp: + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: Disable LLDP service + register: result + cisco.ios.ios_lldp: + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"no lldp run" in result.commands' + +- name: Disable LLDP service (idempotent) + register: result + cisco.ios.ios_lldp: + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- debug: msg="END ios_lldp cli/basic.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/aliases b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/aliases new file mode 100644 index 00000000..6bb69158 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/aliases @@ -0,0 +1 @@ +shippable/ios/group1 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/_parsed.cfg new file mode 100644 index 00000000..a294c041 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/_parsed.cfg @@ -0,0 +1,4 @@ +lldp timer 10 +lldp holdtime 10 +lldp reinit 3 +lldp run
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..80a30cda --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/_populate_config.yaml @@ -0,0 +1,6 @@ +--- +- name: Populate Config + vars: + lines: "lldp holdtime 10\nlldp run\nlldp timer 100\nlldp reinit 3\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..15ffe6c1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/_remove_config.yaml @@ -0,0 +1,6 @@ +--- +- name: Remove Config + vars: + lines: "no lldp holdtime\nno lldp run\nno lldp timer\nno lldp reinit\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/deleted.yaml new file mode 100644 index 00000000..36dee599 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/deleted.yaml @@ -0,0 +1,43 @@ +--- +- debug: + msg: Start Deleted integration state for ios_lldp_global ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete configured Global LLDP + register: result + cisco.ios.ios_lldp_global: &id001 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ deleted['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ deleted['before'] == result['before'] }}" + + - name: Delete configured Global LLDP (IDEMPOTENT) + register: result + cisco.ios.ios_lldp_global: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/empty_config.yaml new file mode 100644 index 00000000..587a70fc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/empty_config.yaml @@ -0,0 +1,49 @@ +--- +- debug: + msg: START ios_lldp_global empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_lldp_global: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_lldp_global: + config: + state: replaced + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_lldp_global: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_lldp_global: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/gathered.yaml new file mode 100644 index 00000000..766e4004 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/gathered.yaml @@ -0,0 +1,23 @@ +--- +- debug: + msg: START ios_lldp_global gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_lldp_global: + config: + state: gathered + + + - name: Assert + assert: + that: + - "{{ result['gathered'] == gathered['config'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/merged.yaml new file mode 100644 index 00000000..4be9bbe6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/merged.yaml @@ -0,0 +1,46 @@ +--- +- debug: + msg: START Merged ios_lldp_global state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge provided configuration Global LLDP + register: result + cisco.ios.ios_lldp_global: &id001 + config: + holdtime: 10 + enabled: true + reinit: 3 + timer: 20 + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['before'] == result['before'] }}" + + - name: Merge provided configuration Global LLDP (IDEMPOTENT) + register: result + cisco.ios.ios_lldp_global: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/parsed.yaml new file mode 100644 index 00000000..9151e6d5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START ios_lldp_global parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_lldp_global: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - "{{ result['parsed'] == parsed['config'] }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/rendered.yaml new file mode 100644 index 00000000..77b9f54d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/rendered.yaml @@ -0,0 +1,22 @@ +--- +- debug: + msg: Start ios_lldp_global rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_lldp_global: + config: + holdtime: 10 + enabled: true + reinit: 3 + timer: 20 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/replaced.yaml new file mode 100644 index 00000000..82251200 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/tests/cli/replaced.yaml @@ -0,0 +1,47 @@ +--- +- debug: + msg: START Replaced ios_lldp_global state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces Global LLDP configuration with provided LLDP configuration + register: result + cisco.ios.ios_lldp_global: &id001 + config: + holdtime: 20 + reinit: 5 + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ replaced['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['before'] == result['before'] }}" + + - name: Replaces Global LLDP configuration with provided LLDP configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_lldp_global: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/vars/main.yaml new file mode 100644 index 00000000..ac53fbe9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_global/vars/main.yaml @@ -0,0 +1,51 @@ +--- +merged: + before: {} + commands: + - lldp holdtime 10 + - lldp run + - lldp timer 20 + - lldp reinit 3 + after: + timer: 20 + holdtime: 10 + reinit: 3 + enabled: true +replaced: + before: + timer: 100 + holdtime: 10 + reinit: 3 + enabled: true + commands: + - no lldp run + - no lldp timer + - lldp holdtime 20 + - lldp reinit 5 + after: + holdtime: 10 + reinit: 3 +deleted: + before: + timer: 100 + holdtime: 10 + reinit: 3 + enabled: true + commands: + - no lldp holdtime + - no lldp run + - no lldp timer + - no lldp reinit + after: {} +gathered: + config: + enabled: true + holdtime: 10 + reinit: 3 + timer: 100 +parsed: + config: + enabled: true + holdtime: 10 + reinit: 3 + timer: 10 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_enable_lldp.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_enable_lldp.yaml new file mode 100644 index 00000000..dc8ecfaf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_enable_lldp.yaml @@ -0,0 +1,6 @@ +--- +- name: Enable LLDP Config + vars: + lines: "lldp run\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_parsed.cfg new file mode 100644 index 00000000..3089d48f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_parsed.cfg @@ -0,0 +1,17 @@ +GigabitEthernet0/0: + Tx: enabled + Rx: disabled + Tx state: IDLE + Rx state: WAIT FOR FRAME + +GigabitEthernet0/1: + Tx: enabled + Rx: enabled + Tx state: IDLE + Rx state: WAIT FOR FRAME + +GigabitEthernet0/2: + Tx: disabled + Rx: enabled + Tx state: IDLE + Rx state: INIT
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..41d1bed7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/0\nlldp receive\nlldp transmit\ninterface\ + \ GigabitEthernet 0/1\nlldp receive\nlldp transmit\ninterface GigabitEthernet\ + \ 0/2\nlldp receive\nlldp transmit\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..8a41fcc8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Remove Config + vars: + lines: "interface GigabitEthernet 0/0\nno lldp receive\nno lldp transmit\ninterface\ + \ GigabitEthernet 0/1\nno lldp receive\nno lldp transmit\ninterface GigabitEthernet\ + \ 0/2\nno lldp receive\nno lldp transmit\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..dbf6ea30 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,47 @@ +--- +- debug: + msg: Start Deleted integration state for ios_lldp_interfaces ansible_connection={{ + ansible_connection }} + +- include_tasks: _enable_lldp.yaml + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete LLDP attributes for respective configured interfaces + register: result + cisco.ios.ios_lldp_interfaces: &id001 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ deleted['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Delete LLDP attributes for respective configured interfaces (IDEMPOTENT) + register: result + cisco.ios.ios_lldp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..58c29743 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START ios_lldp_interfaces empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_lldp_interfaces: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_lldp_interfaces: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_lldp_interfaces: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_lldp_interfaces: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_lldp_interfaces: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..f16b6f30 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,25 @@ +--- +- debug: + msg: START ios_lldp_interfaces gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _enable_lldp.yaml +- include_tasks: _remove_config.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_lldp_interfaces: + config: + state: gathered + + - name: Assert + assert: + that: + - gathered['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..2c578118 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/merged.yaml @@ -0,0 +1,59 @@ +--- +- debug: + msg: START Merged ios_lldp_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _enable_lldp.yaml + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_lldp_interfaces: &id001 + config: + + - name: GigabitEthernet0/0 + receive: true + transmit: true + + - name: GigabitEthernet0/1 + receive: true + transmit: true + + - name: GigabitEthernet0/2 + receive: true + transmit: false + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge the provided configuration with the exisiting running configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_lldp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..adb7b4a1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: START Overridden ios_lldp_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _enable_lldp.yaml + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Override device configuration of all lldp_interfaces with provided configuration + register: result + cisco.ios.ios_lldp_interfaces: &id001 + config: + + - name: GigabitEthernet0/0 + receive: true + transmit: true + + - name: GigabitEthernet0/2 + receive: true + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ overridden['before'] | symmetric_difference(result['before']) |\ + \ length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Override device configuration of all lldp_interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_lldp_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..1d064834 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START ios_lldp_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_lldp_interfaces: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - parsed['config']|symmetric_difference(result.parsed) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..71b0c971 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,26 @@ +--- +- debug: + msg: Start ios_lldp_interfaces rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_lldp_interfaces: + config: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/1 + receive: true + transmit: true + - name: GigabitEthernet0/2 + receive: true + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..3bb30e42 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,57 @@ +--- +- debug: + msg: START Replaced ios_lldp_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _enable_lldp.yaml + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces device configuration of listed lldp_interfaces with provided + configuration + register: result + cisco.ios.ios_lldp_interfaces: &id001 + config: + + - name: GigabitEthernet0/1 + transmit: true + + - name: GigabitEthernet0/2 + receive: true + transmit: false + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ replaced['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Replaces device configuration of listed lldp_interfaces with provided + configuration (IDEMPOTENT) + register: result + cisco.ios.ios_lldp_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..3bc6a841 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,65 @@ +--- +- debug: + msg: START ios_lldp_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _enable_lldp.yaml + +- include_tasks: _remove_config.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: base_config + cisco.ios.ios_lldp_interfaces: + config: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/1 + receive: true + transmit: true + - name: GigabitEthernet0/2 + receive: true + transmit: true + state: merged + + - name: Gather LLDP interfaces facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - lldp_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_lldp_interfaces: + config: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/2 + receive: true + state: overridden + + - assert: + that: + - result.commands|length == 5 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_lldp_interfaces: + config: "{{ ansible_facts['network_resources']['lldp_interfaces'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 5 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/vars/main.yaml new file mode 100644 index 00000000..74c66eea --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_lldp_interfaces/vars/main.yaml @@ -0,0 +1,147 @@ +--- +merged: + before: + - name: GigabitEthernet0/0 + receive: false + transmit: false + - name: GigabitEthernet0/1 + receive: false + transmit: false + - name: GigabitEthernet0/2 + receive: false + transmit: false + commands: + - interface GigabitEthernet0/0 + - lldp receive + - lldp transmit + - interface GigabitEthernet0/1 + - lldp receive + - lldp transmit + - interface GigabitEthernet0/2 + - lldp receive + after: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/1 + receive: true + transmit: true + - name: GigabitEthernet0/2 + receive: true + transmit: false +replaced: + before: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/1 + receive: true + transmit: true + - name: GigabitEthernet0/2 + receive: true + transmit: true + commands: + - interface GigabitEthernet0/1 + - no lldp receive + - interface GigabitEthernet0/2 + - no lldp transmit + after: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/1 + receive: false + transmit: true + - name: GigabitEthernet0/2 + receive: true + transmit: false +overridden: + before: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/1 + receive: true + transmit: true + - name: GigabitEthernet0/2 + receive: true + transmit: true + commands: + - interface GigabitEthernet0/1 + - no lldp receive + - no lldp transmit + - interface GigabitEthernet0/2 + - no lldp transmit + after: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/1 + receive: false + transmit: false + - name: GigabitEthernet0/2 + receive: true + transmit: false +deleted: + before: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/1 + receive: true + transmit: true + - name: GigabitEthernet0/2 + receive: true + transmit: true + commands: + - interface GigabitEthernet0/0 + - no lldp receive + - no lldp transmit + - interface GigabitEthernet0/1 + - no lldp receive + - no lldp transmit + - interface GigabitEthernet0/2 + - no lldp receive + - no lldp transmit + after: + - name: GigabitEthernet0/0 + receive: false + transmit: false + - name: GigabitEthernet0/1 + receive: false + transmit: false + - name: GigabitEthernet0/2 + receive: false + transmit: false + +gathered: + config: + - name: GigabitEthernet0/0 + receive: true + transmit: true + - name: GigabitEthernet0/1 + receive: true + transmit: true + - name: GigabitEthernet0/2 + receive: true + transmit: true + +parsed: + config: + - name: GigabitEthernet0/0 + receive: false + transmit: true + - name: GigabitEthernet0/1 + receive: true + transmit: true + - name: GigabitEthernet0/2 + receive: true + transmit: false + +rtt: + commands: + - interface GigabitEthernet0/1 + - lldp receive + - lldp transmit + - interface GigabitEthernet0/2 + - lldp transmit diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tests/cli/basic.yaml new file mode 100644 index 00000000..467e29d0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tests/cli/basic.yaml @@ -0,0 +1,151 @@ +--- +- name: Remove host logging + cisco.ios.ios_logging: &id001 + dest: host + name: 172.16.0.1 + state: absent + provider: '{{ cli }}' + +- name: Remove console + cisco.ios.ios_logging: + dest: console + level: warnings + state: absent + provider: '{{ cli }}' + +- name: Remove buffer + cisco.ios.ios_logging: + dest: buffered + size: 8000 + provider: '{{ cli }}' + state: absent + +- name: Set up host logging + register: result + cisco.ios.ios_logging: + dest: host + name: 172.16.0.1 + facility: local7 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging host 172.16.0.1" in result.commands' + - '"logging facility local7" in result.commands' + +- name: Set up host logging again (idempotent) + register: result + cisco.ios.ios_logging: + dest: host + name: 172.16.0.1 + state: present + provider: '{{ cli }}' + +- assert: &id002 + that: + - result.changed == false + +- name: Delete/disable host logging + register: result + cisco.ios.ios_logging: *id001 + +- assert: + that: + - result.changed == true + - '"no logging host 172.16.0.1" in result.commands' + +- name: Delete/disable host logging (idempotent) + register: result + cisco.ios.ios_logging: *id001 + +- assert: *id002 + +- name: Console logging with level warnings + register: result + cisco.ios.ios_logging: + dest: console + level: warnings + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging console warnings" in result.commands' + +- name: Configure Buffer size + register: result + cisco.ios.ios_logging: + dest: buffered + size: 8000 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging buffered 8000" in result.commands' + +- name: Change logging parameters using aggregate + register: result + cisco.ios.ios_logging: + aggregate: + + - dest: console + level: notifications + + - dest: buffered + size: 9000 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging buffered 9000" in result.commands' + - '"logging console notifications" in result.commands' + +- name: Set both logging destination and facility + register: result + cisco.ios.ios_logging: &id003 + dest: buffered + facility: uucp + level: alerts + size: 4096 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging buffered 4096 alerts" in result.commands' + - '"logging facility uucp" in result.commands' + +- name: Set both logging destination and facility (idempotent) + register: result + cisco.ios.ios_logging: *id003 + +- assert: *id002 + +- name: remove logging as collection tearDown + register: result + cisco.ios.ios_logging: + aggregate: + + - dest: console + level: notifications + + - dest: buffered + size: 4096 + level: alerts + + - facility: uucp + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"no logging console" in result.commands' + - '"no logging buffered" in result.commands' + - '"no logging facility uucp" in result.commands' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tests/cli/net_logging.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tests/cli/net_logging.yaml new file mode 100644 index 00000000..75e5eb5c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tests/cli/net_logging.yaml @@ -0,0 +1,34 @@ +--- +- debug: msg="START ios cli/net_logging.yaml on connection={{ ansible_connection + }}" + +- name: Remove host logging - setup + ansible.netcommon.net_logging: + dest: host + name: 172.16.0.1 + state: absent + provider: '{{ cli }}' + +- name: Set up host logging using platform agnostic module + register: result + ansible.netcommon.net_logging: + dest: host + name: 172.16.0.1 + facility: local7 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging host 172.16.0.1" in result.commands' + - '"logging facility local7" in result.commands' + +- name: Remove host logging - teardown + ansible.netcommon.net_logging: + dest: host + name: 172.16.0.1 + state: absent + provider: '{{ cli }}' + +- debug: msg="END ios cli/net_logging.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/meta/main.yml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/tests/cli/ntp_configuration.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/tests/cli/ntp_configuration.yaml new file mode 100644 index 00000000..41364ad1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ntp/tests/cli/ntp_configuration.yaml @@ -0,0 +1,106 @@ +--- +- debug: msg="START connection={{ ansible_connection }} ios_ntp sanity test" + +- name: remove NTP (if set) + ignore_errors: true + cisco.ios.ios_ntp: &id007 + server: 10.75.32.5 + source_int: '{{ test_interface }}' + acl: NTP_ACL + logging: true + key_id: 10 + auth_key: 15435A030726242723273C21181319000A + auth: true + state: absent + provider: '{{ cli }}' + +- block: + + - name: configure NTP + register: result + cisco.ios.ios_ntp: &id001 + server: 10.75.32.5 + source_int: '{{ test_interface }}' + state: present + provider: '{{ cli }}' + + - assert: &id002 + that: + - result.changed == true + + - name: idempotence check + register: result + cisco.ios.ios_ntp: *id001 + + - assert: &id004 + that: + - result.changed == false + + - name: load acl NTP_ACL into device + register: result + cisco.ios.ios_config: + lines: + - 10 permit ip host 192.0.2.1 any log + parents: ip access-list extended NTP_ACL + provider: '{{ cli }}' + + - assert: *id002 + + - name: configure NTP + register: result + cisco.ios.ios_ntp: &id003 + acl: NTP_ACL + logging: true + state: present + provider: '{{ cli }}' + + - assert: *id002 + + - name: idempotence check + register: result + cisco.ios.ios_ntp: *id003 + + - assert: *id004 + + - name: configure NTP with diffferen values + register: result + cisco.ios.ios_ntp: &id005 + key_id: 10 + auth_key: 15435A030726242723273C21181319000A + auth: true + state: present + provider: '{{ cli }}' + + - assert: *id002 + + - name: idempotence check + register: result + cisco.ios.ios_ntp: *id005 + + - assert: *id004 + + - name: remove part of config + register: result + cisco.ios.ios_ntp: &id006 + acl: NTP_ACL + logging: true + state: absent + provider: '{{ cli }}' + + - assert: *id002 + + - name: idempotence check + register: result + cisco.ios.ios_ntp: *id006 + + - assert: *id004 + always: + + - name: Remove ntp config + cisco.ios.ios_ntp: *id007 + + - name: remove NTP_ACL from device + cisco.ios.ios_config: + lines: + - no ip access-list extended NTP_ACL + provider: '{{ cli }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_initial_ipv6_setup.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_initial_ipv6_setup.yaml new file mode 100644 index 00000000..b9b5e0f8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_initial_ipv6_setup.yaml @@ -0,0 +1,6 @@ +--- +- name: Create and Setup IPv6 configuration + vars: + lines: "interface GigabitEthernet 0/1\nipv6 address 2001:db8:0:1::/64\ninterface GigabitEthernet 0/2\nipv6 address 2001:db8:0:2::/64\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_parsed.cfg new file mode 100644 index 00000000..e3e70651 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_parsed.cfg @@ -0,0 +1,22 @@ +interface Loopback888 +interface Loopback999 +interface GigabitEthernet0/0 +interface GigabitEthernet0/1 + ip ospf network broadcast + ip ospf authentication message-digest + ip ospf resync-timeout 10 + ip ospf dead-interval 5 + ip ospf priority 25 + ip ospf demand-circuit ignore + ip ospf bfd + ip ospf adjacency stagger disable + ip ospf ttl-security hops 50 + ip ospf shutdown + ip ospf 10 area 30 + ip ospf cost 5 + ipv6 ospf priority 55 + ipv6 ospf transmit-delay 45 + ipv6 ospf database-filter all out + ipv6 ospf adjacency stagger disable + ipv6 ospf manet peering link-metrics 10 +interface GigabitEthernet0/2
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..5312a2d7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,36 @@ +--- +- name: Populate OSPF Interfaces Configuration + cisco.ios.ios_ospf_interfaces: + config: + - name: GigabitEthernet0/1 + address_family: + - afi: ipv4 + authentication: + message_digest: true + process: + id: 10 + area_id: 30 + adjacency: true + bfd: true + cost: + interface_cost: 5 + dead_interval: + time: 5 + demand_circuit: + ignore: true + network: + broadcast: true + priority: 25 + resync_timeout: 10 + shutdown: true + ttl_security: + hops: 50 + - afi: ipv6 + adjacency: true + database_filter: true + manet: + link_metrics: + cost_threshold: 10 + priority: 55 + transmit_delay: 45 + state: merged diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..313daccd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,10 @@ +--- +- name: Remove OSPF Interfaces Config + cisco.ios.ios_ospf_interfaces: + state: deleted + +- name: Delete and Clean IPv6 configuration + vars: + lines: "interface GigabitEthernet 0/1\nno ipv6 address 2001:DB8:0:1::/64\ninterface GigabitEthernet 0/2\nno ipv6 address 2001:DB8:0:2::/64\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..72c9f316 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,70 @@ +--- +- debug: + msg: Start Deleted integration state for ios_ospf_interfaces ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_ipv6_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete provided OSPF Interfaces + register: result + cisco.ios.ios_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/1 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Delete provided OSPF Interfaces (IDEMPOTENT) + register: result + cisco.ios.ios_ospf_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + + - include_tasks: _populate_config.yaml + + - name: Delete provided OSPF Interfaces without any config + register: result + cisco.ios.ios_ospf_interfaces: &id002 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Delete provided OSPF Interfaces without any config (IDEMPOTENT) + register: result + cisco.ios.ios_ospf_interfaces: *id002 + + - name: Assert that the delete task was idempotent + assert: + that: + - result.changed == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..ac76a8fc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START ios_ospf_interfaces empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_ospf_interfaces: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_ospf_interfaces: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_ospf_interfaces: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_ospf_interfaces: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_ospf_interfaces: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..189fbdd1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,27 @@ +--- +- debug: + msg: START ios_ospf_interfaces gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_ipv6_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_ospf_interfaces: + config: + state: gathered + + - name: Assert + assert: + that: + - result.changed == false + - "{{ merged['after'] | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..6e82d25b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/merged.yaml @@ -0,0 +1,75 @@ +--- +- debug: + msg: START Merged ios_ospf_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_ipv6_setup.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/1 + address_family: + - afi: ipv4 + authentication: + message_digest: true + process: + id: 10 + area_id: 30 + adjacency: true + bfd: true + cost: + interface_cost: 5 + dead_interval: + time: 5 + demand_circuit: + ignore: true + network: + broadcast: true + priority: 25 + resync_timeout: 10 + shutdown: true + ttl_security: + hops: 50 + - afi: ipv6 + adjacency: true + database_filter: true + manet: + link_metrics: + cost_threshold: 10 + priority: 55 + transmit_delay: 45 + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] == {} }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_ospf_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..3a978bbf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,65 @@ +--- +- debug: + msg: START Overridden ios_ospf_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_ipv6_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Override provided OSPF Interfaces configuration + register: result + cisco.ios.ios_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/1 + address_family: + - afi: ipv6 + adjacency: true + priority: 20 + transmit_delay: 30 + - name: GigabitEthernet0/2 + address_family: + - afi: ipv4 + process: + id: 10 + area_id: 20 + adjacency: true + cost: + interface_cost: 30 + priority: 40 + ttl_security: + hops: 50 + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Override provided OSPF Interfaces configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_ospf_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..518affbe --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START ios_ospf_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse the commands for provided configuration + register: result + cisco.ios.ios_ospf_interfaces: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - "{{ merged['after'] | symmetric_difference(result['parsed']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..a28a7262 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,47 @@ +--- +- debug: + msg: Start ios_ospf_interfaces rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + - name: Render the commands for provided configuration + register: result + cisco.ios.ios_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/1 + address_family: + - afi: ipv4 + authentication: + message_digest: true + process: + id: 10 + area_id: 30 + adjacency: true + bfd: true + cost: + interface_cost: 5 + dead_interval: + time: 5 + demand_circuit: + ignore: true + network: + broadcast: true + priority: 25 + resync_timeout: 10 + shutdown: true + ttl_security: + hops: 50 + - afi: ipv6 + adjacency: true + database_filter: true + manet: + link_metrics: + cost_threshold: 10 + priority: 55 + transmit_delay: 45 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..fe5c253d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,53 @@ +--- +- debug: + msg: START Replaced ios_ospf_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_ipv6_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaced provided OSPF Interfaces configuration + register: result + cisco.ios.ios_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/2 + address_family: + - afi: ipv6 + adjacency: true + priority: 20 + transmit_delay: 30 + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Replaced provided OSPF Interfaces configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_ospf_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..d556e3ba --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,99 @@ +--- +- debug: + msg: START ios_ospf_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_ipv6_setup.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: base_config + cisco.ios.ios_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/1 + address_family: + - afi: ipv4 + authentication: + message_digest: true + process: + id: 10 + area_id: 30 + adjacency: true + bfd: true + cost: + interface_cost: 5 + dead_interval: + time: 5 + demand_circuit: + ignore: true + network: + broadcast: true + priority: 25 + resync_timeout: 10 + shutdown: true + ttl_security: + hops: 50 + - afi: ipv6 + adjacency: true + database_filter: true + manet: + link_metrics: + cost_threshold: 10 + priority: 55 + transmit_delay: 45 + state: merged + + - name: Gather OSPF Interfaces facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - ospf_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_ospf_interfaces: + config: + - name: GigabitEthernet0/1 + address_family: + - afi: ipv6 + adjacency: true + priority: 20 + transmit_delay: 30 + - name: GigabitEthernet0/2 + address_family: + - afi: ipv4 + process: + id: 10 + area_id: 20 + adjacency: true + cost: + interface_cost: 30 + priority: 40 + ttl_security: + hops: 50 + state: overridden + + - assert: + that: + - result.commands|length == 23 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_ospf_interfaces: + config: "{{ ansible_facts['network_resources']['ospf_interfaces'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 23 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/vars/main.yaml new file mode 100644 index 00000000..ee9a9254 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospf_interfaces/vars/main.yaml @@ -0,0 +1,207 @@ +--- +merged: + before: {} + + commands: + - interface GigabitEthernet0/1 + - ip ospf 10 area 30 + - ip ospf adjacency stagger disable + - ip ospf authentication message-digest + - ip ospf bfd + - ip ospf cost 5 + - ip ospf dead-interval 5 + - ip ospf demand-circuit ignore + - ip ospf network broadcast + - ip ospf priority 25 + - ip ospf resync-timeout 10 + - ip ospf shutdown + - ip ospf ttl-security hops 50 + - ipv6 ospf adjacency stagger disable + - ipv6 ospf database-filter all out + - ipv6 ospf manet peering link-metrics 10 + - ipv6 ospf priority 55 + - ipv6 ospf transmit-delay 45 + + after: + - name: Loopback888 + - name: Loopback999 + - name: GigabitEthernet0/0 + - address_family: + - adjacency: true + afi: ipv4 + authentication: + message_digest: true + bfd: true + cost: + interface_cost: 5 + dead_interval: + time: 5 + demand_circuit: + ignore: true + network: + broadcast: true + priority: 25 + process: + area_id: "30" + id: 10 + resync_timeout: 10 + shutdown: true + ttl_security: + hops: 50 + - adjacency: true + afi: ipv6 + database_filter: true + manet: + link_metrics: + cost_threshold: 10 + priority: 55 + transmit_delay: 45 + name: GigabitEthernet0/1 + - name: GigabitEthernet0/2 + +replaced: + commands: + - interface GigabitEthernet0/2 + - ipv6 ospf adjacency stagger disable + - ipv6 ospf priority 20 + - ipv6 ospf transmit-delay 30 + + after: + - name: Loopback888 + - name: Loopback999 + - name: GigabitEthernet0/0 + - address_family: + - adjacency: true + afi: ipv4 + authentication: + message_digest: true + bfd: true + cost: + interface_cost: 5 + dead_interval: + time: 5 + demand_circuit: + ignore: true + network: + broadcast: true + priority: 25 + process: + area_id: "30" + id: 10 + resync_timeout: 10 + shutdown: true + ttl_security: + hops: 50 + - adjacency: true + afi: ipv6 + database_filter: true + manet: + link_metrics: + cost_threshold: 10 + priority: 55 + transmit_delay: 45 + name: GigabitEthernet0/1 + - address_family: + - adjacency: true + afi: ipv6 + priority: 20 + transmit_delay: 30 + name: GigabitEthernet0/2 + +overridden: + commands: + - interface GigabitEthernet0/2 + - ip ospf 10 area 20 + - ip ospf adjacency stagger disable + - ip ospf cost 30 + - ip ospf priority 40 + - ip ospf ttl-security hops 50 + - interface GigabitEthernet0/1 + - no ipv6 ospf database-filter all out + - no ipv6 ospf manet peering link-metrics 10 + - ipv6 ospf priority 20 + - ipv6 ospf transmit-delay 30 + - no ip ospf 10 area 30 + - no ip ospf adjacency stagger disable + - no ip ospf authentication message-digest + - no ip ospf bfd + - no ip ospf cost 5 + - no ip ospf dead-interval 5 + - no ip ospf demand-circuit ignore + - no ip ospf network broadcast + - no ip ospf priority 25 + - no ip ospf resync-timeout 10 + - no ip ospf shutdown + - no ip ospf ttl-security hops 50 + + after: + - name: Loopback888 + - name: Loopback999 + - name: GigabitEthernet0/0 + - address_family: + - adjacency: true + afi: ipv6 + priority: 20 + transmit_delay: 30 + name: GigabitEthernet0/1 + - address_family: + - adjacency: true + afi: ipv4 + cost: + interface_cost: 30 + priority: 40 + process: + area_id: "20" + id: 10 + ttl_security: + hops: 50 + name: GigabitEthernet0/2 + +deleted: + commands: + - interface GigabitEthernet0/1 + - no ip ospf 10 area 30 + - no ip ospf adjacency stagger disable + - no ip ospf authentication message-digest + - no ip ospf bfd + - no ip ospf cost 5 + - no ip ospf dead-interval 5 + - no ip ospf demand-circuit ignore + - no ip ospf network broadcast + - no ip ospf priority 25 + - no ip ospf resync-timeout 10 + - no ip ospf shutdown + - no ip ospf ttl-security hops 50 + - no ipv6 ospf adjacency stagger disable + - no ipv6 ospf database-filter all out + - no ipv6 ospf manet peering link-metrics 10 + - no ipv6 ospf priority 55 + - no ipv6 ospf transmit-delay 45 + + after: {} + +rtt: + commands: + - interface GigabitEthernet0/2 + - no ip ospf 10 area 20 + - no ip ospf adjacency stagger disable + - no ip ospf cost 30 + - no ip ospf priority 40 + - no ip ospf ttl-security hops 50 + - interface GigabitEthernet0/1 + - ip ospf 10 area 30 + - ip ospf adjacency stagger disable + - ip ospf authentication message-digest + - ip ospf bfd + - ip ospf cost 5 + - ip ospf dead-interval 5 + - ip ospf demand-circuit ignore + - ip ospf network broadcast + - ip ospf priority 25 + - ip ospf resync-timeout 10 + - ip ospf shutdown + - ip ospf ttl-security hops 50 + - ipv6 ospf database-filter all out + - ipv6 ospf manet peering link-metrics 10 + - ipv6 ospf priority 55 + - ipv6 ospf transmit-delay 45 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_initial_vrf_setup.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_initial_vrf_setup.yaml new file mode 100644 index 00000000..af7e0238 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_initial_vrf_setup.yaml @@ -0,0 +1,6 @@ +--- +- name: Create and Setup VRF configuration + vars: + lines: "vrf definition ospf_vrf\naddress-family ipv4\nvrf definition blue\naddress-family ipv4\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_parsed.cfg new file mode 100644 index 00000000..c3b4affb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_parsed.cfg @@ -0,0 +1,19 @@ +router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion +router ospf 1 + default-information originate + max-metric router-lsa on-startup 110 + network 198.51.100.0 0.0.0.255 area 5 + area 10 authentication message-digest + area 10 default-cost 10 + area 10 nssa translate type7 suppress-fa + area 10 nssa default-information-originate metric 10 + area 10 filter-list prefix test_prefix_in in + area 10 filter-list prefix test_prefix_out out + area 5 authentication + area 5 capability default-exclusion diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..178a6702 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_populate_config.yaml @@ -0,0 +1,55 @@ +--- +- name: Populate OSPF Configuration + cisco.ios.ios_ospfv2: + config: + processes: + - process_id: 1 + max_metric: + router_lsa: true + on_startup: + time: 110 + areas: + - area_id: "5" + capability: true + authentication: + enable: true + - area_id: "10" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + default_cost: 10 + filter_list: + - name: test_prefix_in + direction: in + - name: test_prefix_out + direction: out + network: + - address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + area: 5 + default_information: + originate: true + - process_id: 200 + vrf: blue + domain_id: + ip_address: + address: 192.0.3.1 + max_metric: + router_lsa: true + on_startup: + time: 100 + auto_cost: + reference_bandwidth: 4 + areas: + - area_id: "10" + capability: true + distribute_list: + acls: + - name: 10 + direction: out + - name: 123 + direction: in + state: merged diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..d616c3da --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_remove_config.yaml @@ -0,0 +1,10 @@ +--- +- name: Remove OSPFV2 Config + cisco.ios.ios_ospfv2: + state: deleted + +- name: Delete and Clean VRF configuration + vars: + lines: "no vrf definition ospf_vrf\nno vrf definition blue\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/deleted.yaml new file mode 100644 index 00000000..a6fdb0e8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/deleted.yaml @@ -0,0 +1,83 @@ +--- +- debug: + msg: Start Deleted integration state for ios_ospfv2 ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete provided OSPF V2 processes + register: result + cisco.ios.ios_ospfv2: &id001 + config: + processes: + - process_id: 1 + - process_id: 200 + vrf: blue + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['after']['processes'] | symmetric_difference(result['before']['processes']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ result['after'] == {} }}" + + - name: Delete provided OSPF V2 processes (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv2: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + + - include_tasks: _populate_config.yaml + + - name: Delete provided OSPF V2 processes without any config + register: result + cisco.ios.ios_ospfv2: &id002 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['after']['processes'] | symmetric_difference(result['before']['processes']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ result['after'] == {} }}" + + - name: Delete provided OSPF V2 processes without any config (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv2: *id002 + + - name: Assert that the merge task was idempotent + assert: + that: + - result.changed == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/empty_config.yaml new file mode 100644 index 00000000..4fdff081 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START ios_ospfv2 empty_config.yaml integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_ospfv2: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_ospfv2: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_ospfv2: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_ospfv2: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_ospfv2: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/gathered.yaml new file mode 100644 index 00000000..de90db3f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/gathered.yaml @@ -0,0 +1,27 @@ +--- +- debug: + msg: START ios_ospfv2 gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_ospfv2: + config: + state: gathered + + - name: Assert + assert: + that: + - result.changed == false + - "{{ merged['after']['processes'] | symmetric_difference(result['gathered']['processes']) |length\ + \ == 0 }}" + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/merged.yaml new file mode 100644 index 00000000..f1a28ae7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/merged.yaml @@ -0,0 +1,94 @@ +--- +- debug: + msg: START Merged ios_ospfv2 state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_ospfv2: &id001 + config: + processes: + - process_id: 1 + max_metric: + router_lsa: true + on_startup: + time: 110 + areas: + - area_id: "5" + capability: true + authentication: + enable: true + - area_id: "10" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + default_cost: 10 + filter_list: + - name: test_prefix_in + direction: in + - name: test_prefix_out + direction: out + network: + - address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + area: 5 + default_information: + originate: true + - process_id: 200 + vrf: blue + domain_id: + ip_address: + address: 192.0.3.1 + max_metric: + router_lsa: true + on_startup: + time: 100 + auto_cost: + reference_bandwidth: 4 + areas: + - area_id: "10" + capability: true + distribute_list: + acls: + - name: 10 + direction: out + - name: 123 + direction: in + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] == {} }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['after']['processes'] | symmetric_difference(result['after']['processes']) | length\ + \ == 0 }}" + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv2: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/overridden.yaml new file mode 100644 index 00000000..4e5281e8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/overridden.yaml @@ -0,0 +1,80 @@ +--- +- debug: + msg: START Overridden ios_ospfv2 state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Override provided OSPF V2 configuration + register: result + cisco.ios.ios_ospfv2: &id001 + config: + processes: + - process_id: 200 + vrf: blue + domain_id: + ip_address: + address: 192.0.4.1 + max_metric: + router_lsa: true + on_startup: + time: 200 + maximum_paths: 15 + ttl_security: + hops: 7 + areas: + - area_id: "10" + default_cost: 10 + authentication: + message_digest: true + - process_id: 100 + vrf: ospf_vrf + domain_id: + ip_address: + address: 192.0.5.1 + auto_cost: + reference_bandwidth: 5 + areas: + - area_id: "5" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['after']['processes'] | symmetric_difference(result['before']['processes']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after']['processes'] | symmetric_difference(result['after']['processes']) | length\ + \ == 0 }}" + + - name: Override provided OSPF V2 configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv2: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/parsed.yaml new file mode 100644 index 00000000..19592f97 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START ios_ospfv2 parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse the commands for provided configuration + register: result + cisco.ios.ios_ospfv2: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - "{{ merged['after']['processes'] | symmetric_difference(result['parsed']['processes']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rendered.yaml new file mode 100644 index 00000000..f3014839 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rendered.yaml @@ -0,0 +1,66 @@ +--- +- debug: + msg: Start ios_ospfv2 rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + - name: Render the commands for provided configuration + register: result + cisco.ios.ios_ospfv2: &id001 + config: + processes: + - process_id: 1 + max_metric: + router_lsa: true + on_startup: + time: 110 + areas: + - area_id: "5" + capability: true + authentication: + enable: true + - area_id: "10" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + default_cost: 10 + filter_list: + - name: test_prefix_in + direction: in + - name: test_prefix_out + direction: out + network: + - address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + area: 5 + default_information: + originate: true + - process_id: 200 + vrf: blue + domain_id: + ip_address: + address: 192.0.3.1 + max_metric: + router_lsa: true + on_startup: + time: 100 + auto_cost: + reference_bandwidth: 4 + areas: + - area_id: "10" + capability: true + distribute_list: + acls: + - name: 10 + direction: out + - name: 123 + direction: in + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/replaced.yaml new file mode 100644 index 00000000..4f11673e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/replaced.yaml @@ -0,0 +1,80 @@ +--- +- debug: + msg: START Replaced ios_ospfv2 state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaced provided OSPF V2 configuration + register: result + cisco.ios.ios_ospfv2: &id001 + config: + processes: + - process_id: 200 + vrf: blue + domain_id: + ip_address: + address: 192.0.4.1 + max_metric: + router_lsa: true + on_startup: + time: 200 + maximum_paths: 15 + ttl_security: + hops: 7 + areas: + - area_id: "10" + default_cost: 10 + authentication: + message_digest: true + - process_id: 100 + vrf: ospf_vrf + domain_id: + ip_address: + address: 192.0.5.1 + auto_cost: + reference_bandwidth: 5 + areas: + - area_id: "5" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['after']['processes'] | symmetric_difference(result['before']['processes']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after']['processes'] | symmetric_difference(result['after']['processes']) | length\ + \ == 0 }}" + + - name: Replaced provided OSPF V2 configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv2: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rtt.yaml new file mode 100644 index 00000000..1bb85144 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rtt.yaml @@ -0,0 +1,133 @@ +--- +- debug: + msg: START ios_ospfv2 round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: base_config + cisco.ios.ios_ospfv2: &id001 + config: + processes: + - process_id: 1 + max_metric: + router_lsa: true + on_startup: + time: 110 + areas: + - area_id: "5" + capability: true + authentication: + enable: true + - area_id: "10" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + default_cost: 10 + filter_list: + - name: test_prefix_in + direction: in + - name: test_prefix_out + direction: out + network: + - address: 198.51.100.0 + wildcard_bits: 0.0.0.255 + area: 5 + default_information: + originate: true + - process_id: 200 + vrf: blue + domain_id: + ip_address: + address: 192.0.3.1 + max_metric: + router_lsa: true + on_startup: + time: 100 + auto_cost: + reference_bandwidth: 4 + areas: + - area_id: "10" + capability: true + distribute_list: + acls: + - name: 10 + direction: out + - name: 123 + direction: in + state: merged + + - name: Gather OSPFV2 facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - ospfv2 + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_ospfv2: + config: + processes: + - process_id: 200 + vrf: blue + domain_id: + ip_address: + address: 192.0.4.1 + max_metric: + router_lsa: true + on_startup: + time: 200 + maximum_paths: 15 + ttl_security: + hops: 7 + areas: + - area_id: "10" + default_cost: 10 + authentication: + message_digest: true + - process_id: 100 + vrf: ospf_vrf + domain_id: + ip_address: + address: 192.0.5.1 + auto_cost: + reference_bandwidth: 5 + areas: + - area_id: "5" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + state: overridden + + - assert: + that: + - result.commands|length == 18 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_ospfv2: + config: "{{ ansible_facts['network_resources']['ospfv2'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 24 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/vars/main.yaml new file mode 100644 index 00000000..307b591e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/vars/main.yaml @@ -0,0 +1,250 @@ +--- +merged: + before: {} + + commands: + - router ospf 200 vrf blue + - auto-cost reference-bandwidth 4 + - distribute-list 10 out + - distribute-list 123 in + - domain-id 192.0.3.1 + - max-metric router-lsa on-startup 100 + - area 10 capability default-exclusion + - router ospf 1 + - default-information originate + - max-metric router-lsa on-startup 110 + - network 198.51.100.0 0.0.0.255 area 5 + - area 10 authentication message-digest + - area 10 default-cost 10 + - area 10 nssa translate type7 suppress-fa + - area 10 nssa default-information-originate metric 10 + - area 10 filter-list prefix test_prefix_out out + - area 10 filter-list prefix test_prefix_in in + - area 5 authentication + - area 5 capability default-exclusion + + after: + processes: + - areas: + - area_id: "5" + authentication: + enable: true + capability: true + - area_id: "10" + authentication: + message_digest: true + default_cost: 10 + filter_list: + - direction: in + name: test_prefix_in + - direction: out + name: test_prefix_out + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + default_information: + originate: true + max_metric: + on_startup: + time: 110 + router_lsa: true + network: + - address: 198.51.100.0 + area: "5" + wildcard_bits: 0.0.0.255 + process_id: 1 + - areas: + - area_id: "10" + capability: true + auto_cost: + reference_bandwidth: 4 + distribute_list: + acls: + - direction: out + name: "10" + - direction: in + name: "123" + domain_id: + ip_address: + address: 192.0.3.1 + max_metric: + on_startup: + time: 100 + router_lsa: true + process_id: 200 + vrf: blue + +replaced: + commands: + - router ospf 100 vrf ospf_vrf + - auto-cost reference-bandwidth 5 + - domain-id 192.0.5.1 + - area 5 authentication message-digest + - area 5 nssa translate type7 suppress-fa + - area 5 nssa default-information-originate metric 10 + - router ospf 200 vrf blue + - no auto-cost reference-bandwidth 4 + - no distribute-list 10 out + - no distribute-list 123 in + - domain-id 192.0.4.1 + - max-metric router-lsa on-startup 200 + - maximum-paths 15 + - ttl-security all-interfaces hops 7 + - area 10 authentication message-digest + - no area 10 capability default-exclusion + - area 10 default-cost 10 + + after: + processes: + - areas: + - area_id: "5" + authentication: + enable: true + capability: true + - area_id: "10" + authentication: + message_digest: true + default_cost: 10 + filter_list: + - direction: in + name: test_prefix_in + - direction: out + name: test_prefix_out + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + default_information: + originate: true + max_metric: + on_startup: + time: 110 + router_lsa: true + network: + - address: 198.51.100.0 + area: "5" + wildcard_bits: 0.0.0.255 + process_id: 1 + - areas: + - area_id: "5" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + auto_cost: + reference_bandwidth: 5 + domain_id: + ip_address: + address: 192.0.5.1 + process_id: 100 + vrf: ospf_vrf + - areas: + - area_id: "10" + authentication: + message_digest: true + default_cost: 10 + domain_id: + ip_address: + address: 192.0.4.1 + max_metric: + on_startup: + time: 200 + router_lsa: true + maximum_paths: 15 + process_id: 200 + ttl_security: + hops: 7 + vrf: blue + +overridden: + commands: + - no router ospf 1 + - router ospf 100 vrf ospf_vrf + - auto-cost reference-bandwidth 5 + - domain-id 192.0.5.1 + - area 5 authentication message-digest + - area 5 nssa translate type7 suppress-fa + - area 5 nssa default-information-originate metric 10 + - router ospf 200 vrf blue + - no auto-cost reference-bandwidth 4 + - no distribute-list 10 out + - no distribute-list 123 in + - domain-id 192.0.4.1 + - max-metric router-lsa on-startup 200 + - maximum-paths 15 + - ttl-security all-interfaces hops 7 + - area 10 authentication message-digest + - no area 10 capability default-exclusion + - area 10 default-cost 10 + + after: + processes: + - areas: + - area_id: "5" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + auto_cost: + reference_bandwidth: 5 + domain_id: + ip_address: + address: 192.0.5.1 + process_id: 100 + vrf: ospf_vrf + - areas: + - area_id: "10" + authentication: + message_digest: true + default_cost: 10 + domain_id: + ip_address: + address: 192.0.4.1 + max_metric: + on_startup: + time: 200 + router_lsa: true + maximum_paths: 15 + process_id: 200 + ttl_security: + hops: 7 + vrf: blue + +deleted: + commands: + - no router ospf 200 vrf blue + - no router ospf 1 + + after: {} + +rtt: + commands: + - no router ospf 100 vrf ospf_vrf + - router ospf 200 vrf blue + - auto-cost reference-bandwidth 4 + - distribute-list 10 out + - distribute-list 123 in + - domain-id 192.0.3.1 + - max-metric router-lsa on-startup 100 + - no maximum-paths 15 + - no ttl-security all-interfaces hops 7 + - no area 10 authentication message-digest + - area 10 capability default-exclusion + - no area 10 default-cost 10 + - router ospf 1 + - default-information originate + - max-metric router-lsa on-startup 110 + - network 198.51.100.0 0.0.0.255 area 5 + - area 10 authentication message-digest + - area 10 default-cost 10 + - area 10 nssa translate type7 suppress-fa + - area 10 nssa default-information-originate metric 10 + - area 10 filter-list prefix test_prefix_out out + - area 10 filter-list prefix test_prefix_in in + - area 5 authentication + - area 5 capability default-exclusion diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_initial_vrf_setup.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_initial_vrf_setup.yaml new file mode 100644 index 00000000..1128695b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_initial_vrf_setup.yaml @@ -0,0 +1,11 @@ +--- +- name: Enable IPV6 routing configuration + vars: + lines: "ipv6 unicast-routing\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' +- name: Create and Setup VRF configuration + vars: + lines: "vrf definition ospf_vrf\naddress-family ipv4\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_parsed.cfg new file mode 100644 index 00000000..2c504a6a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_parsed.cfg @@ -0,0 +1,15 @@ +router ospfv3 1 + max-metric router-lsa on-startup 110 + area 10 nssa default-information-originate metric 10 + ! + address-family ipv4 unicast vrf ospf_vrf + adjacency stagger 25 25 + area 25 nssa default-information-originate metric 25 nssa-only + exit-address-family +router ospfv3 200 + max-metric router-lsa on-startup 100 + auto-cost reference-bandwidth 4 + ! + address-family ipv4 unicast + adjacency stagger 200 200 + exit-address-family diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..c45cf5f9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_populate_config.yaml @@ -0,0 +1,42 @@ +--- +- name: Populate OSPFv3 Configuration + cisco.ios.ios_ospfv3: + config: + processes: + - process_id: 1 + max_metric: + router_lsa: true + on_startup: + time: 110 + address_family: + - afi: ipv4 + unicast: true + vrf: ospf_vrf + adjacency: + min_adjacency: 25 + max_adjacency: 25 + areas: + - area_id: 25 + nssa: + default_information_originate: + metric: 25 + nssa_only: true + areas: + - area_id: "10" + nssa: + default_information_originate: + metric: 10 + - process_id: 200 + address_family: + - afi: ipv4 + unicast: true + adjacency: + min_adjacency: 200 + max_adjacency: 200 + max_metric: + router_lsa: true + on_startup: + time: 100 + auto_cost: + reference_bandwidth: 4 + state: merged diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..d073b216 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/_remove_config.yaml @@ -0,0 +1,16 @@ +--- +- name: Remove OSPFv3 Config + cisco.ios.ios_ospfv3: + state: deleted + +- name: Delete and Clean IPv6 routings configuration + vars: + lines: "no ipv6 unicast-routing\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' + +- name: Delete and Clean VRF configuration + vars: + lines: "no vrf definition ospf_vrf\nno vrf definition blue\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/deleted.yaml new file mode 100644 index 00000000..c941a125 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/deleted.yaml @@ -0,0 +1,69 @@ +--- +- debug: + msg: Start Deleted integration state for ios_ospfv3 ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete provided OSPF V3 processes + register: result + cisco.ios.ios_ospfv3: &id001 + config: + processes: + - process_id: 1 + - process_id: 200 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ result['after'] == {} }}" + + - name: Delete provided OSPF V3 processes (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv3: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + + - include_tasks: _populate_config.yaml + + - name: Delete provided OSPF V3 processes without any config + register: result + cisco.ios.ios_ospfv3: &id002 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ result['after'] == {} }}" + + - name: Delete provided OSPF V3 processes without any config (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv3: *id002 + + - name: Assert that the merge task was idempotent + assert: + that: + - result.changed == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/empty_config.yaml new file mode 100644 index 00000000..3b4474e5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/empty_config.yaml @@ -0,0 +1,61 @@ +--- +- block: + - debug: + msg: START ios_ospfv3 empty_config.yaml integration tests on connection={{ + ansible_connection }} + + - name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_ospfv3: + config: + state: merged + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_ospfv3: + config: + state: replaced + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_ospfv3: + config: + state: overridden + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_ospfv3: + config: + state: rendered + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_ospfv3: + running_config: + state: parsed + + - assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/gathered.yaml new file mode 100644 index 00000000..04caed7b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/gathered.yaml @@ -0,0 +1,26 @@ +--- +- debug: + msg: START ios_ospfv3 gathered integration tests on connection={{ ansible_connection + }} + +- block: + + - include_tasks: _remove_config.yaml + - include_tasks: _initial_vrf_setup.yaml + - include_tasks: _populate_config.yaml + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_ospfv3: + config: + state: gathered + + - name: Assert + assert: + that: + - result.changed == false + - "{{ merged['after']['processes'] | symmetric_difference(result['gathered']['processes']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/merged.yaml new file mode 100644 index 00000000..5f1194c3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/merged.yaml @@ -0,0 +1,75 @@ +--- +- debug: + msg: START Merged ios_ospfv3 state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_ospfv3: &id001 + config: + processes: + - process_id: 1 + max_metric: + router_lsa: true + on_startup: + time: 110 + address_family: + - afi: ipv4 + unicast: true + vrf: ospf_vrf + adjacency: + min_adjacency: 25 + max_adjacency: 25 + areas: + - area_id: 25 + nssa: + default_information_originate: + metric: 25 + nssa_only: true + areas: + - area_id: "10" + nssa: + default_information_originate: + metric: 10 + - process_id: 200 + address_family: + - afi: ipv4 + unicast: true + adjacency: + min_adjacency: 200 + max_adjacency: 200 + max_metric: + router_lsa: true + on_startup: + time: 100 + auto_cost: + reference_bandwidth: 4 + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] == {} }}" + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv3: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/overridden.yaml new file mode 100644 index 00000000..b04dd626 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/overridden.yaml @@ -0,0 +1,58 @@ +--- +- debug: + msg: START Overridden ios_ospfv3 state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Override provided OSPF V3 configuration + register: result + cisco.ios.ios_ospfv3: &id001 + config: + processes: + - process_id: 200 + max_metric: + router_lsa: true + on_startup: + time: 200 + address_family: + - afi: ipv4 + unicast: true + adjacency: + min_adjacency: 50 + max_adjacency: 50 + areas: + - area_id: 200 + nssa: + default_information_originate: + metric: 200 + nssa_only: true + areas: + - area_id: "10" + nssa: + default_information_originate: + metric: 10 + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Override provided OSPF V3 configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv3: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/parsed.yaml new file mode 100644 index 00000000..e17a2b16 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/parsed.yaml @@ -0,0 +1,17 @@ +--- +- block: + - debug: + msg: START ios_ospfv3 parsed integration tests on connection={{ ansible_connection + }} + + - name: Parse the commands for provided configuration + register: result + cisco.ios.ios_ospfv3: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + + - assert: + that: + - result.changed == false + - "{{ merged['after']['processes'] | symmetric_difference(result['parsed']['processes']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/rendered.yaml new file mode 100644 index 00000000..0f323c24 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/rendered.yaml @@ -0,0 +1,53 @@ +--- +- debug: + msg: Start ios_ospfv3 rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + - name: Render the commands for provided configuration + register: result + cisco.ios.ios_ospfv3: &id001 + config: + processes: + - process_id: 1 + max_metric: + router_lsa: true + on_startup: + time: 110 + address_family: + - afi: ipv4 + unicast: true + vrf: ospf_vrf + adjacency: + min_adjacency: 25 + max_adjacency: 25 + areas: + - area_id: 25 + nssa: + default_information_originate: + metric: 25 + nssa_only: true + areas: + - area_id: "10" + nssa: + default_information_originate: + metric: 10 + - process_id: 200 + address_family: + - afi: ipv4 + unicast: true + adjacency: + min_adjacency: 200 + max_adjacency: 200 + max_metric: + router_lsa: true + on_startup: + time: 100 + auto_cost: + reference_bandwidth: 4 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/replaced.yaml new file mode 100644 index 00000000..7bf5f651 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/replaced.yaml @@ -0,0 +1,58 @@ +--- +- debug: + msg: START Replaced ios_ospfv3 state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaced provided OSPF V3 configuration + register: result + cisco.ios.ios_ospfv3: &id001 + config: + processes: + - process_id: 200 + max_metric: + router_lsa: true + on_startup: + time: 200 + address_family: + - afi: ipv4 + unicast: true + adjacency: + min_adjacency: 50 + max_adjacency: 50 + areas: + - area_id: 200 + nssa: + default_information_originate: + metric: 200 + nssa_only: true + areas: + - area_id: "10" + nssa: + default_information_originate: + metric: 10 + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Replaced provided OSPF V3 configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_ospfv3: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/rtt.yaml new file mode 100644 index 00000000..1707db0f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/tests/cli/rtt.yaml @@ -0,0 +1,116 @@ +--- +- debug: + msg: START ios_ospfv3 round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml +- include_tasks: _initial_vrf_setup.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: base_config + cisco.ios.ios_ospfv3: &id001 + config: + processes: + - process_id: 1 + max_metric: + router_lsa: true + on_startup: + time: 110 + address_family: + - afi: ipv4 + unicast: true + vrf: ospf_vrf + adjacency: + min_adjacency: 25 + max_adjacency: 25 + areas: + - area_id: 25 + nssa: + default_information_originate: + metric: 25 + nssa_only: true + areas: + - area_id: "10" + nssa: + default_information_originate: + metric: 10 + timers: + throttle: + lsa: + first_delay: 12 + min_delay: 14 + max_delay: 16 + - process_id: 200 + address_family: + - afi: ipv4 + unicast: true + adjacency: + min_adjacency: 200 + max_adjacency: 200 + max_metric: + router_lsa: true + on_startup: + time: 100 + auto_cost: + reference_bandwidth: 4 + state: merged + + - name: Gather OSPFV3 facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - ospfv3 + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_ospfv3: + config: + processes: + - process_id: 200 + max_metric: + router_lsa: true + on_startup: + time: 200 + address_family: + - afi: ipv4 + unicast: true + adjacency: + min_adjacency: 50 + max_adjacency: 50 + areas: + - area_id: 200 + nssa: + default_information_originate: + metric: 200 + nssa_only: true + areas: + - area_id: "10" + nssa: + default_information_originate: + metric: 10 + state: overridden + + - assert: + that: + - result.commands|length == 9 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_ospfv3: + config: "{{ ansible_facts['network_resources']['ospfv3'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 14 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/vars/main.yaml new file mode 100644 index 00000000..1424f459 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv3/vars/main.yaml @@ -0,0 +1,104 @@ +--- +merged: + before: {} + + commands: + - router ospfv3 1 + - max-metric router-lsa on-startup 110 + - area 10 nssa default-information-originate metric 10 + - address-family ipv4 unicast vrf ospf_vrf + - adjacency stagger 25 25 + - area 25 nssa default-information-originate metric 25 nssa-only + - exit-address-family + - router ospfv3 200 + - auto-cost reference-bandwidth 4 + - max-metric router-lsa on-startup 100 + - address-family ipv4 unicast + - adjacency stagger 200 200 + - exit-address-family + + after: + processes: + - address_family: + - adjacency: + max_adjacency: 25 + min_adjacency: 25 + afi: ipv4 + areas: + - area_id: "25" + nssa: + default_information_originate: + metric: 25 + nssa_only: true + unicast: true + vrf: ospf_vrf + areas: + - area_id: "10" + nssa: + default_information_originate: + metric: 10 + max_metric: + on_startup: + time: 110 + router_lsa: true + process_id: 1 + - address_family: + - adjacency: + max_adjacency: 200 + min_adjacency: 200 + afi: ipv4 + unicast: true + auto_cost: + reference_bandwidth: 4 + max_metric: + on_startup: + time: 100 + router_lsa: true + process_id: 200 + +replaced: + commands: + - router ospfv3 200 + - no auto-cost reference-bandwidth 4 + - max-metric router-lsa on-startup 200 + - area 10 nssa default-information-originate metric 10 + - address-family ipv4 unicast + - adjacency stagger 50 50 + - area 200 nssa default-information-originate metric 200 nssa-only + - exit-address-family + +overridden: + commands: + - no router ospfv3 1 + - router ospfv3 200 + - no auto-cost reference-bandwidth 4 + - max-metric router-lsa on-startup 200 + - area 10 nssa default-information-originate metric 10 + - address-family ipv4 unicast + - adjacency stagger 50 50 + - area 200 nssa default-information-originate metric 200 nssa-only + - exit-address-family + +deleted: + commands: + - no router ospfv3 1 + - no router ospfv3 200 + + after: {} + +rtt: + commands: + - router ospfv3 1 + - max-metric router-lsa on-startup 110 + - area 10 nssa default-information-originate metric 10 + - address-family ipv4 unicast vrf ospf_vrf + - adjacency stagger 25 25 + - area 25 nssa default-information-originate metric 25 nssa-only + - exit-address-family + - router ospfv3 200 + - auto-cost reference-bandwidth 4 + - max-metric router-lsa on-startup 100 + - no area 10 nssa default-information-originate metric 10 + - address-family ipv4 unicast + - exit-address-family + - adjacency stagger 200 200 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tests/cli/ping.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tests/cli/ping.yaml new file mode 100644 index 00000000..ed365b5e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tests/cli/ping.yaml @@ -0,0 +1,58 @@ +--- +- debug: msg="START cli/ping.yaml on connection={{ ansible_connection }}" + +- register: show_version_result + cisco.ios.ios_command: + commands: show version + provider: '{{ cli }}' + +- set_fact: management_interface=GigabitEthernet0/0 + when: "'Cisco IOS' in show_version_result.stdout[0]" + +- set_fact: management_interface=GigabitEthernet1 + when: "'Cisco IOS-XE' in show_version_result.stdout[0]" + +- name: Get show ip management nterface output + register: show_ip_interface_result + cisco.ios.ios_command: + commands: + - show ip interface {{ management_interface }} | include Internet address + provider: '{{ cli }}' + +- name: Extract the IP address from registered output + set_fact: management_ip="{{ show_ip_interface_result.stdout[0].split()[-1].split('/')[0] + }}" + +- name: expected successful ping + register: esp + cisco.ios.ios_ping: + dest: '{{ management_ip }}' + provider: '{{ cli }}' + +- name: unexpected unsuccessful ping + register: uup + ignore_errors: true + cisco.ios.ios_ping: + dest: 10.255.255.250 + provider: '{{ cli }}' + +- name: unexpected successful ping + register: usp + ignore_errors: true + cisco.ios.ios_ping: + dest: '{{ management_ip }}' + provider: '{{ cli }}' + state: absent + +- name: expected unsuccessful ping + register: eup + cisco.ios.ios_ping: + dest: 10.255.255.250 + provider: '{{ cli }}' + state: absent + +- name: assert + assert: + that: + - esp.failed == eup.failed == false + - usp.failed == uup.failed == true diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tasks/cli.yaml new file mode 100644 index 00000000..826f6a84 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tasks/cli.yaml @@ -0,0 +1,22 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + +- name: run test case (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tasks/main.yaml new file mode 100644 index 00000000..4dfb58b9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['network_cli'] } diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/templates/defaults/config.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/templates/defaults/config.j2 new file mode 100644 index 00000000..1d4d9da8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/templates/defaults/config.j2 @@ -0,0 +1,4 @@ +interface Loopback999 + description this is a test + no shutdown + diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tests/cli/common_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tests/cli/common_config.yaml new file mode 100644 index 00000000..1aff5d6f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tests/cli/common_config.yaml @@ -0,0 +1,213 @@ +--- +# ios_linkagg -> CustomNetworkConfig +# cisco.ios.ios_config -> dumps, NetworkConfig + +- debug: msg="START cli/common_config.yaml on connection={{ ansible_connection }}" + +# Hit NetworkConfig +- name: set hostname + cisco.ios.ios_config: + lines: ['hostname ios-smoke'] + match: none + provider: "{{ cli }}" + +- name: hit diff_ignore_lines + cisco.ios.ios_config: + lines: ['hostname ios-smoke-diff'] + diff_ignore_lines: + - hostname ios-smoke + save_when: modified + provider: "{{ cli }}" + +- name: return hostname + cisco.ios.ios_config: + lines: ['hostname {{ shorter_hostname }}'] + match: none + provider: "{{ cli }}" + +- name: hit items with parents + cisco.ios.ios_config: + lines: ['permit ip any any log'] + parents: ['ip access-list extended test'] + provider: "{{ cli }}" + match: exact + register: result + +- name: teardown + cisco.ios.ios_config: + lines: + - 'no ip access-list extended test' + match: none + provider: "{{ cli }}" + +- name: setup test NetworkConfig.difference, replace=block + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + parents: ['ip access-list extended test'] + before: ['no ip access-list extended test'] + after: ['exit'] + provider: "{{ cli }}" + match: none + +- name: test NetworkConfig.difference, replace=block + cisco.ios.ios_config: + lines: + - permit ip host 192.0.2.1 any log + - permit ip host 192.0.2.2 any log + - permit ip host 192.0.2.3 any log + - permit ip host 192.0.2.4 any log + parents: ['ip access-list extended test'] + replace: block + after: ['exit'] + provider: "{{ cli }}" + register: result + +- assert: + that: + - "result.changed == true" + - "'ip access-list extended test' in result.updates" + - "'permit ip host 192.0.2.1 any log' in result.updates" + - "'permit ip host 192.0.2.2 any log' in result.updates" + - "'permit ip host 192.0.2.3 any log' in result.updates" + - "'permit ip host 192.0.2.4 any log' in result.updates" + +- name: teardown- NetworkConfig.difference, replace=block + cisco.ios.ios_config: + lines: + - no ip access-list extended test + match: none + provider: "{{ cli }}" + +# CustomNetworkConfig +# currently gets skipped because switch_type != 'L2' +- set_fact: switch_type="{{ switch_type }}" + +- block: + + - name: setup - remove config used in test(part1) + cisco.ios.ios_config: + lines: + - no interface port-channel 20 + provider: "{{ cli }}" + ignore_errors: true + + - name: setup - remove config used in test(part2) + cisco.ios.ios_config: + lines: + - no interface port-channel 5 + provider: "{{ cli }}" + ignore_errors: true + + - name: setup - remove config used in test(part3) + cisco.ios.ios_config: + lines: + - no channel-group 20 mode active + provider: "{{ cli }}" + parents: "{{ item }}" + loop: + - interface GigabitEthernet0/1 + - interface GigabitEthernet0/2 + + - name: create linkagg + ios_linkagg: &create + group: 20 + state: present + provider: "{{ cli }}" + register: result + + - assert: + that: + - "result.changed == true" + - "'interface port-channel 20' in result.commands" + + - name: set link aggregation group to members + ios_linkagg: &configure_member + group: 20 + mode: active + members: + - GigabitEthernet0/1 + - GigabitEthernet0/2 + provider: "{{ cli }}" + register: result + + - assert: + that: + - "result.changed == true" + - "'interface GigabitEthernet0/1' in result.commands" + - "'channel-group 20 mode active' in result.commands" + - "'interface GigabitEthernet0/2' in result.commands" + - "'channel-group 20 mode active' in result.commands" + + - name: remove link aggregation group from member + ios_linkagg: &remove_member + group: 20 + mode: active + members: + - GigabitEthernet0/2 + provider: "{{ cli }}" + register: result + + - assert: + that: + - "result.changed == true" + - "'interface GigabitEthernet0/1' in result.commands" + - "'no channel-group 20 mode active' in result.commands" + + - name: remove linkagg + ios_linkagg: &remove + group: 20 + state: absent + provider: "{{ cli }}" + register: result + + - assert: + that: + - "result.changed == true" + - "'no interface port-channel 20' in result.commands" + + - name: create aggregate of linkagg definitions + ios_linkagg: &create_agg + aggregate: + - { group: 5 } + - { group: 20, mode: active, members: ['GigabitEthernet0/1'] } + provider: "{{ cli }}" + register: result + + - assert: + that: + - "result.changed == true" + - "'interface port-channel 5' in result.commands" + - "'interface port-channel 20' in result.commands" + - "'interface GigabitEthernet0/1' in result.commands" + - "'channel-group 20 mode active' in result.commands" + + - name: teardown(part1) + cisco.ios.ios_config: + lines: + - no interface port-channel 20 + provider: "{{ cli }}" + ignore_errors: true + + - name: teardown(part2) + cisco.ios.ios_config: + lines: + - no interface port-channel 5 + provider: "{{ cli }}" + ignore_errors: true + + - name: teardown(part3) + cisco.ios.ios_config: + lines: + - no channel-group 20 mode active + provider: "{{ cli }}" + parents: "{{ item }}" + loop: + - interface GigabitEthernet0/1 + - interface GigabitEthernet0/2 + + when: switch_type == 'L2' + +- debug: msg="END cli/common_config.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tests/cli/common_utils.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tests/cli/common_utils.yaml new file mode 100644 index 00000000..ef0d0d95 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tests/cli/common_utils.yaml @@ -0,0 +1,152 @@ +--- +# ios_command -> ComplexList +# ios_interface -> conditional, remove_default_spec +# ios_logging -> validate_ip_address +# ios_l3_interface -> is_netmask, is_masklen, to_subnet, to_netmask, to_masklen + +# ComplexList already covered + +- debug: msg="START ios_smoke cli/common_utils.yaml on connection={{ ansible_connection }}" + +# hit is_netmask(), is_masklen(), to_netmask(), to_masklen() +- name: Delete interface ipv4 and ipv6 address(setup) + cisco.ios.ios_l3_interface: + name: "{{ test_interface }}" + state: absent + provider: "{{ cli }}" + register: result + +- name: Setup - Ensure interfaces are switchport + cisco.ios.ios_config: + lines: + - no shutdown + parents: + - "interface {{ item }}" + provider: "{{ cli }}" + loop: + - "{{ test_interface }}" + - "{{ test_interface2 }}" + +- name: Configure interface ipv4 address + cisco.ios.ios_l3_interface: + name: "{{ test_interface }}" + ipv4: 192.168.20.1/24 + state: present + provider: "{{ cli }}" + register: result + +- assert: + that: + - 'result.changed == true' + - '"interface {{ test_interface }}" in result.commands' + - '"ip address 192.168.20.1 255.255.255.0" in result.commands' + +- name: test invalid subnet + cisco.ios.ios_l3_interface: + name: "{{ test_interface }}" + ipv4: 192.168.20.1/45 + state: present + provider: "{{ cli }}" + register: result + ignore_errors: true + +- debug: var=result + +- assert: + that: + - 'result.failed == true' + +- name: Change ipv4 and ipv6 address using aggregate + cisco.ios.ios_l3_interface: + aggregate: + - { name: "{{ test_interface }}", ipv4: 193.167.1.1/8, ipv6: "fd5a:12c9:2201:4::4/32" } + - { name: "{{ test_interface2 }}", ipv4: 192.169.2.2/24, ipv6: "fd5b:12c9:2201:5::5/90" } + provider: "{{ cli }}" + register: result + +- assert: + that: + - 'result.changed == true' + - '"interface {{ test_interface }}" in result.commands' + - '"ip address 193.167.1.1 255.0.0.0" in result.commands' + - '"ipv6 address fd5a:12c9:2201:4::4/32" in result.commands' + - '"interface {{ test_interface2 }}" in result.commands' + - '"ip address 192.169.2.2 255.255.255.0" in result.commands' + - '"ipv6 address fd5b:12c9:2201:5::5/90" in result.commands' + +- name: Delete ipv4 and ipv6 address using aggregate + cisco.ios.ios_l3_interface: + aggregate: + - { name: "{{ test_interface }}" } + - { name: "{{ test_interface2 }}" } + state: absent + provider: "{{ cli }}" + register: result + +# hit validate_ip_address() +- name: Remove host logging - setup + net_logging: + dest: host + name: 172.16.0.1 + state: absent + provider: "{{ cli }}" + +- name: Remove host logging - teardown + net_logging: + dest: host + name: 172.16.0.1 + state: absent + provider: "{{ cli }}" + +# hit conditional(), remove_default_spec() +- name: Check intent arguments + ios_interface: + name: "{{ test_interface }}" + state: up + provider: "{{ cli }}" + register: result + +- assert: + that: + - "result.failed == false" + +- name: Check intent arguments (failed condition) + ios_interface: + name: "{{ test_interface }}" + state: down + provider: "{{ cli }}" + ignore_errors: true + register: result + +- assert: + that: + - "result.failed == true" + - "'state eq(down)' in result.failed_conditions" + +- name: Config + intent + ios_interface: + name: "{{ test_interface }}" + enabled: false + state: down + provider: "{{ cli }}" + register: result + +- assert: + that: + - "result.failed == false" + +- name: Config + intent (fail) + ios_interface: + name: "{{ test_interface }}" + enabled: false + provider: "{{ cli }}" + state: up + ignore_errors: true + register: result + +- assert: + that: + - "result.failed == true" + - "'state eq(up)' in result.failed_conditions" + +- debug: msg="END ios_smoke cli/common_utils.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tests/cli/misc_tests.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tests/cli/misc_tests.yaml new file mode 100644 index 00000000..b406505a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_smoke/tests/cli/misc_tests.yaml @@ -0,0 +1,41 @@ +--- +- debug: msg="START ios_smoke cli/misc_tests.yaml on connection={{ ansible_connection }}" + +# hit network.ios.ios- get_defaults_flag() +- name: setup + cisco.ios.ios_config: + commands: + - no description + - shutdown + parents: + - interface Loopback999 + match: none + provider: "{{ cli }}" + +- name: configure device with defaults included + cisco.ios.ios_config: + src: defaults/config.j2 + defaults: true + provider: "{{ cli }}" + register: result + +- name: run ios commands to test command_timeout + cisco.ios.ios_command: + commands: + - show running-config all + - show interfaces + - show running-config all + vars: + ansible_command_timeout: 1 + ansible_buffer_read_timeout: 2 + ignore_errors: true + register: result + when: ansible_connection == 'network_cli' + +- assert: + that: + - 'result.failed == true' + - "'timeout value 1 seconds reached' in result.msg" + when: ansible_connection == 'network_cli' + +- debug: msg="END ios_smoke cli/misc_tests.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tests/cli/basic.yaml new file mode 100644 index 00000000..3a05ffb1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tests/cli/basic.yaml @@ -0,0 +1,159 @@ +--- +- debug: msg="START ios cli/ios_static_route.yaml on connection={{ ansible_connection + }}" + +- name: Clear all static routes + cisco.ios.ios_static_route: &id003 + aggregate: + + - prefix: 172.16.31.0 + + - prefix: 172.16.32.0 + + - prefix: 172.16.33.0 + + - prefix: 172.16.34.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + state: absent + provider: '{{ cli }}' + +- name: create static route + register: result + cisco.ios.ios_static_route: + prefix: 172.16.31.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8"] + +- name: Verify idempotence with default admin_distance + register: result + cisco.ios.ios_static_route: + prefix: 172.16.31.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + admin_distance: 1 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: modify admin distance of static route + register: result + cisco.ios.ios_static_route: &id001 + prefix: 172.16.31.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + admin_distance: 2 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8 2"] + +- name: modify admin distance of static route again (idempotent) + register: result + cisco.ios.ios_static_route: *id001 + +- assert: + that: + - result.changed == false + +- name: Verify idempotence with unspecified admin_distance + register: result + cisco.ios.ios_static_route: + prefix: 172.16.31.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: delete static route + register: result + cisco.ios.ios_static_route: &id002 + prefix: 172.16.31.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands == ["no ip route 172.16.31.0 255.255.255.0 10.0.0.8"] + +- name: delete static route again (idempotent) + register: result + cisco.ios.ios_static_route: *id002 + +- assert: + that: + - result.changed == false + +- name: Add static route aggregates + register: result + cisco.ios.ios_static_route: + aggregate: + + - prefix: 172.16.32.0 + + - prefix: 172.16.33.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands == ["ip route 172.16.32.0 255.255.255.0 10.0.0.8", "ip route + 172.16.33.0 255.255.255.0 10.0.0.8"] + +- name: Add and remove static route aggregates with overrides + register: result + cisco.ios.ios_static_route: + aggregate: + + - prefix: 172.16.32.0 + + - prefix: 172.16.33.0 + state: absent + + - prefix: 172.16.34.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands == ["no ip route 172.16.33.0 255.255.255.0 10.0.0.8", "ip + route 172.16.34.0 255.255.255.0 10.0.0.8"] + +- name: Remove static route aggregates + register: result + cisco.ios.ios_static_route: *id003 + +- assert: + that: + - result.changed == true + - result.commands == ["no ip route 172.16.32.0 255.255.255.0 10.0.0.8", "no + ip route 172.16.34.0 255.255.255.0 10.0.0.8"] + +- debug: msg="END ios cli/ios_static_route.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tests/cli/net_static_route.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tests/cli/net_static_route.yaml new file mode 100644 index 00000000..b892be53 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_route/tests/cli/net_static_route.yaml @@ -0,0 +1,32 @@ +--- +- debug: msg="START ios cli/net_static_route.yaml on connection={{ ansible_connection + }}" + +- name: delete static route - setup + ansible.netcommon.net_static_route: &id001 + prefix: 172.16.31.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + state: absent + provider: '{{ cli }}' + +- name: create static route using platform agnostic module + register: result + ansible.netcommon.net_static_route: + prefix: 172.16.31.0 + mask: 255.255.255.0 + next_hop: 10.0.0.8 + admin_distance: 1 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands == ["ip route 172.16.31.0 255.255.255.0 10.0.0.8 1"] + +- name: delete static route - teardown + ansible.netcommon.net_static_route: *id001 + +- debug: msg="END ios cli/net_static_route.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/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=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/_intial_setup_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/_intial_setup_config.yaml new file mode 100644 index 00000000..4606dcd4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/_intial_setup_config.yaml @@ -0,0 +1,11 @@ +--- +- name: Intitial Setup Config + vars: + lines: "vrf definition ansible_temp_vrf\naddress-family ipv4\nip route vrf ansible_temp_vrf\ + \ 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150\nip route\ + \ 198.51.100.0 255.255.255.0 198.51.101.3 name route_3\nip route 198.51.100.0\ + \ 255.255.255.0 198.51.101.2 30 name route_2\nip route 198.51.100.0 255.255.255.0\ + \ 198.51.101.1 110 tag 40 name route_1 multicast\nipv6 route 2001:DB8:0:3::/64\ + \ 2001:DB8:0:3::2 tag 105 name test_v6\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..7c58707a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/_populate_config.yaml @@ -0,0 +1,10 @@ +--- +- name: Populate Config + 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\nip route 198.51.100.0 255.255.255.0 198.51.101.3\ + \ name route_3\nip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2\n\ + ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast\n\ + ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..633751e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/_remove_config.yaml @@ -0,0 +1,11 @@ +--- +- name: Remove Config + 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\nno ip route 198.51.100.0 255.255.255.0 198.51.101.3\ + \ name route_3\nno ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name\ + \ route_2\nno ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40\ + \ name route_1 multicast\nno ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2\ + \ tag 105 name test_v6\nno vrf definition ansible_temp_vrf\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/deleted.yaml new file mode 100644 index 00000000..f7480c7c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/deleted.yaml @@ -0,0 +1,82 @@ +--- +- 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 + register: result + cisco.ios.ios_static_routes: &id001 + 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 + + - assert: + that: + - result.commands|length == 5 + - result.changed == true + - result.commands|symmetric_difference(deleted.commands) == [] + + - name: Delete attributes of all configured interfaces (IDEMPOTENT) + register: result + cisco.ios.ios_static_routes: *id001 + + - 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/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/empty_config.yaml new file mode 100644 index 00000000..5de7bf25 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- 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 + register: result + ignore_errors: true + cisco.ios.ios_static_routes: + config: + state: merged + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_static_routes: + config: + state: replaced + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_static_routes: + config: + state: overridden + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_static_routes: + config: + state: rendered + +- 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 + register: result + ignore_errors: true + cisco.ios.ios_static_routes: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/gathered.yaml new file mode 100644 index 00000000..1d4743ac --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- 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 + register: result + cisco.ios.ios_static_routes: + config: + state: gathered + + - name: Assert that gathered dicts was correctly generated + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/merged.yaml new file mode 100644 index 00000000..255c7f2e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/merged.yaml @@ -0,0 +1,89 @@ +--- +- 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 + register: result + cisco.ios.ios_static_routes: &id001 + 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 + - dest: 192.51.110.0/32 + next_hops: + + - distance_metric: 10 + forward_router_address: 192.51.111.1 + interface: GigabitEthernet0/2 + name: partner_vrf + + - 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 + + - assert: + that: + - result.commands|length == 6 + - result.changed == true + - result.commands|symmetric_difference(merged.commands) == [] + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_static_routes: *id001 + + - 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/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/overridden.yaml new file mode 100644 index 00000000..0fd4210a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/overridden.yaml @@ -0,0 +1,73 @@ +--- +- 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 + register: result + cisco.ios.ios_static_routes: &id001 + 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 + + - 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) + register: result + cisco.ios.ios_static_routes: *id001 + + - 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/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/rendered.yaml new file mode 100644 index 00000000..4b4b7050 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/rendered.yaml @@ -0,0 +1,69 @@ +--- +- 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 + register: result + cisco.ios.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: 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 + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(rendered.commands) == [] + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/replaced.yaml new file mode 100644 index 00000000..9fe5a94c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/replaced.yaml @@ -0,0 +1,76 @@ +--- +- 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 + register: result + cisco.ios.ios_static_routes: &id001 + 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 + + - 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) + register: result + cisco.ios.ios_static_routes: *id001 + + - 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/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/rtt.yaml new file mode 100644 index 00000000..a76554f1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/tests/cli/rtt.yaml @@ -0,0 +1,94 @@ +--- +- 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) + register: base_config + cisco.ios.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 + + - name: Gather static routes facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - static_routes + + - name: Apply the configuration which need to be reverted + register: result + cisco.ios.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 + + - 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 + register: revert + cisco.ios.ios_static_routes: + config: "{{ ansible_facts['network_resources']['static_routes'] }}" + state: overridden + + - 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 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/vars/main.yaml new file mode 100644 index 00000000..ffc04270 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_static_routes/vars/main.yaml @@ -0,0 +1,96 @@ +--- +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 vrf ansible_temp_vrf 192.51.110.0 255.255.255.255 GigabitEthernet0/2 192.51.111.1 10 name partner_vrf + - 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 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/meta/main.yml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/net_system.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/net_system.yaml new file mode 100644 index 00000000..52b172c2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/net_system.yaml @@ -0,0 +1,35 @@ +--- +- debug: msg="START ios cli/net_system.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - no ip domain-list ansible.com + - no ip domain-list redhat.com + match: none + provider: '{{ cli }}' + +- name: configure domain_search using platform agnostic module + register: result + ansible.netcommon.net_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'ip domain list ansible.com' in result.commands" + - "'ip domain list redhat.com' in result.commands" + +- name: teardown + cisco.ios.ios_config: + lines: + - no ip domain-list ansible.com + - no ip domain-list redhat.com + match: none + provider: '{{ cli }}' + +- debug: msg="END ios cli/net_system.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_domain_list.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_domain_list.yaml new file mode 100644 index 00000000..d051d216 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_domain_list.yaml @@ -0,0 +1,124 @@ +--- +- debug: msg="START cli/set_domain_search.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - no ip domain-list ansible.com + - no ip domain-list redhat.com + match: none + provider: '{{ cli }}' + +- name: configure domain_search + register: result + cisco.ios.ios_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'ip domain list ansible.com' in result.commands" + - "'ip domain list redhat.com' in result.commands" + +- name: verify domain_search + register: result + cisco.ios.ios_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: remove one entry + register: result + cisco.ios.ios_system: + domain_search: + - ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'no ip domain list redhat.com' in result.commands" + +- name: verify remove one entry + register: result + cisco.ios.ios_system: + domain_search: + - ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: add one entry + register: result + cisco.ios.ios_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'ip domain list redhat.com' in result.commands" + +- name: verify add one entry + register: result + cisco.ios.ios_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: add and remove one entry + register: result + cisco.ios.ios_system: + domain_search: + - ansible.com + - eng.ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'no ip domain list redhat.com' in result.commands" + - "'ip domain list eng.ansible.com' in result.commands" + - result.commands|length == 2 + +- name: verify add and remove one entry + register: result + cisco.ios.ios_system: + domain_search: + - ansible.com + - eng.ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: + - no ip domain-list ansible.com + - no ip domain-list redhat.com + - no ip domain-list eng.ansible.com + match: none + provider: '{{ cli }}' + +- debug: msg="END cli/set_domain_search.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_domain_name.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_domain_name.yaml new file mode 100644 index 00000000..eb44e22a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_domain_name.yaml @@ -0,0 +1,37 @@ +--- +- debug: msg="START cli/set_domain_name.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: no ip domain-name + match: none + provider: '{{ cli }}' + +- name: configure domain_name + register: result + cisco.ios.ios_system: + domain_name: eng.ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + +- name: verify domain_name + register: result + cisco.ios.ios_system: + domain_name: eng.ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: no ip domain-name + match: none + provider: '{{ cli }}' + +- debug: msg="END cli/set_domain_name.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_hostname.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_hostname.yaml new file mode 100644 index 00000000..82053356 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_hostname.yaml @@ -0,0 +1,36 @@ +--- +- debug: msg="START cli/set_hostname.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.ios.ios_config: + lines: hostname switch + match: none + provider: '{{ cli }}' + +- name: configure hostname + register: result + cisco.ios.ios_system: + hostname: foo + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + +- name: verify hostname + register: result + cisco.ios.ios_system: + hostname: foo + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.ios.ios_config: + lines: hostname {{ inventory_hostname }} + match: none + provider: '{{ cli }}' + +- debug: msg="END cli/set_hostname.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_lookup_source.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_lookup_source.yaml new file mode 100644 index 00000000..46fa39d0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_lookup_source.yaml @@ -0,0 +1,66 @@ +--- +- debug: msg="START cli/set_lookup_source.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - no ip domain lookup source-interface Loopback888 + - vrf definition ansible + match: none + provider: '{{ cli }}' + +- name: configure lookup_source + register: result + cisco.ios.ios_system: + lookup_source: Loopback888 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'ip domain lookup source-interface Loopback888' in result.commands" + +- name: verify lookup_source + register: result + cisco.ios.ios_system: + lookup_source: Loopback888 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: Disable lookup_source + register: result + cisco.ios.ios_system: + lookup_enabled: false + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'no ip domain lookup' in result.commands" + +- name: Disable lookup_source + register: result + cisco.ios.ios_system: + lookup_enabled: true + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'ip domain lookup' in result.commands" + +- name: teardown + ignore_errors: true + cisco.ios.ios_config: + lines: + - no ip domain lookup source-interface Loopback888 + - no vrf definition ansible + match: none + provider: '{{ cli }}' + +- debug: msg="END cli/set_lookup_source.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_name_servers.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_name_servers.yaml new file mode 100644 index 00000000..b313edac --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_system/tests/cli/set_name_servers.yaml @@ -0,0 +1,64 @@ +--- +- debug: msg="START cli/set_name_servers.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.ios.ios_config: + lines: + - no ip name-server + match: none + provider: '{{ cli }}' + +- name: configure name_servers + register: result + cisco.ios.ios_system: + name_servers: + - 192.0.2.1 + - 192.0.2.2 + - 192.0.2.3 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands|length == 3 + - "'ip name-server 192.0.2.1' in result.commands" + - "'ip name-server 192.0.2.2' in result.commands" + - "'ip name-server 192.0.2.3' in result.commands" + +- name: verify name_servers + register: result + cisco.ios.ios_system: + name_servers: + - 192.0.2.1 + - 192.0.2.2 + - 192.0.2.3 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: remove one + register: result + cisco.ios.ios_system: + name_servers: + - 192.0.2.1 + - 192.0.2.2 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands|length == 1 + - "'no ip name-server 192.0.2.3' in result.commands" + +- name: teardown + cisco.ios.ios_config: + lines: + - no ip name-server + match: none + provider: '{{ cli }}' + +- debug: msg="END cli/set_name_servers.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/files/test_rsa b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/files/test_rsa new file mode 100644 index 00000000..9fdc8c3a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/files/test_rsa @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAseTsv6oTMJbsRgOSaNEVBlsqE4tKI2MBEOHzTlUnE3GBRtZi +xlUlF9rZcjtk+hTIz3N3UrLtxMnWqv0YGM8tXZTcz50M9ANDE/oNXrXkkMKX5WWr +OcgDCAAZYSVJ/vIt/xZkYteax6zMZQqEBIc/rKo8KuxKZTUMqj0GHkCQbA/o7lBQ +hpdUZxtU/Y2uc9tXVhav3jVzTFUOdwZrCAJghdCCweJfwAj1DdHODip+/hNu+3Sk +DNl0bdhWoNNnUFCYPOUK2B79OMg2+r5bwH7xgURIoTuc54HlGectJpIzI7GB6VfL +UCsJn0uQ7HwX7XAtZjhJWP8dKPd1FuUgg5M8MwIDAQABAoIBACfBVz9GDN/Q+qBy +7+dIwoAXI4IWoMzjtTtGo48f7Iml1hQ0mQJlyNJZ8DpdF6XjuzTRQxtSLVzLFpRD +13zD4AmH2Qj0ug5WJEl0mkRONfQ76KI1ZFyXXEYPb5yMLssw6CKXqHuGX2q8LTlv +bi1s5Ef8C1I0WDPh9SCeXp2oJB5h2G+HtCXDyxASK2nAKqhkpQqPhg5Rd50mBOpD +WE/lor358hU0Aj/qhzjeWKNNK8pgeahXz5anEQZ69TUH102B6bNh8Ao4ZL2j3tr0 +6FbE3ooQT7+zOLm5xOFJ9OnJ2yDVW6Dj1Czllx2vJUcxKsKxaGF76xNCIPiSUUfS +mnOnEfECgYEA2bBFc9Pb8AI0bZZ8Q6XE7Jqa6BOaLbzyjK6IzdyAV/LKdk3yRfEZ +Rb2iNy8poBUYBqBUMfRsRVq5dabjYkz9X5e+75S8Lm/qiktlhTpQYWk5q+eBZdPm +I+dG64Tdyv+Y/NwN4enIsw8LGllY472iUf37ms2+uOA8/BysQ2n7ss0CgYEA0TPD +IhmLqNhQGkS2GU6tM8G7LyGOaIH3mmyCviYgEauWWw3bn/Hhiq/6tLtQc6pv2nIa +ifbACnI+GiIoBFwz8ofuFA8dm76uro7o6eWP5iUizoGISYSewCFpcCpp0xn7/FNR +3RT4YRBMt3yL8J1cVBpPRRbIwp/bZ+pRb0Ggqv8CgYEAoNAFHqHdkhou3N4UgmzN +YvR7hwIkHbG9hIvS6DECZvYm9upyFZUcVFbYpOekWmv6ybpbOGQWL83rv6w/wfia +HKofFSHNOojWvL8iCh+gDbYMMp/dCXpWQyOxUn9e0X2saO+vGbr41r5AN4DVl7gZ +V3THD/75691Lb/tGjq6Wj+kCgYB6ZhadNOUJfMYhGGKSm/2qcobaJH/1lVUQ/Lvi +FNxeek4WKB1/jz2urxe39oAzrFyVKn1sivoBIqZDFAjlxCyAkhcxlUZ1gTMi3mpX +rwBqXv/mYtMicH2RW/scrTQNVv6fuwACoepQoADCuhQGS4thiaMngRUlCfKM8gOD +XJpscQKBgQDIMURtVIV/2ZcGqHv/3G5jsPJPsTycv6YR4gTs5GUBy5If2Rs7DMWE +pJLIcU+SJhMeVKTZPrePibzCp2+rMSI5pc6T+9LC79RKsfie3UybWfLZrSmtnxJx +MgC49TR4NFP6yoYJPYiTdRJ/1Bu68WfVafFK86i9MKAI5OU2ba3/Bg== +-----END RSA PRIVATE KEY----- diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/files/test_rsa.pub b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/files/test_rsa.pub new file mode 100644 index 00000000..e6939a29 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/files/test_rsa.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCx5Oy/qhMwluxGA5Jo0RUGWyoTi0ojYwEQ4fNOVScTcYFG1mLGVSUX2tlyO2T6FMjPc3dSsu3Eydaq/RgYzy1dlNzPnQz0A0MT+g1eteSQwpflZas5yAMIABlhJUn+8i3/FmRi15rHrMxlCoQEhz+sqjwq7EplNQyqPQYeQJBsD+juUFCGl1RnG1T9ja5z21dWFq/eNXNMVQ53BmsIAmCF0ILB4l/ACPUN0c4OKn7+E277dKQM2XRt2Fag02dQUJg85QrYHv04yDb6vlvAfvGBREihO5zngeUZ5y0mkjMjsYHpV8tQKwmfS5DsfBftcC1mOElY/x0o93UW5SCDkzwz ansible_ios_user_test diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tasks/cli.yaml new file mode 100644 index 00000000..dd8b399e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tasks/cli.yaml @@ -0,0 +1,17 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/auth.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/auth.yaml new file mode 100644 index 00000000..2ed3dbaf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/auth.yaml @@ -0,0 +1,109 @@ +--- +- block: + + - name: Create user with password + cisco.ios.ios_user: + name: auth_user + privilege: 15 + role: network-operator + state: present + configured_password: pass123 + + - name: reset connection with {{ ansible_user } + meta: reset_connection + + - name: test login for {{ ansible_user }} user with password + cisco.ios.ios_command: + commands: + - show version + vars: + ansible_user: auth_user + ansible_password: pass123 + + - name: reset connection with {{ ansible_user } + meta: reset_connection + + - name: test login with invalid password (should fail) + cisco.ios.ios_command: + commands: + - show version + ignore_errors: true + register: results + vars: + ansible_user: auth_user + ansible_password: badpass + + - name: reset connection with {{ ansible_user } + meta: reset_connection + + - name: check that attempt failed + assert: + that: + - results.failed + always: + + - name: delete user + register: result + cisco.ios.ios_user: + name: auth_user + state: absent + + - name: reset connection + meta: reset_connection + +- block: + + - name: Ensure ssh key is not world readable + file: + path: '{{ role_path }}/files/test_rsa' + mode: 384 + + - name: Create user with sshkey + cisco.ios.ios_user: + name: ssh_user + privilege: 15 + role: network-operator + state: present + sshkey: "{{ lookup('file', 'files/test_rsa.pub') }}" + + - name: reset connection with {{ ansible_user } + meta: reset_connection + + - name: test sshkey login for {{ ansible_user }} user + cisco.ios.ios_command: + commands: + - show version + vars: + ansible_user: ssh_user + ansible_private_key_file: "{{ role_path }}/files/test_rsa" + + - name: reset connection with {{ ansible_user }} + meta: reset_connection + + - name: test with {{ ansible_user }} user without keys + cisco.ios.ios_command: + commands: + - show version + ignore_errors: true + register: results + vars: + ansible_user: ssh_user + ansible_private_key_file: "" + + - name: reset connection with {{ ansible_user }} + meta: reset_connection + + - name: check that attempt failed + assert: + that: + - results.failed + always: + + - name: delete user + register: result + cisco.ios.ios_user: + name: ssh_user + state: absent + + - name: reset connection + meta: reset_connection diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/basic.yaml new file mode 100644 index 00000000..e3159a0a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/basic.yaml @@ -0,0 +1,160 @@ +--- +- name: tear down old users if they exist (Setup) + become: true + cisco.ios.ios_user: + aggregate: + + - name: ansibletest1 + + - name: ansibletest2 + + - name: ansibletest3 + + - name: ansibletest4 + + - name: ansibletest5 + + - name: ansibletest6 + state: absent + provider: '{{ cli }}' + +- name: Create user (SetUp) + become: true + register: result + cisco.ios.ios_user: + name: ansibletest1 + privilege: 15 + role: network-operator + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands == ["username ansibletest1 view network-operator", "username + ansibletest1 privilege 15"] + +- name: Collection of users (SetUp) + become: true + register: result + cisco.ios.ios_user: + aggregate: + + - name: ansibletest2 + + - name: ansibletest3 + provider: '{{ cli }}' + state: present + view: network-admin + +- assert: + that: + - result.changed == true + - result.commands == ["username ansibletest2 view network-admin", "username + ansibletest3 view network-admin"] + +- name: Add user again (Idempotent) + become: true + register: result + cisco.ios.ios_user: + name: ansibletest1 + privilege: 15 + role: network-operator + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 + +- name: Add collection of users again (Idempotent) + become: true + register: result + cisco.ios.ios_user: + aggregate: + + - name: ansibletest2 + + - name: ansibletest3 + provider: '{{ cli }}' + state: present + view: network-admin + +- assert: + that: + - result.changed == false + - result.commands | length == 0 + +- name: Create user with password_type (password) + become: true + register: result + cisco.ios.ios_user: + name: ansibleuser4 + password_type: password + configured_password: testpass + provider: '{{ cli }}' + state: present + +- assert: + that: + - result.changed == true + - "'username ansibleuser4 password' in result.commands[0]" + +- name: Create user with password_type (secret) + become: true + register: result + cisco.ios.ios_user: + name: ansibleuser5 + password_type: secret + configured_password: testpass + provider: '{{ cli }}' + state: present + +- assert: + that: + - result.changed == true + - "'username ansibleuser5 secret' in result.commands[0]" + +- name: Create user with hashed_password + become: true + register: result + cisco.ios.ios_user: + name: ansibleuser6 + hashed_password: + type: 5 + value: $3$8JcDilcYgFZi.yz4ApaqkHG2.8/ + provider: '{{ cli }}' + state: present + +- assert: + that: + - result.changed == true + - "'username ansibleuser6 secret' in result.commands[0]" + +- name: tearDown + become: true + register: result + cisco.ios.ios_user: + aggregate: + + - name: ansibletest1 + + - name: ansibletest2 + + - name: ansibletest3 + + - name: ansibletest4 + + - name: ansibletest5 + + - name: ansibletest6 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"no username ansibletest1" in result.commands[0]["command"]' + - '"no username ansibletest2" in result.commands[1]["command"]' + - '"no username ansibletest3" in result.commands[2]["command"]' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/meta/main.yaml new file mode 100644 index 00000000..ab3ad91b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_ios_tests diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/tasks/cli.yaml new file mode 100644 index 00000000..a65d756b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: network_cli + +- name: run test case (connection=local) + include: '{{ test_case_to_run }} ansible_connection=local' + with_first_found: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: local diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/tasks/main.yaml new file mode 100644 index 00000000..07b0f2e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- include: cli.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/tests/cli/basic.yaml new file mode 100644 index 00000000..3b56f537 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlan/tests/cli/basic.yaml @@ -0,0 +1,246 @@ +--- +- debug: msg="START cli/basic.yaml on connection={{ ansible_connection }}" + +- set_fact: switch_type="{{ switch_type }}" + +- block: + + - name: setup - remove vlan used in test + cisco.ios.ios_config: + lines: + - no vlan 100 + - no vlan 200 + - no vlan 300 + provider: '{{ cli }}' + + - name: setup - remove switchport settings on interfaces used in test + loop: + - interface GigabitEthernet0/1 + - interface GigabitEthernet0/2 + cisco.ios.ios_config: + lines: + - switchport mode access + - no switchport access vlan 100 + provider: '{{ cli }}' + parents: '{{ item }}' + + - name: create vlan + register: result + cisco.ios.ios_vlan: &id001 + vlan_id: 100 + name: test-vlan + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'vlan 100' in result.commands" + - "'name test-vlan' in result.commands" + + - name: create vlan(idempotence) + register: result + cisco.ios.ios_vlan: *id001 + + - assert: + that: + - result.changed == false + + - name: Add interfaces to vlan + register: result + cisco.ios.ios_vlan: &id002 + vlan_id: 100 + interfaces: + - GigabitEthernet0/1 + - GigabitEthernet0/2 + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'interface GigabitEthernet0/1' in result.commands" + - "'switchport mode access' in result.commands" + - "'switchport access vlan 100' in result.commands" + - "'interface GigabitEthernet0/2' in result.commands" + - "'switchport mode access' in result.commands" + - "'switchport access vlan 100' in result.commands" + + - name: Add interfaces to vlan(idempotence) + register: result + cisco.ios.ios_vlan: *id002 + + - assert: + that: + - result.changed == false + + - name: Check interface assigned to vrf (intent) + register: result + cisco.ios.ios_vlan: + vlan_id: 100 + associated_interfaces: + - GigabitEthernet0/1 + - GigabitEthernet0/2 + provider: '{{ cli }}' + + - assert: + that: + - result.failed == false + + - name: Check interface assigned to vrf (fail) + ignore_errors: true + register: result + cisco.ios.ios_vlan: + vlan_id: 100 + associated_interfaces: + - test + provider: '{{ cli }}' + + - assert: + that: + - result.failed == True + + - name: Remove interface from vlan + register: result + cisco.ios.ios_vlan: &id003 + vlan_id: 100 + interfaces: + - GigabitEthernet0/1 + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'vlan 100' in result.commands" + - "'interface GigabitEthernet0/2' in result.commands" + - "'switchport mode access' in result.commands" + - "'no switchport access vlan 100' in result.commands" + + - name: Remove interface from vlan(idempotence) + register: result + cisco.ios.ios_vlan: *id003 + + - assert: + that: + - result.changed == false + + - name: Suspend vlan + register: result + cisco.ios.ios_vlan: + vlan_id: 100 + state: suspend + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'vlan 100' in result.commands" + - "'state suspend' in result.commands" + + - name: Unsuspend vlan + register: result + cisco.ios.ios_vlan: + vlan_id: 100 + state: active + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'vlan 100' in result.commands" + - "'state active' in result.commands" + + - name: delete vlan + register: result + cisco.ios.ios_vlan: &id004 + vlan_id: 100 + provider: '{{ cli }}' + state: absent + + - assert: + that: + - result.changed == true + - "'no vlan 100' in result.commands" + + - name: delete vlan(idempotence) + register: result + cisco.ios.ios_vlan: *id004 + + - assert: + that: + - result.changed == false + + - name: create vlans using aggregate + register: result + cisco.ios.ios_vlan: &id005 + aggregate: + + - vlan_id: 200 + name: vlan-200 + + - vlan_id: 300 + name: vlan-300 + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'vlan 200' in result.commands" + - "'name vlan-200' in result.commands" + - "'vlan 300' in result.commands" + - "'name vlan-300' in result.commands" + + - name: create vlans using aggregate(idempotence) + register: result + cisco.ios.ios_vlan: *id005 + + - assert: + that: + - result.changed == false + + - name: delete vlans using aggregate + register: result + cisco.ios.ios_vlan: &id006 + aggregate: + + - vlan_id: 200 + name: vlan-200 + + - vlan_id: 300 + name: vlan-300 + state: absent + provider: '{{ cli }}' + + - assert: + that: + - result.changed == true + - "'no vlan 200' in result.commands" + - "'no vlan 300' in result.commands" + + - name: delete vlans using aggregate(idempotence) + register: result + cisco.ios.ios_vlan: *id006 + + - assert: + that: + - result.changed == false + + - name: teardown(part1) + cisco.ios.ios_config: + lines: + - no vlan 100 + - no vlan 200 + - no vlan 300 + provider: '{{ cli }}' + + - name: teardown(part2) + loop: + - interface GigabitEthernet0/1 + - interface GigabitEthernet0/2 + cisco.ios.ios_config: + lines: + - switchport mode access + - no switchport access vlan 100 + provider: '{{ cli }}' + parents: '{{ item }}' + when: switch_type == 'L2' + +- debug: msg="END cli/basic.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tasks/cli.yaml new file mode 100644 index 00000000..b14576a6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tasks/cli.yaml @@ -0,0 +1,24 @@ +--- +- 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: Get the IOS version + cisco.ios.ios_facts: + gather_subset: all + +- name: Run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_parsed.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_parsed.cfg new file mode 100644 index 00000000..409931d2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_parsed.cfg @@ -0,0 +1,21 @@ +VLAN Name Status Ports +---- -------------------------------- --------- ------------------------------- +1 default active Gi0/1, Gi0/2 +10 vlan_10 active +20 vlan_20 act/lshut +30 vlan_30 sus/lshut +1002 fddi-default act/unsup +1003 token-ring-default act/unsup +1004 fddinet-default act/unsup +1005 trnet-default act/unsup + +VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 +---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ +1 enet 100001 1500 - - - - - 0 0 +10 enet 100010 1500 - - - - - 0 0 +20 enet 100020 1500 - - - - - 0 0 +30 enet 100030 1500 - - - - - 0 0 +1002 fddi 101002 1500 - - - - - 0 0 +1003 tr 101003 1500 - - - - - 0 0 +1004 fdnet 101004 1500 - - - ieee - 0 0 +1005 trnet 101005 1500 - - - ibm - 0 0 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..81e1ba39 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_populate_config.yaml @@ -0,0 +1,7 @@ +--- +- name: Setup + vars: + lines: "vlan 10\nvlan 20\nvlan 30\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..2ff9dcb7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_remove_config.yaml @@ -0,0 +1,7 @@ +--- +- name: Remove Config + vars: + lines: "no vlan 10\nno vlan 20\nno vlan 30\nno vlan 40\n" + when: ansible_net_version != "15.6(2)T" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/deleted.yaml new file mode 100644 index 00000000..2f3da53f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/deleted.yaml @@ -0,0 +1,46 @@ +--- +- debug: + msg: Start Deleted integration state for ios_vlans ansible_connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete VLANs attributes for all configured VLANs + register: result + cisco.ios.ios_vlans: &id001 + state: deleted + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ deleted['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Delete VLANs attributes for all configured VLANs (IDEMPOTENT) + register: result + cisco.ios.ios_vlans: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/empty_config.yaml new file mode 100644 index 00000000..06ed21a9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/empty_config.yaml @@ -0,0 +1,66 @@ +--- +- debug: + msg: START ios_vlans empty_config.yaml integration tests on connection={{ ansible_connection + }} + +- block: + + - name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_vlans: + config: + state: merged + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_vlans: + config: + state: replaced + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_vlans: + config: + state: overridden + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_vlans: + config: + state: rendered + + - 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 + register: result + ignore_errors: true + cisco.ios.ios_vlans: + running_config: + state: parsed + + - assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml new file mode 100644 index 00000000..0faf02b1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START ios_vlans gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather the provided configuration with the exisiting running configuration + register: result + cisco.ios.ios_vlans: + config: + state: gathered + + - name: Assert + assert: + that: + - gathered['config'] | symmetric_difference(result.gathered) == [] + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/merged.yaml new file mode 100644 index 00000000..8e828372 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/merged.yaml @@ -0,0 +1,62 @@ +--- +- debug: + msg: START Merged ios_vlans state for integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_vlans: &id001 + config: + + - name: Vlan_10 + vlan_id: 10 + state: active + shutdown: disabled + remote_span: true + + - name: Vlan_20 + vlan_id: 20 + mtu: 610 + state: active + shutdown: enabled + + - name: Vlan_30 + vlan_id: 30 + state: suspend + shutdown: enabled + state: merged + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |\ + \ length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ merged['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge provided configuration with device configuration (IDEMPOTENT) + register: result + cisco.ios.ios_vlans: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml new file mode 100644 index 00000000..dfd6430b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/overridden.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: START Overridden ios_vlans state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Override device configuration of all VLANs with provided configuration + register: result + cisco.ios.ios_vlans: &id001 + config: + + - name: VLAN_10 + vlan_id: 10 + mtu: 1000 + + - name: VLAN_40 + vlan_id: 40 + mtu: 850 + state: overridden + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ overridden['before'] | symmetric_difference(result['before']) |\ + \ length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Override device configuration of all interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_vlans: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml new file mode 100644 index 00000000..1e9d6a39 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/parsed.yaml @@ -0,0 +1,18 @@ +--- +- debug: + msg: START ios_vlans parsed integration tests on connection={{ ansible_connection + }} + +- block: + - name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_vlans: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + + - assert: + that: + - result.changed == false + - parsed['config']|symmetric_difference(result.parsed) == [] + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml new file mode 100644 index 00000000..f55d3c8c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/rendered.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: Start ios_vlans rendered integration tests ansible_connection={{ + ansible_connection }} + +- block: + + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_vlans: + config: + - name: Vlan_10 + vlan_id: 10 + state: active + shutdown: disabled + remote_span: true + - name: Vlan_20 + vlan_id: 20 + mtu: 610 + state: active + shutdown: enabled + - name: Vlan_30 + vlan_id: 30 + state: suspend + shutdown: enabled + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] + when: ansible_net_version != "15.6(2)T" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/replaced.yaml new file mode 100644 index 00000000..fbb5c036 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/replaced.yaml @@ -0,0 +1,61 @@ +--- +- debug: + msg: START Replaced ios_vlans state for integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replaces device configuration of listed VLANs with provided configuration + register: result + cisco.ios.ios_vlans: &id001 + config: + + - vlan_id: 20 + name: Test_VLAN20 + mtu: 700 + shutdown: disabled + + - vlan_id: 30 + name: Test_VLAN30 + mtu: 1000 + + - vlan_id: 40 + name: Test_new_VLAN40 + state: suspend + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ | length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ replaced['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Replaces device configuration of listed interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.ios.ios_vlans: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + when: ansible_net_version != "15.6(2)T" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/rtt.yaml new file mode 100644 index 00000000..b4874485 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/rtt.yaml @@ -0,0 +1,72 @@ +--- +- debug: + msg: START ios_vlans round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Apply the provided configuration (Base config) + register: base_config + cisco.ios.ios_vlans: + config: + - name: Vlan_10 + vlan_id: 10 + state: active + shutdown: disabled + remote_span: true + + - name: Vlan_20 + vlan_id: 20 + mtu: 610 + state: active + shutdown: enabled + + - name: Vlan_30 + vlan_id: 30 + state: suspend + shutdown: enabled + state: merged + + - name: Gather VLANs interfaces facts + cisco.ios.ios_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - vlans + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.ios.ios_vlans: + config: + - name: VLAN_10 + vlan_id: 10 + mtu: 1000 + + - name: VLAN_40 + vlan_id: 40 + mtu: 850 + state: overridden + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + + - name: Revert back to base config using facts round trip + register: revert + cisco.ios.ios_vlans: + config: "{{ ansible_facts['network_resources']['vlans'] }}" + state: overridden + + - assert: + that: + - revert.commands|length == 14 + - revert.changed == true + - revert.commands|symmetric_difference(rtt.commands) == [] + when: ansible_net_version != "15.6(2)T" + always: + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/vars/main.yaml new file mode 100644 index 00000000..3b3d3477 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/vars/main.yaml @@ -0,0 +1,442 @@ +--- +merged: + before: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 + commands: + - vlan 10 + - name Vlan_10 + - state active + - remote-span + - no shutdown + - vlan 20 + - name Vlan_20 + - state active + - mtu 610 + - shutdown + - vlan 30 + - name Vlan_30 + - state suspend + - shutdown + after: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1500 + name: Vlan_10 + remote_span: true + shutdown: disabled + state: active + vlan_id: 10 + - mtu: 610 + name: Vlan_20 + shutdown: enabled + state: active + vlan_id: 20 + - mtu: 1500 + name: Vlan_30 + shutdown: enabled + state: suspend + vlan_id: 30 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 +replaced: + before: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1500 + name: VLAN0010 + shutdown: disabled + state: active + vlan_id: 10 + - mtu: 1500 + name: VLAN0020 + shutdown: disabled + state: active + vlan_id: 20 + - mtu: 1500 + name: VLAN0030 + shutdown: disabled + state: active + vlan_id: 30 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 + commands: + - vlan 20 + - name Test_VLAN20 + - mtu 700 + - vlan 30 + - name Test_VLAN30 + - mtu 1000 + - vlan 40 + - name Test_new_VLAN40 + - state suspend + after: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1500 + name: VLAN0010 + shutdown: disabled + state: active + vlan_id: 10 + - mtu: 700 + name: Test_VLAN20 + shutdown: disabled + state: active + vlan_id: 20 + - mtu: 1000 + name: Test_VLAN30 + shutdown: disabled + state: active + vlan_id: 30 + - mtu: 1500 + name: Test_new_VLAN40 + shutdown: disabled + state: suspend + vlan_id: 40 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 +overridden: + before: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1500 + name: VLAN0010 + shutdown: disabled + state: active + vlan_id: 10 + - mtu: 1500 + name: VLAN0020 + shutdown: disabled + state: active + vlan_id: 20 + - mtu: 1500 + name: VLAN0030 + shutdown: disabled + state: active + vlan_id: 30 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 + commands: + - vlan 10 + - name VLAN_10 + - mtu 1000 + - no vlan 20 + - no vlan 30 + - vlan 40 + - name VLAN_40 + - mtu 850 + after: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1000 + name: VLAN_10 + shutdown: disabled + state: active + vlan_id: 10 + - mtu: 850 + name: VLAN_40 + shutdown: disabled + state: active + vlan_id: 40 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 +deleted: + before: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1500 + name: VLAN0010 + shutdown: disabled + state: active + vlan_id: 10 + - mtu: 1500 + name: VLAN0020 + shutdown: disabled + state: active + vlan_id: 20 + - mtu: 1500 + name: VLAN0030 + shutdown: disabled + state: active + vlan_id: 30 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 + commands: + - no vlan 10 + - no vlan 20 + - no vlan 30 + after: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 +gathered: + config: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1500 + name: VLAN0010 + shutdown: disabled + state: active + vlan_id: 10 + - mtu: 1500 + name: VLAN0020 + shutdown: disabled + state: active + vlan_id: 20 + - mtu: 1500 + name: VLAN0030 + shutdown: disabled + state: active + vlan_id: 30 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 +parsed: + config: + - mtu: 1500 + name: default + shutdown: disabled + state: active + vlan_id: 1 + - mtu: 1500 + name: vlan_10 + shutdown: disabled + state: active + vlan_id: 10 + - mtu: 1500 + name: vlan_20 + shutdown: enabled + state: active + vlan_id: 20 + - mtu: 1500 + name: vlan_30 + shutdown: enabled + state: suspend + vlan_id: 30 + - mtu: 1500 + name: fddi-default + shutdown: enabled + state: active + vlan_id: 1002 + - mtu: 1500 + name: token-ring-default + shutdown: enabled + state: active + vlan_id: 1003 + - mtu: 1500 + name: fddinet-default + shutdown: enabled + state: active + vlan_id: 1004 + - mtu: 1500 + name: trnet-default + shutdown: enabled + state: active + vlan_id: 1005 +rtt: + commands: + - vlan 10 + - name Vlan_10 + - mtu 1500 + - no vlan 40 + - vlan 20 + - name Vlan_20 + - state active + - mtu 610 + - shutdown + - vlan 30 + - name Vlan_30 + - state suspend + - mtu 1500 + - shutdown diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/prepare_ios_tests/tasks/main.yml b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/prepare_ios_tests/tasks/main.yml new file mode 100644 index 00000000..c0800ee8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/prepare_ios_tests/tasks/main.yml @@ -0,0 +1,54 @@ +--- +- name: Ensure we have loopback 888 for testing + connection: ansible.netcommon.network_cli + become: true + cisco.ios.ios_config: + src: config.j2 + +- set_fact: + shorter_hostname: '{{ inventory_hostname_short| truncate(10, True, "") }}' + +- name: Discover IOS L2/L3 switch type + connection: ansible.netcommon.network_cli + become: true + register: result + cisco.ios.ios_command: + commands: + - show version + +- set_fact: switch_type="" + +- set_fact: switch_type="L2" + when: '"l2" in result.stdout[0]' + +- block: + + - name: Set test interface to GigabitEthernet0/1 as we are on Cisco IOS + set_fact: test_interface=GigabitEthernet0/1 + + - name: Set test interface 2 to GigabitEthernet0/2 as we are on Cisco IOS + set_fact: test_interface2=GigabitEthernet0/2 + when: "'Cisco IOS' in result.stdout[0]" + +- block: + + - name: Set test interface to GigabitEthernet2 as we are on Cisco IOS-XE + set_fact: test_interface=GigabitEthernet2 + + - name: Disable autonegotiation on GigabitEthernet2 + cisco.ios.ios_config: + lines: + - no negotiation auto + parents: int GigabitEthernet2 + authorize: true + + - name: Set test interface 2 to GigabitEthernet3 as we are on Cisco IOS-XE + set_fact: test_interface2=GigabitEthernet3 + + - name: Disable autonegotiation on GigabitEthernet3 + cisco.ios.ios_config: + lines: + - no negotiation auto + parents: int GigabitEthernet3 + authorize: true + when: "'Cisco IOS-XE' in result.stdout[0]" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/prepare_ios_tests/templates/config.j2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/prepare_ios_tests/templates/config.j2 new file mode 100644 index 00000000..c8eb3457 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/integration/targets/prepare_ios_tests/templates/config.j2 @@ -0,0 +1,4 @@ +interface Loopback888 + description test for ansible + shutdown + diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/ignore-2.10.txt b/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/ignore-2.10.txt new file mode 100644 index 00000000..d7ff17ca --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/ignore-2.10.txt @@ -0,0 +1 @@ +plugins/action/ios.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/ignore-2.11.txt b/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/ignore-2.11.txt new file mode 100644 index 00000000..d7ff17ca --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/ignore-2.11.txt @@ -0,0 +1 @@ +plugins/action/ios.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/ignore-2.9.txt b/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/ignore-2.9.txt new file mode 100644 index 00000000..d8cc7b28 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/ignore-2.9.txt @@ -0,0 +1,11 @@ +plugins/modules/ios_interface.py validate-modules:deprecation-mismatch +plugins/modules/ios_interface.py validate-modules:invalid-documentation +plugins/modules/ios_l2_interface.py validate-modules:deprecation-mismatch +plugins/modules/ios_l2_interface.py validate-modules:invalid-documentation +plugins/modules/ios_l3_interface.py validate-modules:deprecation-mismatch +plugins/modules/ios_l3_interface.py validate-modules:invalid-documentation +plugins/modules/ios_static_route.py validate-modules:deprecation-mismatch +plugins/modules/ios_static_route.py validate-modules:invalid-documentation +plugins/modules/ios_vlan.py validate-modules:deprecation-mismatch +plugins/modules/ios_vlan.py validate-modules:invalid-documentation +plugins/action/ios.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/requirements.txt b/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/requirements.txt new file mode 100644 index 00000000..3e3a9669 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/sanity/requirements.txt @@ -0,0 +1,4 @@ +packaging # needed for update-bundled and changelog +sphinx ; python_version >= '3.5' # docs build requires python 3+ +sphinx-notfound-page ; python_version >= '3.5' # docs build requires python 3+ +straight.plugin ; python_version >= '3.5' # needed for hacking/build-ansible.py which will host changelog generation and requires python 3+ diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/builtins.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/builtins.py new file mode 100644 index 00000000..bfc8adfb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/builtins.py @@ -0,0 +1,34 @@ +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +# +# Compat for python2.7 +# + +# One unittest needs to import builtins via __import__() so we need to have +# the string that represents it +try: + import __builtin__ +except ImportError: + BUILTINS = "builtins" +else: + BUILTINS = "__builtin__" diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/mock.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/mock.py new file mode 100644 index 00000000..2ea98a17 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/mock.py @@ -0,0 +1,128 @@ +# pylint: skip-file +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +""" +Compat module for Python3.x's unittest.mock module +""" +import sys + +# Python 2.7 + +# Note: Could use the pypi mock library on python3.x as well as python2.x. It +# is the same as the python3 stdlib mock library + +try: + # Allow wildcard import because we really do want to import all of mock's + # symbols into this compat shim + # pylint: disable=wildcard-import,unused-wildcard-import + from unittest.mock import * +except ImportError: + # Python 2 + # pylint: disable=wildcard-import,unused-wildcard-import + try: + from mock import * + except ImportError: + print("You need the mock library installed on python2.x to run tests") + + +# Prior to 3.4.4, mock_open cannot handle binary read_data +if sys.version_info >= (3,) and sys.version_info < (3, 4, 4): + file_spec = None + + def _iterate_read_data(read_data): + # Helper for mock_open: + # Retrieve lines from read_data via a generator so that separate calls to + # readline, read, and readlines are properly interleaved + sep = b"\n" if isinstance(read_data, bytes) else "\n" + data_as_list = [l + sep for l in read_data.split(sep)] + + if data_as_list[-1] == sep: + # If the last line ended in a newline, the list comprehension will have an + # extra entry that's just a newline. Remove this. + data_as_list = data_as_list[:-1] + else: + # If there wasn't an extra newline by itself, then the file being + # emulated doesn't have a newline to end the last line remove the + # newline that our naive format() added + data_as_list[-1] = data_as_list[-1][:-1] + + for line in data_as_list: + yield line + + def mock_open(mock=None, read_data=""): + """ + A helper function to create a mock to replace the use of `open`. It works + for `open` called directly or used as a context manager. + + The `mock` argument is the mock object to configure. If `None` (the + default) then a `MagicMock` will be created for you, with the API limited + to methods or attributes available on standard file handles. + + `read_data` is a string for the `read` methoddline`, and `readlines` of the + file handle to return. This is an empty string by default. + """ + + def _readlines_side_effect(*args, **kwargs): + if handle.readlines.return_value is not None: + return handle.readlines.return_value + return list(_data) + + def _read_side_effect(*args, **kwargs): + if handle.read.return_value is not None: + return handle.read.return_value + return type(read_data)().join(_data) + + def _readline_side_effect(): + if handle.readline.return_value is not None: + while True: + yield handle.readline.return_value + for line in _data: + yield line + + global file_spec + if file_spec is None: + import _io + + file_spec = list( + set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))) + ) + + if mock is None: + mock = MagicMock(name="open", spec=open) + + handle = MagicMock(spec=file_spec) + handle.__enter__.return_value = handle + + _data = _iterate_read_data(read_data) + + handle.write.return_value = None + handle.read.return_value = None + handle.readline.return_value = None + handle.readlines.return_value = None + + handle.read.side_effect = _read_side_effect + handle.readline.side_effect = _readline_side_effect() + handle.readlines.side_effect = _readlines_side_effect + + mock.return_value = handle + return mock diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/unittest.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/unittest.py new file mode 100644 index 00000000..df3379b8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/compat/unittest.py @@ -0,0 +1,39 @@ +# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +""" +Compat module for Python2.7's unittest module +""" + +import sys + +# Allow wildcard import because we really do want to import all of +# unittests's symbols into this compat shim +# pylint: disable=wildcard-import,unused-wildcard-import +if sys.version_info < (2, 7): + try: + # Need unittest2 on python2.6 + from unittest2 import * + except ImportError: + print("You need unittest2 installed on python2.6.x to run tests") +else: + from unittest import * diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/loader.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/loader.py new file mode 100644 index 00000000..c21188ee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/loader.py @@ -0,0 +1,116 @@ +# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import os + +from ansible.errors import AnsibleParserError +from ansible.parsing.dataloader import DataLoader +from ansible.module_utils._text import to_bytes, to_text + + +class DictDataLoader(DataLoader): + def __init__(self, file_mapping=None): + file_mapping = {} if file_mapping is None else file_mapping + assert type(file_mapping) == dict + + super(DictDataLoader, self).__init__() + + self._file_mapping = file_mapping + self._build_known_directories() + self._vault_secrets = None + + def load_from_file(self, path, cache=True, unsafe=False): + path = to_text(path) + if path in self._file_mapping: + return self.load(self._file_mapping[path], path) + return None + + # TODO: the real _get_file_contents returns a bytestring, so we actually convert the + # unicode/text it's created with to utf-8 + def _get_file_contents(self, path): + path = to_text(path) + if path in self._file_mapping: + return (to_bytes(self._file_mapping[path]), False) + else: + raise AnsibleParserError("file not found: %s" % path) + + def path_exists(self, path): + path = to_text(path) + return path in self._file_mapping or path in self._known_directories + + def is_file(self, path): + path = to_text(path) + return path in self._file_mapping + + def is_directory(self, path): + path = to_text(path) + return path in self._known_directories + + def list_directory(self, path): + ret = [] + path = to_text(path) + for x in list(self._file_mapping.keys()) + self._known_directories: + if x.startswith(path): + if os.path.dirname(x) == path: + ret.append(os.path.basename(x)) + return ret + + def is_executable(self, path): + # FIXME: figure out a way to make paths return true for this + return False + + def _add_known_directory(self, directory): + if directory not in self._known_directories: + self._known_directories.append(directory) + + def _build_known_directories(self): + self._known_directories = [] + for path in self._file_mapping: + dirname = os.path.dirname(path) + while dirname not in ("/", ""): + self._add_known_directory(dirname) + dirname = os.path.dirname(dirname) + + def push(self, path, content): + rebuild_dirs = False + if path not in self._file_mapping: + rebuild_dirs = True + + self._file_mapping[path] = content + + if rebuild_dirs: + self._build_known_directories() + + def pop(self, path): + if path in self._file_mapping: + del self._file_mapping[path] + self._build_known_directories() + + def clear(self): + self._file_mapping = dict() + self._known_directories = [] + + def get_basedir(self): + return os.getcwd() + + def set_vault_secrets(self, vault_secrets): + self._vault_secrets = vault_secrets diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/path.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/path.py new file mode 100644 index 00000000..356cd59f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/path.py @@ -0,0 +1,10 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type +from ansible_collections.cisco.ios.tests.unit.compat.mock import MagicMock +from ansible.utils.path import unfrackpath + + +mock_unfrackpath_noop = MagicMock( + spec_set=unfrackpath, side_effect=lambda x, *args, **kwargs: x +) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/procenv.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/procenv.py new file mode 100644 index 00000000..44fe6bf0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/procenv.py @@ -0,0 +1,94 @@ +# (c) 2016, Matt Davis <mdavis@ansible.com> +# (c) 2016, Toshio Kuratomi <tkuratomi@ansible.com> +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import sys +import json + +from contextlib import contextmanager +from io import BytesIO, StringIO +from ansible_collections.cisco.ios.tests.unit.compat import unittest +from ansible.module_utils.six import PY3 +from ansible.module_utils._text import to_bytes + + +@contextmanager +def swap_stdin_and_argv(stdin_data="", argv_data=tuple()): + """ + context manager that temporarily masks the test runner's values for stdin and argv + """ + real_stdin = sys.stdin + real_argv = sys.argv + + if PY3: + fake_stream = StringIO(stdin_data) + fake_stream.buffer = BytesIO(to_bytes(stdin_data)) + else: + fake_stream = BytesIO(to_bytes(stdin_data)) + + try: + sys.stdin = fake_stream + sys.argv = argv_data + + yield + finally: + sys.stdin = real_stdin + sys.argv = real_argv + + +@contextmanager +def swap_stdout(): + """ + context manager that temporarily replaces stdout for tests that need to verify output + """ + old_stdout = sys.stdout + + if PY3: + fake_stream = StringIO() + else: + fake_stream = BytesIO() + + try: + sys.stdout = fake_stream + + yield fake_stream + finally: + sys.stdout = old_stdout + + +class ModuleTestCase(unittest.TestCase): + def setUp(self, module_args=None): + if module_args is None: + module_args = { + "_ansible_remote_tmp": "/tmp", + "_ansible_keep_remote_files": False, + } + + args = json.dumps(dict(ANSIBLE_MODULE_ARGS=module_args)) + + # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually + self.stdin_swap = swap_stdin_and_argv(stdin_data=args) + self.stdin_swap.__enter__() + + def tearDown(self): + # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually + self.stdin_swap.__exit__(None, None, None) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/vault_helper.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/vault_helper.py new file mode 100644 index 00000000..b34ae134 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/vault_helper.py @@ -0,0 +1,42 @@ +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible.module_utils._text import to_bytes + +from ansible.parsing.vault import VaultSecret + + +class TextVaultSecret(VaultSecret): + """A secret piece of text. ie, a password. Tracks text encoding. + + The text encoding of the text may not be the default text encoding so + we keep track of the encoding so we encode it to the same bytes.""" + + def __init__(self, text, encoding=None, errors=None, _bytes=None): + super(TextVaultSecret, self).__init__() + self.text = text + self.encoding = encoding or "utf-8" + self._bytes = _bytes + self.errors = errors or "strict" + + @property + def bytes(self): + """The text encoded with encoding, unless we specifically set _bytes.""" + return self._bytes or to_bytes( + self.text, encoding=self.encoding, errors=self.errors + ) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/yaml_helper.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/yaml_helper.py new file mode 100644 index 00000000..5df30aae --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/mock/yaml_helper.py @@ -0,0 +1,167 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type +import io +import yaml + +from ansible.module_utils.six import PY3 +from ansible.parsing.yaml.loader import AnsibleLoader +from ansible.parsing.yaml.dumper import AnsibleDumper + + +class YamlTestUtils(object): + """Mixin class to combine with a unittest.TestCase subclass.""" + + def _loader(self, stream): + """Vault related tests will want to override this. + + Vault cases should setup a AnsibleLoader that has the vault password.""" + return AnsibleLoader(stream) + + def _dump_stream(self, obj, stream, dumper=None): + """Dump to a py2-unicode or py3-string stream.""" + if PY3: + return yaml.dump(obj, stream, Dumper=dumper) + else: + return yaml.dump(obj, stream, Dumper=dumper, encoding=None) + + def _dump_string(self, obj, dumper=None): + """Dump to a py2-unicode or py3-string""" + if PY3: + return yaml.dump(obj, Dumper=dumper) + else: + return yaml.dump(obj, Dumper=dumper, encoding=None) + + def _dump_load_cycle(self, obj): + # Each pass though a dump or load revs the 'generation' + # obj to yaml string + string_from_object_dump = self._dump_string(obj, dumper=AnsibleDumper) + + # wrap a stream/file like StringIO around that yaml + stream_from_object_dump = io.StringIO(string_from_object_dump) + loader = self._loader(stream_from_object_dump) + # load the yaml stream to create a new instance of the object (gen 2) + obj_2 = loader.get_data() + + # dump the gen 2 objects directory to strings + string_from_object_dump_2 = self._dump_string( + obj_2, dumper=AnsibleDumper + ) + + # The gen 1 and gen 2 yaml strings + self.assertEqual(string_from_object_dump, string_from_object_dump_2) + # the gen 1 (orig) and gen 2 py object + self.assertEqual(obj, obj_2) + + # again! gen 3... load strings into py objects + stream_3 = io.StringIO(string_from_object_dump_2) + loader_3 = self._loader(stream_3) + obj_3 = loader_3.get_data() + + string_from_object_dump_3 = self._dump_string( + obj_3, dumper=AnsibleDumper + ) + + self.assertEqual(obj, obj_3) + # should be transitive, but... + self.assertEqual(obj_2, obj_3) + self.assertEqual(string_from_object_dump, string_from_object_dump_3) + + def _old_dump_load_cycle(self, obj): + """Dump the passed in object to yaml, load it back up, dump again, compare.""" + stream = io.StringIO() + + yaml_string = self._dump_string(obj, dumper=AnsibleDumper) + self._dump_stream(obj, stream, dumper=AnsibleDumper) + + yaml_string_from_stream = stream.getvalue() + + # reset stream + stream.seek(0) + + loader = self._loader(stream) + # loader = AnsibleLoader(stream, vault_password=self.vault_password) + obj_from_stream = loader.get_data() + + stream_from_string = io.StringIO(yaml_string) + loader2 = self._loader(stream_from_string) + # loader2 = AnsibleLoader(stream_from_string, vault_password=self.vault_password) + obj_from_string = loader2.get_data() + + stream_obj_from_stream = io.StringIO() + stream_obj_from_string = io.StringIO() + + if PY3: + yaml.dump( + obj_from_stream, stream_obj_from_stream, Dumper=AnsibleDumper + ) + yaml.dump( + obj_from_stream, stream_obj_from_string, Dumper=AnsibleDumper + ) + else: + yaml.dump( + obj_from_stream, + stream_obj_from_stream, + Dumper=AnsibleDumper, + encoding=None, + ) + yaml.dump( + obj_from_stream, + stream_obj_from_string, + Dumper=AnsibleDumper, + encoding=None, + ) + + yaml_string_stream_obj_from_stream = stream_obj_from_stream.getvalue() + yaml_string_stream_obj_from_string = stream_obj_from_string.getvalue() + + stream_obj_from_stream.seek(0) + stream_obj_from_string.seek(0) + + if PY3: + yaml_string_obj_from_stream = yaml.dump( + obj_from_stream, Dumper=AnsibleDumper + ) + yaml_string_obj_from_string = yaml.dump( + obj_from_string, Dumper=AnsibleDumper + ) + else: + yaml_string_obj_from_stream = yaml.dump( + obj_from_stream, Dumper=AnsibleDumper, encoding=None + ) + yaml_string_obj_from_string = yaml.dump( + obj_from_string, Dumper=AnsibleDumper, encoding=None + ) + + assert yaml_string == yaml_string_obj_from_stream + assert ( + yaml_string + == yaml_string_obj_from_stream + == yaml_string_obj_from_string + ) + assert ( + yaml_string + == yaml_string_obj_from_stream + == yaml_string_obj_from_string + == yaml_string_stream_obj_from_stream + == yaml_string_stream_obj_from_string + ) + assert obj == obj_from_stream + assert obj == obj_from_string + assert obj == yaml_string_obj_from_stream + assert obj == yaml_string_obj_from_string + assert ( + obj + == obj_from_stream + == obj_from_string + == yaml_string_obj_from_stream + == yaml_string_obj_from_string + ) + return { + "obj": obj, + "yaml_string": yaml_string, + "yaml_string_from_stream": yaml_string_from_stream, + "obj_from_stream": obj_from_stream, + "obj_from_string": obj_from_string, + "yaml_string_obj_from_string": yaml_string_obj_from_string, + } diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/conftest.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/conftest.py new file mode 100644 index 00000000..e19a1e04 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/conftest.py @@ -0,0 +1,40 @@ +# Copyright (c) 2017 Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import json + +import pytest + +from ansible.module_utils.six import string_types +from ansible.module_utils._text import to_bytes +from ansible.module_utils.common._collections_compat import MutableMapping + + +@pytest.fixture +def patch_ansible_module(request, mocker): + if isinstance(request.param, string_types): + args = request.param + elif isinstance(request.param, MutableMapping): + if "ANSIBLE_MODULE_ARGS" not in request.param: + request.param = {"ANSIBLE_MODULE_ARGS": request.param} + if "_ansible_remote_tmp" not in request.param["ANSIBLE_MODULE_ARGS"]: + request.param["ANSIBLE_MODULE_ARGS"][ + "_ansible_remote_tmp" + ] = "/tmp" + if ( + "_ansible_keep_remote_files" + not in request.param["ANSIBLE_MODULE_ARGS"] + ): + request.param["ANSIBLE_MODULE_ARGS"][ + "_ansible_keep_remote_files" + ] = False + args = json.dumps(request.param) + else: + raise Exception( + "Malformed data to the patch_ansible_module pytest fixture" + ) + + mocker.patch("ansible.module_utils.basic._ANSIBLE_ARGS", to_bytes(args)) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/configure_terminal b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/configure_terminal new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/configure_terminal @@ -0,0 +1,2 @@ + + diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_acl_interfaces.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_acl_interfaces.cfg new file mode 100644 index 00000000..1462c135 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_acl_interfaces.cfg @@ -0,0 +1,8 @@ +interface GigabitEthernet0/1 +ip access-group 110 in +ip access-group 123 out +ipv6 traffic-filter temp_v6 in +ipv6 traffic-filter test_v6 out +interface GigabitEthernet0/2 +ip access-group 110 in +ip access-group 123 out diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_acls_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_acls_config.cfg new file mode 100644 index 00000000..cf9ad041 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_acls_config.cfg @@ -0,0 +1,4 @@ +Extended IP access list 110 + 10 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 +IPv6 access list R1_TRAFFIC + deny tcp any eq www any eq telnet ack dscp af11 sequence 10
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_banner_show_banner.txt b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_banner_show_banner.txt new file mode 100644 index 00000000..a134a317 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_banner_show_banner.txt @@ -0,0 +1,3 @@ +this is a sample +mulitline banner +used for testing diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_banner_show_running_config_ios12.txt b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_banner_show_running_config_ios12.txt new file mode 100644 index 00000000..004387a9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_banner_show_running_config_ios12.txt @@ -0,0 +1,15 @@ +banner exec ^C +this is a sample +mulitline banner +used for testing +^C +banner login ^C +this is a sample +mulitline banner +used for testing +^C +! +dummy +end +of +config diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_bgp_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_bgp_config.cfg new file mode 100644 index 00000000..9fec934a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_bgp_config.cfg @@ -0,0 +1,24 @@ +! +router bgp 64496 + bgp router-id 192.0.2.1 + bgp log-neighbor-changes + neighbor 192.51.100.1 remote-as 64496 + neighbor 192.51.100.1 timers 120 360 360 + neighbor 198.51.100.3 remote-as 64498 + neighbor 203.0.113.5 remote-as 500 + neighbor 203.0.113.5 description EBGP_PEER + ! + address-family ipv4 + network 192.0.2.0 mask 255.255.254.0 route-map RMAP_1 + network 198.51.100.0 mask 255.255.255.128 route-map RMAP_2 + redistribute static metric 100 + redistribute eigrp metric 10 route-map RMAP_3 + neighbor 203.0.113.1 remove-private-as + neighbor 203.0.113.1 maximum-prefix 100 + exit-address-family + ! + address-family ipv4 multicast + network 203.0.113.0 mask 255.255.255.224 route-map RMAP_1 + network 192.0.2.0 mask 255.255.255.192 route-map RMAP_2 + exit-address-family +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_bgp_global.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_bgp_global.cfg new file mode 100644 index 00000000..17df6fd7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_bgp_global.cfg @@ -0,0 +1,8 @@ +router bgp 65000 + bgp nopeerup-delay post-boot 10 + bgp bestpath compare-routerid + bgp advertise-best-external + timers bgp 100 200 150 + redistribute connected metric 10 + neighbor 198.51.100.1 remote-as 100 + neighbor 198.51.100.1 route-map test-route out
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_config_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_config_config.cfg new file mode 100644 index 00000000..afad9d08 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_config_config.cfg @@ -0,0 +1,12 @@ +! +hostname router +! +interface GigabitEthernet0/0 + ip address 1.2.3.4 255.255.255.0 + description test string +! +interface GigabitEthernet0/1 + ip address 6.7.8.9 255.255.255.0 + description test string + shutdown +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_config_defaults.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_config_defaults.cfg new file mode 100644 index 00000000..e54645ab --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_config_defaults.cfg @@ -0,0 +1,13 @@ +! +hostname router +! +interface GigabitEthernet0/0 + ip address 1.2.3.4 255.255.255.0 + description test string + no shutdown +! +interface GigabitEthernet0/1 + ip address 6.7.8.9 255.255.255.0 + description test string + shutdown +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_config_src.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_config_src.cfg new file mode 100644 index 00000000..b3d8961a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_config_src.cfg @@ -0,0 +1,11 @@ +! +hostname foo +! +interface GigabitEthernet0/0 + no ip address +! +interface GigabitEthernet0/1 + ip address 6.7.8.9 255.255.255.0 + description test string + shutdown +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_dir b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_dir new file mode 100644 index 00000000..3adc44ad --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_dir @@ -0,0 +1,23 @@ +Directory of bootflash:/ + + 11 drwx 16384 Jun 1 2017 13:03:27 +00:00 lost+found +325121 drwx 4096 Jun 1 2017 13:03:54 +00:00 .super.iso.dir + 12 -rw- 31 Jun 22 2018 15:17:06 +00:00 .CsrLxc_LastInstall + 13 -rw- 69 Jun 1 2017 13:05:53 +00:00 virtual-instance.conf +438913 drwx 4096 Jun 1 2017 13:04:57 +00:00 core + 15 -rw- 125736960 Jun 1 2017 13:03:54 +00:00 iosxe-remote-mgmt.16.03.04.ova +105667 -rw- 292164568 Jun 1 2017 13:04:04 +00:00 csr1000v-mono-universalk9.16.03.04.SPA.pkg +105668 -rw- 34370768 Jun 1 2017 13:04:10 +00:00 csr1000v-rpboot.16.03.04.SPA.pkg +105666 -rw- 5317 Jun 1 2017 13:04:10 +00:00 packages.conf +195073 drwx 4096 Jun 1 2017 13:04:51 +00:00 .prst_sync +414529 drwx 4096 Jun 1 2017 13:04:57 +00:00 .rollback_timer + 16 -rw- 0 Jun 1 2017 13:05:00 +00:00 tracelogs.kZn +16257 drwx 24576 Jun 22 2018 16:03:11 +00:00 tracelogs +349505 drwx 4096 Jun 1 2017 13:05:08 +00:00 .installer +292609 drwx 4096 Jun 1 2017 13:05:59 +00:00 virtual-instance + 17 -rw- 30 Jun 22 2018 15:17:59 +00:00 throughput_monitor_params +48769 drwx 4096 Jun 1 2017 13:06:04 +00:00 onep + 19 -rw- 376 Jun 22 2018 15:18:11 +00:00 csrlxc-cfg.log + 20 -rw- 0 Jun 22 2018 15:17:59 +00:00 cvac.log + +7897796608 bytes total (6608056320 bytes free) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_cdp b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_cdp new file mode 100644 index 00000000..c5fff7d2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_cdp @@ -0,0 +1,4 @@ +Global CDP information: + Sending CDP packets every 60 seconds + Sending a holdtime value of 180 seconds + Sending CDPv2 advertisements is enabled diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_cdp_neighbors_detail b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_cdp_neighbors_detail new file mode 100644 index 00000000..b3d5453d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_cdp_neighbors_detail @@ -0,0 +1,40 @@ +------------------------- +Device ID: R2 +Entry address(es): + IP address: 10.0.0.3 +Platform: cisco CSR1000V, Capabilities: Router IGMP +Interface: GigabitEthernet1, Port ID (outgoing port): GigabitEthernet2 +Holdtime : 149 sec + +Version : +Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.4, RELEASE SOFTWARE (fc3) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2018 by Cisco Systems, Inc. +Compiled Sun 08-Jul-18 04:30 by mcpre + +advertisement version: 2 +Duplex: full +Management address(es): + IP address: 10.0.0.3 + +------------------------- +Device ID: R3 +Entry address(es): + IP address: 10.0.0.4 +Platform: cisco CSR1000V, Capabilities: Router IGMP +Interface: GigabitEthernet1, Port ID (outgoing port): GigabitEthernet3 +Holdtime : 149 sec + +Version : +Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.4, RELEASE SOFTWARE (fc3) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2018 by Cisco Systems, Inc. +Compiled Sun 08-Jul-18 04:30 by mcpre + +advertisement version: 2 +Duplex: full +Management address(es): + IP address: 10.0.0.4 + + +Total cdp entries displayed : 2 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_interfaces b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_interfaces new file mode 100644 index 00000000..002b8b9e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_interfaces @@ -0,0 +1,61 @@ +GigabitEthernet0/0 is up, line protocol is up + Hardware is iGbE, address is 5e00.0003.0000 (bia 5e00.0003.0000) + Description: OOB Management + Internet address is 10.8.38.66/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 253/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, Auto Speed, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:00, output 00:00:00, output hang never + Last clearing of "show interface" counters never + Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 3000 bits/sec, 2 packets/sec + 5 minute output rate 2000 bits/sec, 2 packets/sec + 2226666 packets input, 398288440 bytes, 0 no buffer + Received 156442 broadcasts (0 IP multicasts) + 25440 runts, 0 giants, 0 throttles + 25440 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 1304895 packets output, 119337031 bytes, 0 underruns + 0 output errors, 0 collisions, 3 interface resets + 1083697 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 1 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out +GigabitEthernet1 is up, line protocol is up + Hardware is CSR vNIC, address is 5e00.0006.0000 (bia 5e00.0006.0000) + Description: OOB Management + Internet address is 10.8.38.67/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:01, output 00:00:07, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 3000 bits/sec, 3 packets/sec + 5 minute output rate 3000 bits/sec, 3 packets/sec + 8463791 packets input, 1445150230 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 3521571 packets output, 348781823 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 4150764 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out +Tunnel1110 is up, line protocol is up + Hardware is Tunnel + Internet address is 10.10.10.2/30 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_ip_interface b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_ip_interface new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_ip_interface diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_ipv6_interface b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_ipv6_interface new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_ipv6_interface diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_lldp b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_lldp new file mode 100644 index 00000000..09847c31 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_lldp @@ -0,0 +1,6 @@ + +Global LLDP Information: + Status: ACTIVE + LLDP advertisements are sent every 30 seconds + LLDP hold time advertised is 120 seconds + LLDP interface reinitialisation delay is 2 seconds diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_lldp_neighbors_detail b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_lldp_neighbors_detail new file mode 100644 index 00000000..adc4f30e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_lldp_neighbors_detail @@ -0,0 +1,50 @@ +------------------------------------------------ +Local Intf: Gi1 +Chassis id: 001e.14d4.5300 +Port id: Gi3 +Port Description: GigabitEthernet3 +System Name: R3 + +System Description: +Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.4, RELEASE SOFTWARE (fc3) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2018 by Cisco Systems, Inc. +Compiled Sun 08-Jul-18 04:30 by + +Time remaining: 116 seconds +System Capabilities: B,R +Enabled Capabilities: R +Management Addresses: + IP: 10.0.0.4 +Auto Negotiation - not supported +Physical media capabilities - not advertised +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Local Intf: Gi3 +Chassis id: 001e.e6c9.6d00 +Port id: Gi1 +Port Description: GigabitEthernet1 +System Name: Rtest + +System Description: +Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.4, RELEASE SOFTWARE (fc3) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2018 by Cisco Systems, Inc. +Compiled Sun 08-Jul-18 04:30 by + +Time remaining: 116 seconds +System Capabilities: B,R +Enabled Capabilities: R +Management Addresses: + IP: 10.3.0.3 +Auto Negotiation - not supported +Physical media capabilities - not advertised +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + + +Total entries displayed: 2 + + diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_memory_statistics b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_memory_statistics new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_memory_statistics diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_version b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_version new file mode 100644 index 00000000..58322c80 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_version @@ -0,0 +1,68 @@ +Cisco Internetwork Operating System Software +IOS (tm) C3750 Software (C3750-I5-M), Version 12.1(14)EA1, RELEASE SOFTWARE (fc1) +Copyright (c) 1986-2003 by cisco Systems, Inc. +Compiled Tue 22-Jul-03 13:17 by antonino +Image text-base: 0x00003000, data-base: 0x008F0CF8 + +ROM: Bootstrap program is C3750 boot loader +BOOTLDR: C3750 Boot Loader (C3750-HBOOT-M) Version 12.1(11r)AX, RELEASE SOFTWARE (fc1) + +3750RJ uptime is 1 hour, 29 minutes +System returned to ROM by power-on +System image file is "flash:c3750-i5-mz.121.14-EA1/c3750-i5-mz.121.14-EA1.bin" + +cisco WS-C3750-24TS (PowerPC405) processor (revision A0) with 120822K/10240K bytes of memory. +Processor board ID CAT0726R0ZU +Last reset from power-on +Bridging software. +2 Virtual Ethernet/IEEE 802.3 interface(s) +48 FastEthernet/IEEE 802.3 interface(s) +16 Gigabit Ethernet/IEEE 802.3 interface(s) +The password-recovery mechanism is enabled. + +512K bytes of flash-simulated non-volatile configuration memory. +Base ethernet MAC Address : 00:0D:29:B4:18:00 +Motherboard assembly number : 73-7055-06 +Power supply part number : 341-0034-01 +Motherboard serial number : CAT0726043V +Power supply serial number : PHI0708009K +Model revision number : A0 +Motherboard revision number : A0 +Model number : WS-C3750-24TS-E +System serial number : CAT0726R0ZU + +Switch Ports Model SW Version SW Image +------ ----- ----- ---------- ---------- +* 1 26 WS-C3750-24TS 12.1(14)EA1 C3750-I5-M +2 26 WS-C3750-24TS 12.1(14)EA1 C3750-I5-M +3 12 WS-C3750G-12S 12.1(14)EA1 C3750-I5-M + +Switch 02 +--------- +Switch Uptime : 1 hour, 29 minutes +Base ethernet MAC Address : 00:0D:29:B4:3F:00 +Motherboard assembly number : 73-7055-06 +Power supply part number : 341-0034-01 +Motherboard serial number : CAT07260438 +Power supply serial number : PHI0708008X +Model revision number : A0 +Motherboard revision number : A0 +Model number : WS-C3750-24TS-E +System serial number : CAT0726R10A + +Switch 03 +--------- +Switch Uptime : 1 hour, 29 minutes +Base ethernet MAC Address : 00:0D:BD:6A:3E:00 +Motherboard assembly number : 73-8307-06 +Power supply part number : 341-0048-01 +Motherboard serial number : CAT073205S2 +Power supply serial number : DTH0731055Z +Model revision number : A0 +Motherboard revision number : A0 +Model number : WS-C3750G-12S-E +System serial number : CAT0732R0M4 +Top assembly part number : 800-23419-01 +Top assembly revision number : A0 + +Configuration register is 0xF diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_virtual_switch b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_virtual_switch new file mode 100644 index 00000000..be3c5f87 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_virtual_switch @@ -0,0 +1,21 @@ + +Executing the command on VSS member switch role = VSS Active, id = 1 + + +Switch mode : Virtual Switch +Virtual switch domain number : 102 +Local switch number : 1 +Local switch operational role: Virtual Switch Active +Peer switch number : 2 +Peer switch operational role : Virtual Switch Standby + +Executing the command on VSS member switch role = VSS Standby, id = 2 + + +Switch mode : Virtual Switch +Virtual switch domain number : 102 +Local switch number : 2 +Local switch operational role: Virtual Switch Standby +Peer switch number : 1 +Peer switch operational role : Virtual Switch Active + diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_l2_interfaces.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_l2_interfaces.cfg new file mode 100644 index 00000000..c62ec0d5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_l2_interfaces.cfg @@ -0,0 +1,9 @@ +interface GigabitEthernet0/1 + switchport mode access + switchport access vlan 10 +interface GigabitEthernet0/2 + switchport trunk allowed vlan 10-20,40 + switchport trunk encapsulation dot1q + switchport trunk native vlan 10 + switchport trunk pruning vlan 10,20 + switchport mode trunk
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_logging_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_logging_config.cfg new file mode 100644 index 00000000..8a51afa7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_logging_config.cfg @@ -0,0 +1,11 @@ +! +logging buffered 5000 +logging console informational +logging facility local0 +no logging monitor +logging host 1.2.3.4 transport tcp +logging host 1.2.3.4 +logging host 2.3.4.5 +logging host 1.2.3.4 transport tcp port 1000 +logging host 1.2.3.4 transport udp port 1000 +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_logging_config_ios12.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_logging_config_ios12.cfg new file mode 100644 index 00000000..58be36df --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_logging_config_ios12.cfg @@ -0,0 +1,6 @@ +! +logging buffered 5000 +logging console informational +logging facility local0 +logging 2.3.4.5 +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ntp_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ntp_config.cfg new file mode 100644 index 00000000..ccd8558a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ntp_config.cfg @@ -0,0 +1,7 @@ +ntp logging +ntp authentication-key 10 md5 15435A030726242723273C21181319000A 7 +ntp authenticate +ntp trusted-key 10 +ntp source Loopback0 +ntp access-group peer NTP_ACL +ntp server 10.75.32.5 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ospf_interfaces.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ospf_interfaces.cfg new file mode 100644 index 00000000..bc65ecc3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ospf_interfaces.cfg @@ -0,0 +1,11 @@ +interface GigabitEthernet0/2 + ip ospf priority 40 + ip ospf adjacency stagger disable + ip ospf ttl-security hops 50 + ip ospf 10 area 20 + ip ospf cost 30 +interface GigabitEthernet0/3 + ipv6 ospf 55 area 105 + ipv6 ospf priority 20 + ipv6 ospf transmit-delay 30 + ipv6 ospf adjacency stagger disable diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ospfv2.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ospfv2.cfg new file mode 100644 index 00000000..ce0cbc99 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ospfv2.cfg @@ -0,0 +1,8 @@ +router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion +
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ospfv3.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ospfv3.cfg new file mode 100644 index 00000000..e27e9419 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ospfv3.cfg @@ -0,0 +1,8 @@ +router ospfv3 1 + max-metric router-lsa on-startup 110 + area 10 nssa default-information-originate metric 10 + ! + address-family ipv4 unicast vrf blue + adjacency stagger 50 50 + area 25 nssa default-information-originate metric 25 nssa-only + exit-address-family
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_10.255.255.250_repeat_2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_10.255.255.250_repeat_2 new file mode 100644 index 00000000..9b25d645 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_10.255.255.250_repeat_2 @@ -0,0 +1,4 @@ +Type escape sequence to abort. +Sending 2, 100-byte ICMP Echos to 10.255.255.250, timeout is 2 seconds: +.. +Success rate is 0 percent (0/2) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_8.8.8.8_repeat_2 b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_8.8.8.8_repeat_2 new file mode 100644 index 00000000..4dddd76b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_8.8.8.8_repeat_2 @@ -0,0 +1,4 @@ +Type escape sequence to abort. +Sending 2, 100-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds: +!! +Success rate is 100 percent (2/2), round-trip min/avg/max = 25/25/25 ms diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_8.8.8.8_size_1400 b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_8.8.8.8_size_1400 new file mode 100644 index 00000000..2e8d64cd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_8.8.8.8_size_1400 @@ -0,0 +1,4 @@ +Type escape sequence to abort. +Sending 5, 1400-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds: +!!!!! +Success rate is 100 percent (5/5), round-trip min/avg/max = 25/25/25 ms diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_8.8.8.8_size_1400_df-bit b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_8.8.8.8_size_1400_df-bit new file mode 100644 index 00000000..fe84e260 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_ping_ping_8.8.8.8_size_1400_df-bit @@ -0,0 +1,5 @@ +Type escape sequence to abort. +Sending 5, 1400-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds: +Packet sent with the DF bit set +!!!!! +Success rate is 100 percent (5/5), round-trip min/avg/max = 25/25/25 ms diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_static_routes_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_static_routes_config.cfg new file mode 100644 index 00000000..04aeeb2c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_static_routes_config.cfg @@ -0,0 +1,5 @@ +ip route vrf ansible_vrf 0.0.0.0 0.0.0.0 198.51.101.1 name test_vrf_1 track 150 tag 100 +ip route vrf ansible_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name test_vrf_2 track 175 tag 50 +ip route vrf ansible_vrf 192.51.110.0 255.255.255.255 GigabitEthernet0/2 192.51.111.1 10 name partner +ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name route_1 tag 60 +ipv6 route 2001:DB8:0:3::/64 GigabitEthernet0/2 2001:DB8:0:3::2 tag 105 name test_v6 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_system_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_system_config.cfg new file mode 100644 index 00000000..3330b4aa --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_system_config.cfg @@ -0,0 +1,14 @@ +! +hostname ios01 +! +ip domain list vrf management example.net +ip domain list example.net +ip domain list example.com +ip domain lookup source-interface GigabitEthernet0/0 +ip domain name vrf management eng.example.net +ip domain name eng.example.net +ip name-server vrf management 8.8.8.8 +ip name-server 8.8.8.8 +! +vrf definition test +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_user_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_user_config.cfg new file mode 100644 index 00000000..dd5b2095 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_user_config.cfg @@ -0,0 +1,2 @@ +username admin view network-admin secret 5 $1$mdQIUxjg$3t3lzBpfKfITKvFm1uEIY. +username ansible view network-admin secret 5 $1$3yWSXiIi$VdzV59ChiurrNdGxlDeAW/ diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_vlan_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_vlan_config.cfg new file mode 100644 index 00000000..69ac0b5e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_vlan_config.cfg @@ -0,0 +1,9 @@ +VLAN Name Status Ports +---- -------------------------------- --------- ------------------------------- +1 default active Gi1/0/4, Gi1/0/5 + Gi1/0/52 + Gi1/0/54 +2 vlan2 active Gi1/0/6, Gi1/0/7 +9 vlan9 active Gi1/0/6 +1002 fddi-default act/unsup +1003 fddo-default act/unsup diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_vlans_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_vlans_config.cfg new file mode 100644 index 00000000..416bc3d4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_vlans_config.cfg @@ -0,0 +1,34 @@ +VLAN Name Status Ports +---- -------------------------------- --------- ------------------------------- +1 default active Gi0/1, Gi0/2 +123 RemoteIsInMyName act/unsup +150 VLAN0150 active +888 a_very_long_vlan_name_a_very_long_vlan_name + active +1002 fddi-default act/unsup +1003 trcrf-default act/unsup +1004 fddinet-default act/unsup +1005 trbrf-default act/unsup + +VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2 +---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------ +1 enet 100001 1500 - - - - - 0 0 +123 enet 100123 610 - - - - - 0 0 +150 enet 100150 1500 - - - - - 0 0 +888 enet 100888 1500 - - - - - 0 0 +1002 fddi 101002 1500 - - - - - 0 0 +1003 trcrf 101003 4472 1005 3276 - - srb 0 0 +1004 fdnet 101004 1500 - - - ieee - 0 0 +1005 trbrf 101005 4472 - - 15 ibm - 0 0 + + +VLAN AREHops STEHops Backup CRF +---- ------- ------- ---------- +1003 7 7 off + +Remote SPAN VLANs +------------------------------------------------------------------------------ +150 + +Primary Secondary Type Ports +------- --------- ----------------- ------------------------------------------
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_vrf_config.cfg b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_vrf_config.cfg new file mode 100644 index 00000000..0a2d35f8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_vrf_config.cfg @@ -0,0 +1,81 @@ +! +vrf definition test_1 + description test vrf 1 + rd 1:100 +! +vrf definition test_2 + description test vrf 2 +! +vrf definition test_3 +! +vrf definition test_17 + rd 2:100 + ! + address-family ipv4 + exit-address-family + ! + address-family ipv6 + route-target export 168.0.0.15:100 + route-target export 4:100 + route-target export 2:100 + route-target export 168.0.0.13:100 + route-target import 168.0.0.14:100 + route-target import 2:100 + route-target import 168.0.0.13:100 + exit-address-family +! +vrf definition test_18 + rd 168.0.0.9:100 + ! + address-family ipv4 + route-target export 168.0.0.10:100 + route-target export 168.0.0.9:100 + route-target export 3:100 + route-target import 168.0.0.9:100 + route-target import 3:100 + route-target import 168.0.0.10:600 + exit-address-family + ! + address-family ipv6 + exit-address-family +! +vrf definition test_19 + rd 10:700 + route-target export 2:102 + route-target export 2:103 + route-target export 2:100 + route-target export 2:101 + route-target import 2:104 + route-target import 2:105 + route-target import 2:100 + route-target import 2:101 + ! + address-family ipv4 + route-target export 2:102 + route-target export 2:103 + route-target export 2:100 + route-target export 2:101 + route-target import 2:104 + route-target import 2:105 + route-target import 2:100 + route-target import 2:101 + exit-address-family + ! + address-family ipv6 + route-target export 2:102 + route-target export 2:103 + route-target export 2:100 + route-target export 2:101 + route-target import 2:104 + route-target import 2:105 + route-target import 2:100 + route-target import 2:101 + exit-address-family +! +interface Ethernet1 + ip address 1.2.3.4/5 +! +interface Ethernet2 + ip address 1.2.3.4/5 + vrf forwarding test_1 +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/show_version b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/show_version new file mode 100644 index 00000000..d293df3a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/show_version @@ -0,0 +1,45 @@ +Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(1)T, RELEASE SOFTWARE (fc1) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2015 by Cisco Systems, Inc. +Compiled Fri 20-Nov-15 13:39 by prod_rel_team + + +ROM: Bootstrap program is IOSv + +ios01 uptime is 7 weeks, 5 days, 11 hours, 14 minutes +System returned to ROM by reload +System image file is "flash0:/vios-adventerprisek9-m" +Last reload reason: Unknown reason + + + +This product contains cryptographic features and is subject to United +States and local country laws governing import, export, transfer and +use. Delivery of Cisco cryptographic products does not imply +third-party authority to import, export, distribute or use encryption. +Importers, exporters, distributors and users are responsible for +compliance with U.S. and local country laws. By using this product you +agree to comply with applicable laws and regulations. If you are unable +to comply with U.S. and local laws, return this product immediately. + +A summary of U.S. laws governing Cisco cryptographic products may be found at: +http://www.cisco.com/wwl/export/crypto/tool/stqrg.html + +If you require further assistance please contact us by sending email to +export@cisco.com. + +Cisco IOSv (revision 1.0) with with 472441K/50176K bytes of memory. +Processor board ID 99I10YFMUCJ3JEZMV4DQB +3 Gigabit Ethernet interfaces +DRAM configuration is 72 bits wide with parity disabled. +256K bytes of non-volatile configuration memory. +2097152K bytes of ATA System CompactFlash 0 (Read/Write) +0K bytes of ATA CompactFlash 1 (Read/Write) +0K bytes of ATA CompactFlash 2 (Read/Write) +10080K bytes of ATA CompactFlash 3 (Read/Write) + + + +Configuration register is 0x0 + + diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/ios_module.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/ios_module.py new file mode 100644 index 00000000..d6848ddc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/ios_module.py @@ -0,0 +1,104 @@ +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import os +import json + +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + AnsibleExitJson, + AnsibleFailJson, + ModuleTestCase, +) + + +fixture_path = os.path.join(os.path.dirname(__file__), "fixtures") +fixture_data = {} + + +def load_fixture(name): + path = os.path.join(fixture_path, name) + + if path in fixture_data: + return fixture_data[path] + + with open(path) as f: + data = f.read() + + try: + data = json.loads(data) + except Exception: + pass + + fixture_data[path] = data + return data + + +class TestIosModule(ModuleTestCase): + def execute_module( + self, + failed=False, + changed=False, + commands=None, + sort=True, + defaults=False, + ): + self.load_fixtures(commands) + + if failed: + result = self.failed() + self.assertTrue(result["failed"], result) + else: + result = self.changed(changed) + self.assertEqual(result["changed"], changed, result) + + if commands is not None: + if sort: + self.assertEqual( + sorted(commands), + sorted(result["commands"]), + result["commands"], + ) + else: + self.assertEqual( + commands, result["commands"], result["commands"] + ) + + return result + + def failed(self): + with self.assertRaises(AnsibleFailJson) as exc: + self.module.main() + + result = exc.exception.args[0] + self.assertTrue(result["failed"], result) + return result + + def changed(self, changed=False): + with self.assertRaises(AnsibleExitJson) as exc: + self.module.main() + + result = exc.exception.args[0] + self.assertEqual(result["changed"], changed, result) + return result + + def load_fixtures(self, commands=None): + pass diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py new file mode 100644 index 00000000..c9bb3328 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py @@ -0,0 +1,390 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_acl_interfaces +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosAclInterfacesModule(TestIosModule): + module = ios_acl_interfaces + + def setUp(self): + super(TestIosAclInterfacesModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." + "get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts." + "get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_edit_config = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.acl_interfaces.acl_interfaces." + "Acl_InterfacesFacts.get_acl_interfaces_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosAclInterfacesModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_edit_config.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + return load_fixture("ios_acl_interfaces.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_ios_acl_interfaces_merged(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/1", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="merge_110", direction="in"), + dict(name="merge_123", direction="out"), + ], + ), + dict( + afi="ipv6", + acls=[ + dict(name="merge_temp_v6", direction="in"), + dict( + name="merge_test_v6", direction="out" + ), + ], + ), + ], + ), + dict( + name="GigabitEthernet0/2", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="merge_110", direction="in"), + dict(name="merge_123", direction="out"), + ], + ) + ], + ), + ], + state="merged", + ) + ) + commands = [ + "interface GigabitEthernet0/1", + "ip access-group merge_110 in", + "ip access-group merge_123 out", + "ipv6 traffic-filter merge_temp_v6 in", + "ipv6 traffic-filter merge_test_v6 out", + "interface GigabitEthernet0/2", + "ip access-group merge_110 in", + "ip access-group merge_123 out", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_acl_interfaces_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/1", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="110", direction="in"), + dict(name="123", direction="out"), + ], + ), + dict( + afi="ipv6", + acls=[ + dict(name="test_v6", direction="out"), + dict(name="temp_v6", direction="in"), + ], + ), + ], + ), + dict( + name="GigabitEthernet0/2", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="110", direction="in"), + dict(name="123", direction="out"), + ], + ) + ], + ), + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_acl_interfaces_replaced(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/1", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="replace_100", direction="out"), + dict(name="110", direction="in"), + ], + ) + ], + ) + ], + state="replaced", + ) + ) + commands = [ + "interface GigabitEthernet0/1", + "no ip access-group 123 out", + "no ipv6 traffic-filter temp_v6 in", + "no ipv6 traffic-filter test_v6 out", + "ip access-group replace_100 out", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_acl_interfaces_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/1", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="110", direction="in"), + dict(name="123", direction="out"), + ], + ), + dict( + afi="ipv6", + acls=[ + dict(name="test_v6", direction="out"), + dict(name="temp_v6", direction="in"), + ], + ), + ], + ) + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_acl_interfaces_overridden(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/1", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="100", direction="out"), + dict(name="110", direction="in"), + ], + ) + ], + ) + ], + state="overridden", + ) + ) + + commands = [ + "interface GigabitEthernet0/1", + "no ip access-group 123 out", + "no ipv6 traffic-filter test_v6 out", + "no ipv6 traffic-filter temp_v6 in", + "ip access-group 100 out", + "interface GigabitEthernet0/2", + "no ip access-group 110 in", + "no ip access-group 123 out", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_acl_interfaces_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/1", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="110", direction="in"), + dict(name="123", direction="out"), + ], + ), + dict( + afi="ipv6", + acls=[ + dict(name="test_v6", direction="out"), + dict(name="temp_v6", direction="in"), + ], + ), + ], + ), + dict( + name="GigabitEthernet0/2", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="110", direction="in"), + dict(name="123", direction="out"), + ], + ) + ], + ), + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_acl_interfaces_deleted_interface(self): + set_module_args( + dict(config=[dict(name="GigabitEthernet0/1")], state="deleted") + ) + commands = [ + "interface GigabitEthernet0/1", + "no ip access-group 110 in", + "no ip access-group 123 out", + "no ipv6 traffic-filter test_v6 out", + "no ipv6 traffic-filter temp_v6 in", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_acl_interfaces_deleted(self): + set_module_args( + dict(config=[dict(name="GigabitEthernet0/1")], state="deleted") + ) + commands = [ + "interface GigabitEthernet0/1", + "no ip access-group 110 in", + "no ip access-group 123 out", + "no ipv6 traffic-filter test_v6 out", + "no ipv6 traffic-filter temp_v6 in", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_acl_interfaces_parsed(self): + set_module_args( + dict( + running_config="interface GigabitEthernet0/1\nip access-group 110 in\nipv6 traffic-filter test_v6 out", + state="parsed", + ) + ) + result = self.execute_module(changed=False) + parsed_list = [ + { + "access_groups": [ + { + "acls": [{"direction": "in", "name": "110"}], + "afi": "ipv4", + }, + { + "acls": [{"direction": "out", "name": "test_v6"}], + "afi": "ipv6", + }, + ], + "name": "GigabitEthernet0/1", + } + ] + self.assertEqual(parsed_list, result["parsed"]) + + def test_ios_acl_interfaces_rendered(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/1", + access_groups=[ + dict( + afi="ipv4", + acls=[ + dict(name="110", direction="in"), + dict(name="123", direction="out"), + ], + ), + dict( + afi="ipv6", + acls=[ + dict(name="temp_v6", direction="in"), + dict(name="test_v6", direction="out"), + ], + ), + ], + ) + ], + state="rendered", + ) + ) + commands = [ + "interface GigabitEthernet0/1", + "ip access-group 110 in", + "ip access-group 123 out", + "ipv6 traffic-filter temp_v6 in", + "ipv6 traffic-filter test_v6 out", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py new file mode 100644 index 00000000..5e99b2da --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py @@ -0,0 +1,540 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import sys + +import pytest + +# These tests and/or the module under test are unstable on Python 3.5. +# See: https://app.shippable.com/github/ansible/ansible/runs/161331/15/tests +# This is most likely due to CPython 3.5 not maintaining dict insertion order. +pytestmark = pytest.mark.skipif( + sys.version_info[:2] == (3, 5), + reason="Tests and/or module are unstable on Python 3.5.", +) + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_acls +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosAclsModule(TestIosModule): + module = ios_acls + + def setUp(self): + super(TestIosAclsModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." + "get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module." + "get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_edit_config = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.acls.acls." + "AclsFacts.get_acl_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosAclsModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_edit_config.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None, transport="cli"): + def load_from_file(*args, **kwargs): + return load_fixture("ios_acls_config.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_ios_acls_merged(self): + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="std_acl", + acl_type="standard", + aces=[ + dict( + grant="deny", + source=dict( + address="192.0.2.0", + wildcard_bits="0.0.0.255", + ), + ) + ], + ), + dict( + name="in_to_out", + acl_type="extended", + aces=[ + dict( + grant="permit", + protocol="tcp", + source=dict(host="10.1.1.2"), + destination=dict( + host="172.16.1.1", + port_protocol=dict(eq="telnet"), + ), + ) + ], + ), + ], + ) + ], + state="merged", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "ip access-list standard std_acl", + "deny 192.0.2.0 0.0.0.255", + "ip access-list extended in_to_out", + "permit tcp host 10.1.1.2 host 172.16.1.1 eq telnet", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_acls_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="110", + aces=[ + dict( + grant="deny", + protocol_options=dict( + icmp=dict(echo="true") + ), + sequence="10", + source=dict( + address="192.0.2.0", + wildcard_bits="0.0.0.255", + ), + destination=dict( + address="192.0.3.0", + wildcard_bits="0.0.0.255", + ), + dscp="ef", + ttl=dict(eq=10), + ) + ], + ) + ], + ), + dict( + afi="ipv6", + acls=[ + dict( + name="R1_TRAFFIC", + aces=[ + dict( + grant="deny", + protocol_options=dict( + tcp=dict(ack="true") + ), + sequence="10", + source=dict( + any="true", + port_protocol=dict(eq="www"), + ), + destination=dict( + any="true", + port_protocol=dict(eq="telnet"), + ), + dscp="af11", + ) + ], + ) + ], + ), + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_acls_replaced(self): + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="replace_acl", + acl_type="extended", + aces=[ + dict( + grant="deny", + protocol_options=dict( + tcp=dict(ack="true") + ), + source=dict( + address="198.51.100.0", + wildcard_bits="0.0.0.255", + ), + destination=dict( + address="198.51.101.0", + wildcard_bits="0.0.0.255", + port_protocol=dict(eq="telnet"), + ), + tos=dict(service_value=12), + ) + ], + ) + ], + ) + ], + state="replaced", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "ip access-list extended replace_acl", + "deny tcp 198.51.100.0 0.0.0.255 198.51.101.0 0.0.0.255 eq telnet ack tos 12", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_acls_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="110", + aces=[ + dict( + grant="deny", + protocol_options=dict( + icmp=dict(echo="true") + ), + sequence="10", + source=dict( + address="192.0.2.0", + wildcard_bits="0.0.0.255", + ), + destination=dict( + address="192.0.3.0", + wildcard_bits="0.0.0.255", + ), + dscp="ef", + ttl=dict(eq=10), + ) + ], + ) + ], + ) + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_acls_overridden(self): + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="150", + aces=[ + dict( + grant="deny", + protocol_options=dict( + tcp=dict(syn="true") + ), + source=dict( + address="198.51.100.0", + wildcard_bits="0.0.0.255", + port_protocol=dict(eq="telnet"), + ), + destination=dict( + address="198.51.110.0", + wildcard_bits="0.0.0.255", + port_protocol=dict(eq="telnet"), + ), + dscp="ef", + ttl=dict(eq=10), + ) + ], + ) + ], + ) + ], + state="overridden", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "no ip access-list extended 110", + "no ipv6 access-list R1_TRAFFIC", + "ip access-list extended 150", + "deny tcp 198.51.100.0 0.0.0.255 eq telnet 198.51.110.0 0.0.0.255 eq telnet syn dscp ef ttl eq 10", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_acls_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="110", + aces=[ + dict( + grant="deny", + protocol_options=dict( + icmp=dict(echo="true") + ), + sequence="10", + source=dict( + address="192.0.2.0", + wildcard_bits="0.0.0.255", + ), + destination=dict( + address="192.0.3.0", + wildcard_bits="0.0.0.255", + ), + dscp="ef", + ttl=dict(eq=10), + ) + ], + ) + ], + ), + dict( + afi="ipv6", + acls=[ + dict( + name="R1_TRAFFIC", + aces=[ + dict( + grant="deny", + protocol_options=dict( + tcp=dict(ack="true") + ), + sequence="10", + source=dict( + any="true", + port_protocol=dict(eq="www"), + ), + destination=dict( + any="true", + port_protocol=dict(eq="telnet"), + ), + dscp="af11", + ) + ], + ) + ], + ), + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_acls_deleted_afi_based(self): + set_module_args(dict(config=[dict(afi="ipv4")], state="deleted")) + result = self.execute_module(changed=True) + commands = ["no ip access-list extended 110"] + self.assertEqual(result["commands"], commands) + + def test_ios_acls_deleted_acl_based(self): + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="110", + aces=[ + dict( + grant="deny", + protocol_options=dict( + icmp=dict(echo="true") + ), + sequence="10", + source=dict( + address="192.0.2.0", + wildcard_bits="0.0.0.255", + ), + destination=dict( + address="192.0.3.0", + wildcard_bits="0.0.0.255", + ), + dscp="ef", + ttl=dict(eq=10), + ) + ], + ) + ], + ), + dict( + afi="ipv6", + acls=[ + dict( + name="R1_TRAFFIC", + aces=[ + dict( + grant="deny", + protocol_options=dict( + tcp=dict(ack="true") + ), + sequence="10", + source=dict( + any="true", + port_protocol=dict(eq="www"), + ), + destination=dict( + any="true", + port_protocol=dict(eq="telnet"), + ), + dscp="af11", + ) + ], + ) + ], + ), + ], + state="deleted", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "no ip access-list extended 110", + "no ipv6 access-list R1_TRAFFIC", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_acls_rendered(self): + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="110", + aces=[ + dict( + grant="deny", + sequence="10", + protocol_options=dict( + tcp=dict(syn="true") + ), + source=dict( + address="192.0.2.0", + wildcard_bits="0.0.0.255", + ), + destination=dict( + address="192.0.3.0", + wildcard_bits="0.0.0.255", + port_protocol=dict(eq="www"), + ), + dscp="ef", + ttl=dict(eq=10), + ) + ], + ) + ], + ) + ], + state="rendered", + ) + ) + commands = [ + "ip access-list extended 110", + "10 deny tcp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 eq www syn dscp ef ttl eq 10", + ] + result = self.execute_module(changed=False) + self.assertEqual(result["rendered"], commands) + + def test_ios_acls_parsed(self): + set_module_args( + dict( + running_config="IPv6 access list R1_TRAFFIC\ndeny tcp any eq www any eq telnet ack dscp af11 sequence 10", + state="parsed", + ) + ) + result = self.execute_module(changed=False) + parsed_list = [ + { + "acls": [ + { + "aces": [ + { + "destination": { + "any": True, + "port_protocol": {"eq": "telnet"}, + }, + "dscp": "af11", + "grant": "deny", + "protocol": "tcp", + "protocol_options": {"tcp": {"ack": True}}, + "sequence": 10, + "source": { + "any": True, + "port_protocol": {"eq": "www"}, + }, + } + ], + "name": "R1_TRAFFIC", + } + ], + "afi": "ipv6", + } + ] + self.assertEqual(parsed_list, result["parsed"]) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_banner.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_banner.py new file mode 100644 index 00000000..bb3bf4fd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_banner.py @@ -0,0 +1,88 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_banner +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosBannerModule(TestIosModule): + + module = ios_banner + + def setUp(self): + super(TestIosBannerModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_banner.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_banner.load_config" + ) + self.load_config = self.mock_load_config.start() + + def tearDown(self): + super(TestIosBannerModule, self).tearDown() + self.mock_get_config.stop() + self.mock_load_config.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + return load_fixture("ios_banner_show_running_config_ios12.txt") + + self.get_config.side_effect = load_from_file + + def test_ios_banner_create(self): + for banner_type in ("login", "motd", "exec", "incoming", "slip-ppp"): + set_module_args( + dict(banner=banner_type, text="test\nbanner\nstring") + ) + commands = [ + "banner {0} @\ntest\nbanner\nstring\n@".format(banner_type) + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_banner_remove(self): + set_module_args(dict(banner="login", state="absent")) + commands = ["no banner login"] + self.execute_module(changed=True, commands=commands) + + def test_ios_banner_nochange(self): + banner_text = load_fixture("ios_banner_show_banner.txt") + set_module_args(dict(banner="login", text=banner_text)) + self.execute_module() + + +class TestIosBannerIos12Module(TestIosBannerModule): + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + return load_fixture("ios_banner_show_running_config_ios12.txt") + + self.get_config.side_effect = load_from_file + + def test_ios_banner_nochange(self): + banner_text = load_fixture("ios_banner_show_banner.txt") + set_module_args(dict(banner="exec", text=banner_text)) + self.execute_module() diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp.py new file mode 100644 index 00000000..f0b08980 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp.py @@ -0,0 +1,390 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.cli.config.bgp.process import ( + Provider, +) +from ansible_collections.cisco.ios.plugins.modules import ios_bgp +from .ios_module import TestIosModule, load_fixture + + +class TestIosBgpModule(TestIosModule): + module = ios_bgp + + def setUp(self): + super(TestIosBgpModule, self).setUp() + self._bgp_config = load_fixture("ios_bgp_config.cfg") + + def test_ios_bgp(self): + obj = Provider( + params=dict( + config=dict( + bgp_as=64496, + router_id="192.0.2.2", + networks=None, + address_family=None, + ), + operation="merge", + ) + ) + commands = obj.render(self._bgp_config) + self.assertEqual( + commands, ["router bgp 64496", "bgp router-id 192.0.2.2", "exit"] + ) + + def test_ios_bgp_idempotent(self): + obj = Provider( + params=dict( + config=dict( + bgp_as=64496, + router_id="192.0.2.1", + networks=None, + address_family=None, + ), + operation="merge", + ) + ) + commands = obj.render(self._bgp_config) + self.assertEqual(commands, []) + + def test_ios_bgp_remove(self): + obj = Provider( + params=dict( + config=dict(bgp_as=64496, networks=None, address_family=None), + operation="delete", + ) + ) + commands = obj.render(self._bgp_config) + self.assertEqual(commands, ["no router bgp 64496"]) + + def test_ios_bgp_neighbor(self): + obj = Provider( + params=dict( + config=dict( + bgp_as=64496, + neighbors=[dict(neighbor="192.51.100.2", remote_as=64496)], + networks=None, + address_family=None, + ), + operation="merge", + ) + ) + commands = obj.render(self._bgp_config) + self.assertEqual( + commands, + [ + "router bgp 64496", + "neighbor 192.51.100.2 remote-as 64496", + "exit", + ], + ) + + def test_ios_bgp_neighbor_idempotent(self): + obj = Provider( + params=dict( + config=dict( + bgp_as=64496, + neighbors=[ + dict( + neighbor="192.51.100.1", + remote_as=64496, + timers=dict( + keepalive=120, + holdtime=360, + min_neighbor_holdtime=360, + ), + ) + ], + networks=None, + address_family=None, + ), + operation="merge", + ) + ) + commands = obj.render(self._bgp_config) + self.assertEqual(commands, []) + + def test_ios_bgp_network(self): + obj = Provider( + params=dict( + config=dict( + bgp_as=64496, + networks=[ + dict( + prefix="192.0.1.0", masklen=23, route_map="RMAP_1" + ) + ], + address_family=None, + ), + operation="merge", + ) + ) + commands = obj.render(self._bgp_config) + self.assertEqual( + sorted(commands), + sorted( + [ + "router bgp 64496", + "network 192.0.1.0 mask 255.255.254.0 route-map RMAP_1", + "exit", + ] + ), + ) + + def test_ios_bgp_network_idempotent(self): + obj = Provider( + params=dict( + config=dict( + bgp_as=64496, + networks=[ + dict( + prefix="192.0.2.0", masklen=23, route_map="RMAP_1" + ), + dict( + prefix="198.51.100.0", + masklen=25, + route_map="RMAP_2", + ), + ], + address_family=None, + ), + operation="merge", + ) + ) + commands = obj.render(self._bgp_config) + self.assertEqual(commands, []) + + def test_ios_bgp_address_family_redistribute(self): + rd_1 = dict(protocol="ospf", id="233", metric=90, route_map=None) + + config = dict( + bgp_as=64496, + address_family=[ + dict(afi="ipv4", safi="unicast", redistribute=[rd_1]) + ], + networks=None, + ) + + obj = Provider(params=dict(config=config, operation="merge")) + + commands = obj.render(self._bgp_config) + cmd = [ + "router bgp 64496", + "address-family ipv4", + "redistribute ospf 233 metric 90", + "exit-address-family", + "exit", + ] + self.assertEqual(sorted(commands), sorted(cmd)) + + def test_ios_bgp_address_family_redistribute_idempotent(self): + rd_1 = dict(protocol="eigrp", metric=10, route_map="RMAP_3", id=None) + rd_2 = dict(protocol="static", metric=100, id=None, route_map=None) + + config = dict( + bgp_as=64496, + address_family=[ + dict(afi="ipv4", safi="unicast", redistribute=[rd_1, rd_2]) + ], + networks=None, + ) + + obj = Provider(params=dict(config=config, operation="merge")) + + commands = obj.render(self._bgp_config) + self.assertEqual(commands, []) + + def test_ios_bgp_address_family_neighbors(self): + af_nbr_1 = dict( + neighbor="192.51.100.1", maximum_prefix=35, activate=True + ) + af_nbr_2 = dict( + neighbor="192.51.100.3", route_reflector_client=True, activate=True + ) + + config = dict( + bgp_as=64496, + address_family=[ + dict( + afi="ipv4", + safi="multicast", + neighbors=[af_nbr_1, af_nbr_2], + ) + ], + networks=None, + ) + + obj = Provider(params=dict(config=config, operation="merge")) + + commands = obj.render(self._bgp_config) + cmd = [ + "router bgp 64496", + "address-family ipv4 multicast", + "neighbor 192.51.100.1 activate", + "neighbor 192.51.100.1 maximum-prefix 35", + "neighbor 192.51.100.3 activate", + "neighbor 192.51.100.3 route-reflector-client", + "exit-address-family", + "exit", + ] + self.assertEqual(sorted(commands), sorted(cmd)) + + def test_ios_bgp_address_family_neighbors_idempotent(self): + af_nbr_1 = dict( + neighbor="203.0.113.1", remove_private_as=True, maximum_prefix=100 + ) + + config = dict( + bgp_as=64496, + address_family=[ + dict(afi="ipv4", safi="unicast", neighbors=[af_nbr_1]) + ], + networks=None, + ) + + obj = Provider(params=dict(config=config, operation="merge")) + + commands = obj.render(self._bgp_config) + self.assertEqual(commands, []) + + def test_ios_bgp_address_family_networks(self): + net = dict(prefix="1.0.0.0", masklen=8, route_map="RMAP_1") + net2 = dict(prefix="192.168.1.0", masklen=24, route_map="RMAP_2") + + config = dict( + bgp_as=64496, + address_family=[ + dict(afi="ipv4", safi="multicast", networks=[net, net2]) + ], + networks=None, + ) + + obj = Provider(params=dict(config=config, operation="merge")) + + commands = obj.render(self._bgp_config) + cmd = [ + "router bgp 64496", + "address-family ipv4 multicast", + "network 1.0.0.0 mask 255.0.0.0 route-map RMAP_1", + "network 192.168.1.0 mask 255.255.255.0 route-map RMAP_2", + "exit-address-family", + "exit", + ] + self.assertEqual(sorted(commands), sorted(cmd)) + + def test_ios_bgp_address_family_networks_idempotent(self): + net = dict(prefix="203.0.113.0", masklen=27, route_map="RMAP_1") + net2 = dict(prefix="192.0.2.0", masklen=26, route_map="RMAP_2") + + config = dict( + bgp_as=64496, + address_family=[ + dict(afi="ipv4", safi="multicast", networks=[net, net2]) + ], + networks=None, + ) + + obj = Provider(params=dict(config=config, operation="merge")) + + commands = obj.render(self._bgp_config) + self.assertEqual(commands, []) + + def test_ios_bgp_operation_override(self): + net_1 = dict(prefix="1.0.0.0", masklen=8, route_map="RMAP_1") + net_2 = dict(prefix="192.168.1.0", masklen=24, route_map="RMAP_2") + nbr_1 = dict( + neighbor="192.51.100.1", + remote_as=64496, + update_source="GigabitEthernet0/1", + ) + nbr_2 = dict( + neighbor="192.51.100.3", + remote_as=64496, + timers=dict( + keepalive=300, holdtime=360, min_neighbor_holdtime=360 + ), + ) + af_nbr_1 = dict(neighbor="192.51.100.1", maximum_prefix=35) + af_nbr_2 = dict(neighbor="192.51.100.3", route_reflector_client=True) + + af_1 = dict(afi="ipv4", safi="unicast", neighbors=[af_nbr_1, af_nbr_2]) + af_2 = dict(afi="ipv4", safi="multicast", networks=[net_1, net_2]) + config = dict( + bgp_as=64496, + neighbors=[nbr_1, nbr_2], + address_family=[af_1, af_2], + networks=None, + ) + + obj = Provider(params=dict(config=config, operation="override")) + commands = obj.render(self._bgp_config) + + cmd = [ + "no router bgp 64496", + "router bgp 64496", + "neighbor 192.51.100.1 remote-as 64496", + "neighbor 192.51.100.1 update-source GigabitEthernet0/1", + "neighbor 192.51.100.3 remote-as 64496", + "neighbor 192.51.100.3 timers 300 360 360", + "address-family ipv4", + "neighbor 192.51.100.1 maximum-prefix 35", + "neighbor 192.51.100.3 route-reflector-client", + "exit-address-family", + "address-family ipv4 multicast", + "network 1.0.0.0 mask 255.0.0.0 route-map RMAP_1", + "network 192.168.1.0 mask 255.255.255.0 route-map RMAP_2", + "exit-address-family", + "exit", + ] + + self.assertEqual(sorted(commands), sorted(cmd)) + + def test_ios_bgp_operation_replace(self): + rd = dict(protocol="ospf", id=223, metric=110, route_map=None) + net = dict(prefix="203.0.113.0", masklen=27, route_map="RMAP_1") + net2 = dict(prefix="192.0.2.0", masklen=26, route_map="RMAP_2") + + af_1 = dict(afi="ipv4", safi="unicast", redistribute=[rd]) + af_2 = dict(afi="ipv4", safi="multicast", networks=[net, net2]) + + config = dict(bgp_as=64496, address_family=[af_1, af_2], networks=None) + obj = Provider(params=dict(config=config, operation="replace")) + commands = obj.render(self._bgp_config) + + cmd = [ + "router bgp 64496", + "address-family ipv4", + "redistribute ospf 223 metric 110", + "no redistribute eigrp", + "no redistribute static", + "exit-address-family", + "exit", + ] + + self.assertEqual(sorted(commands), sorted(cmd)) + + def test_ios_bgp_operation_replace_with_new_as(self): + rd = dict(protocol="ospf", id=223, metric=110, route_map=None) + + af_1 = dict(afi="ipv4", safi="unicast", redistribute=[rd]) + + config = dict(bgp_as=64497, address_family=[af_1], networks=None) + obj = Provider(params=dict(config=config, operation="replace")) + commands = obj.render(self._bgp_config) + + cmd = [ + "no router bgp 64496", + "router bgp 64497", + "address-family ipv4", + "redistribute ospf 223 metric 110", + "exit-address-family", + "exit", + ] + + self.assertEqual(sorted(commands), sorted(cmd)) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py new file mode 100644 index 00000000..c6b6f6bc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py @@ -0,0 +1,244 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_bgp_global +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosBgpGlobalModule(TestIosModule): + module = ios_bgp_global + + def setUp(self): + super(TestIosBgpGlobalModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." + "get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module." + "get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_edit_config = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.bgp_global.bgp_global." + "Bgp_globalFacts.get_bgp_global_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosBgpGlobalModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_edit_config.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + return load_fixture("ios_bgp_global.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_ios_bgp_global_merged(self): + set_module_args( + dict( + config=dict( + as_number="65000", + bgp=dict( + dampening=dict( + penalty_half_time=1, + reuse_route_val=1, + suppress_route_val=1, + max_suppress=1, + ), + graceful_shutdown=dict( + neighbors=dict(time=50), + community=100, + local_preference=100, + ), + ), + neighbor=[ + dict( + address="198.51.100.1", + description="merge neighbor", + aigp=dict( + send=dict( + cost_community=dict( + id=100, + poi=dict( + igp_cost=True, transitive=True + ), + ) + ) + ), + ) + ], + ), + state="merged", + ) + ) + commands = [ + "router bgp 65000", + "bgp graceful-shutdown all neighbors 50 local-preference 100 community 100", + "bgp dampening 1 1 1 1", + "neighbor 198.51.100.1 aigp send cost-community 100 poi igp-cost transitive", + "neighbor 198.51.100.1 description merge neighbor", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_bgp_global_merged_idempotent(self): + set_module_args( + dict( + config=dict( + as_number="65000", + bgp=dict( + advertise_best_external=True, + bestpath=[dict(compare_routerid=True)], + nopeerup_delay=[dict(post_boot=10)], + ), + redistribute=[dict(connected=dict(metric=10))], + neighbor=[ + dict( + address="198.51.100.1", + remote_as=100, + route_map=dict(name="test-route", out=True), + ) + ], + timers=dict(keepalive=100, holdtime=200, min_holdtime=150), + ), + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_bgp_global_replaced(self): + set_module_args( + dict( + config=dict( + as_number="65000", + bgp=dict( + advertise_best_external=True, + bestpath=[dict(compare_routerid=True)], + log_neighbor_changes=True, + nopeerup_delay=[ + dict(cold_boot=20), + dict(post_boot=10), + ], + ), + redistribute=[dict(connected=dict(metric=10))], + neighbor=[ + dict( + address="192.0.2.1", + remote_as=200, + description="replace neighbor", + ) + ], + ), + state="replaced", + ) + ) + commands = [ + "bgp nopeerup-delay cold-boot 20", + "neighbor 192.0.2.1 description replace neighbor", + "neighbor 192.0.2.1 remote-as 200", + "no neighbor 198.51.100.1 remote-as 100", + "no neighbor 198.51.100.1 route-map test-route out", + "no timers bgp 100 200 150", + "router bgp 65000", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_bgp_global_replaced_idempotent(self): + set_module_args( + dict( + config=dict( + as_number="65000", + bgp=dict( + advertise_best_external=True, + bestpath=[dict(compare_routerid=True)], + nopeerup_delay=[dict(post_boot=10)], + ), + redistribute=[dict(connected=dict(metric=10))], + neighbor=[ + dict( + address="198.51.100.1", + remote_as=100, + route_map=dict(name="test-route", out=True), + ) + ], + timers=dict(keepalive=100, holdtime=200, min_holdtime=150), + ), + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_bgp_global_deleted(self): + set_module_args(dict(config=dict(as_number=65000), state="deleted")) + commands = [ + "router bgp 65000", + "no bgp nopeerup-delay post-boot 10", + "no bgp bestpath compare-routerid", + "no bgp advertise-best-external", + "no timers bgp 100 200 150", + "no redistribute connected metric 10", + "no neighbor 198.51.100.1 remote-as 100", + "no neighbor 198.51.100.1 route-map test-route out", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_bgp_global_purged(self): + set_module_args(dict(config=dict(as_number=65000), state="purged")) + commands = ["no router bgp 65000"] + self.execute_module(changed=True, commands=commands) + + def test_ios_bgp_global_parsed(self): + set_module_args( + dict( + running_config="router bgp 65000\n bgp nopeerup-delay post-boot 10", + state="parsed", + ) + ) + result = self.execute_module(changed=False) + parsed_list = { + "as_number": "65000", + "bgp": {"nopeerup_delay": [{"post_boot": 10}]}, + } + self.assertEqual(parsed_list, result["parsed"]) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_command.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_command.py new file mode 100644 index 00000000..6d50176e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_command.py @@ -0,0 +1,143 @@ +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import json + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_command +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosCommandModule(TestIosModule): + + module = ios_command + + def setUp(self): + super(TestIosCommandModule, self).setUp() + + self.mock_run_commands = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_command.run_commands" + ) + self.run_commands = self.mock_run_commands.start() + + def tearDown(self): + super(TestIosCommandModule, self).tearDown() + self.mock_run_commands.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + module, commands = args + output = list() + + for item in commands: + try: + obj = json.loads(item["command"]) + command = obj["command"] + except ValueError: + command = item["command"] + filename = str(command).replace(" ", "_") + output.append(load_fixture(filename)) + return output + + self.run_commands.side_effect = load_from_file + + def test_ios_command_simple(self): + set_module_args(dict(commands=["show version"])) + result = self.execute_module() + self.assertEqual(len(result["stdout"]), 1) + self.assertTrue(result["stdout"][0].startswith("Cisco IOS Software")) + + def test_ios_command_multiple(self): + set_module_args(dict(commands=["show version", "show version"])) + result = self.execute_module() + self.assertEqual(len(result["stdout"]), 2) + self.assertTrue(result["stdout"][0].startswith("Cisco IOS Software")) + + def test_ios_command_wait_for(self): + wait_for = 'result[0] contains "Cisco IOS"' + set_module_args(dict(commands=["show version"], wait_for=wait_for)) + self.execute_module() + + def test_ios_command_wait_for_fails(self): + wait_for = 'result[0] contains "test string"' + set_module_args(dict(commands=["show version"], wait_for=wait_for)) + self.execute_module(failed=True) + self.assertEqual(self.run_commands.call_count, 10) + + def test_ios_command_retries(self): + wait_for = 'result[0] contains "test string"' + set_module_args( + dict(commands=["show version"], wait_for=wait_for, retries=2) + ) + self.execute_module(failed=True) + self.assertEqual(self.run_commands.call_count, 2) + + def test_ios_command_match_any(self): + wait_for = [ + 'result[0] contains "Cisco IOS"', + 'result[0] contains "test string"', + ] + set_module_args( + dict(commands=["show version"], wait_for=wait_for, match="any") + ) + self.execute_module() + + def test_ios_command_match_all(self): + wait_for = [ + 'result[0] contains "Cisco IOS"', + 'result[0] contains "IOSv Software"', + ] + set_module_args( + dict(commands=["show version"], wait_for=wait_for, match="all") + ) + self.execute_module() + + def test_ios_command_match_all_failure(self): + wait_for = [ + 'result[0] contains "Cisco IOS"', + 'result[0] contains "test string"', + ] + commands = ["show version", "show version"] + set_module_args( + dict(commands=commands, wait_for=wait_for, match="all") + ) + self.execute_module(failed=True) + + def test_ios_command_configure_check_warning(self): + commands = ["configure terminal"] + set_module_args({"commands": commands, "_ansible_check_mode": True}) + result = self.execute_module() + self.assertEqual( + result["warnings"], + [ + "Only show commands are supported when using check mode, not executing configure terminal" + ], + ) + + def test_ios_command_configure_not_warning(self): + commands = ["configure terminal"] + set_module_args(dict(commands=commands)) + result = self.execute_module() + self.assertEqual(result["warnings"], []) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py new file mode 100644 index 00000000..b279328b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py @@ -0,0 +1,339 @@ +# +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import ( + patch, + MagicMock, +) +from ansible_collections.cisco.ios.plugins.modules import ios_config +from ansible_collections.cisco.ios.plugins.cliconf.ios import Cliconf +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosConfigModule(TestIosModule): + + module = ios_config + + def setUp(self): + super(TestIosConfigModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_get_connection = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_config.get_connection" + ) + self.get_connection = self.mock_get_connection.start() + + self.conn = self.get_connection() + self.conn.edit_config = MagicMock() + + self.mock_run_commands = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_config.run_commands" + ) + self.run_commands = self.mock_run_commands.start() + + self.cliconf_obj = Cliconf(MagicMock()) + self.running_config = load_fixture("ios_config_config.cfg") + + def tearDown(self): + super(TestIosConfigModule, self).tearDown() + self.mock_get_config.stop() + self.mock_run_commands.stop() + self.mock_get_connection.stop() + + def load_fixtures(self, commands=None): + config_file = "ios_config_config.cfg" + self.get_config.return_value = load_fixture(config_file) + self.get_connection.edit_config.return_value = None + + def test_ios_config_unchanged(self): + src = load_fixture("ios_config_config.cfg") + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff(src, src) + ) + set_module_args(dict(src=src)) + self.execute_module() + + def test_ios_config_src(self): + src = load_fixture("ios_config_src.cfg") + set_module_args(dict(src=src)) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff(src, self.running_config) + ) + commands = [ + "hostname foo", + "interface GigabitEthernet0/0", + "no ip address", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_config_backup(self): + set_module_args(dict(backup=True)) + result = self.execute_module() + self.assertIn("__backup__", result) + + def test_ios_config_save_changed_true(self): + src = load_fixture("ios_config_src.cfg") + set_module_args(dict(src=src, save_when="changed")) + commands = [ + "hostname foo", + "interface GigabitEthernet0/0", + "no ip address", + ] + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff(src, self.running_config) + ) + self.execute_module(changed=True, commands=commands) + self.assertEqual(self.run_commands.call_count, 1) + self.assertEqual(self.get_config.call_count, 1) + self.assertEqual(self.conn.edit_config.call_count, 1) + args = self.run_commands.call_args[0][1] + self.assertIn("copy running-config startup-config\r", args) + + def test_ios_config_save_changed_false(self): + set_module_args(dict(save_when="changed")) + self.execute_module(changed=False) + self.assertEqual(self.run_commands.call_count, 0) + self.assertEqual(self.get_config.call_count, 0) + self.assertEqual(self.conn.edit_config.call_count, 0) + + def test_ios_config_save_always(self): + self.run_commands.return_value = "hostname foo" + set_module_args(dict(save_when="always")) + self.execute_module(changed=True) + self.assertEqual(self.run_commands.call_count, 1) + self.assertEqual(self.get_config.call_count, 0) + self.assertEqual(self.conn.edit_config.call_count, 0) + args = self.run_commands.call_args[0][1] + self.assertIn("copy running-config startup-config\r", args) + + def test_ios_config_lines_wo_parents(self): + lines = ["hostname foo"] + set_module_args(dict(lines=lines)) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), self.running_config + ) + ) + commands = ["hostname foo"] + self.execute_module(changed=True, commands=commands) + + def test_ios_config_lines_w_parents(self): + lines = ["shutdown"] + parents = ["interface GigabitEthernet0/0"] + set_module_args(dict(lines=lines, parents=parents)) + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = ios_config.get_candidate_config(module) + + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, self.running_config + ) + ) + + commands = ["interface GigabitEthernet0/0", "shutdown"] + self.execute_module(changed=True, commands=commands) + + def test_ios_config_before(self): + lines = ["hostname foo"] + set_module_args(dict(lines=lines, before=["test1", "test2"])) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), self.running_config + ) + ) + commands = ["test1", "test2", "hostname foo"] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_config_after(self): + lines = ["hostname foo"] + set_module_args(dict(lines=lines, after=["test1", "test2"])) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), self.running_config + ) + ) + commands = ["hostname foo", "test1", "test2"] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_config_before_after_no_change(self): + lines = ["hostname router"] + set_module_args( + dict( + lines=lines, + before=["test1", "test2"], + after=["test3", "test4"], + ) + ) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), self.running_config + ) + ) + self.execute_module() + + def test_ios_config_config(self): + config = "hostname localhost" + lines = ["hostname router"] + set_module_args(dict(lines=lines, config=config)) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff("\n".join(lines), config) + ) + commands = ["hostname router"] + self.execute_module(changed=True, commands=commands) + + def test_ios_config_replace_block(self): + lines = ["description test string", "test string"] + parents = ["interface GigabitEthernet0/0"] + set_module_args(dict(lines=lines, replace="block", parents=parents)) + + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = ios_config.get_candidate_config(module) + + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + diff_replace="block", + path=parents, + ) + ) + + commands = parents + lines + self.execute_module(changed=True, commands=commands) + + def test_ios_config_match_none(self): + lines = ["hostname router"] + set_module_args(dict(lines=lines, match="none")) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), self.running_config, diff_match="none" + ) + ) + self.execute_module(changed=True, commands=lines) + + def test_ios_config_match_none2(self): + lines = ["ip address 1.2.3.4 255.255.255.0", "description test string"] + parents = ["interface GigabitEthernet0/0"] + set_module_args(dict(lines=lines, parents=parents, match="none")) + + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = ios_config.get_candidate_config(module) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + diff_match="none", + path=parents, + ) + ) + + commands = parents + lines + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_config_match_strict(self): + lines = [ + "ip address 1.2.3.4 255.255.255.0", + "description test string", + "shutdown", + ] + parents = ["interface GigabitEthernet0/0"] + set_module_args(dict(lines=lines, parents=parents, match="strict")) + + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = ios_config.get_candidate_config(module) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + diff_match="strict", + path=parents, + ) + ) + + commands = parents + ["shutdown"] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_config_match_exact(self): + lines = [ + "ip address 1.2.3.4 255.255.255.0", + "description test string", + "shutdown", + ] + parents = ["interface GigabitEthernet0/0"] + set_module_args(dict(lines=lines, parents=parents, match="exact")) + + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = ios_config.get_candidate_config(module) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + diff_match="exact", + path=parents, + ) + ) + + commands = parents + lines + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_config_src_and_lines_fails(self): + args = dict(src="foo", lines="foo") + set_module_args(args) + self.execute_module(failed=True) + + def test_ios_config_src_and_parents_fails(self): + args = dict(src="foo", parents="foo") + set_module_args(args) + self.execute_module(failed=True) + + def test_ios_config_match_exact_requires_lines(self): + args = dict(match="exact") + set_module_args(args) + self.execute_module(failed=True) + + def test_ios_config_match_strict_requires_lines(self): + args = dict(match="strict") + set_module_args(args) + self.execute_module(failed=True) + + def test_ios_config_replace_block_requires_lines(self): + args = dict(replace="block") + set_module_args(args) + self.execute_module(failed=True) + + def test_ios_config_replace_config_requires_src(self): + args = dict(replace="config") + set_module_args(args) + self.execute_module(failed=True) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py new file mode 100644 index 00000000..e26aad69 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py @@ -0,0 +1,168 @@ +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_facts +from ansible.module_utils.six import assertCountEqual +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosFactsModule(TestIosModule): + + module = ios_facts + + def setUp(self): + super(TestIosFactsModule, self).setUp() + self.mock_run_commands = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.legacy.base.run_commands" + ) + self.run_commands = self.mock_run_commands.start() + + self.mock_get_resource_connection = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" + ) + self.get_resource_connection = ( + self.mock_get_resource_connection.start() + ) + + self.mock_get_capabilities = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.legacy.base.get_capabilities" + ) + self.get_capabilities = self.mock_get_capabilities.start() + self.get_capabilities.return_value = { + "device_info": { + "network_os": "ios", + "network_os_hostname": "an-ios-01", + "network_os_image": "flash0:/vios-adventerprisek9-m", + "network_os_model": "WS-C3750-24TS", + "network_os_version": "15.6(3)M2", + }, + "network_api": "cliconf", + } + + def tearDown(self): + super(TestIosFactsModule, self).tearDown() + self.mock_run_commands.stop() + self.mock_get_capabilities.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + commands = kwargs["commands"] + output = list() + + for command in commands: + filename = str(command).split(" | ")[0].replace(" ", "_") + output.append(load_fixture("ios_facts_%s" % filename)) + return output + + self.run_commands.side_effect = load_from_file + + def test_ios_facts_stacked(self): + set_module_args(dict(gather_subset="default")) + result = self.execute_module() + self.assertEqual( + result["ansible_facts"]["ansible_net_model"], "WS-C3750-24TS" + ) + self.assertEqual( + result["ansible_facts"]["ansible_net_serialnum"], "CAT0726R0ZU" + ) + self.assertEqual( + result["ansible_facts"]["ansible_net_stacked_models"], + ["WS-C3750-24TS-E", "WS-C3750-24TS-E", "WS-C3750G-12S-E"], + ) + self.assertEqual( + result["ansible_facts"]["ansible_net_stacked_serialnums"], + ["CAT0726R0ZU", "CAT0726R10A", "CAT0732R0M4"], + ) + + def test_ios_facts_tunnel_address(self): + set_module_args(dict(gather_subset="interfaces")) + result = self.execute_module() + self.assertEqual( + result["ansible_facts"]["ansible_net_interfaces"][ + "GigabitEthernet0/0" + ]["macaddress"], + "5e00.0003.0000", + ) + self.assertEqual( + result["ansible_facts"]["ansible_net_interfaces"][ + "GigabitEthernet1" + ]["macaddress"], + "5e00.0006.0000", + ) + self.assertIsNone( + result["ansible_facts"]["ansible_net_interfaces"]["Tunnel1110"][ + "macaddress" + ] + ) + + def test_ios_facts_filesystems_info(self): + set_module_args(dict(gather_subset="hardware")) + result = self.execute_module() + self.assertEqual( + result["ansible_facts"]["ansible_net_filesystems_info"][ + "bootflash:" + ]["spacetotal_kb"], + 7712692.0, + ) + self.assertEqual( + result["ansible_facts"]["ansible_net_filesystems_info"][ + "bootflash:" + ]["spacefree_kb"], + 6453180.0, + ) + + def test_ios_facts_neighbors(self): + set_module_args(dict(gather_subset="interfaces")) + result = self.execute_module() + assertCountEqual( + self, + result["ansible_facts"]["ansible_net_neighbors"].keys(), + ["GigabitEthernet1", "GigabitEthernet3"], + ) + assertCountEqual( + self, + result["ansible_facts"]["ansible_net_neighbors"][ + "GigabitEthernet1" + ], + [ + { + "platform": "cisco CSR1000V", + "host": "R2", + "port": "GigabitEthernet2", + }, + { + "platform": "cisco CSR1000V", + "host": "R3", + "port": "GigabitEthernet3", + }, + ], + ) + assertCountEqual( + self, + result["ansible_facts"]["ansible_net_neighbors"][ + "GigabitEthernet3" + ], + [{"host": "Rtest", "port": "Gi1"}], + ) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py new file mode 100644 index 00000000..8f4934e1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py @@ -0,0 +1,327 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_l2_interfaces +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosL2InterfacesModule(TestIosModule): + module = ios_l2_interfaces + + def setUp(self): + super(TestIosL2InterfacesModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." + "get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts." + "get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_edit_config = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.l2_interfaces.l2_interfaces." + "L2_InterfacesFacts.get_l2_interfaces_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosL2InterfacesModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_edit_config.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + return load_fixture("ios_l2_interfaces.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_ios_l2_interfaces_merged(self): + set_module_args( + dict( + config=[ + dict( + access=dict(vlan=20), + mode="access", + name="GigabitEthernet0/1", + voice=dict(vlan=40), + ), + dict( + mode="trunk", + name="GigabitEthernet0/2", + trunk=dict( + allowed_vlans=["60"], + encapsulation="isl", + native_vlan=20, + pruning_vlans=["12-15", "20"], + ), + ), + ], + state="merged", + ) + ) + commands = [ + "interface GigabitEthernet0/1", + "switchport access vlan 20", + "switchport voice vlan 40", + "interface GigabitEthernet0/2", + "switchport trunk encapsulation isl", + "switchport trunk native vlan 20", + "switchport trunk allowed vlan add 60", + "switchport trunk pruning vlan add 12-15", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_l2_interfaces_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + access=dict(vlan=10), + mode="access", + name="GigabitEthernet0/1", + ), + dict( + mode="trunk", + name="GigabitEthernet0/2", + trunk=dict( + allowed_vlans=["10-20", "40"], + encapsulation="dot1q", + native_vlan=10, + pruning_vlans=["10", "20"], + ), + ), + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_l2_interfaces_replaced(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/2", + trunk=dict( + allowed_vlans=["20-25", "40"], + encapsulation="isl", + native_vlan=20, + pruning_vlans=["10"], + ), + ) + ], + state="replaced", + ) + ) + commands = [ + "interface GigabitEthernet0/2", + "no switchport mode", + "switchport trunk encapsulation isl", + "switchport trunk native vlan 20", + "switchport trunk allowed vlan 20-25,40", + "switchport trunk pruning vlan 10", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_l2_interfaces_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + access=dict(vlan=10), + mode="access", + name="GigabitEthernet0/1", + ), + dict( + mode="trunk", + name="GigabitEthernet0/2", + trunk=dict( + allowed_vlans=["10-20", "40"], + encapsulation="dot1q", + native_vlan=10, + pruning_vlans=["10", "20"], + ), + ), + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_l2_interfaces_overridden(self): + set_module_args( + dict( + config=[ + dict( + access=dict(vlan=10), + voice=dict(vlan=20), + mode="access", + name="GigabitEthernet0/2", + ) + ], + state="overridden", + ) + ) + commands = [ + "interface GigabitEthernet0/1", + "no switchport mode", + "no switchport access vlan", + "interface GigabitEthernet0/2", + "no switchport trunk encapsulation", + "no switchport trunk native vlan", + "no switchport trunk allowed vlan", + "no switchport trunk pruning vlan", + "switchport access vlan 10", + "switchport voice vlan 20", + "switchport mode access", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_l2_interfaces_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + access=dict(vlan=10), + mode="access", + name="GigabitEthernet0/1", + ), + dict( + mode="trunk", + name="GigabitEthernet0/2", + trunk=dict( + allowed_vlans=["10-20", "40"], + encapsulation="dot1q", + native_vlan=10, + pruning_vlans=["10", "20"], + ), + ), + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_l2_interfaces_deleted_interface(self): + set_module_args( + dict(config=[dict(name="GigabitEthernet0/1")], state="deleted") + ) + commands = [ + "interface GigabitEthernet0/1", + "no switchport mode", + "no switchport access vlan", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_l2_interfaces_deleted_all(self): + set_module_args(dict(config=[], state="deleted")) + commands = [ + "interface GigabitEthernet0/1", + "no switchport mode", + "no switchport access vlan", + "interface GigabitEthernet0/2", + "no switchport mode", + "no switchport trunk encapsulation", + "no switchport trunk native vlan", + "no switchport trunk allowed vlan", + "no switchport trunk pruning vlan", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_l2_interfaces_parsed(self): + set_module_args( + dict( + running_config="interface GigabitEthernet0/1\nswitchport mode trunk\nswitchport trunk native vlan 10\nswitchport trunk encapsulation dot1q\n", + state="parsed", + ) + ) + result = self.execute_module(changed=False) + parsed_list = [ + { + "mode": "trunk", + "name": "GigabitEthernet0/1", + "trunk": {"encapsulation": "dot1q", "native_vlan": 10}, + } + ] + self.assertEqual(parsed_list, result["parsed"]) + + def test_ios_l2_interfaces_rendered(self): + set_module_args( + dict( + config=[ + dict( + access=dict(vlan=20), + mode="access", + name="GigabitEthernet0/1", + voice=dict(vlan=40), + ), + dict( + mode="trunk", + name="GigabitEthernet0/2", + trunk=dict( + allowed_vlans=["10-20", "40"], + encapsulation="isl", + native_vlan=20, + pruning_vlans=["12-15", "20"], + ), + ), + ], + state="rendered", + ) + ) + commands = [ + "interface GigabitEthernet0/1", + "switchport access vlan 20", + "switchport voice vlan 40", + "switchport mode access", + "interface GigabitEthernet0/2", + "switchport trunk encapsulation isl", + "switchport trunk native vlan 20", + "switchport trunk allowed vlan 10-20,40", + "switchport trunk pruning vlan 12-15,20", + "switchport mode trunk", + ] + result = self.execute_module(changed=False) + self.assertEqual(result["rendered"], commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging.py new file mode 100644 index 00000000..3f2c227a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging.py @@ -0,0 +1,161 @@ +# +# (c) 2016 Red Hat Inc. +# (c) 2017 Paul Neumann +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_logging +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosLoggingModule(TestIosModule): + + module = ios_logging + + def setUp(self): + super(TestIosLoggingModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_logging.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_logging.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_capabilities = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_logging.get_capabilities" + ) + self.get_capabilities = self.mock_get_capabilities.start() + self.get_capabilities.return_value = { + "device_info": {"network_os_version": "15.6(2)T"} + } + + def tearDown(self): + super(TestIosLoggingModule, self).tearDown() + + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_get_capabilities.stop() + + def load_fixtures(self, commands=None): + self.get_config.return_value = load_fixture("ios_logging_config.cfg") + self.load_config.return_value = None + + def test_ios_logging_buffer_size_changed_implicit(self): + set_module_args(dict(dest="buffered")) + commands = ["logging buffered 4096"] + self.execute_module(changed=True, commands=commands) + + def test_ios_logging_buffer_size_changed_explicit(self): + set_module_args(dict(dest="buffered", size=6000)) + commands = ["logging buffered 6000"] + self.execute_module(changed=True, commands=commands) + + def test_ios_logging_add_host(self): + set_module_args(dict(dest="host", name="192.168.1.1")) + commands = ["logging host 192.168.1.1"] + self.execute_module(changed=True, commands=commands) + + def test_ios_logging_host_idempotent(self): + set_module_args(dict(dest="host", name="2.3.4.5")) + commands = [] + self.execute_module(changed=False, commands=commands) + + def test_ios_logging_delete_non_exist_host(self): + set_module_args(dict(dest="host", name="192.168.1.1", state="absent")) + commands = [] + self.execute_module(changed=False, commands=commands) + + def test_ios_logging_delete_host(self): + set_module_args(dict(dest="host", name="2.3.4.5", state="absent")) + commands = ["no logging host 2.3.4.5"] + self.execute_module(changed=True, commands=commands) + + def test_ios_logging_configure_disabled_monitor_destination(self): + set_module_args(dict(dest="monitor", level="debugging")) + commands = ["logging monitor debugging"] + self.execute_module(changed=True, commands=commands) + + +class TestIosLoggingModuleIOS12(TestIosModule): + + module = ios_logging + + def setUp(self): + super(TestIosLoggingModuleIOS12, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_logging.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_logging.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_capabilities = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_logging.get_capabilities" + ) + self.get_capabilities = self.mock_get_capabilities.start() + self.get_capabilities.return_value = { + "device_info": {"network_os_version": "12.1(2)T"} + } + + def tearDown(self): + super(TestIosLoggingModuleIOS12, self).tearDown() + + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_get_capabilities.stop() + + def load_fixtures(self, commands=None): + self.get_config.return_value = load_fixture( + "ios_logging_config_ios12.cfg" + ) + self.load_config.return_value = None + + def test_ios_logging_add_host(self): + set_module_args(dict(dest="host", name="192.168.1.1")) + commands = ["logging 192.168.1.1"] + self.execute_module(changed=True, commands=commands) + + def test_ios_logging_host_idempotent(self): + set_module_args(dict(dest="host", name="2.3.4.5")) + commands = [] + self.execute_module(changed=False, commands=commands) + + def test_ios_logging_delete_non_exist_host(self): + set_module_args(dict(dest="host", name="192.168.1.1", state="absent")) + commands = [] + self.execute_module(changed=False, commands=commands) + + def test_ios_logging_delete_host(self): + set_module_args(dict(dest="host", name="2.3.4.5", state="absent")) + commands = ["no logging 2.3.4.5"] + self.execute_module(changed=True, commands=commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp.py new file mode 100644 index 00000000..38cf00a8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp.py @@ -0,0 +1,111 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_ntp +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosNtpModule(TestIosModule): + + module = ios_ntp + + def setUp(self): + super(TestIosNtpModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_ntp.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_ntp.load_config" + ) + self.load_config = self.mock_load_config.start() + + def tearDown(self): + super(TestIosNtpModule, self).tearDown() + self.mock_get_config.stop() + self.mock_load_config.stop() + + def load_fixtures(self, commands=None): + self.get_config.return_value = load_fixture( + "ios_ntp_config.cfg" + ).strip() + self.load_config.return_value = dict(diff=None, session="session") + + def test_ios_ntp_idempotent(self): + set_module_args( + dict( + server="10.75.32.5", + source_int="Loopback0", + acl="NTP_ACL", + logging=True, + auth=True, + auth_key="15435A030726242723273C21181319000A", + key_id="10", + state="present", + ) + ) + commands = [] + self.execute_module(changed=False, commands=commands) + + def test_ios_ntp_config(self): + set_module_args( + dict( + server="10.75.33.5", + source_int="Vlan2", + acl="NTP_ACL", + logging=True, + auth=True, + auth_key="15435A030726242723273C21181319000A", + key_id="10", + state="present", + ) + ) + commands = ["ntp server 10.75.33.5", "ntp source Vlan2"] + self.execute_module(changed=True, commands=commands) + + def test_ios_ntp_remove(self): + set_module_args( + dict( + server="10.75.32.5", + source_int="Loopback0", + acl="NTP_ACL", + logging=True, + auth=True, + auth_key="15435A030726242723273C21181319000A", + key_id="10", + state="absent", + ) + ) + commands = [ + "no ntp server 10.75.32.5", + "no ntp source Loopback0", + "no ntp access-group peer NTP_ACL", + "no ntp logging", + "no ntp authenticate", + "no ntp trusted-key 10", + "no ntp authentication-key 10 md5 15435A030726242723273C21181319000A 7", + ] + self.execute_module(changed=True, commands=commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py new file mode 100644 index 00000000..3a49a1bc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py @@ -0,0 +1,405 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_ospf_interfaces +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosOspfInterfacesModule(TestIosModule): + module = ios_ospf_interfaces + + def setUp(self): + super(TestIosOspfInterfacesModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." + "get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module." + "get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_edit_config = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ospf_interfaces.ospf_interfaces." + "Ospf_InterfacesFacts.get_ospf_interfaces_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosOspfInterfacesModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_edit_config.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + return load_fixture("ios_ospf_interfaces.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_ios_ospf_interfaces_merged(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/2", + address_family=[ + dict( + afi="ipv4", + bfd=True, + cost=dict(interface_cost=30), + network=dict(broadcast=True), + priority=60, + resync_timeout=90, + ttl_security=dict(hops=120), + authentication=dict(key_chain="test_key"), + ), + dict( + afi="ipv6", + bfd=True, + dead_interval=dict(time=100), + network=dict(manet=True), + priority=50, + ), + ], + ), + dict( + name="GigabitEthernet0/3", + address_family=[ + dict( + afi="ipv4", + bfd=True, + cost=dict(interface_cost=50), + priority=50, + ttl_security=dict(hops=150), + ) + ], + ), + ], + state="merged", + ) + ) + commands = [ + "interface GigabitEthernet0/3", + "ip ospf bfd", + "ip ospf cost 50", + "ip ospf priority 50", + "ip ospf ttl-security hops 150", + "interface GigabitEthernet0/2", + "ip ospf authentication key-chain test_key", + "ip ospf bfd", + "ip ospf cost 30", + "ip ospf network broadcast", + "ip ospf priority 60", + "ip ospf resync-timeout 90", + "ip ospf ttl-security hops 120", + "ipv6 ospf bfd", + "ipv6 ospf dead-interval 100", + "ipv6 ospf network manet", + "ipv6 ospf priority 50", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_ospf_interfaces_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + address_family=[ + dict( + afi="ipv4", + adjacency=True, + cost=dict(interface_cost=30), + priority=40, + process=dict(id=10, area_id="20"), + ttl_security=dict(hops=50), + ) + ], + name="GigabitEthernet0/2", + ), + dict( + address_family=[ + dict( + afi="ipv6", + adjacency=True, + priority=20, + process=dict(id=55, area_id="105"), + transmit_delay=30, + ) + ], + name="GigabitEthernet0/3", + ), + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_ospf_interfaces_replaced(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/3", + address_family=[ + dict( + afi="ipv4", + bfd=True, + cost=dict(interface_cost=50), + priority=50, + ttl_security=dict(hops=150), + ) + ], + ) + ], + state="replaced", + ) + ) + commands = [ + "interface GigabitEthernet0/3", + "ip ospf bfd", + "ip ospf cost 50", + "ip ospf priority 50", + "ip ospf ttl-security hops 150", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_ospf_interfaces_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + address_family=[ + dict( + afi="ipv4", + adjacency=True, + cost=dict(interface_cost=30), + priority=40, + process=dict(id=10, area_id="20"), + ttl_security=dict(hops=50), + ) + ], + name="GigabitEthernet0/2", + ), + dict( + address_family=[ + dict( + afi="ipv6", + adjacency=True, + priority=20, + process=dict(id=55, area_id="105"), + transmit_delay=30, + ) + ], + name="GigabitEthernet0/3", + ), + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_ospf_interfaces_overridden(self): + set_module_args( + dict( + config=[ + dict( + address_family=[ + dict( + afi="ipv6", + manet=dict(cost=dict(percent=10)), + priority=40, + process=dict(id=10, area_id="20"), + transmit_delay=50, + ) + ], + name="GigabitEthernet0/3", + ) + ], + state="overridden", + ) + ) + commands = [ + "interface GigabitEthernet0/2", + "no ip ospf 10 area 20", + "no ip ospf adjacency stagger disable", + "no ip ospf cost 30", + "no ip ospf priority 40", + "no ip ospf ttl-security hops 50", + "interface GigabitEthernet0/3", + "ipv6 ospf 10 area 20", + "no ipv6 ospf adjacency stagger disable", + "ipv6 ospf manet peering cost percent 10", + "ipv6 ospf priority 40", + "ipv6 ospf transmit-delay 50" "", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_ospf_interfaces_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + address_family=[ + dict( + afi="ipv4", + adjacency=True, + cost=dict(interface_cost=30), + priority=40, + process=dict(id=10, area_id="20"), + ttl_security=dict(hops=50), + ) + ], + name="GigabitEthernet0/2", + ), + dict( + address_family=[ + dict( + afi="ipv6", + adjacency=True, + priority=20, + process=dict(id=55, area_id="105"), + transmit_delay=30, + ) + ], + name="GigabitEthernet0/3", + ), + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_ospf_interfaces_deleted_interface(self): + set_module_args( + dict(config=[dict(name="GigabitEthernet0/2")], state="deleted") + ) + commands = [ + "interface GigabitEthernet0/2", + "no ip ospf priority 40", + "no ip ospf adjacency stagger disable", + "no ip ospf ttl-security hops 50", + "no ip ospf 10 area 20", + "no ip ospf cost 30", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_ospf_interfaces_deleted_all(self): + set_module_args(dict(config=[], state="deleted")) + commands = [ + "interface GigabitEthernet0/3", + "no ipv6 ospf 55 area 105", + "no ipv6 ospf adjacency stagger disable", + "no ipv6 ospf priority 20", + "no ipv6 ospf transmit-delay 30", + "interface GigabitEthernet0/2", + "no ip ospf 10 area 20", + "no ip ospf adjacency stagger disable", + "no ip ospf cost 30", + "no ip ospf priority 40", + "no ip ospf ttl-security hops 50", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_ospf_interfaces_rendered(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/2", + address_family=[ + dict( + afi="ipv4", + bfd=True, + cost=dict(interface_cost=30), + network=dict(broadcast=True), + priority=60, + resync_timeout=90, + ttl_security=dict(hops=120), + ), + dict( + afi="ipv6", + bfd=True, + dead_interval=dict(time=100), + network=dict(manet=True), + priority=50, + ), + ], + ), + dict( + name="GigabitEthernet0/3", + address_family=[ + dict( + afi="ipv4", + bfd=True, + cost=dict(interface_cost=50), + priority=50, + ttl_security=dict(hops=150), + ) + ], + ), + ], + state="rendered", + ) + ) + commands = [ + "interface GigabitEthernet0/3", + "ip ospf bfd", + "ip ospf cost 50", + "ip ospf priority 50", + "ip ospf ttl-security hops 150", + "interface GigabitEthernet0/2", + "ip ospf bfd", + "ip ospf cost 30", + "ip ospf network broadcast", + "ip ospf priority 60", + "ip ospf resync-timeout 90", + "ip ospf ttl-security hops 120", + "ipv6 ospf bfd", + "ipv6 ospf dead-interval 100", + "ipv6 ospf network manet", + "ipv6 ospf priority 50", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(commands)) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py new file mode 100644 index 00000000..97e9b81c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py @@ -0,0 +1,353 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_ospfv2 +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosOspfV2Module(TestIosModule): + module = ios_ospfv2 + + def setUp(self): + super(TestIosOspfV2Module, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." + "get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module." + "get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_edit_config = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ospfv2.ospfv2." + "Ospfv2Facts.get_ospfv2_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosOspfV2Module, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_edit_config.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + return load_fixture("ios_ospfv2.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_ios_ospfv2_merged(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="100", + auto_cost=dict(reference_bandwidth="4"), + distribute_list=dict( + acls=[ + dict(direction="out", name="10"), + dict(direction="in", name="123"), + ] + ), + network=[ + dict( + address="198.51.100.0", + wildcard_bits="0.0.0.255", + area=5, + ), + dict( + address="192.0.2.0", + wildcard_bits="0.0.0.255", + area=5, + ), + ], + domain_id=dict( + ip_address=dict(address="192.0.3.1") + ), + max_metric=dict( + on_startup=dict(time=100), router_lsa=True + ), + vrf="blue", + ) + ] + ), + state="merged", + ) + ) + commands = [ + "router ospf 100 vrf blue", + "auto-cost reference-bandwidth 4", + "distribute-list 123 in", + "distribute-list 10 out", + "network 198.51.100.0 0.0.0.255 area 5", + "network 192.0.2.0 0.0.0.255 area 5", + "domain-id 192.0.3.1", + "max-metric router-lsa on-startup 100", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_ospfv2_merged_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="200", + auto_cost=dict(reference_bandwidth="4"), + distribute_list=dict( + acls=[ + dict(direction="out", name="10"), + dict(direction="in", name="123"), + ] + ), + domain_id=dict( + ip_address=dict(address="192.0.3.1") + ), + max_metric=dict( + on_startup=dict(time=100), router_lsa=True + ), + areas=[dict(area_id="10", capability=True)], + vrf="blue", + ) + ] + ), + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_ospfv2_replaced(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="200", + auto_cost=dict(reference_bandwidth="4"), + domain_id=dict( + ip_address=dict(address="192.0.1.1") + ), + max_metric=dict( + on_startup=dict(time=200), router_lsa=True + ), + areas=[dict(area_id="10", capability=True)], + vrf="blue", + ) + ] + ), + state="replaced", + ) + ) + commands = [ + "router ospf 200 vrf blue", + "no distribute-list 123 in", + "no distribute-list 10 out", + "domain-id 192.0.1.1", + "max-metric router-lsa on-startup 200", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + # + def test_ios_ospfv2_replaced_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="200", + auto_cost=dict(reference_bandwidth="4"), + distribute_list=dict( + acls=[ + dict(direction="out", name="10"), + dict(direction="in", name="123"), + ] + ), + domain_id=dict( + ip_address=dict(address="192.0.3.1") + ), + max_metric=dict( + on_startup=dict(time=100), router_lsa=True + ), + areas=[dict(area_id="10", capability=True)], + vrf="blue", + ) + ] + ), + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_ospfv2_overridden(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="200", + auto_cost=dict(reference_bandwidth="4"), + domain_id=dict( + ip_address=dict(address="192.0.1.1") + ), + max_metric=dict( + on_startup=dict(time=200), router_lsa=True + ), + areas=[dict(area_id="10", capability=True)], + vrf="blue", + ) + ] + ), + state="overridden", + ) + ) + + commands = [ + "router ospf 200 vrf blue", + "no distribute-list 10 out", + "no distribute-list 123 in", + "domain-id 192.0.1.1", + "max-metric router-lsa on-startup 200", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_ospfv2_overridden_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="200", + auto_cost=dict(reference_bandwidth="4"), + distribute_list=dict( + acls=[ + dict(direction="out", name="10"), + dict(direction="in", name="123"), + ] + ), + domain_id=dict( + ip_address=dict(address="192.0.3.1") + ), + max_metric=dict( + on_startup=dict(time=100), router_lsa=True + ), + areas=[dict(area_id="10", capability=True)], + vrf="blue", + ) + ] + ), + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_ospfv2_deleted(self): + set_module_args( + dict( + config=dict(processes=[dict(process_id="200", vrf="blue")]), + state="deleted", + ) + ) + commands = ["no router ospf 200 vrf blue"] + self.execute_module(changed=True, commands=commands) + + def test_ios_ospfv2_parsed(self): + set_module_args( + dict( + running_config="router ospf 1\n area 5 authentication\n area 5 capability default-exclusion", + state="parsed", + ) + ) + result = self.execute_module(changed=False) + parsed_list = { + "processes": [ + { + "areas": [ + { + "area_id": "5", + "authentication": {"enable": True}, + "capability": True, + } + ], + "process_id": 1, + } + ] + } + self.assertEqual(parsed_list, result["parsed"]) + + def test_ios_ospfv2_rendered(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="100", + vrf="blue", + auto_cost=dict(reference_bandwidth="4"), + distribute_list=dict( + acls=[ + dict(direction="out", name="10"), + dict(direction="in", name="123"), + ] + ), + domain_id=dict( + ip_address=dict(address="192.0.3.1") + ), + max_metric=dict( + on_startup=dict(time=100), router_lsa=True + ), + ) + ] + ), + state="rendered", + ) + ) + commands = [ + "auto-cost reference-bandwidth 4", + "distribute-list 10 out", + "distribute-list 123 in", + "domain-id 192.0.3.1", + "max-metric router-lsa on-startup 100", + "router ospf 100 vrf blue", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py new file mode 100644 index 00000000..bacbc3fa --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py @@ -0,0 +1,427 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_ospfv3 +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosOspfV3Module(TestIosModule): + module = ios_ospfv3 + + def setUp(self): + super(TestIosOspfV3Module, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." + "get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module." + "get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_edit_config = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ospfv3.ospfv3." + "Ospfv3Facts.get_ospfv3_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosOspfV3Module, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_edit_config.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + return load_fixture("ios_ospfv3.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_ios_ospfv3_merged(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="1", + auto_cost=dict(reference_bandwidth="4"), + areas=[dict(area_id=10, default_cost=10)], + address_family=[ + dict( + afi="ipv4", + unicast=True, + vrf="blue", + adjacency=dict( + min_adjacency=100, max_adjacency=100 + ), + ) + ], + ) + ] + ), + state="merged", + ) + ) + commands = [ + "router ospfv3 1", + "auto-cost reference-bandwidth 4", + "area 10 default-cost 10", + "address-family ipv4 unicast vrf blue", + "adjacency stagger 100 100", + "exit-address-family", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_ospfv3_merged_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="1", + max_metric=dict( + router_lsa=True, on_startup=dict(time=110) + ), + areas=[ + dict( + area_id=10, + nssa=dict( + default_information_originate=dict( + metric=10 + ) + ), + ) + ], + address_family=[ + dict( + afi="ipv4", + unicast=True, + vrf="blue", + adjacency=dict( + min_adjacency=50, max_adjacency=50 + ), + areas=[ + dict( + area_id=25, + nssa=dict( + default_information_originate=dict( + metric=25, nssa_only=True + ) + ), + ) + ], + ) + ], + ) + ] + ), + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_ospfv3_replaced(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="1", + max_metric=dict( + router_lsa=True, on_startup=dict(time=100) + ), + address_family=[ + dict( + afi="ipv4", + unicast=True, + vrf="blue", + adjacency=dict( + min_adjacency=100, max_adjacency=100 + ), + ) + ], + ) + ] + ), + state="replaced", + ) + ) + commands = [ + "router ospfv3 1", + "max-metric router-lsa on-startup 100", + "no area 10 nssa default-information-originate metric 10", + "address-family ipv4 unicast vrf blue", + "adjacency stagger 100 100", + "exit-address-family", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + # + def test_ios_ospfv3_replaced_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="1", + max_metric=dict( + router_lsa=True, on_startup=dict(time=110) + ), + areas=[ + dict( + area_id=10, + nssa=dict( + default_information_originate=dict( + metric=10 + ) + ), + ) + ], + address_family=[ + dict( + afi="ipv4", + unicast=True, + vrf="blue", + adjacency=dict( + min_adjacency=50, max_adjacency=50 + ), + areas=[ + dict( + area_id=25, + nssa=dict( + default_information_originate=dict( + metric=25, nssa_only=True + ) + ), + ) + ], + ) + ], + ) + ] + ), + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_ospfv3_overridden(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="200", + max_metric=dict( + router_lsa=True, on_startup=dict(time=200) + ), + areas=[ + dict( + area_id=10, + nssa=dict( + default_information_originate=dict( + metric=10 + ) + ), + ) + ], + address_family=[ + dict( + afi="ipv4", + unicast=True, + adjacency=dict( + min_adjacency=50, max_adjacency=50 + ), + areas=[ + dict( + area_id=200, + nssa=dict( + default_information_originate=dict( + metric=200, nssa_only=True + ) + ), + ) + ], + ) + ], + ) + ] + ), + state="overridden", + ) + ) + + commands = [ + "no router ospfv3 1", + "router ospfv3 200", + "max-metric router-lsa on-startup 200", + "area 10 nssa default-information-originate metric 10", + "address-family ipv4 unicast", + "adjacency stagger 50 50", + "area 200 nssa default-information-originate metric 200 nssa-only", + "exit-address-family", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_ospfv3_overridden_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="1", + max_metric=dict( + router_lsa=True, on_startup=dict(time=110) + ), + areas=[ + dict( + area_id=10, + nssa=dict( + default_information_originate=dict( + metric=10 + ) + ), + ) + ], + address_family=[ + dict( + afi="ipv4", + unicast=True, + vrf="blue", + adjacency=dict( + min_adjacency=50, max_adjacency=50 + ), + areas=[ + dict( + area_id=25, + nssa=dict( + default_information_originate=dict( + metric=25, nssa_only=True + ) + ), + ) + ], + ) + ], + ) + ] + ), + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_ospfv3_deleted(self): + set_module_args( + dict( + config=dict(processes=[dict(process_id="1")]), state="deleted" + ) + ) + commands = ["no router ospfv3 1"] + self.execute_module(changed=True, commands=commands) + + def test_ios_ospfv3_parsed(self): + set_module_args( + dict(running_config="router ospfv3 1\n area 5", state="parsed") + ) + result = self.execute_module(changed=False) + parsed_list = { + "processes": [{"areas": [{"area_id": "5"}], "process_id": 1}] + } + self.assertEqual(parsed_list, result["parsed"]) + + def test_ios_ospfv3_rendered(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="1", + max_metric=dict( + router_lsa=True, on_startup=dict(time=110) + ), + areas=[ + dict( + area_id=10, + nssa=dict( + default_information_originate=dict( + metric=10 + ) + ), + ) + ], + address_family=[ + dict( + afi="ipv4", + unicast=True, + vrf="blue", + adjacency=dict( + min_adjacency=50, max_adjacency=50 + ), + areas=[ + dict( + area_id=25, + nssa=dict( + default_information_originate=dict( + metric=25, nssa_only=True + ) + ), + ) + ], + ) + ], + ) + ] + ), + state="rendered", + ) + ) + commands = [ + "address-family ipv4 unicast vrf blue", + "adjacency stagger 50 50", + "area 10 nssa default-information-originate metric 10", + "area 25 nssa default-information-originate metric 25 nssa-only", + "exit-address-family", + "max-metric router-lsa on-startup 110", + "router ospfv3 1", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py new file mode 100644 index 00000000..72e45e9d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py @@ -0,0 +1,90 @@ +# +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_ping +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosPingModule(TestIosModule): + """ Class used for Unit Tests agains ios_ping module """ + + module = ios_ping + + def setUp(self): + super(TestIosPingModule, self).setUp() + self.mock_run_commands = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_ping.run_commands" + ) + self.run_commands = self.mock_run_commands.start() + + def tearDown(self): + super(TestIosPingModule, self).tearDown() + self.mock_run_commands.stop() + + def load_fixtures(self, commands=None): + def load_from_file(*args, **kwargs): + commands = kwargs["commands"] + output = list() + + for command in commands: + filename = str(command).split(" | ")[0].replace(" ", "_") + output.append(load_fixture("ios_ping_%s" % filename)) + return output + + self.run_commands.side_effect = load_from_file + + def test_ios_ping_expected_success(self): + """ Test for successful pings when destination should be reachable """ + set_module_args(dict(count=2, dest="8.8.8.8")) + self.execute_module() + + def test_ios_ping_expected_failure(self): + """ Test for unsuccessful pings when destination should not be reachable """ + set_module_args(dict(count=2, dest="10.255.255.250", state="absent")) + self.execute_module() + + def test_ios_ping_unexpected_success(self): + """ Test for successful pings when destination should not be reachable - FAIL. """ + set_module_args(dict(count=2, dest="8.8.8.8", state="absent")) + self.execute_module(failed=True) + + def test_ios_ping_unexpected_failure(self): + """ Test for unsuccessful pings when destination should be reachable - FAIL. """ + set_module_args(dict(count=2, dest="10.255.255.250")) + self.execute_module(failed=True) + + def test_ios_ping_with_size(self): + """ Test for successful pings using size option. """ + set_module_args(dict(size=1400, dest="8.8.8.8")) + commands = ["ping 8.8.8.8 size 1400"] + self.execute_module(commands=commands) + + def test_ios_ping_with_size_df_bit(self): + """ Test for successful pings using size and df-bit options. """ + set_module_args(dict(size=1400, df_bit=True, dest="8.8.8.8")) + commands = ["ping 8.8.8.8 size 1400 df-bit"] + self.execute_module(commands=commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py new file mode 100644 index 00000000..624ff16d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py @@ -0,0 +1,707 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_static_routes +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosStaticRoutesModule(TestIosModule): + module = ios_static_routes + + def setUp(self): + super(TestIosStaticRoutesModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." + "get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts." + "get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_edit_config = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.static_routes.static_routes." + "Static_RoutesFacts.get_static_routes_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosStaticRoutesModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_edit_config.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None, transport="cli"): + def load_from_file(*args, **kwargs): + return load_fixture("ios_static_routes_config.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_ios_static_routes_merged(self): + set_module_args( + dict( + config=[ + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.0.2.0 255.255.255.0", + next_hops=[ + dict( + forward_router_address="192.0.2.1", + name="test_vrf", + tag=50, + track=150, + ) + ], + ) + ], + ) + ], + ), + dict( + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="198.51.100.0 255.255.255.0", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="route_1", + distance_metric=110, + tag=40, + multicast=True, + ) + ], + ) + ], + ) + ] + ), + ], + state="merged", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "ip route vrf ansible_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", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_static_routes_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="0.0.0.0/0", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="test_vrf_1", + tag=100, + track=150, + ) + ], + ) + ], + ) + ], + ), + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.0.2.0/24", + next_hops=[ + dict( + forward_router_address="192.0.2.1", + name="test_vrf_2", + tag=50, + track=175, + ) + ], + ) + ], + ) + ], + ), + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.51.110.0/32", + next_hops=[ + dict( + distance_metric=10, + forward_router_address="192.51.111.1", + interface="GigabitEthernet0/2", + name="partner", + ) + ], + ) + ], + ) + ], + ), + dict( + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="198.51.100.0/24", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="route_1", + distance_metric=110, + tag=60, + multicast=True, + ) + ], + ) + ], + ) + ] + ), + dict( + address_families=[ + dict( + afi="ipv6", + routes=[ + dict( + dest="2001:DB8:0:3::/64", + next_hops=[ + dict( + forward_router_address="2001:DB8:0:3::2", + interface="GigabitEthernet0/2", + name="test_v6", + tag=105, + ) + ], + ) + ], + ) + ] + ), + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_static_routes_replaced(self): + set_module_args( + dict( + config=[ + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.0.2.0 255.255.255.0", + next_hops=[ + dict( + forward_router_address="192.0.2.1", + name="replaced_vrf", + tag=10, + track=170, + ) + ], + ) + ], + ) + ], + ), + dict( + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="198.51.100.0 255.255.255.0", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="replaced_route_1", + distance_metric=110, + tag=60, + multicast=True, + ) + ], + ) + ], + ) + ] + ), + ], + state="replaced", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "ip route vrf ansible_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name replaced_vrf track 170 tag 10", + "ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name replaced_route_1 tag 60", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_static_routes_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="0.0.0.0/0", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="test_vrf_1", + tag=100, + track=150, + ) + ], + ) + ], + ) + ], + ), + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.0.2.0/24", + next_hops=[ + dict( + forward_router_address="192.0.2.1", + name="test_vrf_2", + tag=50, + track=175, + ) + ], + ) + ], + ) + ], + ), + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.51.110.0/32", + next_hops=[ + dict( + distance_metric=10, + forward_router_address="192.51.111.1", + interface="GigabitEthernet0/2", + name="partner", + ) + ], + ) + ], + ) + ], + ), + dict( + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="198.51.100.0/24", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="route_1", + distance_metric=110, + tag=60, + multicast=True, + ) + ], + ) + ], + ) + ] + ), + dict( + address_families=[ + dict( + afi="ipv6", + routes=[ + dict( + dest="2001:DB8:0:3::/64", + next_hops=[ + dict( + forward_router_address="2001:DB8:0:3::2", + interface="GigabitEthernet0/2", + name="test_v6", + tag=105, + ) + ], + ) + ], + ) + ] + ), + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_static_routes_overridden(self): + set_module_args( + dict( + config=[ + dict( + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="198.51.100.0 255.255.255.0", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="override_route_1", + distance_metric=150, + tag=50, + multicast=True, + ) + ], + ) + ], + ) + ] + ) + ], + state="overridden", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name route_1 tag 60", + "no ip route vrf ansible_vrf 0.0.0.0 0.0.0.0 198.51.101.1 name test_vrf_1 track 150 tag 100", + "no ip route vrf ansible_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name test_vrf_2 track 175 tag 50", + "no ip route vrf ansible_vrf 192.51.110.0 255.255.255.255 GigabitEthernet0/2 192.51.111.1 10 name partner", + "no ipv6 route 2001:DB8:0:3::/64 GigabitEthernet0/2 2001:DB8:0:3::2 name test_v6 tag 105", + "ip route 198.51.100.0 255.255.255.0 198.51.101.1 150 multicast name override_route_1 tag 50", + ] + + self.assertEqual(result["commands"], commands) + + def test_ios_static_routes_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="0.0.0.0/0", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="test_vrf_1", + tag=100, + track=150, + ) + ], + ) + ], + ) + ], + ), + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.0.2.0/24", + next_hops=[ + dict( + forward_router_address="192.0.2.1", + name="test_vrf_2", + tag=50, + track=175, + ) + ], + ) + ], + ) + ], + ), + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.51.110.0/32", + next_hops=[ + dict( + distance_metric=10, + forward_router_address="192.51.111.1", + interface="GigabitEthernet0/2", + name="partner", + ) + ], + ) + ], + ) + ], + ), + dict( + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="198.51.100.0/24", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="route_1", + distance_metric=110, + tag=60, + multicast=True, + ) + ], + ) + ], + ) + ] + ), + dict( + address_families=[ + dict( + afi="ipv6", + routes=[ + dict( + dest="2001:DB8:0:3::/64", + next_hops=[ + dict( + forward_router_address="2001:DB8:0:3::2", + interface="GigabitEthernet0/2", + name="test_v6", + tag=105, + ) + ], + ) + ], + ) + ] + ), + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_delete_static_route_config(self): + set_module_args( + dict( + config=[ + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.0.2.0/24", + next_hops=[ + dict( + forward_router_address="192.0.2.1", + name="test_vrf", + tag=50, + track=175, + ) + ], + ) + ], + ) + ], + ), + dict( + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="198.51.100.0/24", + next_hops=[ + dict( + forward_router_address="198.51.101.1", + name="route_1", + distance_metric=110, + tag=60, + multicast=True, + ) + ], + ) + ], + ) + ] + ), + ], + state="deleted", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "no ip route vrf ansible_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name test_vrf track 175 tag 50", + "no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name route_1 tag 60", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_delete_static_route_dest_based(self): + set_module_args( + dict( + config=[ + dict( + address_families=[ + dict( + afi="ipv4", + routes=[dict(dest="198.51.100.0/24")], + ) + ] + ) + ], + state="deleted", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 multicast name route_1 tag 60" + ] + self.assertEqual(result["commands"], commands) + + def test_ios_delete_static_route_vrf_based(self): + set_module_args( + dict( + config=[ + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", routes=[dict(dest="192.0.2.0/24")] + ) + ], + ) + ], + state="deleted", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "no ip route vrf ansible_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name test_vrf_2 track 175 tag 50" + ] + self.assertEqual(result["commands"], commands) + + def test_static_route_rendered(self): + set_module_args( + dict( + config=[ + dict( + vrf="ansible_vrf", + address_families=[ + dict( + afi="ipv4", + routes=[ + dict( + dest="192.0.2.0/24", + next_hops=[ + dict( + forward_router_address="192.0.2.1", + name="test_vrf", + tag=50, + track=175, + ) + ], + ) + ], + ) + ], + ) + ], + state="rendered", + ) + ) + commands = [ + "ip route vrf ansible_vrf 192.0.2.0 255.255.255.0 192.0.2.1 name test_vrf track 175 tag 50" + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_system.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_system.py new file mode 100644 index 00000000..6c62d39f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_system.py @@ -0,0 +1,155 @@ +# +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_system +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosSystemModule(TestIosModule): + + module = ios_system + + def setUp(self): + super(TestIosSystemModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_system.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_system.load_config" + ) + self.load_config = self.mock_load_config.start() + + def tearDown(self): + super(TestIosSystemModule, self).tearDown() + self.mock_get_config.stop() + self.mock_load_config.stop() + + def load_fixtures(self, commands=None): + self.get_config.return_value = load_fixture("ios_system_config.cfg") + self.load_config.return_value = None + + def test_ios_system_hostname_changed(self): + set_module_args(dict(hostname="foo")) + commands = ["hostname foo"] + self.execute_module(changed=True, commands=commands) + + def test_ios_system_domain_name(self): + set_module_args(dict(domain_name=["test.com"])) + commands = [ + "ip domain name test.com", + "no ip domain name eng.example.net", + "no ip domain name vrf management eng.example.net", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_system_domain_name_complex(self): + set_module_args( + dict( + domain_name=[ + {"name": "test.com", "vrf": "test"}, + {"name": "eng.example.net"}, + ] + ) + ) + commands = [ + "ip domain name vrf test test.com", + "no ip domain name vrf management eng.example.net", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_system_domain_search(self): + set_module_args(dict(domain_search=["ansible.com", "redhat.com"])) + commands = [ + "no ip domain list vrf management example.net", + "no ip domain list example.net", + "no ip domain list example.com", + "ip domain list ansible.com", + "ip domain list redhat.com", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_system_domain_search_complex(self): + set_module_args( + dict(domain_search=[{"name": "ansible.com", "vrf": "test"}]) + ) + commands = [ + "no ip domain list vrf management example.net", + "no ip domain list example.net", + "no ip domain list example.com", + "ip domain list vrf test ansible.com", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_system_lookup_source(self): + set_module_args(dict(lookup_source="Ethernet1")) + commands = ["ip domain lookup source-interface Ethernet1"] + self.execute_module(changed=True, commands=commands) + + def test_ios_system_name_servers(self): + name_servers = ["8.8.8.8", "8.8.4.4"] + set_module_args(dict(name_servers=name_servers)) + commands = [ + "no ip name-server vrf management 8.8.8.8", + "ip name-server 8.8.4.4", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def rest_ios_system_name_servers_complex(self): + name_servers = dict(server="8.8.8.8", vrf="test") + set_module_args(dict(name_servers=name_servers)) + commands = [ + "no name-server 8.8.8.8", + "no name-server vrf management 8.8.8.8", + "ip name-server vrf test 8.8.8.8", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_system_state_absent(self): + set_module_args(dict(state="absent")) + commands = [ + "no hostname", + "no ip domain lookup source-interface GigabitEthernet0/0", + "no ip domain list vrf management", + "no ip domain list", + "no ip domain name vrf management", + "no ip domain name", + "no ip name-server vrf management", + "no ip name-server", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_system_no_change(self): + set_module_args(dict(hostname="ios01")) + self.execute_module(commands=[]) + + def test_ios_system_missing_vrf(self): + name_servers = dict(server="8.8.8.8", vrf="missing") + set_module_args(dict(name_servers=name_servers)) + self.execute_module(failed=True) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py new file mode 100644 index 00000000..e24542d5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py @@ -0,0 +1,170 @@ +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_user +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosUserModule(TestIosModule): + + module = ios_user + + def setUp(self): + super(TestIosUserModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_user.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_user.load_config" + ) + self.load_config = self.mock_load_config.start() + + def tearDown(self): + super(TestIosUserModule, self).tearDown() + self.mock_get_config.stop() + self.mock_load_config.stop() + + def load_fixtures(self, commands=None, transport="cli"): + self.get_config.return_value = load_fixture("ios_user_config.cfg") + self.load_config.return_value = dict(diff=None, session="session") + + def test_ios_user_create(self): + set_module_args(dict(name="test", nopassword=True)) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["username test nopassword"]) + + def test_ios_user_delete(self): + set_module_args(dict(name="ansible", state="absent")) + result = self.execute_module(changed=True) + cmds = [ + { + "command": "no username ansible", + "answer": "y", + "newline": False, + "prompt": "This operation will remove all username related configurations with same name", + } + ] + + result_cmd = [] + for i in result["commands"]: + result_cmd.append(i) + + self.assertEqual(result_cmd, cmds) + + def test_ios_user_password(self): + set_module_args(dict(name="ansible", configured_password="test")) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["username ansible secret test"]) + + def test_ios_user_privilege(self): + set_module_args(dict(name="ansible", privilege=15)) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["username ansible privilege 15"]) + + def test_ios_user_privilege_invalid(self): + set_module_args(dict(name="ansible", privilege=25)) + self.execute_module(failed=True) + + def test_ios_user_purge(self): + set_module_args(dict(purge=True)) + result = self.execute_module(changed=True) + cmd = { + "command": "no username ansible", + "answer": "y", + "newline": False, + "prompt": "This operation will remove all username related configurations with same name", + } + + result_cmd = [] + for i in result["commands"]: + result_cmd.append(i) + + self.assertEqual(result_cmd, [cmd]) + + def test_ios_user_view(self): + set_module_args(dict(name="ansible", view="test")) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["username ansible view test"]) + + def test_ios_user_update_password_changed(self): + set_module_args( + dict( + name="test", + configured_password="test", + update_password="on_create", + ) + ) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["username test secret test"]) + + def test_ios_user_update_password_on_create_ok(self): + set_module_args( + dict( + name="ansible", + configured_password="test", + update_password="on_create", + ) + ) + self.execute_module() + + def test_ios_user_update_password_always(self): + set_module_args( + dict( + name="ansible", + configured_password="test", + update_password="always", + ) + ) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["username ansible secret test"]) + + def test_ios_user_set_sshkey(self): + set_module_args(dict(name="ansible", sshkey="dGVzdA==")) + commands = [ + "ip ssh pubkey-chain", + "username ansible", + "key-hash ssh-rsa 098F6BCD4621D373CADE4E832627B4F6", + "exit", + "exit", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(result["commands"], commands) + + def test_ios_user_set_sshkey_multiple(self): + set_module_args(dict(name="ansible", sshkey=["dGVzdA==", "eHWacB2=="])) + commands = [ + "ip ssh pubkey-chain", + "username ansible", + "key-hash ssh-rsa 098F6BCD4621D373CADE4E832627B4F6", + "key-hash ssh-rsa A019918340A1E9183388D9A675603036", + "exit", + "exit", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(result["commands"], commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlan.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlan.py new file mode 100644 index 00000000..ae18be6a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlan.py @@ -0,0 +1,161 @@ +# (c) 2018 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_vlan +from ansible_collections.cisco.ios.plugins.modules.ios_vlan import ( + parse_vlan_brief, +) +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosVlanModule(TestIosModule): + + module = ios_vlan + + def setUp(self): + super(TestIosVlanModule, self).setUp() + + self.mock_run_commands = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_vlan.run_commands" + ) + self.run_commands = self.mock_run_commands.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_vlan.load_config" + ) + self.load_config = self.mock_load_config.start() + + def tearDown(self): + super(TestIosVlanModule, self).tearDown() + self.mock_run_commands.stop() + self.mock_load_config.stop() + + def load_fixtures(self, commands=None, transport="cli"): + self.run_commands.return_value = [load_fixture("ios_vlan_config.cfg")] + self.load_config.return_value = {"diff": None, "session": "session"} + + def test_ios_vlan_create(self): + set_module_args({"vlan_id": "3", "name": "test", "state": "present"}) + result = self.execute_module(changed=True) + expected_commands = ["vlan 3", "name test"] + self.assertEqual(result["commands"], expected_commands) + + def test_ios_vlan_id_startwith_9(self): + set_module_args({"vlan_id": "9", "name": "vlan9", "state": "present"}) + result = self.execute_module(changed=False) + expected_commands = [] + self.assertEqual(result["commands"], expected_commands) + + def test_ios_vlan_rename(self): + set_module_args({"vlan_id": "2", "name": "test", "state": "present"}) + result = self.execute_module(changed=True) + expected_commands = ["vlan 2", "name test"] + self.assertEqual(result["commands"], expected_commands) + + def test_ios_vlan_with_interfaces(self): + set_module_args( + { + "vlan_id": "2", + "name": "vlan2", + "state": "present", + "interfaces": ["GigabitEthernet1/0/8", "GigabitEthernet1/0/7"], + } + ) + result = self.execute_module(changed=True) + expected_commands = [ + "vlan 2", + "interface GigabitEthernet1/0/8", + "switchport mode access", + "switchport access vlan 2", + "vlan 2", + "interface GigabitEthernet1/0/6", + "switchport mode access", + "no switchport access vlan 2", + ] + self.assertEqual(result["commands"], expected_commands) + + def test_ios_vlan_with_interfaces_and_newvlan(self): + set_module_args( + { + "vlan_id": "3", + "name": "vlan3", + "state": "present", + "interfaces": ["GigabitEthernet1/0/8", "GigabitEthernet1/0/7"], + } + ) + result = self.execute_module(changed=True) + expected_commands = [ + "vlan 3", + "name vlan3", + "interface GigabitEthernet1/0/8", + "switchport mode access", + "switchport access vlan 3", + "interface GigabitEthernet1/0/7", + "switchport mode access", + "switchport access vlan 3", + ] + self.assertEqual(result["commands"], expected_commands) + + def test_parse_vlan_brief(self): + result = parse_vlan_brief(load_fixture("ios_vlan_config.cfg")) + obj = [ + { + "name": "default", + "interfaces": [ + "GigabitEthernet1/0/4", + "GigabitEthernet1/0/5", + "GigabitEthernet1/0/52", + "GigabitEthernet1/0/54", + ], + "state": "active", + "vlan_id": "1", + }, + { + "name": "vlan2", + "interfaces": ["GigabitEthernet1/0/6", "GigabitEthernet1/0/7"], + "state": "active", + "vlan_id": "2", + }, + { + "name": "vlan9", + "interfaces": ["GigabitEthernet1/0/6"], + "state": "active", + "vlan_id": "9", + }, + { + "name": "fddi-default", + "interfaces": [], + "state": "act/unsup", + "vlan_id": "1002", + }, + { + "name": "fddo-default", + "interfaces": [], + "state": "act/unsup", + "vlan_id": "1003", + }, + ] + self.assertEqual(result, obj) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py new file mode 100644 index 00000000..0e6744f9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py @@ -0,0 +1,385 @@ +# +# (c) 2019, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_vlans +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosVlansModule(TestIosModule): + module = ios_vlans + + def setUp(self): + super(TestIosVlansModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." + "get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts." + "get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_edit_config = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans." + "VlansFacts.get_vlans_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosVlansModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_edit_config.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None, transport="cli"): + def load_from_file(*args, **kwargs): + return load_fixture("ios_vlans_config.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_ios_vlans_merged(self): + set_module_args( + dict( + config=[ + dict( + name="test_vlan_200", + state="active", + shutdown="disabled", + remote_span=True, + vlan_id=200, + ) + ], + state="merged", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "vlan 200", + "name test_vlan_200", + "state active", + "remote-span", + "no shutdown", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_vlans_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + mtu=1500, + name="default", + shutdown="disabled", + state="active", + vlan_id=1, + ), + dict( + mtu=610, + name="RemoteIsInMyName", + shutdown="enabled", + state="active", + vlan_id=123, + ), + dict( + mtu=1500, + name="VLAN0150", + remote_span=True, + shutdown="disabled", + state="active", + vlan_id=150, + ), + dict( + mtu=1500, + name="a_very_long_vlan_name_a_very_long_vlan_name", + shutdown="disabled", + state="active", + vlan_id=888, + ), + dict( + mtu=1500, + name="fddi-default", + shutdown="enabled", + state="active", + vlan_id=1002, + ), + dict( + mtu=4472, + name="trcrf-default", + shutdown="enabled", + state="active", + vlan_id=1003, + ), + dict( + mtu=1500, + name="fddinet-default", + shutdown="enabled", + state="active", + vlan_id=1004, + ), + dict( + mtu=4472, + name="trbrf-default", + shutdown="enabled", + state="active", + vlan_id=1005, + ), + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_vlans_replaced(self): + set_module_args( + dict( + config=[ + dict( + name="test_vlan_200", + state="active", + shutdown="disabled", + remote_span=True, + vlan_id=200, + ) + ], + state="replaced", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "vlan 200", + "name test_vlan_200", + "state active", + "remote-span", + "no shutdown", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_vlans_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + mtu=1500, + name="default", + shutdown="disabled", + state="active", + vlan_id=1, + ), + dict( + mtu=610, + name="RemoteIsInMyName", + shutdown="enabled", + state="active", + vlan_id=123, + ), + dict( + mtu=1500, + name="VLAN0150", + remote_span=True, + shutdown="disabled", + state="active", + vlan_id=150, + ), + dict( + mtu=1500, + name="a_very_long_vlan_name_a_very_long_vlan_name", + shutdown="disabled", + state="active", + vlan_id=888, + ), + dict( + mtu=1500, + name="fddi-default", + shutdown="enabled", + state="active", + vlan_id=1002, + ), + dict( + mtu=4472, + name="trcrf-default", + shutdown="enabled", + state="active", + vlan_id=1003, + ), + dict( + mtu=1500, + name="fddinet-default", + shutdown="enabled", + state="active", + vlan_id=1004, + ), + dict( + mtu=4472, + name="trbrf-default", + shutdown="enabled", + state="active", + vlan_id=1005, + ), + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_vlans_overridden(self): + set_module_args( + dict( + config=[ + dict( + name="test_vlan_200", + state="active", + shutdown="disabled", + remote_span=True, + vlan_id=200, + ) + ], + state="overridden", + ) + ) + result = self.execute_module(changed=True) + commands = [ + "no vlan 123", + "no vlan 150", + "no vlan 888", + "vlan 200", + "name test_vlan_200", + "state active", + "remote-span", + "no shutdown", + ] + + self.assertEqual(result["commands"], commands) + + def test_ios_vlans_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + mtu=1500, + name="default", + shutdown="disabled", + state="active", + vlan_id=1, + ), + dict( + mtu=610, + name="RemoteIsInMyName", + shutdown="enabled", + state="active", + vlan_id=123, + ), + dict( + mtu=1500, + name="VLAN0150", + remote_span=True, + shutdown="disabled", + state="active", + vlan_id=150, + ), + dict( + mtu=1500, + name="a_very_long_vlan_name_a_very_long_vlan_name", + shutdown="disabled", + state="active", + vlan_id=888, + ), + dict( + mtu=1500, + name="fddi-default", + shutdown="enabled", + state="active", + vlan_id=1002, + ), + dict( + mtu=4472, + name="trcrf-default", + shutdown="enabled", + state="active", + vlan_id=1003, + ), + dict( + mtu=1500, + name="fddinet-default", + shutdown="enabled", + state="active", + vlan_id=1004, + ), + dict( + mtu=4472, + name="trbrf-default", + shutdown="enabled", + state="active", + vlan_id=1005, + ), + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_delete_vlans_config(self): + set_module_args(dict(config=[dict(vlan_id=150)], state="deleted")) + result = self.execute_module(changed=True) + commands = ["no vlan 150"] + self.assertEqual(result["commands"], commands) + + def test_vlans_rendered(self): + set_module_args( + dict( + config=[ + dict( + name="test_vlan_200", + state="active", + shutdown="disabled", + remote_span=True, + vlan_id=200, + ) + ], + state="rendered", + ) + ) + commands = [ + "name test_vlan_200", + "no shutdown", + "remote-span", + "state active", + "vlan 200", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), commands) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py new file mode 100644 index 00000000..f09376c2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py @@ -0,0 +1,420 @@ +# +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.plugins.modules import ios_vrf +from ansible_collections.cisco.ios.tests.unit.modules.utils import ( + set_module_args, +) +from .ios_module import TestIosModule, load_fixture + + +class TestIosVrfModule(TestIosModule): + module = ios_vrf + + def setUp(self): + super(TestIosVrfModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_vrf.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_vrf.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_exec_command = patch( + "ansible_collections.cisco.ios.plugins.modules.ios_vrf.exec_command" + ) + self.exec_command = self.mock_exec_command.start() + + def tearDown(self): + super(TestIosVrfModule, self).tearDown() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_exec_command.stop() + + def load_fixtures(self, commands=None): + self.get_config.return_value = load_fixture("ios_vrf_config.cfg") + self.exec_command.return_value = ( + 0, + load_fixture("ios_vrf_config.cfg").strip(), + None, + ) + self.load_config.return_value = None + + def test_ios_vrf_name(self): + set_module_args(dict(name="test_4")) + commands = ["vrf definition test_4"] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_name_unchanged(self): + set_module_args( + dict(name="test_1", rd="1:100", description="test vrf 1") + ) + self.execute_module() + + def test_ios_vrf_description(self): + set_module_args(dict(name="test_1", description="test string")) + commands = ["vrf definition test_1", "description test string"] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_rd(self): + set_module_args(dict(name="test_1", rd="2:100")) + commands = ["vrf definition test_1", "rd 2:100"] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_interfaces(self): + set_module_args(dict(name="test_1", interfaces=["Ethernet1"])) + commands = [ + "interface Ethernet2", + "no vrf forwarding test_1", + "interface Ethernet1", + "vrf forwarding test_1", + "ip address 1.2.3.4/5", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_state_absent(self): + set_module_args(dict(name="test_1", state="absent")) + commands = ["no vrf definition test_1"] + self.execute_module(changed=True, commands=commands) + + def test_ios_vrf_purge_all(self): + set_module_args(dict(purge=True)) + commands = [ + "no vrf definition test_1", + "no vrf definition test_2", + "no vrf definition test_3", + "no vrf definition test_17", + "no vrf definition test_18", + "no vrf definition test_19", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_vrf_purge_all_but_one(self): + set_module_args(dict(name="test_1", purge=True)) + commands = [ + "no vrf definition test_2", + "no vrf definition test_3", + "no vrf definition test_17", + "no vrf definition test_18", + "no vrf definition test_19", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_vrfs_no_purge(self): + vrfs = [{"name": "test_1"}, {"name": "test_4"}] + set_module_args(dict(vrfs=vrfs)) + commands = ["vrf definition test_4"] + self.execute_module(changed=True, commands=commands) + + def test_ios_vrfs_purge(self): + vrfs = [{"name": "test_1"}, {"name": "test_4"}] + set_module_args(dict(vrfs=vrfs, purge=True)) + commands = [ + "vrf definition test_4", + "no vrf definition test_2", + "no vrf definition test_3", + "no vrf definition test_17", + "no vrf definition test_18", + "no vrf definition test_19", + ] + self.execute_module(changed=True, commands=commands) + + def test_ios_vrfs_global_arg(self): + vrfs = [{"name": "test_1"}, {"name": "test_2"}] + set_module_args(dict(vrfs=vrfs, description="test string")) + commands = [ + "vrf definition test_1", + "description test string", + "vrf definition test_2", + "description test string", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrfs_local_override_description(self): + vrfs = [ + {"name": "test_1", "description": "test vrf 1"}, + {"name": "test_2"}, + ] + set_module_args(dict(vrfs=vrfs, description="test string")) + commands = ["vrf definition test_2", "description test string"] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrfs_local_override_state(self): + vrfs = [{"name": "test_1", "state": "absent"}, {"name": "test_2"}] + set_module_args(dict(vrfs=vrfs, description="test string")) + commands = [ + "no vrf definition test_1", + "vrf definition test_2", + "description test string", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_both(self): + set_module_args( + dict(name="test_5", rd="2:100", route_both=["2:100", "3:100"]) + ) + commands = [ + "vrf definition test_5", + "address-family ipv4", + "exit", + "address-family ipv6", + "exit", + "rd 2:100", + "route-target import 2:100", + "route-target import 3:100", + "route-target export 2:100", + "route-target export 3:100", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_import(self): + set_module_args( + dict(name="test_6", rd="3:100", route_import=["3:100", "4:100"]) + ) + commands = [ + "vrf definition test_6", + "rd 3:100", + "route-target import 3:100", + "route-target import 4:100", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_export(self): + set_module_args( + dict(name="test_7", rd="4:100", route_export=["3:100", "4:100"]) + ) + commands = [ + "vrf definition test_7", + "rd 4:100", + "route-target export 3:100", + "route-target export 4:100", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_both_mixed(self): + set_module_args( + dict( + name="test_8", + rd="5:100", + route_both=["3:100", "4:100"], + route_export=["3:100", "4:100"], + ) + ) + self.execute_module(changed=True) + + def test_ios_vrf_route_both_ipv4(self): + set_module_args( + dict( + name="test_9", + rd="168.0.0.9:100", + route_both_ipv4=["168.0.0.9:100", "3:100"], + ) + ) + commands = [ + "vrf definition test_9", + "address-family ipv4", + "exit", + "rd 168.0.0.9:100", + "address-family ipv4", + "route-target import 168.0.0.9:100", + "route-target import 3:100", + "exit-address-family", + "address-family ipv4", + "route-target export 168.0.0.9:100", + "route-target export 3:100", + "exit-address-family", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_import_ipv4(self): + set_module_args( + dict( + name="test_10", + rd="168.0.0.10:100", + route_import_ipv4=["168.0.0.10:100", "3:100"], + ) + ) + commands = [ + "vrf definition test_10", + "address-family ipv4", + "exit", + "rd 168.0.0.10:100", + "address-family ipv4", + "route-target import 168.0.0.10:100", + "route-target import 3:100", + "exit-address-family", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_export_ipv4(self): + set_module_args( + dict( + name="test_11", + rd="168.0.0.11:100", + route_export_ipv4=["168.0.0.11:100", "3:100"], + ) + ) + commands = [ + "vrf definition test_11", + "address-family ipv4", + "exit", + "rd 168.0.0.11:100", + "address-family ipv4", + "route-target export 168.0.0.11:100", + "route-target export 3:100", + "exit-address-family", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_both_ipv4_mixed(self): + set_module_args( + dict( + name="test_12", + rd="168.0.0.12:100", + route_both_ipv4=["168.0.0.12:100", "3:100"], + route_export_ipv4=["168.0.0.15:100", "6:100"], + ) + ) + self.execute_module(changed=True) + + def test_ios_vrf_route_both_ipv6(self): + set_module_args( + dict( + name="test_13", + rd="2:100", + route_both_ipv6=["2:100", "168.0.0.13:100"], + ) + ) + commands = [ + "vrf definition test_13", + "address-family ipv6", + "exit", + "rd 2:100", + "address-family ipv6", + "route-target import 2:100", + "route-target import 168.0.0.13:100", + "exit-address-family", + "address-family ipv6", + "route-target export 2:100", + "route-target export 168.0.0.13:100", + "exit-address-family", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_import_ipv6(self): + set_module_args( + dict( + name="test_14", + rd="3:100", + route_import_ipv6=["3:100", "168.0.0.14:100"], + ) + ) + commands = [ + "vrf definition test_14", + "address-family ipv6", + "exit", + "rd 3:100", + "address-family ipv6", + "route-target import 3:100", + "route-target import 168.0.0.14:100", + "exit-address-family", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_export_ipv6(self): + set_module_args( + dict( + name="test_15", + rd="4:100", + route_export_ipv6=["168.0.0.15:100", "4:100"], + ) + ) + commands = [ + "vrf definition test_15", + "address-family ipv6", + "exit", + "rd 4:100", + "address-family ipv6", + "route-target export 168.0.0.15:100", + "route-target export 4:100", + "exit-address-family", + ] + self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_vrf_route_both_ipv6_mixed(self): + set_module_args( + dict( + name="test_16", + rd="5:100", + route_both_ipv6=["168.0.0.9:100", "4:100"], + route_export_ipv6=["168.0.0.12:100", "6:100"], + ) + ) + self.execute_module(changed=True) + + def test_ios_vrf_route_both_ipv6_mixed_idempotent(self): + set_module_args( + dict( + name="test_17", + rd="2:100", + route_import_ipv6=["168.0.0.14:100"], + route_both_ipv6=["2:100", "168.0.0.13:100"], + route_export_ipv6=["168.0.0.15:100", "4:100"], + ) + ) + self.execute_module(changed=False, commands=[], sort=False) + + def test_ios_vrf_route_both_ipv4_mixed_idempotent(self): + set_module_args( + dict( + name="test_18", + rd="168.0.0.9:100", + route_import_ipv4=["168.0.0.10:600"], + route_export_ipv4=["168.0.0.10:100"], + route_both_ipv4=["168.0.0.9:100", "3:100"], + ) + ) + self.execute_module(changed=False, commands=[], sort=False) + + def test_ios_vrf_all_route_both_idempotent(self): + set_module_args( + dict( + name="test_19", + rd="10:700", + route_both=["2:100", "2:101"], + route_export=["2:102", "2:103"], + route_import=["2:104", "2:105"], + route_both_ipv4=["2:100", "2:101"], + route_export_ipv4=["2:102", "2:103"], + route_import_ipv4=["2:104", "2:105"], + route_both_ipv6=["2:100", "2:101"], + route_export_ipv6=["2:102", "2:103"], + route_import_ipv6=["2:104", "2:105"], + ) + ) + self.execute_module(changed=False, commands=[], sort=False) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/utils.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/utils.py new file mode 100644 index 00000000..0b8fee88 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/modules/utils.py @@ -0,0 +1,51 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type +import json + +from ansible_collections.cisco.ios.tests.unit.compat import unittest +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible.module_utils import basic +from ansible.module_utils._text import to_bytes + + +def set_module_args(args): + if "_ansible_remote_tmp" not in args: + args["_ansible_remote_tmp"] = "/tmp" + if "_ansible_keep_remote_files" not in args: + args["_ansible_keep_remote_files"] = False + + args = json.dumps({"ANSIBLE_MODULE_ARGS": args}) + basic._ANSIBLE_ARGS = to_bytes(args) + + +class AnsibleExitJson(Exception): + pass + + +class AnsibleFailJson(Exception): + pass + + +def exit_json(*args, **kwargs): + if "changed" not in kwargs: + kwargs["changed"] = False + raise AnsibleExitJson(kwargs) + + +def fail_json(*args, **kwargs): + kwargs["failed"] = True + raise AnsibleFailJson(kwargs) + + +class ModuleTestCase(unittest.TestCase): + def setUp(self): + self.mock_module = patch.multiple( + basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json + ) + self.mock_module.start() + self.mock_sleep = patch("time.sleep") + self.mock_sleep.start() + set_module_args({}) + self.addCleanup(self.mock_module.stop) + self.addCleanup(self.mock_sleep.stop) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/ios/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/ios/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/ios/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/ios/show_version b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/ios/show_version new file mode 100644 index 00000000..eadd3d3a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/ios/show_version @@ -0,0 +1,54 @@ +Cisco IOS XE Software, Version 16.06.01 +Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.1, RELEASE SOFTWARE (fc2) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2017 by Cisco Systems, Inc. +Compiled Sat 22-Jul-17 05:51 by mcpre + + +Cisco IOS-XE software, Copyright (c) 2005-2017 by cisco Systems, Inc. +All rights reserved. Certain components of Cisco IOS-XE software are +licensed under the GNU General Public License ("GPL") Version 2.0. The +software code licensed under GPL Version 2.0 is free software that comes +with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such +GPL code under the terms of GPL Version 2.0. For more details, see the +documentation or "License Notice" file accompanying the IOS-XE software, +or the applicable URL provided on the flyer accompanying the IOS-XE +software. + + +ROM: IOS-XE ROMMON + +an-csr-01 uptime is 1 day, 16 hours, 15 minutes +Uptime for this control processor is 1 day, 16 hours, 16 minutes +System returned to ROM by reload +System image file is "bootflash:packages.conf" +Last reload reason: Reload Command + + + +This product contains cryptographic features and is subject to United +States and local country laws governing import, export, transfer and +use. Delivery of Cisco cryptographic products does not imply +third-party authority to import, export, distribute or use encryption. +Importers, exporters, distributors and users are responsible for +compliance with U.S. and local country laws. By using this product you +agree to comply with applicable laws and regulations. If you are unable +to comply with U.S. and local laws, return this product immediately. + +A summary of U.S. laws governing Cisco cryptographic products may be found at: +http://www.cisco.com/wwl/export/crypto/tool/stqrg.html + +If you require further assistance please contact us by sending email to +export@cisco.com. + +License Level: ax +License Type: Default. No valid license found. +Next reload license Level: ax + +cisco CSR1000V (VXE) processor (revision VXE) with 1225511K/3075K bytes of memory. +Processor board ID 9I5BX4UHSO4 +3 Gigabit Ethernet interfaces +32768K bytes of non-volatile configuration memory. +3018776K bytes of physical memory. +16162815K bytes of virtual hard disk at bootflash:. +0K bytes of WebUI ODM Files at webui:. diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/show_chassis b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/show_chassis new file mode 100644 index 00000000..af51cbaf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/show_chassis @@ -0,0 +1,30 @@ + +Chassis Name: BR-VDX6740 +switchType: 131 + +FAN Unit: 1 +Time Awake: 0 days + +FAN Unit: 2 +Time Awake: 0 days + +POWER SUPPLY Unit: 1 +Factory Part Num: 23-1000043-01 +Factory Serial Num: +Time Awake: 0 days + +POWER SUPPLY Unit: 2 +Factory Part Num: 23-1000043-01 +Factory Serial Num: +Time Awake: 0 days + +CHASSIS/WWN Unit: 1 +Power Consume Factor: 0 +Factory Part Num: 40-1000927-06 +Factory Serial Num: CPL2541K01E +Manufacture: Day: 11 Month: 8 Year: 14 +Update: Day: 18 Month: 7 Year: 2018 +Time Alive: 1116 days +Time Awake: 0 days + +Airflow direction : Port side INTAKE diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/show_running-config b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/show_running-config new file mode 100644 index 00000000..8a4f631f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/show_running-config @@ -0,0 +1,549 @@ +diag post rbridge-id 104 enable +ntp server 10.10.10.1 use-vrf mgmt-vrf +logging raslog console INFO +logging auditlog class SECURITY +logging auditlog class CONFIGURATION +logging auditlog class FIRMWARE +logging syslog-facility local LOG_LOCAL7 +logging syslog-client localip CHASSIS_IP +switch-attributes 104 + chassis-name VDX6740 + host-name LEAF4 +! +no support autoupload enable +line vty + exec-timeout 10 +! +zoning enabled-configuration cfg-name "" +zoning enabled-configuration default-zone-access allaccess +zoning enabled-configuration cfg-action cfg-save +dpod 104/0/1 + reserve +! +dpod 104/0/2 +! +dpod 104/0/3 +! +dpod 104/0/4 +! +dpod 104/0/5 +! +dpod 104/0/6 +! +dpod 104/0/7 +! +dpod 104/0/8 +! +dpod 104/0/9 +! +dpod 104/0/10 +! +dpod 104/0/11 +! +dpod 104/0/12 +! +dpod 104/0/13 +! +dpod 104/0/14 +! +dpod 104/0/15 +! +dpod 104/0/16 +! +dpod 104/0/17 +! +dpod 104/0/18 +! +dpod 104/0/19 +! +dpod 104/0/20 +! +dpod 104/0/21 +! +dpod 104/0/22 +! +dpod 104/0/23 +! +dpod 104/0/24 +! +dpod 104/0/25 +! +dpod 104/0/26 +! +dpod 104/0/27 +! +dpod 104/0/28 +! +dpod 104/0/29 +! +dpod 104/0/30 +! +dpod 104/0/31 +! +dpod 104/0/32 +! +dpod 104/0/33 +! +dpod 104/0/34 +! +dpod 104/0/35 +! +dpod 104/0/36 +! +dpod 104/0/37 +! +dpod 104/0/38 +! +dpod 104/0/39 +! +dpod 104/0/40 +! +dpod 104/0/41 +! +dpod 104/0/42 +! +dpod 104/0/43 +! +dpod 104/0/44 +! +dpod 104/0/45 +! +dpod 104/0/46 +! +dpod 104/0/47 +! +dpod 104/0/48 +! +dpod 104/0/49 +! +dpod 104/0/50 +! +dpod 104/0/51 +! +dpod 104/0/52 +! +role name admin desc Administrator +role name user desc User +aaa authentication login local +aaa accounting exec default start-stop none +aaa accounting commands default start-stop none +service password-encryption +username admin password "BwrsDbB+tABWGWpINOVKoQ==\n" encryption-level 7 role admin desc Administrator +username user password "BwrsDbB+tABWGWpINOVKoQ==\n" encryption-level 7 role user desc User +ip access-list extended test + seq 10 permit ip host 1.1.1.1 any log +! +snmp-server contact "Field Support." +snmp-server location "End User Premise." +snmp-server sys-descr "Extreme VDX Switch." +snmp-server enable trap +snmp-server community private groupname admin +snmp-server community public groupname user +snmp-server view All 1 included +snmp-server group admin v1 read All write All notify All +snmp-server group public v1 read All +snmp-server group public v2c read All +snmp-server group user v1 read All +snmp-server group user v2c read All +hardware + connector-group 104/0/1 + speed LowMixed + ! + connector-group 104/0/3 + speed LowMixed + ! + connector-group 104/0/5 + speed LowMixed + ! + connector-group 104/0/6 + speed LowMixed + ! +! +cee-map default + precedence 1 + priority-group-table 1 weight 40 pfc on + priority-group-table 15.0 pfc off + priority-group-table 15.1 pfc off + priority-group-table 15.2 pfc off + priority-group-table 15.3 pfc off + priority-group-table 15.4 pfc off + priority-group-table 15.5 pfc off + priority-group-table 15.6 pfc off + priority-group-table 15.7 pfc off + priority-group-table 2 weight 60 pfc off + priority-table 2 2 2 1 2 2 2 15.0 + remap fabric-priority priority 0 + remap lossless-priority priority 0 +! +fcoe + fabric-map default + vlan 1002 + san-mode local + priority 3 + virtual-fabric 128 + fcmap 0E:FC:00 + advertisement interval 8000 + keep-alive timeout + ! +! +interface Vlan 1 +! +fabric route mcast rbridge-id 104 +! +protocol lldp + advertise dcbx-fcoe-app-tlv + advertise dcbx-fcoe-logical-link-tlv + advertise dcbx-tlv + advertise bgp-auto-nbr-tlv + advertise optional-tlv management-address + advertise optional-tlv system-name + system-description Extreme-VDX-VCS 120 +! +vlan dot1q tag native +port-profile UpgradedVlanProfile + vlan-profile + switchport + switchport mode trunk + switchport trunk allowed vlan all + ! +! +port-profile default + vlan-profile + switchport + switchport mode trunk + switchport trunk native-vlan 1 + ! +! +port-profile-domain default + port-profile UpgradedVlanProfile +! +class-map cee +! +class-map default +! +rbridge-id 104 + switch-attributes chassis-name VDX6740 + switch-attributes host-name LEAF4 + vrf mgmt-vrf + address-family ipv4 unicast + ip route 0.0.0.0/0 10.26.0.1 + ! + address-family ipv6 unicast + ! + ! + system-monitor fan threshold marginal-threshold 1 down-threshold 2 + system-monitor fan alert state removed action raslog + system-monitor power threshold marginal-threshold 1 down-threshold 2 + system-monitor power alert state removed action raslog + system-monitor temp threshold marginal-threshold 1 down-threshold 2 + system-monitor cid-card threshold marginal-threshold 1 down-threshold 2 + system-monitor cid-card alert state none action none + system-monitor sfp alert state none action none + system-monitor compact-flash threshold marginal-threshold 1 down-threshold 0 + system-monitor MM threshold marginal-threshold 1 down-threshold 0 + system-monitor LineCard threshold marginal-threshold 1 down-threshold 2 + system-monitor LineCard alert state none action none + system-monitor SFM threshold marginal-threshold 1 down-threshold 2 + resource-monitor cpu enable + resource-monitor memory enable threshold 100 action raslog + resource-monitor process memory enable alarm 500 critical 600 + no protocol vrrp + no protocol vrrp-extended + hardware-profile tcam default + hardware-profile route-table default maximum_paths 8 openflow off + hardware-profile kap default + fabric neighbor-discovery + clock timezone America/Los_Angeles + ag + enable + counter reliability 25 + timeout fnm 120 + pg 0 + modes lb + rename pg0 + ! + ! + telnet server use-vrf default-vrf + telnet server use-vrf mgmt-vrf + ssh server key rsa 2048 + ssh server key ecdsa 256 + ssh server key dsa + ssh server use-vrf default-vrf + ssh server use-vrf mgmt-vrf + http server use-vrf default-vrf + http server use-vrf mgmt-vrf + fcoe + fcoe-enodes 0 + ! +! +interface Management 104/0 + no tcp burstrate + ip icmp echo-reply + no ip address dhcp + ip address 10.26.7.226/17 + ipv6 icmpv6 echo-reply + no ipv6 address autoconfig + no ipv6 address dhcp + vrf forwarding mgmt-vrf + no shutdown +! +interface TenGigabitEthernet 104/0/1 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/2 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/3 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/4 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/5 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/6 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/7 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/8 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/9 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/10 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/11 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/12 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/13 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/14 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/15 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/16 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/17 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/18 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/19 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/20 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/21 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/22 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/23 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/24 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/25 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/26 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/27 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/28 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/29 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/30 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/31 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/32 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/33 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/34 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/35 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/36 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/37 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/38 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/39 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/40 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/41 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/42 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/43 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/44 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/45 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/46 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/47 + fabric isl enable + fabric trunk enable + no shutdown +! +interface TenGigabitEthernet 104/0/48 + fabric isl enable + fabric trunk enable + no shutdown +! +interface FortyGigabitEthernet 104/0/49 + fabric isl enable + fabric trunk enable + no shutdown +! +interface FortyGigabitEthernet 104/0/50 + fabric isl enable + fabric trunk enable + no shutdown +! +interface FortyGigabitEthernet 104/0/51 + fabric isl enable + fabric trunk enable + no shutdown +! +interface FortyGigabitEthernet 104/0/52 + fabric isl enable + fabric trunk enable + no shutdown +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/show_version b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/show_version new file mode 100644 index 00000000..1accd819 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/nos/show_version @@ -0,0 +1,17 @@ +Network Operating System Software +Network Operating System Version: 7.2.0 +Copyright (c) 1995-2017 Brocade Communications Systems, Inc. +Firmware name: 7.2.0 +Build Time: 10:52:47 Jul 10, 2017 +Install Time: 01:32:03 Jan 5, 2018 +Kernel: 2.6.34.6 + +BootProm: 1.0.1 +Control Processor: e500mc with 4096 MB of memory + +Slot Name Primary/Secondary Versions Status +--------------------------------------------------------------------------- +SW/0 NOS 7.2.0 ACTIVE* + 7.2.0 +SW/1 NOS 7.2.0 STANDBY + 7.2.0 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/__init__.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_chassis b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_chassis new file mode 100644 index 00000000..1f7f0c51 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_chassis @@ -0,0 +1,40 @@ + +Chassis Name: BR-SLX9140 +switchType: 3001 + +FAN Unit: 1 +Time Awake: 36 days + +FAN Unit: 2 +Time Awake: 36 days + +FAN Unit: 3 +Time Awake: 36 days + +FAN Unit: 5 +Time Awake: 36 days + +FAN Unit: 6 +Time Awake: 36 days + +POWER SUPPLY Unit: 1 +Factory Part Num: 11-1111111-11 +Factory Serial Num: ASERIALNUMB +Time Awake: 36 days + +POWER SUPPLY Unit: 2 +Factory Part Num: 11-1111111-11 +Factory Serial Num: ASERIALNUMB +Time Awake: 36 days + +CHASSIS/WWN Unit: 1 +Power Consume Factor: 0 +Factory Part Num: 11-1111111-11 +Factory Serial Num: ASERIALNUMB +Manufacture: Day: 12 Month: 1 Year: 2017 +Update: Day: 5 Month: 4 Year: 2018 +Time Alive: 277 days +Time Awake: 36 days + +Airflow direction : Port side INTAKE + diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_running-config b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_running-config new file mode 100644 index 00000000..b2e540d9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_running-config @@ -0,0 +1,624 @@ +root enable +host-table aging-mode conversational +clock timezone Europe/Warsaw +hardware + profile tcam default + profile overlay-visibility default + profile route-table default maximum_paths 8 + system-mode default +! +http server use-vrf default-vrf +http server use-vrf mgmt-vrf +node-id 1 +! +ntp server 172.16.10.2 use-vrf mgmt-vrf +! +logging raslog console INFO +logging syslog-server 10.1.5.11 use-vrf mgmt-vrf +! +logging auditlog class SECURITY +logging auditlog class CONFIGURATION +logging auditlog class FIRMWARE +logging syslog-facility local LOG_LOCAL0 +logging syslog-client localip CHASSIS_IP +switch-attributes chassis-name SLX9140-LEAF2 +switch-attributes host-name DC2LEAF2 +no support autoupload enable +support ffdc +resource-monitor cpu enable threshold 90 action raslog +resource-monitor memory enable threshold 100 action raslog +resource-monitor process memory enable alarm 1000 critical 1200 +system-monitor fan threshold marginal-threshold 1 down-threshold 2 +system-monitor fan alert state removed action raslog +system-monitor power threshold marginal-threshold 1 down-threshold 2 +system-monitor power alert state removed action raslog +system-monitor temp threshold marginal-threshold 1 down-threshold 2 +system-monitor cid-card threshold marginal-threshold 1 down-threshold 2 +system-monitor cid-card alert state none action none +system-monitor compact-flash threshold marginal-threshold 1 down-threshold 0 +system-monitor MM threshold marginal-threshold 1 down-threshold 0 +system-monitor LineCard threshold marginal-threshold 1 down-threshold 2 +system-monitor LineCard alert state none action none +system-monitor SFM threshold marginal-threshold 1 down-threshold 2 +telemetry server use-vrf mgmt-vrf + transport tcp + port 50051 + activate +! +telemetry profile system-utilization default_system_utilization_statistics + interval 60 + add total-system-memory + add total-used-memory + add total-free-memory + add cached-memory + add buffers + add user-free-memory + add kernel-free-memory + add total-swap-memory + add total-free-swap-memory + add total-used-swap-memory + add user-process + add system-process + add niced-process + add iowait + add hw-interrupt + add sw-interrupt + add idle-state + add steal-time + add uptime +! +telemetry profile interface default_interface_statistics + interval 30 + add out-pkts + add in-pkts + add out-unicast-pkts + add in-unicast-pkts + add out-broadcast-pkts + add in-broadcast-pkts + add out-multicast-pkts + add in-multicast-pkts + add out-pkts-per-second + add in-pkts-per-second + add out-bandwidth + add in-bandwidth + add out-octets + add in-octets + add out-errors + add in-errors + add out-crc-errors + add in-crc-errors + add out-discards + add in-discards +! +line vty + exec-timeout 10 +! +threshold-monitor Buffer limit 70 +vrf mgmt-vrf + address-family ipv4 unicast + ip route 0.0.0.0/0 172.168.192.1 + ! + address-family ipv6 unicast + ! +! +ssh server key rsa 2048 +ssh server key ecdsa 256 +ssh server key dsa +ssh server use-vrf default-vrf +ssh server use-vrf mgmt-vrf +telnet server use-vrf default-vrf +telnet server use-vrf mgmt-vrf +role name admin desc Administrator +role name user desc User +aaa authentication login local +aaa accounting exec default start-stop none +aaa accounting commands default start-stop none +service password-encryption +username admin password "AINTNOPARTYLIKEAHOTELPARTYCAUSEAHOTELPARTYDONTSLEEPNOONEWOULDEVERACTUALLYTYPETHISWHYAREYOUHERE\n" encryption-level 7 role admin desc Administrator +cee-map default + precedence 1 + priority-group-table 1 weight 40 pfc on + priority-group-table 15.0 pfc off + priority-group-table 15.1 pfc off + priority-group-table 15.2 pfc off + priority-group-table 15.3 pfc off + priority-group-table 15.4 pfc off + priority-group-table 15.5 pfc off + priority-group-table 15.6 pfc off + priority-group-table 15.7 pfc off + priority-group-table 2 weight 60 pfc off + priority-table 2 2 2 1 2 2 2 15.0 + remap lossless-priority priority 0 +! +mac access-list extended M1 + seq 10 permit any any +! +vlan 1 + ip igmp snooping startup-query-interval 100 + ipv6 mld snooping startup-query-interval 100 +! +vlan 100 +! +vlan 200 +! +vlan 1001 + router-interface Ve 1001 + description Thomas-Test-Cluster +! +qos map cos-mutation all-zero-map + map cos 0 to cos 0 + map cos 1 to cos 0 + map cos 2 to cos 0 + map cos 3 to cos 0 + map cos 4 to cos 0 + map cos 5 to cos 0 + map cos 6 to cos 0 + map cos 7 to cos 0 +! +qos map cos-mutation default + map cos 0 to cos 0 + map cos 1 to cos 1 + map cos 2 to cos 2 + map cos 3 to cos 3 + map cos 4 to cos 4 + map cos 5 to cos 5 + map cos 6 to cos 6 + map cos 7 to cos 7 +! +qos map cos-traffic-class all-zero-map + map cos 0 to traffic-class 0 + map cos 1 to traffic-class 0 + map cos 2 to traffic-class 0 + map cos 3 to traffic-class 0 + map cos 4 to traffic-class 0 + map cos 5 to traffic-class 0 + map cos 6 to traffic-class 0 + map cos 7 to traffic-class 0 +! +qos map cos-traffic-class default + map cos 0 to traffic-class 1 + map cos 1 to traffic-class 0 + map cos 2 to traffic-class 2 + map cos 3 to traffic-class 3 + map cos 4 to traffic-class 4 + map cos 5 to traffic-class 5 + map cos 6 to traffic-class 6 + map cos 7 to traffic-class 7 +! +qos map cos-dscp all-zero-map + map cos 0 to dscp 0 + map cos 1 to dscp 0 + map cos 2 to dscp 0 + map cos 3 to dscp 0 + map cos 4 to dscp 0 + map cos 5 to dscp 0 + map cos 6 to dscp 0 + map cos 7 to dscp 0 +! +qos map cos-dscp default + map cos 0 to dscp 0 + map cos 1 to dscp 8 + map cos 2 to dscp 16 + map cos 3 to dscp 24 + map cos 4 to dscp 32 + map cos 5 to dscp 40 + map cos 6 to dscp 48 + map cos 7 to dscp 56 +! +qos map traffic-class-cos all-zero-map + map traffic-class 0 to cos 0 + map traffic-class 1 to cos 0 + map traffic-class 2 to cos 0 + map traffic-class 3 to cos 0 + map traffic-class 4 to cos 0 + map traffic-class 5 to cos 0 + map traffic-class 6 to cos 0 + map traffic-class 7 to cos 0 +! +qos map traffic-class-cos default + map traffic-class 0 to cos 0 + map traffic-class 1 to cos 1 + map traffic-class 2 to cos 2 + map traffic-class 3 to cos 3 + map traffic-class 4 to cos 4 + map traffic-class 5 to cos 5 + map traffic-class 6 to cos 6 + map traffic-class 7 to cos 7 +! +qos map traffic-class-mutation all-zero-map + map traffic-class 0 to traffic-class 0 + map traffic-class 1 to traffic-class 0 + map traffic-class 2 to traffic-class 0 + map traffic-class 3 to traffic-class 0 + map traffic-class 4 to traffic-class 0 + map traffic-class 5 to traffic-class 0 + map traffic-class 6 to traffic-class 0 + map traffic-class 7 to traffic-class 0 +! +qos map traffic-class-mutation default + map traffic-class 0 to traffic-class 0 + map traffic-class 1 to traffic-class 1 + map traffic-class 2 to traffic-class 2 + map traffic-class 3 to traffic-class 3 + map traffic-class 4 to traffic-class 4 + map traffic-class 5 to traffic-class 5 + map traffic-class 6 to traffic-class 6 + map traffic-class 7 to traffic-class 7 +! +qos map traffic-class-dscp all-zero-map + map traffic-class 0 to dscp 0 + map traffic-class 1 to dscp 0 + map traffic-class 2 to dscp 0 + map traffic-class 3 to dscp 0 + map traffic-class 4 to dscp 0 + map traffic-class 5 to dscp 0 + map traffic-class 6 to dscp 0 + map traffic-class 7 to dscp 0 +! +qos map traffic-class-dscp default + map traffic-class 0 to dscp 0 + map traffic-class 1 to dscp 8 + map traffic-class 2 to dscp 16 + map traffic-class 3 to dscp 24 + map traffic-class 4 to dscp 32 + map traffic-class 5 to dscp 40 + map traffic-class 6 to dscp 48 + map traffic-class 7 to dscp 56 +! +qos map dscp-mutation all-zero-map + map dscp 0-63 to dscp 0 +! +qos map dscp-mutation default + map dscp 0 to dscp 0 + map dscp 1 to dscp 1 + map dscp 10 to dscp 10 + map dscp 11 to dscp 11 + map dscp 12 to dscp 12 + map dscp 13 to dscp 13 + map dscp 14 to dscp 14 + map dscp 15 to dscp 15 + map dscp 16 to dscp 16 + map dscp 17 to dscp 17 + map dscp 18 to dscp 18 + map dscp 19 to dscp 19 + map dscp 2 to dscp 2 + map dscp 20 to dscp 20 + map dscp 21 to dscp 21 + map dscp 22 to dscp 22 + map dscp 23 to dscp 23 + map dscp 24 to dscp 24 + map dscp 25 to dscp 25 + map dscp 26 to dscp 26 + map dscp 27 to dscp 27 + map dscp 28 to dscp 28 + map dscp 29 to dscp 29 + map dscp 3 to dscp 3 + map dscp 30 to dscp 30 + map dscp 31 to dscp 31 + map dscp 32 to dscp 32 + map dscp 33 to dscp 33 + map dscp 34 to dscp 34 + map dscp 35 to dscp 35 + map dscp 36 to dscp 36 + map dscp 37 to dscp 37 + map dscp 38 to dscp 38 + map dscp 39 to dscp 39 + map dscp 4 to dscp 4 + map dscp 40 to dscp 40 + map dscp 41 to dscp 41 + map dscp 42 to dscp 42 + map dscp 43 to dscp 43 + map dscp 44 to dscp 44 + map dscp 45 to dscp 45 + map dscp 46 to dscp 46 + map dscp 47 to dscp 47 + map dscp 48 to dscp 48 + map dscp 49 to dscp 49 + map dscp 5 to dscp 5 + map dscp 50 to dscp 50 + map dscp 51 to dscp 51 + map dscp 52 to dscp 52 + map dscp 53 to dscp 53 + map dscp 54 to dscp 54 + map dscp 55 to dscp 55 + map dscp 56 to dscp 56 + map dscp 57 to dscp 57 + map dscp 58 to dscp 58 + map dscp 59 to dscp 59 + map dscp 6 to dscp 6 + map dscp 60 to dscp 60 + map dscp 61 to dscp 61 + map dscp 62 to dscp 62 + map dscp 63 to dscp 63 + map dscp 7 to dscp 7 + map dscp 8 to dscp 8 + map dscp 9 to dscp 9 +! +qos map dscp-traffic-class all-zero-map + map dscp 0-63 to traffic-class 0 +! +qos map dscp-traffic-class default + map dscp 0-7 to traffic-class 0 + map dscp 16-23 to traffic-class 2 + map dscp 24-31 to traffic-class 3 + map dscp 32-39 to traffic-class 4 + map dscp 40-47 to traffic-class 5 + map dscp 48-55 to traffic-class 6 + map dscp 56-63 to traffic-class 7 + map dscp 8-15 to traffic-class 1 +! +qos map dscp-cos all-zero-map + map dscp 0-63 to cos 0 +! +qos map dscp-cos default + map dscp 0-7 to cos 0 + map dscp 16-23 to cos 2 + map dscp 24-31 to cos 3 + map dscp 32-39 to cos 4 + map dscp 40-47 to cos 5 + map dscp 48-55 to cos 6 + map dscp 56-63 to cos 7 + map dscp 8-15 to cos 1 +! +protocol lldp + advertise optional-tlv management-address + system-description Brocade BR-SLX9140 Router +! +vlan dot1q tag native +police-remark-profile default +! +class-map BD-100 +! +class-map C1 + match access-group M1 +! +class-map cee +! +class-map default +! +policy-map P1 + class C1 + police cir 1000000 + ! +! +policy-map P2 + class default + police cir 12121212 + ! +! +no protocol vrrp +no protocol vrrp-extended +router bgp + local-as 65301 + capability as4-enable + bfd interval 300 min-rx 300 multiplier 3 + neighbor leaf_group peer-group + neighbor leaf_group remote-as 65500 + neighbor leaf_group bfd + neighbor 10.220.4.3 remote-as 65500 + neighbor 10.220.4.3 peer-group leaf_group + address-family ipv4 unicast + network 172.32.252.5/32 + maximum-paths 8 + ! + address-family ipv6 unicast + ! + address-family l2vpn evpn + ! +! +interface Loopback 1 + ip address 172.16.128.6/32 + no shutdown +! +interface Loopback 2 + ip address 172.16.129.5/32 + no shutdown +! +interface Management 0 + no tcp burstrate + no shutdown + vrf forwarding mgmt-vrf + ip address dhcp +! +interface Ethernet 0/1 + speed 25000 + fec mode disabled + switchport + switchport mode access + switchport access vlan 1 + no shutdown +! +interface Ethernet 0/2 + no shutdown +! +interface Ethernet 0/3 + speed 25000 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/4 + shutdown +! +interface Ethernet 0/5 + service-policy in P1 + no shutdown +! +interface Ethernet 0/6 + mtu 1548 + description L2 Interface + no shutdown +! +interface Ethernet 0/7 + mtu 1548 + description L2 Interface + no shutdown +! +interface Ethernet 0/8 + switchport + switchport mode trunk + switchport trunk allowed vlan add 100,200 + switchport trunk tag native-vlan + shutdown +! +interface Ethernet 0/9 + shutdown +! +interface Ethernet 0/10 + no shutdown +! +interface Ethernet 0/11 + no shutdown +! +interface Ethernet 0/12 + no shutdown +! +interface Ethernet 0/13 + no shutdown +! +interface Ethernet 0/14 + no shutdown +! +interface Ethernet 0/15 + shutdown +! +interface Ethernet 0/16 + shutdown +! +interface Ethernet 0/17 + shutdown +! +interface Ethernet 0/18 + shutdown +! +interface Ethernet 0/19 + shutdown +! +interface Ethernet 0/20 + shutdown +! +interface Ethernet 0/21 + shutdown +! +interface Ethernet 0/22 + shutdown +! +interface Ethernet 0/23 + shutdown +! +interface Ethernet 0/24 + shutdown +! +interface Ethernet 0/25 + shutdown +! +interface Ethernet 0/26 + shutdown +! +interface Ethernet 0/27 + shutdown +! +interface Ethernet 0/28 + shutdown +! +interface Ethernet 0/29 + shutdown +! +interface Ethernet 0/30 + shutdown +! +interface Ethernet 0/31 + shutdown +! +interface Ethernet 0/32 + shutdown +! +interface Ethernet 0/33 + shutdown +! +interface Ethernet 0/34 + shutdown +! +interface Ethernet 0/35 + shutdown +! +interface Ethernet 0/36 + shutdown +! +interface Ethernet 0/37 + shutdown +! +interface Ethernet 0/38 + shutdown +! +interface Ethernet 0/39 + shutdown +! +interface Ethernet 0/40 + shutdown +! +interface Ethernet 0/41 + shutdown +! +interface Ethernet 0/42 + shutdown +! +interface Ethernet 0/43 + shutdown +! +interface Ethernet 0/44 + shutdown +! +interface Ethernet 0/45 + shutdown +! +interface Ethernet 0/46 + shutdown +! +interface Ethernet 0/47 + shutdown +! +interface Ethernet 0/48 + shutdown +! +interface Ethernet 0/49 + shutdown +! +interface Ethernet 0/50 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/51 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/52 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/53 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/54 + fec mode disabled + no shutdown +! +interface Port-channel 200 + switchport + switchport mode access + switchport access vlan 200 + shutdown +! +interface Port-channel 1024 + insight enable + no shutdown +! +monitor session 1 + source ethernet 0/1 destination port-channel 1024 direction both +! +monitor session 2 +! +bridge-domain 100 p2mp +! +cluster MCT1 1 +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_startup-config b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_startup-config new file mode 100644 index 00000000..b2e540d9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_startup-config @@ -0,0 +1,624 @@ +root enable +host-table aging-mode conversational +clock timezone Europe/Warsaw +hardware + profile tcam default + profile overlay-visibility default + profile route-table default maximum_paths 8 + system-mode default +! +http server use-vrf default-vrf +http server use-vrf mgmt-vrf +node-id 1 +! +ntp server 172.16.10.2 use-vrf mgmt-vrf +! +logging raslog console INFO +logging syslog-server 10.1.5.11 use-vrf mgmt-vrf +! +logging auditlog class SECURITY +logging auditlog class CONFIGURATION +logging auditlog class FIRMWARE +logging syslog-facility local LOG_LOCAL0 +logging syslog-client localip CHASSIS_IP +switch-attributes chassis-name SLX9140-LEAF2 +switch-attributes host-name DC2LEAF2 +no support autoupload enable +support ffdc +resource-monitor cpu enable threshold 90 action raslog +resource-monitor memory enable threshold 100 action raslog +resource-monitor process memory enable alarm 1000 critical 1200 +system-monitor fan threshold marginal-threshold 1 down-threshold 2 +system-monitor fan alert state removed action raslog +system-monitor power threshold marginal-threshold 1 down-threshold 2 +system-monitor power alert state removed action raslog +system-monitor temp threshold marginal-threshold 1 down-threshold 2 +system-monitor cid-card threshold marginal-threshold 1 down-threshold 2 +system-monitor cid-card alert state none action none +system-monitor compact-flash threshold marginal-threshold 1 down-threshold 0 +system-monitor MM threshold marginal-threshold 1 down-threshold 0 +system-monitor LineCard threshold marginal-threshold 1 down-threshold 2 +system-monitor LineCard alert state none action none +system-monitor SFM threshold marginal-threshold 1 down-threshold 2 +telemetry server use-vrf mgmt-vrf + transport tcp + port 50051 + activate +! +telemetry profile system-utilization default_system_utilization_statistics + interval 60 + add total-system-memory + add total-used-memory + add total-free-memory + add cached-memory + add buffers + add user-free-memory + add kernel-free-memory + add total-swap-memory + add total-free-swap-memory + add total-used-swap-memory + add user-process + add system-process + add niced-process + add iowait + add hw-interrupt + add sw-interrupt + add idle-state + add steal-time + add uptime +! +telemetry profile interface default_interface_statistics + interval 30 + add out-pkts + add in-pkts + add out-unicast-pkts + add in-unicast-pkts + add out-broadcast-pkts + add in-broadcast-pkts + add out-multicast-pkts + add in-multicast-pkts + add out-pkts-per-second + add in-pkts-per-second + add out-bandwidth + add in-bandwidth + add out-octets + add in-octets + add out-errors + add in-errors + add out-crc-errors + add in-crc-errors + add out-discards + add in-discards +! +line vty + exec-timeout 10 +! +threshold-monitor Buffer limit 70 +vrf mgmt-vrf + address-family ipv4 unicast + ip route 0.0.0.0/0 172.168.192.1 + ! + address-family ipv6 unicast + ! +! +ssh server key rsa 2048 +ssh server key ecdsa 256 +ssh server key dsa +ssh server use-vrf default-vrf +ssh server use-vrf mgmt-vrf +telnet server use-vrf default-vrf +telnet server use-vrf mgmt-vrf +role name admin desc Administrator +role name user desc User +aaa authentication login local +aaa accounting exec default start-stop none +aaa accounting commands default start-stop none +service password-encryption +username admin password "AINTNOPARTYLIKEAHOTELPARTYCAUSEAHOTELPARTYDONTSLEEPNOONEWOULDEVERACTUALLYTYPETHISWHYAREYOUHERE\n" encryption-level 7 role admin desc Administrator +cee-map default + precedence 1 + priority-group-table 1 weight 40 pfc on + priority-group-table 15.0 pfc off + priority-group-table 15.1 pfc off + priority-group-table 15.2 pfc off + priority-group-table 15.3 pfc off + priority-group-table 15.4 pfc off + priority-group-table 15.5 pfc off + priority-group-table 15.6 pfc off + priority-group-table 15.7 pfc off + priority-group-table 2 weight 60 pfc off + priority-table 2 2 2 1 2 2 2 15.0 + remap lossless-priority priority 0 +! +mac access-list extended M1 + seq 10 permit any any +! +vlan 1 + ip igmp snooping startup-query-interval 100 + ipv6 mld snooping startup-query-interval 100 +! +vlan 100 +! +vlan 200 +! +vlan 1001 + router-interface Ve 1001 + description Thomas-Test-Cluster +! +qos map cos-mutation all-zero-map + map cos 0 to cos 0 + map cos 1 to cos 0 + map cos 2 to cos 0 + map cos 3 to cos 0 + map cos 4 to cos 0 + map cos 5 to cos 0 + map cos 6 to cos 0 + map cos 7 to cos 0 +! +qos map cos-mutation default + map cos 0 to cos 0 + map cos 1 to cos 1 + map cos 2 to cos 2 + map cos 3 to cos 3 + map cos 4 to cos 4 + map cos 5 to cos 5 + map cos 6 to cos 6 + map cos 7 to cos 7 +! +qos map cos-traffic-class all-zero-map + map cos 0 to traffic-class 0 + map cos 1 to traffic-class 0 + map cos 2 to traffic-class 0 + map cos 3 to traffic-class 0 + map cos 4 to traffic-class 0 + map cos 5 to traffic-class 0 + map cos 6 to traffic-class 0 + map cos 7 to traffic-class 0 +! +qos map cos-traffic-class default + map cos 0 to traffic-class 1 + map cos 1 to traffic-class 0 + map cos 2 to traffic-class 2 + map cos 3 to traffic-class 3 + map cos 4 to traffic-class 4 + map cos 5 to traffic-class 5 + map cos 6 to traffic-class 6 + map cos 7 to traffic-class 7 +! +qos map cos-dscp all-zero-map + map cos 0 to dscp 0 + map cos 1 to dscp 0 + map cos 2 to dscp 0 + map cos 3 to dscp 0 + map cos 4 to dscp 0 + map cos 5 to dscp 0 + map cos 6 to dscp 0 + map cos 7 to dscp 0 +! +qos map cos-dscp default + map cos 0 to dscp 0 + map cos 1 to dscp 8 + map cos 2 to dscp 16 + map cos 3 to dscp 24 + map cos 4 to dscp 32 + map cos 5 to dscp 40 + map cos 6 to dscp 48 + map cos 7 to dscp 56 +! +qos map traffic-class-cos all-zero-map + map traffic-class 0 to cos 0 + map traffic-class 1 to cos 0 + map traffic-class 2 to cos 0 + map traffic-class 3 to cos 0 + map traffic-class 4 to cos 0 + map traffic-class 5 to cos 0 + map traffic-class 6 to cos 0 + map traffic-class 7 to cos 0 +! +qos map traffic-class-cos default + map traffic-class 0 to cos 0 + map traffic-class 1 to cos 1 + map traffic-class 2 to cos 2 + map traffic-class 3 to cos 3 + map traffic-class 4 to cos 4 + map traffic-class 5 to cos 5 + map traffic-class 6 to cos 6 + map traffic-class 7 to cos 7 +! +qos map traffic-class-mutation all-zero-map + map traffic-class 0 to traffic-class 0 + map traffic-class 1 to traffic-class 0 + map traffic-class 2 to traffic-class 0 + map traffic-class 3 to traffic-class 0 + map traffic-class 4 to traffic-class 0 + map traffic-class 5 to traffic-class 0 + map traffic-class 6 to traffic-class 0 + map traffic-class 7 to traffic-class 0 +! +qos map traffic-class-mutation default + map traffic-class 0 to traffic-class 0 + map traffic-class 1 to traffic-class 1 + map traffic-class 2 to traffic-class 2 + map traffic-class 3 to traffic-class 3 + map traffic-class 4 to traffic-class 4 + map traffic-class 5 to traffic-class 5 + map traffic-class 6 to traffic-class 6 + map traffic-class 7 to traffic-class 7 +! +qos map traffic-class-dscp all-zero-map + map traffic-class 0 to dscp 0 + map traffic-class 1 to dscp 0 + map traffic-class 2 to dscp 0 + map traffic-class 3 to dscp 0 + map traffic-class 4 to dscp 0 + map traffic-class 5 to dscp 0 + map traffic-class 6 to dscp 0 + map traffic-class 7 to dscp 0 +! +qos map traffic-class-dscp default + map traffic-class 0 to dscp 0 + map traffic-class 1 to dscp 8 + map traffic-class 2 to dscp 16 + map traffic-class 3 to dscp 24 + map traffic-class 4 to dscp 32 + map traffic-class 5 to dscp 40 + map traffic-class 6 to dscp 48 + map traffic-class 7 to dscp 56 +! +qos map dscp-mutation all-zero-map + map dscp 0-63 to dscp 0 +! +qos map dscp-mutation default + map dscp 0 to dscp 0 + map dscp 1 to dscp 1 + map dscp 10 to dscp 10 + map dscp 11 to dscp 11 + map dscp 12 to dscp 12 + map dscp 13 to dscp 13 + map dscp 14 to dscp 14 + map dscp 15 to dscp 15 + map dscp 16 to dscp 16 + map dscp 17 to dscp 17 + map dscp 18 to dscp 18 + map dscp 19 to dscp 19 + map dscp 2 to dscp 2 + map dscp 20 to dscp 20 + map dscp 21 to dscp 21 + map dscp 22 to dscp 22 + map dscp 23 to dscp 23 + map dscp 24 to dscp 24 + map dscp 25 to dscp 25 + map dscp 26 to dscp 26 + map dscp 27 to dscp 27 + map dscp 28 to dscp 28 + map dscp 29 to dscp 29 + map dscp 3 to dscp 3 + map dscp 30 to dscp 30 + map dscp 31 to dscp 31 + map dscp 32 to dscp 32 + map dscp 33 to dscp 33 + map dscp 34 to dscp 34 + map dscp 35 to dscp 35 + map dscp 36 to dscp 36 + map dscp 37 to dscp 37 + map dscp 38 to dscp 38 + map dscp 39 to dscp 39 + map dscp 4 to dscp 4 + map dscp 40 to dscp 40 + map dscp 41 to dscp 41 + map dscp 42 to dscp 42 + map dscp 43 to dscp 43 + map dscp 44 to dscp 44 + map dscp 45 to dscp 45 + map dscp 46 to dscp 46 + map dscp 47 to dscp 47 + map dscp 48 to dscp 48 + map dscp 49 to dscp 49 + map dscp 5 to dscp 5 + map dscp 50 to dscp 50 + map dscp 51 to dscp 51 + map dscp 52 to dscp 52 + map dscp 53 to dscp 53 + map dscp 54 to dscp 54 + map dscp 55 to dscp 55 + map dscp 56 to dscp 56 + map dscp 57 to dscp 57 + map dscp 58 to dscp 58 + map dscp 59 to dscp 59 + map dscp 6 to dscp 6 + map dscp 60 to dscp 60 + map dscp 61 to dscp 61 + map dscp 62 to dscp 62 + map dscp 63 to dscp 63 + map dscp 7 to dscp 7 + map dscp 8 to dscp 8 + map dscp 9 to dscp 9 +! +qos map dscp-traffic-class all-zero-map + map dscp 0-63 to traffic-class 0 +! +qos map dscp-traffic-class default + map dscp 0-7 to traffic-class 0 + map dscp 16-23 to traffic-class 2 + map dscp 24-31 to traffic-class 3 + map dscp 32-39 to traffic-class 4 + map dscp 40-47 to traffic-class 5 + map dscp 48-55 to traffic-class 6 + map dscp 56-63 to traffic-class 7 + map dscp 8-15 to traffic-class 1 +! +qos map dscp-cos all-zero-map + map dscp 0-63 to cos 0 +! +qos map dscp-cos default + map dscp 0-7 to cos 0 + map dscp 16-23 to cos 2 + map dscp 24-31 to cos 3 + map dscp 32-39 to cos 4 + map dscp 40-47 to cos 5 + map dscp 48-55 to cos 6 + map dscp 56-63 to cos 7 + map dscp 8-15 to cos 1 +! +protocol lldp + advertise optional-tlv management-address + system-description Brocade BR-SLX9140 Router +! +vlan dot1q tag native +police-remark-profile default +! +class-map BD-100 +! +class-map C1 + match access-group M1 +! +class-map cee +! +class-map default +! +policy-map P1 + class C1 + police cir 1000000 + ! +! +policy-map P2 + class default + police cir 12121212 + ! +! +no protocol vrrp +no protocol vrrp-extended +router bgp + local-as 65301 + capability as4-enable + bfd interval 300 min-rx 300 multiplier 3 + neighbor leaf_group peer-group + neighbor leaf_group remote-as 65500 + neighbor leaf_group bfd + neighbor 10.220.4.3 remote-as 65500 + neighbor 10.220.4.3 peer-group leaf_group + address-family ipv4 unicast + network 172.32.252.5/32 + maximum-paths 8 + ! + address-family ipv6 unicast + ! + address-family l2vpn evpn + ! +! +interface Loopback 1 + ip address 172.16.128.6/32 + no shutdown +! +interface Loopback 2 + ip address 172.16.129.5/32 + no shutdown +! +interface Management 0 + no tcp burstrate + no shutdown + vrf forwarding mgmt-vrf + ip address dhcp +! +interface Ethernet 0/1 + speed 25000 + fec mode disabled + switchport + switchport mode access + switchport access vlan 1 + no shutdown +! +interface Ethernet 0/2 + no shutdown +! +interface Ethernet 0/3 + speed 25000 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/4 + shutdown +! +interface Ethernet 0/5 + service-policy in P1 + no shutdown +! +interface Ethernet 0/6 + mtu 1548 + description L2 Interface + no shutdown +! +interface Ethernet 0/7 + mtu 1548 + description L2 Interface + no shutdown +! +interface Ethernet 0/8 + switchport + switchport mode trunk + switchport trunk allowed vlan add 100,200 + switchport trunk tag native-vlan + shutdown +! +interface Ethernet 0/9 + shutdown +! +interface Ethernet 0/10 + no shutdown +! +interface Ethernet 0/11 + no shutdown +! +interface Ethernet 0/12 + no shutdown +! +interface Ethernet 0/13 + no shutdown +! +interface Ethernet 0/14 + no shutdown +! +interface Ethernet 0/15 + shutdown +! +interface Ethernet 0/16 + shutdown +! +interface Ethernet 0/17 + shutdown +! +interface Ethernet 0/18 + shutdown +! +interface Ethernet 0/19 + shutdown +! +interface Ethernet 0/20 + shutdown +! +interface Ethernet 0/21 + shutdown +! +interface Ethernet 0/22 + shutdown +! +interface Ethernet 0/23 + shutdown +! +interface Ethernet 0/24 + shutdown +! +interface Ethernet 0/25 + shutdown +! +interface Ethernet 0/26 + shutdown +! +interface Ethernet 0/27 + shutdown +! +interface Ethernet 0/28 + shutdown +! +interface Ethernet 0/29 + shutdown +! +interface Ethernet 0/30 + shutdown +! +interface Ethernet 0/31 + shutdown +! +interface Ethernet 0/32 + shutdown +! +interface Ethernet 0/33 + shutdown +! +interface Ethernet 0/34 + shutdown +! +interface Ethernet 0/35 + shutdown +! +interface Ethernet 0/36 + shutdown +! +interface Ethernet 0/37 + shutdown +! +interface Ethernet 0/38 + shutdown +! +interface Ethernet 0/39 + shutdown +! +interface Ethernet 0/40 + shutdown +! +interface Ethernet 0/41 + shutdown +! +interface Ethernet 0/42 + shutdown +! +interface Ethernet 0/43 + shutdown +! +interface Ethernet 0/44 + shutdown +! +interface Ethernet 0/45 + shutdown +! +interface Ethernet 0/46 + shutdown +! +interface Ethernet 0/47 + shutdown +! +interface Ethernet 0/48 + shutdown +! +interface Ethernet 0/49 + shutdown +! +interface Ethernet 0/50 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/51 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/52 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/53 + fec mode RS-FEC + no shutdown +! +interface Ethernet 0/54 + fec mode disabled + no shutdown +! +interface Port-channel 200 + switchport + switchport mode access + switchport access vlan 200 + shutdown +! +interface Port-channel 1024 + insight enable + no shutdown +! +monitor session 1 + source ethernet 0/1 destination port-channel 1024 direction both +! +monitor session 2 +! +bridge-domain 100 p2mp +! +cluster MCT1 1 +! diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_version b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_version new file mode 100644 index 00000000..0d648378 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/fixtures/slxos/show_version @@ -0,0 +1,18 @@ +SLX-OS Operating System Software +SLX-OS Operating System Version: 17s.1.02 +Copyright (c) 1995-2018 Brocade Communications Systems, Inc. +Firmware name: 17s.1.02 +Build Time: 00:06:59 Sep 28, 2017 +Install Time: 15:58:29 Feb 9, 2018 +Kernel: 2.6.34.6 +Host Version: Ubuntu 14.04 LTS +Host Kernel: Linux 3.14.17 + +Control Processor: QEMU Virtual CPU version 2.0.0 + +System Uptime: 34days 4hrs 41mins 53secs + +Slot Name Primary/Secondary Versions Status +--------------------------------------------------------------------------- +SW/0 SLX-OS 17s.1.02 ACTIVE* + 17s.1.02 diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py new file mode 100644 index 00000000..bce2dbef --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py @@ -0,0 +1,135 @@ +# +# (c) 2019 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. +# +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +from os import path +import json + +from mock import MagicMock + +from ansible_collections.cisco.ios.tests.unit.compat import unittest +from ansible_collections.cisco.ios.plugins.cliconf import ios +from ansible.module_utils._text import to_bytes + + +b_FIXTURE_DIR = b"%s/fixtures/ios" % ( + to_bytes( + path.dirname(path.abspath(__file__)), errors="surrogate_or_strict" + ) +) + + +def _connection_side_effect(*args, **kwargs): + try: + if args: + value = args[0] + else: + value = kwargs.get("command") + + fixture_path = path.abspath( + b"%s/%s" % (b_FIXTURE_DIR, b"_".join(value.split(b" "))) + ) + with open(fixture_path, "rb") as file_desc: + return file_desc.read() + except (OSError, IOError): + if args: + value = args[0] + return value + elif kwargs.get("command"): + value = kwargs.get("command") + return value + + return "Nope" + + +class TestPluginCLIConfIOS(unittest.TestCase): + """ Test class for IOS CLI Conf Methods + """ + + def setUp(self): + self._mock_connection = MagicMock() + self._mock_connection.send.side_effect = _connection_side_effect + self._cliconf = ios.Cliconf(self._mock_connection) + self.maxDiff = None + + def tearDown(self): + pass + + def test_get_device_info(self): + """ Test get_device_info + """ + device_info = self._cliconf.get_device_info() + + mock_device_info = { + "network_os": "ios", + "network_os_model": "CSR1000V", + "network_os_version": "16.06.01", + "network_os_hostname": "an-csr-01", + "network_os_image": "bootflash:packages.conf", + } + + self.assertEqual(device_info, mock_device_info) + + def test_get_capabilities(self): + """ Test get_capabilities + """ + capabilities = json.loads(self._cliconf.get_capabilities()) + mock_capabilities = { + "network_api": "cliconf", + "rpc": [ + "get_config", + "edit_config", + "get_capabilities", + "get", + "enable_response_logging", + "disable_response_logging", + "edit_banner", + "get_diff", + "run_commands", + "get_defaults_flag", + ], + "device_operations": { + "supports_diff_replace": True, + "supports_commit": False, + "supports_rollback": False, + "supports_defaults": True, + "supports_onbox_diff": False, + "supports_commit_comment": False, + "supports_multiline_delimiter": True, + "supports_diff_match": True, + "supports_diff_ignore_lines": True, + "supports_generate_diff": True, + "supports_replace": False, + }, + "device_info": { + "network_os_hostname": "an-csr-01", + "network_os_image": "bootflash:packages.conf", + "network_os_model": "CSR1000V", + "network_os_version": "16.06.01", + "network_os": "ios", + }, + "format": ["text"], + "diff_match": ["line", "strict", "exact", "none"], + "diff_replace": ["line", "block"], + "output": [], + } + + self.assertEqual(mock_capabilities, capabilities) diff --git a/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/requirements.txt b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/requirements.txt new file mode 100644 index 00000000..a9772bea --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/ios/tests/unit/requirements.txt @@ -0,0 +1,42 @@ +boto3 +placebo +pycrypto +passlib +pypsrp +python-memcached +pytz +pyvmomi +redis +requests +setuptools > 0.6 # pytest-xdist installed via requirements does not work with very old setuptools (sanity_ok) +unittest2 ; python_version < '2.7' +importlib ; python_version < '2.7' +netaddr +ipaddress +netapp-lib +solidfire-sdk-python + +# requirements for F5 specific modules +f5-sdk ; python_version >= '2.7' +f5-icontrol-rest ; python_version >= '2.7' +deepdiff + +# requirement for Fortinet specific modules +pyFMG + +# requirement for aci_rest module +xmljson + +# requirement for winrm connection plugin tests +pexpect + +# requirement for the linode module +linode-python # APIv3 +linode_api4 ; python_version > '2.6' # APIv4 + +# requirement for the gitlab module +python-gitlab +httmock + +# requirment for kubevirt modules +openshift ; python_version >= '2.7' |