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/iosxr/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/iosxr/tests')
415 files changed, 20187 insertions, 0 deletions
diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/.gitignore b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/.gitignore new file mode 100644 index 00000000..ea1472ec --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/.gitignore @@ -0,0 +1 @@ +output/ diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/network-integration.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/network-integration.cfg new file mode 100644 index 00000000..d12c1efe --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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/iosxr/tests/integration/target-prefixes.network b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/target-prefixes.network new file mode 100644 index 00000000..97a9d298 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/target-prefixes.network @@ -0,0 +1 @@ +iosxr
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_acl_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_populate.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_populate.yaml new file mode 100644 index 00000000..85fe0a12 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_populate.yaml @@ -0,0 +1,18 @@ +--- +- name: Populate the device with ACLs + cisco.iosxr.iosxr_config: + lines: "ipv4 access-list acl_1\n10 permit ipv4 any any\nipv4 access-list acl_2\n\ + 10 permit ipv4 any any\nipv4 access-list acl_3\n10 permit ipv4 any any\nipv6\ + \ access-list acl6_1\n10 permit ipv6 any any\nipv6 access-list acl6_2\n10\ + \ permit ipv6 any any\nipv6 access-list acl6_3\n10 permit ipv6 any any\n" + +- name: Setup ACL interfaces configuration for GigabitEthernet0/0/0/0 + cisco.iosxr.iosxr_config: + lines: "ipv4 access-group acl_1 ingress\nipv4 access-group acl_2 egress\nipv6\ + \ access-group acl6_1 ingress\nipv6 access-group acl6_2 egress\n" + parents: interface GigabitEthernet0/0/0/0 + +- name: Setup ACL interfaces configuration for GigabitEthernet0/0/0/1 + cisco.iosxr.iosxr_config: + lines: ipv4 access-group acl_1 egress + parents: interface GigabitEthernet0/0/0/1 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..830213fc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,27 @@ +--- +- name: Remove/Default Resources + vars: + lines: "default interface GigabitEthernet0/0/0/0\ndefault interface GigabitEthernet0/0/0/1\n\ + no ipv4 access-list acl_1\nno ipv4 access-list acl_2\nno ipv6 access-list\ + \ acl6_1\nno ipv6 access-list acl6_2\nno ipv6 access-list acl6_3\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' + +- name: Initialize interfaces + loop: + - interface GigabitEthernet0/0/0/0 + - interface GigabitEthernet0/0/0/1 + cisco.iosxr.iosxr_config: + lines: shutdown + parents: '{{ item }}' + +- name: Remove unwanted interfaces from config + loop: + - 0/0/0/2 + - 0/0/0/3 + - 0/0/0/4 + - 0/0/0/5 + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no interface GigabitEthernet{{ item }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..0481e755 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: Start iosxr_acl_interfaces deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + - name: Delete ACL attributes of GigabitEthernet0/0/0/1 + register: result + cisco.iosxr.iosxr_acl_interfaces: &id001 + config: + - name: GigabitEthernet0/0/0/1 + state: deleted + + - assert: + that: + - "'interface GigabitEthernet0/0/0/1' in result.commands" + - "'no ipv4 access-group acl_1 egress' in result.commands" + - result.commands|length == 2 + + - name: Delete ACL attributes of GigabitEthernet0/0/0/1 (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acl_interfaces: *id001 + + - assert: + that: + - result.changed == False + - result.commands|length == 0 + always: + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/deleted_all.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/deleted_all.yaml new file mode 100644 index 00000000..f980a08f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/deleted_all.yaml @@ -0,0 +1,52 @@ +--- +- debug: + msg: Start iosxr_acl_interfaces deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Delete all ACL interfaces configuration from the device + register: result + cisco.iosxr.iosxr_acl_interfaces: &id001 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete ACL attributes of all interfaces (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acl_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + - result.commands|length == 0 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..fe75770e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_acl_interfaces empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..81823360 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,14 @@ +interface MgmtEth0/0/CPU0/0 + ipv4 address dhcp +! +interface GigabitEthernet0/0/0/0 + shutdown + ipv4 access-group acl_1 ingress + ipv4 access-group acl_2 egress + ipv6 access-group acl6_1 ingress + ipv6 access-group acl6_2 egress +! +interface GigabitEthernet0/0/0/1 + shutdown + ipv4 access-group acl_1 egress +!
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..d6404ef3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,63 @@ +--- +- debug: + msg: START iosxr_acl_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- name: Populate the device with ACLs + cisco.iosxr.iosxr_config: + lines: "ipv4 access-list acl_1\n10 permit ipv4 any any\nipv4 access-list acl_2\n\ + 10 permit ipv4 any any\nipv6 access-list acl6_1\n10 permit ipv6 any any\n\ + ipv6 access-list acl6_2\n10 permit ipv6 any any\n" + +- block: + + - name: Merge the provided configuration with the existing running configuration + register: result + cisco.iosxr.iosxr_acl_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: in + + - name: acl_2 + direction: out + + - afi: ipv6 + acls: + + - name: acl6_1 + direction: in + + - name: acl6_2 + direction: out + + - name: GigabitEthernet0/0/0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: out + state: merged + + - name: Gather ACL interfaces facts using gathered state + register: result + cisco.iosxr.iosxr_acl_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: "{{ merged['after'] | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..44b134cf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/merged.yaml @@ -0,0 +1,132 @@ +--- +- debug: + msg: START iosxr_acl_interfaces merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- name: Populate the device with ACLs + cisco.iosxr.iosxr_config: + lines: "ipv4 access-list acl_1\n10 permit ipv4 any any\nipv4 access-list acl_2\n\ + 10 permit ipv4 any any\nipv6 access-list acl6_1\n10 permit ipv6 any any\n\ + ipv6 access-list acl6_2\n10 permit ipv6 any any\n" + +- block: + + - name: Merge the provided configuration with the existing running configuration + register: result + cisco.iosxr.iosxr_acl_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: in + + - name: acl_2 + direction: out + + - afi: ipv6 + acls: + + - name: acl6_1 + direction: in + + - name: acl6_2 + direction: out + + - name: GigabitEthernet0/0/0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: out + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acl_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Update acl_interfaces configuration using merged + register: result + cisco.iosxr.iosxr_acl_interfaces: &id002 + config: + + - name: GigabitEthernet0/0/0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_2 + direction: out + + - name: acl_1 + direction: in + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['update_before'] | symmetric_difference(result['before'])\ + \ |length == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['update_commands'] | symmetric_difference(result['commands'])\ + \ |length == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['update_after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Update acl_interfaces configuration using merged (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acl_interfaces: *id002 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..27a48689 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,78 @@ +--- +- debug: + msg: START iosxr_acl_interfaces overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Overridde all interface ACL configuration with provided configuration + register: result + cisco.iosxr.iosxr_acl_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + access_groups: + + - afi: ipv6 + acls: + + - name: acl6_3 + direction: in + + - name: GigabitEthernet0/0/0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_2 + direction: in + + - afi: ipv6 + acls: + + - name: acl6_3 + direction: out + 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: Overridde all interface ACL configuration with provided configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acl_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..3edc6faf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START iosxr_acl_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided ACL interfaces config to agnostic model + register: result + cisco.iosxr.iosxr_acl_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..f67d4520 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,46 @@ +--- +- debug: + msg: START iosxr_acl_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- name: Render platform specific commands from task input using rendered state + register: result + cisco.iosxr.iosxr_acl_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: in + + - name: acl_2 + direction: out + + - afi: ipv6 + acls: + + - name: acl6_1 + direction: in + + - name: acl6_2 + direction: out + + - name: GigabitEthernet0/0/0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: out + state: rendered + +- name: Assert that correct set of commands were rendered + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..4881afc5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,63 @@ +--- +- debug: + msg: START iosxr_acl_interfaces replaced integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Replace device configurations of listed interface with provided configurations + register: result + cisco.iosxr.iosxr_acl_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + access_groups: + + - afi: ipv6 + acls: + + - name: acl6_3 + direction: in + 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: Replace device configurations of listed interfaces with provided configurarions + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acl_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..8ee32f7b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,114 @@ +--- +- debug: + msg: START iosxr_acl_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Populate the device with ACLs + cisco.iosxr.iosxr_config: + lines: "ipv4 access-list acl_1\n10 permit ipv4 any any\nipv4 access-list\ + \ acl_2\n10 permit ipv4 any any\nipv4 access-list acl_3\n10 permit ipv4\ + \ any any\nipv6 access-list acl6_1\n10 permit ipv6 any any\nipv6 access-list\ + \ acl6_2\n10 permit ipv6 any any\nipv6 access-list acl6_3\n10 permit ipv6\ + \ any any\n" + + - name: Apply the provided configuration (base config) + cisco.iosxr.iosxr_acl_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: in + + - name: acl_2 + direction: out + + - afi: ipv6 + acls: + + - name: acl6_1 + direction: in + + - name: acl6_2 + direction: out + + - name: GigabitEthernet0/0/0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: out + state: merged + + - name: Gather interfaces facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - acl_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_acl_interfaces: + config: + + - name: GigabitEthernet0/0/0/1 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: in + + - name: acl_2 + direction: out + + - afi: ipv6 + acls: + + - name: acl6_1 + direction: in + + - name: acl6_2 + direction: out + + - name: GigabitEthernet0/0/0/0 + access_groups: + + - afi: ipv4 + acls: + + - name: acl_1 + direction: out + state: overridden + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_acl_interfaces: + config: "{{ ansible_facts['network_resources']['acl_interfaces'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: "{{ merged['after'] | symmetric_difference(revert['after']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/vars/main.yaml new file mode 100644 index 00000000..c96adb12 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acl_interfaces/vars/main.yaml @@ -0,0 +1,172 @@ +--- +merged: + before: + - name: MgmtEth0/0/CPU0/0 + - name: GigabitEthernet0/0/0/0 + - name: GigabitEthernet0/0/0/1 + commands: + - interface GigabitEthernet0/0/0/0 + - ipv4 access-group acl_1 ingress + - ipv4 access-group acl_2 egress + - ipv6 access-group acl6_1 ingress + - ipv6 access-group acl6_2 egress + - interface GigabitEthernet0/0/0/1 + - ipv4 access-group acl_1 egress + update_commands: + - interface GigabitEthernet0/0/0/1 + - ipv4 access-group acl_2 egress + - ipv4 access-group acl_1 ingress + after: + - name: MgmtEth0/0/CPU0/0 + - name: GigabitEthernet0/0/0/0 + access_groups: + - acls: + - name: acl_1 + direction: in + - name: acl_2 + direction: out + afi: ipv4 + - acls: + - name: acl6_1 + direction: in + - name: acl6_2 + direction: out + afi: ipv6 + - name: GigabitEthernet0/0/0/1 + access_groups: + - acls: + - name: acl_1 + direction: out + afi: ipv4 + update_before: + - name: MgmtEth0/0/CPU0/0 + - access_groups: + - acls: + - direction: in + name: acl_1 + - direction: out + name: acl_2 + afi: ipv4 + - acls: + - direction: in + name: acl6_1 + - direction: out + name: acl6_2 + afi: ipv6 + name: GigabitEthernet0/0/0/0 + - access_groups: + - acls: + - direction: out + name: acl_1 + afi: ipv4 + name: GigabitEthernet0/0/0/1 + update_after: + - name: MgmtEth0/0/CPU0/0 + - access_groups: + - acls: + - direction: in + name: acl_1 + - direction: out + name: acl_2 + afi: ipv4 + - acls: + - direction: in + name: acl6_1 + - direction: out + name: acl6_2 + afi: ipv6 + name: GigabitEthernet0/0/0/0 + - access_groups: + - acls: + - direction: in + name: acl_1 + - direction: out + name: acl_2 + afi: ipv4 + name: GigabitEthernet0/0/0/1 +replaced: + commands: + - interface GigabitEthernet0/0/0/0 + - no ipv4 access-group acl_1 ingress + - no ipv4 access-group acl_2 egress + - no ipv6 access-group acl6_2 egress + - ipv6 access-group acl6_3 ingress + after: + - name: MgmtEth0/0/CPU0/0 + - name: GigabitEthernet0/0/0/0 + access_groups: + - afi: ipv6 + acls: + - name: acl6_3 + direction: in + - name: GigabitEthernet0/0/0/1 + access_groups: + - acls: + - name: acl_1 + direction: out + afi: ipv4 +overridden: + commands: + - interface GigabitEthernet0/0/0/0 + - no ipv4 access-group acl_1 ingress + - no ipv4 access-group acl_2 egress + - no ipv6 access-group acl6_2 egress + - ipv6 access-group acl6_3 ingress + - interface GigabitEthernet0/0/0/1 + - no ipv4 access-group acl_1 egress + - ipv4 access-group acl_2 ingress + - ipv6 access-group acl6_3 egress + after: + - name: MgmtEth0/0/CPU0/0 + - name: GigabitEthernet0/0/0/0 + access_groups: + - afi: ipv6 + acls: + - name: acl6_3 + direction: in + - name: GigabitEthernet0/0/0/1 + access_groups: + - acls: + - name: acl_2 + direction: in + afi: ipv4 + - acls: + - name: acl6_3 + direction: out + afi: ipv6 +deleted: + commands: + - interface GigabitEthernet0/0/0/0 + - no ipv4 access-group acl_1 ingress + - no ipv4 access-group acl_2 egress + - no ipv6 access-group acl6_1 ingress + - no ipv6 access-group acl6_2 egress + - interface GigabitEthernet0/0/0/1 + - no ipv4 access-group acl_1 egress + after: + - name: MgmtEth0/0/CPU0/0 + - name: GigabitEthernet0/0/0/0 + - name: GigabitEthernet0/0/0/1 +round_trip: + after: + - name: MgmtEth0/0/CPU0/0 + - access_groups: + - acls: + - direction: out + name: acl_1 + afi: ipv4 + name: GigabitEthernet0/0/0/0 + - access_groups: + - acls: + - direction: in + name: acl_1 + - direction: out + name: acl_2 + afi: ipv4 + - acls: + - direction: in + name: acl6_1 + - direction: out + name: acl6_2 + afi: ipv6 + name: GigabitEthernet0/0/0/1 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_acls/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..0f840b45 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/_populate_config.yaml @@ -0,0 +1,9 @@ +--- +- name: Setup + cisco.iosxr.iosxr_config: + lines: "ipv6 access-list acl6_1\n10 deny tcp 2001:db8:1234::/48 range ftp telnet\ + \ any syn ttl range 180 250 authen routing log\n20 permit icmpv6 any any router-advertisement\ + \ precedence network destopts\nipv4 access-list acl_1\n16 remark TEST_ACL_1_REMARK\n\ + 21 permit tcp host 192.0.2.10 range pop3 121 198.51.100.0 0.0.0.15 rst\n23\ + \ deny icmp any 198.51.100.0 0.0.0.15 reassembly-timeout dscp lt af12\nipv4\ + \ access-list acl_2\n10 remark TEST_ACL_2_REMARK" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..42a59d70 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/_remove_config.yaml @@ -0,0 +1,9 @@ +--- +- name: Remove ACLs + vars: + lines: "no ipv4 access-list acl_1\nno ipv4 access-list acl_2\nno ipv4 access-list\ + \ acl_3\nno ipv4 access-list acl_3\nno ipv6 access-list acl6_1\nno ipv6 access-list\ + \ acl6_2\nno ipv6 access-list acl6_3\n" + ignore_errors: true + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/deleted.yaml new file mode 100644 index 00000000..25bca57b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/deleted.yaml @@ -0,0 +1,100 @@ +--- +- debug: + msg: Start iosxr_lag_interfaces deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + - name: Delete a single ACL + register: result + cisco.iosxr.iosxr_acls: &id002 + config: + + - afi: ipv6 + acls: + + - name: acl6_1 + state: deleted + + - assert: + that: + - '"no ipv6 access-list acl6_1" in result.commands' + - result.commands|length == 1 + + - name: Delete a single ACL (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acls: *id002 + + - name: Assert that the previous task was idempotent + assert: &id003 + that: + - result.changed == false + - result.commands|length == 0 + + - name: Delete all ACLs under one AFI + register: result + cisco.iosxr.iosxr_acls: &id004 + config: + + - afi: ipv4 + state: deleted + + - assert: + that: + - '"no ipv4 access-list acl_1" in result.commands' + - '"no ipv4 access-list acl_2" in result.commands' + - result.commands|length == 2 + + - name: Delete all ACLs under one AFI (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acls: *id004 + + - name: Assert that the previous task was idempotent + assert: *id003 + + - include_tasks: _populate_config.yaml + + - name: Delete all ACLs from the device + register: result + cisco.iosxr.iosxr_acls: &id005 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete all ACLs from the device (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acls: *id005 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + - result.commands|length == 0 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/empty_config.yaml new file mode 100644 index 00000000..311c5a08 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_acls empty_config integration tests on connection={{ ansible_connection + }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_acls/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..31155e23 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,8 @@ +ipv4 access-list acl_1 + 10 remark TEST_ACL_2_REMARK +ipv4 access-list acl_2 + 11 deny tcp 2001:db8:1234::/48 range ftp telnet any syn ttl range 180 250 authen routing log + 21 permit icmpv6 any any router-advertisement precedence network packet-length eq 576 destopts +ipv6 access-list acl6_1 + 10 deny tcp 2001:db8:1234::/48 range ftp telnet any syn ttl range 180 250 routing authen log + 20 permit icmpv6 any any router-advertisement precedence network packet-length eq 576 destopts diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/gathered.yaml new file mode 100644 index 00000000..ca4d0ffb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/gathered.yaml @@ -0,0 +1,23 @@ +--- +- debug: + msg: START iosxr_acls gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather ACL interfaces facts using gathered state + register: result + cisco.iosxr.iosxr_acls: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: "{{ merged['after'] | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/merged.yaml new file mode 100644 index 00000000..cdc39ae0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/merged.yaml @@ -0,0 +1,186 @@ +--- +- debug: + msg: START iosxr_acls merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_acls: &id001 + config: + + - afi: ipv6 + acls: + + - name: acl6_1 + aces: + + - sequence: 10 + grant: deny + protocol: tcp + source: + prefix: 2001:db8:1234::/48 + port_protocol: + range: + start: ftp + end: telnet + destination: + any: true + protocol_options: + tcp: + syn: true + ttl: + range: + start: 180 + end: 250 + routing: true + authen: true + log: true + + - sequence: 20 + grant: permit + protocol: icmpv6 + source: + any: true + destination: + any: true + protocol_options: + icmpv6: + router_advertisement: true + precedence: network + destopts: true + + - afi: ipv4 + acls: + + - name: acl_1 + aces: + + - sequence: 16 + remark: TEST_ACL_1_REMARK + + - sequence: 21 + grant: permit + protocol: tcp + source: + host: 192.0.2.10 + port_protocol: + range: + start: pop3 + end: 121 + destination: + address: 198.51.100.0 + wildcard_bits: 0.0.0.15 + protocol_options: + tcp: + rst: true + + - sequence: 23 + grant: deny + protocol: icmp + source: + any: true + destination: + prefix: 198.51.100.0/28 + protocol_options: + icmp: + reassembly_timeout: true + dscp: + lt: af12 + + - name: acl_2 + aces: + + - sequence: 10 + remark: TEST_ACL_2_REMARK + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acls: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Update existing ACEs + register: result + cisco.iosxr.iosxr_acls: &id002 + config: + + - afi: ipv4 + acls: + + - name: acl_1 + aces: + + - sequence: 21 + source: + prefix: 198.51.100.32/28 + port_protocol: + range: + start: pop3 + end: 121 + protocol_options: + tcp: + syn: true + + - sequence: 23 + protocol_options: + icmp: + router_advertisement: true + dscp: + eq: af23 + state: merged + + - name: Assert that the correct set of commands were generated + assert: + that: + - '"ipv4 access-list acl_1" in result.commands' + - '"21 permit tcp 198.51.100.32 0.0.0.15 range pop3 121 198.51.100.0 0.0.0.15 + syn" in result.commands' + - '"23 deny icmp any 198.51.100.0 0.0.0.15 router-advertisement dscp eq + af23" in result.commands' + - result.commands|length == 3 + + - name: Update existing ACEs (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acls: *id002 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/overridden.yaml new file mode 100644 index 00000000..884bb9c3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/overridden.yaml @@ -0,0 +1,79 @@ +--- +- debug: + msg: START iosxr_acls overridden integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Overridde all ACLs configuration with provided configuration + register: result + cisco.iosxr.iosxr_acls: &id001 + config: + + - afi: ipv4 + acls: + + - name: acl_1 + aces: + + - sequence: 10 + grant: permit + source: + any: true + destination: + any: true + protocol: tcp + + - name: acl_2 + aces: + + - sequence: 20 + grant: permit + source: + any: true + destination: + any: true + protocol: igmp + 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: Overridde all interface LAG interface configuration with provided configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acls: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/parsed.yaml new file mode 100644 index 00000000..4a046ade --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/parsed.yaml @@ -0,0 +1,15 @@ +--- +- debug: + msg: START iosxr_acls parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided ACL config to agnostic model + register: result + cisco.iosxr.iosxr_acls: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ parsed | symmetric_difference(result['parsed']) |length == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/rendered.yaml new file mode 100644 index 00000000..976a1627 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/rendered.yaml @@ -0,0 +1,101 @@ +--- +- debug: + msg: START iosxr_acls rendered integration tests on connection={{ ansible_connection + }} + +- name: Render platform specific commands from task input using rendered state + register: result + cisco.iosxr.iosxr_acls: + config: + + - afi: ipv6 + acls: + + - name: acl6_1 + aces: + + - sequence: 10 + grant: deny + protocol: tcp + source: + prefix: 2001:db8:1234::/48 + port_protocol: + range: + start: ftp + end: telnet + destination: + any: true + protocol_options: + tcp: + syn: true + ttl: + range: + start: 180 + end: 250 + routing: true + authen: true + log: true + + - sequence: 20 + grant: permit + protocol: icmpv6 + source: + any: true + destination: + any: true + protocol_options: + icmpv6: + router_advertisement: true + precedence: network + destopts: true + + - afi: ipv4 + acls: + + - name: acl_1 + aces: + + - sequence: 16 + remark: TEST_ACL_1_REMARK + + - sequence: 21 + grant: permit + protocol: tcp + source: + host: 192.0.2.10 + port_protocol: + range: + start: pop3 + end: 121 + destination: + address: 198.51.100.0 + wildcard_bits: 0.0.0.15 + protocol_options: + tcp: + rst: true + + - sequence: 23 + grant: deny + protocol: icmp + source: + any: true + destination: + prefix: 198.51.100.0/28 + protocol_options: + icmp: + reassembly_timeout: true + dscp: + lt: af12 + + - name: acl_2 + aces: + + - sequence: 10 + remark: TEST_ACL_2_REMARK + state: rendered + +- name: Assert that correct set of commands were rendered + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/replaced.yaml new file mode 100644 index 00000000..fb6b6230 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/replaced.yaml @@ -0,0 +1,78 @@ +--- +- debug: + msg: START iosxr_acl_interfaces replaced integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replace device configurations of listed ACL with provided configurations + register: result + cisco.iosxr.iosxr_acls: &id001 + config: + + - afi: ipv4 + acls: + + - name: acl_2 + aces: + + - sequence: 11 + grant: permit + protocol: igmp + source: + host: 198.51.100.130 + destination: + any: true + ttl: + eq: 100 + + - sequence: 12 + grant: deny + source: + any: true + destination: + any: true + protocol: icmp + 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: Replace device configurations of listed interfaces with provided configurarions + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_acls: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/rtt.yaml new file mode 100644 index 00000000..68ead0b1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/tests/cli/rtt.yaml @@ -0,0 +1,96 @@ +--- +- debug: + msg: START iosxr_acls round trip integration tests on connection={{ ansible_connection + }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_acls: + config: + + - afi: ipv4 + acls: + + - name: acl_2 + aces: + + - sequence: 11 + grant: permit + protocol: igmp + source: + host: 198.51.100.130 + destination: + any: true + ttl: + eq: 100 + + - sequence: 12 + grant: deny + source: + any: true + destination: + any: true + protocol: icmp + state: merged + + - name: Gather interfaces facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - acls + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_acls: + config: + + - afi: ipv4 + acls: + + - name: acl_1 + aces: + + - sequence: 10 + grant: permit + source: + any: true + destination: + any: true + protocol: tcp + + - name: acl_2 + aces: + + - sequence: 20 + grant: permit + source: + any: true + destination: + any: true + protocol: igmp + state: overridden + + - name: Assert that changes were applied + assert: + that: "{{ overridden['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_acls: + config: "{{ ansible_facts['network_resources']['acls'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/vars/main.yaml new file mode 100644 index 00000000..86b2569d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_acls/vars/main.yaml @@ -0,0 +1,317 @@ +--- +merged: + before: [] + commands: + - ipv6 access-list acl6_1 + - 10 deny tcp 2001:db8:1234::/48 range ftp telnet any syn ttl range 180 250 authen + routing log + - 20 permit icmpv6 any any router-advertisement precedence network destopts + - ipv4 access-list acl_1 + - 16 remark TEST_ACL_1_REMARK + - 21 permit tcp host 192.0.2.10 range pop3 121 198.51.100.0 0.0.0.15 rst + - 23 deny icmp any 198.51.100.0 0.0.0.15 reassembly-timeout dscp lt af12 + - ipv4 access-list acl_2 + - 10 remark TEST_ACL_2_REMARK + after: + - acls: + - aces: + - remark: TEST_ACL_1_REMARK + sequence: 16 + - destination: + address: 198.51.100.0 + wildcard_bits: 0.0.0.15 + grant: permit + protocol: tcp + protocol_options: + tcp: + rst: true + sequence: 21 + source: + host: 192.0.2.10 + port_protocol: + range: + end: '121' + start: pop3 + - destination: + address: 198.51.100.0 + wildcard_bits: 0.0.0.15 + dscp: + lt: af12 + grant: deny + protocol: icmp + protocol_options: + icmp: + reassembly_timeout: true + sequence: 23 + source: + any: true + name: acl_1 + - aces: + - remark: TEST_ACL_2_REMARK + sequence: 10 + name: acl_2 + afi: ipv4 + - acls: + - aces: + - authen: true + destination: + any: true + grant: deny + log: true + protocol: tcp + protocol_options: + tcp: + syn: true + routing: true + sequence: 10 + source: + port_protocol: + range: + end: telnet + start: ftp + prefix: 2001:db8:1234::/48 + ttl: + range: + end: 250 + start: 180 + - destination: + any: true + destopts: true + grant: permit + precedence: network + protocol: icmpv6 + protocol_options: + icmpv6: + router_advertisement: true + sequence: 20 + source: + any: true + name: acl6_1 + afi: ipv6 +replaced: + commands: + - ipv4 access-list acl_2 + - no 10 + - 11 permit igmp host 198.51.100.130 any ttl eq 100 + - 12 deny icmp any any + after: + - acls: + - aces: + - remark: TEST_ACL_1_REMARK + sequence: 16 + - destination: + address: 198.51.100.0 + wildcard_bits: 0.0.0.15 + grant: permit + protocol: tcp + protocol_options: + tcp: + rst: true + sequence: 21 + source: + host: 192.0.2.10 + port_protocol: + range: + end: '121' + start: pop3 + - destination: + address: 198.51.100.0 + wildcard_bits: 0.0.0.15 + dscp: + lt: af12 + grant: deny + protocol: icmp + protocol_options: + icmp: + reassembly_timeout: true + sequence: 23 + source: + any: true + name: acl_1 + - aces: + - destination: + any: true + grant: permit + protocol: igmp + sequence: 11 + source: + host: 198.51.100.130 + ttl: + eq: 100 + - destination: + any: true + grant: deny + protocol: icmp + sequence: 12 + source: + any: true + name: acl_2 + afi: ipv4 + - acls: + - aces: + - authen: true + destination: + any: true + grant: deny + log: true + protocol: tcp + protocol_options: + tcp: + syn: true + routing: true + sequence: 10 + source: + port_protocol: + range: + end: telnet + start: ftp + prefix: 2001:db8:1234::/48 + ttl: + range: + end: 250 + start: 180 + - destination: + any: true + destopts: true + grant: permit + precedence: network + protocol: icmpv6 + protocol_options: + icmpv6: + router_advertisement: true + sequence: 20 + source: + any: true + name: acl6_1 + afi: ipv6 +overridden: + commands: + - no ipv6 access-list acl6_1 + - ipv4 access-list acl_1 + - no 16 + - no 21 + - no 23 + - 10 permit tcp any any + - ipv4 access-list acl_2 + - no 10 + - 20 permit igmp any any + after: + - acls: + - aces: + - destination: + any: true + grant: permit + protocol: tcp + sequence: 10 + source: + any: true + name: acl_1 + - aces: + - destination: + any: true + grant: permit + protocol: igmp + sequence: 20 + source: + any: true + name: acl_2 + afi: ipv4 +deleted: + commands: + - no ipv4 access-list acl_1 + - no ipv4 access-list acl_2 + - no ipv6 access-list acl6_1 + after: [] +parsed: + - acls: + - aces: + - remark: TEST_ACL_2_REMARK + sequence: 10 + name: acl_1 + - aces: + - authen: true + destination: + any: true + grant: deny + log: true + protocol: tcp + protocol_options: + tcp: + syn: true + routing: true + sequence: 11 + source: + port_protocol: + range: + end: telnet + start: ftp + prefix: 2001:db8:1234::/48 + ttl: + range: + end: 250 + start: 180 + - destination: + any: true + destopts: true + grant: permit + packet_length: + eq: 576 + precedence: network + protocol: icmpv6 + protocol_options: + icmpv6: + router_advertisement: true + sequence: 21 + source: + any: true + name: acl_2 + afi: ipv4 + - acls: + - aces: + - authen: true + destination: + any: true + grant: deny + log: true + protocol: tcp + protocol_options: + tcp: + syn: true + routing: true + sequence: 10 + source: + port_protocol: + range: + end: telnet + start: ftp + prefix: 2001:db8:1234::/48 + ttl: + range: + end: 250 + start: 180 + - destination: + any: true + destopts: true + grant: permit + packet_length: + eq: 576 + precedence: network + protocol: icmpv6 + protocol_options: + icmpv6: + router_advertisement: true + sequence: 20 + source: + any: true + name: acl6_1 + afi: ipv6 +round_trip: + after: + - members: + - member: GigabitEthernet0/0/0/8 + mode: passive + - member: GigabitEthernet0/0/0/9 + mode: active + name: Bundle-Ether10 + - mode: active + name: Bundle-Ether11 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/meta/main.yaml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/cli.yaml new file mode 100644 index 00000000..8f7b62f9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/cli.yaml @@ -0,0 +1,18 @@ +--- +- 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 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 + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/main.yaml new file mode 100644 index 00000000..5d082a6f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- include: cli.yaml +- include: netconf.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/netconf.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/netconf.yaml new file mode 100644 index 00000000..7579953a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tasks/netconf.yaml @@ -0,0 +1,26 @@ +--- +- name: collect all netconf test cases + find: + paths: '{{ role_path }}/tests/netconf' + 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.netconf) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.netconf' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: + - netconf + +- 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/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-login.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-login.yaml new file mode 100644 index 00000000..82f48d6b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-login.yaml @@ -0,0 +1,36 @@ +--- +- name: setup - remove login + cisco.iosxr.iosxr_banner: + banner: login + provider: '{{ cli }}' + state: absent + +- name: Set login + register: result + cisco.iosxr.iosxr_banner: + banner: login + text: "@this is my login banner\nthat has a multiline\nstring\n@" + provider: '{{ cli }}' + state: present + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + - "'this is my login banner' in result.commands[0]" + - "'that has a multiline' in result.commands[0]" + +- name: Set login again (idempotent) + register: result + cisco.iosxr.iosxr_banner: + banner: login + text: "@this is my login banner\nthat has a multiline\nstring\n@" + provider: '{{ cli }}' + state: present + +- assert: + that: + - result.changed == false + - result.commands | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-motd.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-motd.yaml new file mode 100644 index 00000000..1b442c0d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-motd.yaml @@ -0,0 +1,36 @@ +--- +- name: setup - remove motd + cisco.iosxr.iosxr_banner: + banner: motd + state: absent + provider: '{{ cli }}' + +- name: Set motd + register: result + cisco.iosxr.iosxr_banner: + banner: motd + text: "@this is my motd banner\nthat has a multiline\nstring\n@" + provider: '{{ cli }}' + state: present + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + - "'this is my motd banner' in result.commands[0]" + - "'that has a multiline' in result.commands[0]" + +- name: Set motd again (idempotent) + register: result + cisco.iosxr.iosxr_banner: + banner: motd + text: "@this is my motd banner\nthat has a multiline\nstring\n@" + provider: '{{ cli }}' + state: present + +- assert: + that: + - result.changed == false + - result.commands | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-no-login.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-no-login.yaml new file mode 100644 index 00000000..0274ca26 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/cli/basic-no-login.yaml @@ -0,0 +1,34 @@ +--- +- name: Setup + cisco.iosxr.iosxr_banner: + banner: login + text: "@Junk login banner\nover multiple lines\n@" + provider: '{{ cli }}' + state: present + +- name: remove login + register: result + cisco.iosxr.iosxr_banner: + banner: login + state: absent + provider: '{{ cli }}' + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + - "'no banner login' in result.commands[0]" + +- name: remove login (idempotent) + register: result + cisco.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-login.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-login.yaml new file mode 100644 index 00000000..057a1ab9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-login.yaml @@ -0,0 +1,36 @@ +--- +- name: setup - remove login + cisco.iosxr.iosxr_banner: + banner: login + provider: '{{ netconf }}' + state: absent + +- name: Set login + register: result + cisco.iosxr.iosxr_banner: + banner: login + text: "@this is my login banner\nthat has a multiline\nstring\n@" + provider: '{{ netconf }}' + state: present + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + - "'this is my login banner' in result.xml" + - "'that has a multiline' in result.xml" + +- name: Set login again (idempotent) + register: result + cisco.iosxr.iosxr_banner: + banner: login + text: "@this is my login banner\nthat has a multiline\nstring\n@" + provider: '{{ netconf }}' + state: present + +- assert: + that: + - result.changed == false + - result.xml | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-motd.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-motd.yaml new file mode 100644 index 00000000..52bd3a76 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-motd.yaml @@ -0,0 +1,36 @@ +--- +- name: setup - remove motd + cisco.iosxr.iosxr_banner: + banner: motd + state: absent + provider: '{{ netconf }}' + +- name: Set motd + register: result + cisco.iosxr.iosxr_banner: + banner: motd + text: "@this is my motd banner\nthat has a multiline\nstring\n@" + provider: '{{ netconf }}' + state: present + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + - "'this is my motd banner' in result.xml" + - "'that has a multiline' in result.xml" + +- name: Set motd again (idempotent) + register: result + cisco.iosxr.iosxr_banner: + banner: motd + text: "@this is my motd banner\nthat has a multiline\nstring\n@" + provider: '{{ netconf }}' + state: present + +- assert: + that: + - result.changed == false + - result.xml | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-no-login.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-no-login.yaml new file mode 100644 index 00000000..72d125d9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_banner/tests/netconf/basic-no-login.yaml @@ -0,0 +1,34 @@ +--- +- name: Setup + cisco.iosxr.iosxr_banner: + banner: login + text: "@Junk login banner\nover multiple lines\n@" + provider: '{{ netconf }}' + state: present + +- name: remove login + register: result + cisco.iosxr.iosxr_banner: + banner: login + state: absent + provider: '{{ netconf }}' + +- debug: + msg: '{{ result }}' + +- assert: + that: + - result.changed == true + - "'xc:operation=\"delete\"' in result.xml" + +- name: remove login (idempotent) + register: result + cisco.iosxr.iosxr_banner: + banner: login + state: absent + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + - result.xml | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/meta/main.yaml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tasks/cli.yaml new file mode 100644 index 00000000..163934f5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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 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/iosxr/tests/integration/targets/iosxr_bgp/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tests/cli/basic.yaml new file mode 100644 index 00000000..dc2b4c44 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_bgp/tests/cli/basic.yaml @@ -0,0 +1,256 @@ +--- +- debug: msg="START iosxr cli/iosxr_bgp.yaml on connection={{ ansible_connection + }}" + +- name: Check IOS-XR version + register: facts + cisco.iosxr.iosxr_facts: + gather_subset: default + +- block: + + - name: Clear existing BGP config + ignore_errors: true + cisco.iosxr.iosxr_bgp: + operation: delete + + - name: Configure BGP with AS 64496 and a router-id + register: result + cisco.iosxr.iosxr_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.iosxr.iosxr_bgp: *id001 + + - assert: + that: + - result.changed == false + + - name: Configure BGP neighbors + register: result + cisco.iosxr.iosxr_bgp: &id002 + operation: merge + config: + bgp_as: 64496 + neighbors: + + - neighbor: 192.0.2.10 + remote_as: 64496 + description: IBGP_NBR_1 + advertisement_interval: 120 + timers: + keepalive: 300 + holdtime: 360 + + - neighbor: 192.0.2.15 + remote_as: 64496 + description: IBGP_NBR_2 + tcp_mss: 1500 + + - assert: + that: + - result.changed == true + - "'router bgp 64496' in result.commands" + - "'neighbor 192.0.2.10' in result.commands" + - "'remote-as 64496' in result.commands" + - "'description IBGP_NBR_1' in result.commands" + - "'timers 300 360' in result.commands" + - "'advertisement-interval 120' in result.commands" + - "'neighbor 192.0.2.15' in result.commands" + - "'remote-as 64496' in result.commands" + - "'description IBGP_NBR_2' in result.commands" + - "'tcp mss 1500' in result.commands" + + - name: Configure BGP neighbors (idempotent) + register: result + cisco.iosxr.iosxr_bgp: *id002 + + - assert: + that: + - result.changed == false + + - name: Configure BGP neighbors with operation replace + register: result + cisco.iosxr.iosxr_bgp: &id003 + operation: replace + config: + bgp_as: 64496 + neighbors: + + - neighbor: 192.0.2.15 + remote_as: 64496 + description: IBGP_NBR_2 + tcp_mss: 1500 + + - neighbor: 203.0.113.10 + remote_as: 64511 + description: EBGP_NBR_1 + + - assert: + that: + - result.changed == true + - "'neighbor 203.0.113.10' in result.commands" + - "'remote-as 64511' in result.commands" + - "'description EBGP_NBR_1' in result.commands" + - "'no neighbor 192.0.2.10' in result.commands" + + - name: Configure BGP neighbors with operation replace (idempotent) + register: result + cisco.iosxr.iosxr_bgp: *id003 + + - assert: + that: + - result.changed == false + + - name: create route-policy as prerequisite for BGP configuration + register: result + cisco.iosxr.iosxr_config: + lines: + - no route-policy RMAP_1 + - route-policy RMAP_1 + - exit + + - name: Configure networks under address family + register: result + cisco.iosxr.iosxr_bgp: &id004 + operation: merge + config: + bgp_as: 64496 + address_family: + + - afi: ipv4 + 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 + + - afi: ipv4 + safi: multicast + networks: + + - prefix: 198.51.100.64 + masklen: 28 + + - assert: + that: + - result.changed == true + - "'router bgp 64496' in result.commands" + - "'address-family ipv4 unicast' in result.commands" + - "'network 198.51.100.48/28 route-policy RMAP_1' in result.commands" + - "'network 192.0.2.64/27' in result.commands" + - "'network 203.0.113.160/27' in result.commands" + - "'address-family ipv4 multicast' in result.commands" + - "'network 198.51.100.64/28' in result.commands" + + - name: Configure networks under address family (idempotent) + register: result + cisco.iosxr.iosxr_bgp: *id004 + + - assert: + that: + - result.changed == false + + - name: Configure networks under address family with operation replace + register: result + cisco.iosxr.iosxr_bgp: &id005 + operation: replace + config: + bgp_as: 64496 + address_family: + + - afi: ipv4 + safi: unicast + 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: multicast + networks: + + - prefix: 198.51.100.64 + masklen: 28 + + - assert: + that: + - result.changed == true + - '"router bgp 64496" in result.commands' + - '"address-family ipv4 unicast" in result.commands' + - '"network 198.51.100.80/28" in result.commands' + - '"network 203.0.113.192/27" in result.commands' + - '"no network 198.51.100.48/28" in result.commands' + - '"no network 203.0.113.160/27" in result.commands' + + - name: Configure networks under address family with operation replace (idempotent) + register: result + cisco.iosxr.iosxr_bgp: *id005 + + - assert: + that: + - result.changed == false + + - name: Override all the exisiting BGP config + register: result + cisco.iosxr.iosxr_bgp: + operation: override + config: + bgp_as: 64497 + router_id: 192.0.2.10 + log_neighbor_changes: true + + - assert: + that: + - result.changed == true + - "'router bgp 64497' in result.commands" + - "'bgp router-id 192.0.2.10' in result.commands" + - "'bgp log neighbor changes detail' in result.commands" + + - name: Teardown + register: result + cisco.iosxr.iosxr_bgp: &id006 + operation: delete + + - assert: + that: + - result.changed == true + - "'no router bgp 64497' in result.commands" + + - name: Teardown again (idempotent) + register: result + cisco.iosxr.iosxr_bgp: *id006 + + - assert: + that: + - result.changed == false + + - name: delete route-policy configures as prerequisite for BGP configuration + (teardown) + cisco.iosxr.iosxr_config: + lines: no route-policy RMAP_1 + when: facts['ansible_facts']['ansible_net_version'].split('[')[0] == '6.1.3' + +- debug: msg="END iosxr cli/iosxr_bgp.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/meta/main.yml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tasks/cli.yaml new file mode 100644 index 00000000..163934f5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/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 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/iosxr/tests/integration/targets/iosxr_command/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/bad_operator.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/bad_operator.yaml new file mode 100644 index 00000000..8831d890 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/bad_operator.yaml @@ -0,0 +1,20 @@ +--- +- debug: msg="START cli/bad_operator.yaml on connection={{ ansible_connection }}" + +- name: test bad operator + register: result + ignore_errors: true + cisco.iosxr.iosxr_command: + commands: + - show version + - show interfaces GigabitEthernet 0/0 + 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/iosxr/tests/integration/targets/iosxr_command/tests/cli/cli_command.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/cli_command.yaml new file mode 100644 index 00000000..496478fb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/cli_command.yaml @@ -0,0 +1,45 @@ +--- +- debug: + msg: START cli/cli_command.yaml on connection={{ ansible_connection }} + +- 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 + +- name: delete config file on disk to prevent failure of copy task for duplicate + ignore_errors: true + ansible.netcommon.cli_command: + command: delete harddisk:ansible_tmp.txt + prompt: Delete harddisk\:/?ansible_tmp\.txt\[confirm\] + answer: '' + +- name: Run command with prompt + register: result + ansible.netcommon.cli_command: + command: copy running-config harddisk:ansible_tmp.txt + prompt: 'Destination file name \(control-c to abort\)\: \[\/ansible_tmp.txt\]\?' + answer: ansible_tmp.txt + +- assert: + that: + - result.stdout is defined + - "'ansible_tmp' in result.stdout" + +- debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/contains.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/contains.yaml new file mode 100644 index 00000000..c36ea300 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/contains.yaml @@ -0,0 +1,19 @@ +--- +- debug: msg="START cli/contains.yaml on connection={{ ansible_connection }}" + +- name: test contains operator + register: result + cisco.iosxr.iosxr_command: + commands: + - show version + - show interfaces Loopback 888 + wait_for: + - result[0] contains 'Cisco IOS XR Software' + - result[1] contains 'Hardware is Loopback interface' + +- 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/iosxr/tests/integration/targets/iosxr_command/tests/cli/invalid.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/invalid.yaml new file mode 100644 index 00000000..585dd24e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/invalid.yaml @@ -0,0 +1,32 @@ +--- +- debug: msg="START cli/invalid.yaml on connection={{ ansible_connection }}" + +- name: run invalid command + register: result + ignore_errors: true + cisco.iosxr.iosxr_command: + commands: + command: show foo + prompt: fooprompt + answer: "yes" + +- assert: + that: + - result.failed + +- name: run commands that include invalid command + register: result + ignore_errors: true + cisco.iosxr.iosxr_command: + commands: + - show version + + - command: show foo + prompt: fooprompt + answer: "yes" + +- assert: + that: + - result.failed + +- debug: msg="END cli/invalid.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/output.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/output.yaml new file mode 100644 index 00000000..468b556f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/output.yaml @@ -0,0 +1,28 @@ +--- +- debug: msg="START cli/output.yaml on connection={{ ansible_connection }}" + +- name: get output for single command + register: result + cisco.iosxr.iosxr_command: + commands: + - show version + +- assert: + that: + - result.changed == false + - result.stdout is defined + +- name: get output for multiple commands + register: result + cisco.iosxr.iosxr_command: + commands: + - show version + - show interfaces + +- 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/iosxr/tests/integration/targets/iosxr_command/tests/cli/prompt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/prompt.yaml new file mode 100644 index 00000000..4a82d0d0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/prompt.yaml @@ -0,0 +1,28 @@ +--- +- debug: + msg: START cli/prompt.yaml on connection={{ ansible_connection }} + +- name: delete config file on disk to prevent failure of copy task for duplicate + ignore_errors: true + cisco.iosxr.iosxr_command: + commands: + + - command: delete harddisk:ansible_tmp.txt + prompt: Delete harddisk\:/?ansible_tmp\.txt\[confirm\] + answer: '' + +- name: copy + register: result + cisco.iosxr.iosxr_command: + commands: + + - command: copy running-config harddisk:ansible_tmp.txt + prompt: 'Destination file name \(control-c to abort\)\: \[\/ansible_tmp.txt\]\?' + answer: ansible_tmp.txt + +- assert: + that: + - result.stdout is defined + - "'ansible_tmp' in result.stdout[0]" + +- debug: msg="END cli/prompt.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/timeout.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/timeout.yaml new file mode 100644 index 00000000..374271d3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_command/tests/cli/timeout.yaml @@ -0,0 +1,18 @@ +--- +- debug: msg="START cli/timeout.yaml on connection={{ ansible_connection }}" + +- name: test bad condition + register: result + ignore_errors: true + cisco.iosxr.iosxr_command: + commands: + - show version + 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/iosxr/tests/integration/targets/iosxr_config/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/fixtures/config_add_interface.txt b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/fixtures/config_add_interface.txt new file mode 100644 index 00000000..4aca2814 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/fixtures/config_add_interface.txt @@ -0,0 +1,35 @@ +hostname iosxr01 +line default + transport input ssh +! +interface Loopback888 + description test for ansible + shutdown +! +interface MgmtEth0/0/CPU0/0 + ipv4 address dhcp +! +interface preconfigure GigabitEthernet0/0/0/3 + description test-interface-3 + mtu 256 + speed 100 + duplex full +! +interface GigabitEthernet0/0/0/0 + shutdown +! +interface GigabitEthernet0/0/0/1 + shutdown +! +router static + address-family ipv4 unicast + 0.0.0.0/0 10.0.2.2 + ! +! +netconf-yang agent + ssh +! +ssh server v2 +ssh server netconf vrf default +! +end diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/fixtures/config_del_interface.txt b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/fixtures/config_del_interface.txt new file mode 100644 index 00000000..a35e4da7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/fixtures/config_del_interface.txt @@ -0,0 +1,29 @@ +hostname iosxr01 +line default + transport input ssh +! +interface Loopback888 + description test for ansible + shutdown +! +interface MgmtEth0/0/CPU0/0 + ipv4 address dhcp +! +interface GigabitEthernet0/0/0/0 + shutdown +! +interface GigabitEthernet0/0/0/1 + shutdown +! +router static + address-family ipv4 unicast + 0.0.0.0/0 10.0.2.2 + ! +! +netconf-yang agent + ssh +! +ssh server v2 +ssh server netconf vrf default +! +end diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/meta/main.yml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli.yaml new file mode 100644 index 00000000..8f7b62f9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli.yaml @@ -0,0 +1,18 @@ +--- +- 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 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 + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli_config.yaml new file mode 100644 index 00000000..6edbb8f3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/cli_config.yaml @@ -0,0 +1,18 @@ +--- +- name: collect all cli 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 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 + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/main.yaml new file mode 100644 index 00000000..5604e9eb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/main.yaml @@ -0,0 +1,6 @@ +--- +- include: cli.yaml +- include: cli_config.yaml + +- include: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/redirection.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tasks/redirection.yaml new file mode 100644 index 00000000..6282ad40 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_config/templates/basic/change_prefix_set.j2 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/change_prefix_set.j2 new file mode 100644 index 00000000..572d15bf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/change_prefix_set.j2 @@ -0,0 +1,7 @@ +prefix-set ebpg_filter + 192.168.0.0/16 ge 15 le 30 +end-set + +interface Loopback999 + description this is a test interface for prefix-set + diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/config.j2 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/config.j2 new file mode 100644 index 00000000..06f98488 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_config/templates/basic/configuration.j2 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/configuration.j2 new file mode 100644 index 00000000..73c98879 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/configuration.j2 @@ -0,0 +1,3 @@ +interface Loopback888 + description test for ansible automation + shutdown diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/init_prefix_set.j2 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/init_prefix_set.j2 new file mode 100644 index 00000000..d1170b02 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/init_prefix_set.j2 @@ -0,0 +1,3 @@ +prefix-set ebpg_filter + 192.168.0.0/16 ge 17 le 30 +end-set diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/route_policy.j2 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/route_policy.j2 new file mode 100644 index 00000000..ecc68e81 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/route_policy.j2 @@ -0,0 +1,121 @@ +router ospf 1 + area 0 +! +prefix-set EBGP-PEER-BOGONS + 0.0.0.0/0, + 0.0.0.0/8 le 32, + 10.0.0.0/8 le 32, + 127.0.0.0/8 le 32, + 169.254.0.0/16 le 32, + 172.16.0.0/12 le 32, + 192.0.0.0/24 le 32, + 192.0.2.0/24 le 32, + 192.168.0.0/16 le 32, + 198.18.0.0/15 le 32, + 224.0.0.0/4 le 32, + 240.0.0.0/4 le 32 +end-set +! +prefix-set cust-ddos-DDOS +end-set +! +prefix-set cust-no-export +end-set +! +prefix-set acme_DC_Internal + 137.1.0.0/16, + 137.1.16.0/24, + 137.1.18.0/24, + 137.1.20.0/24, + 137.1.22.0/24, + 137.1.23.0/24, + 137.1.24.0/24, + 137.1.29.0/24, + 137.1.30.0/24, + 137.1.31.0/24, + 137.1.32.0/21, + 137.1.40.0/22, + 209.1.0.0/16 +end-set +! +as-path-set EBGP-PEER-AS16509-403-PERMIT-PATHS + ios-regex '^11164_8075_', + ios-regex '^11164_16509$', + ios-regex '^1116_16509_[0-9]+$', + ios-regex '^8075_', + ios-regex '^16509$', + ios-regex '^16509_[0-9]+$' +end-set +! +community-set cust-announce + 1525:65298, + 1525:65436, + 1525:65438, + 1525:65439, + 1525:65498, + 1525:65511, + 1523:65418, + 1523:65436, + 1523:65438 +end-set +! +community-set cust-no-export + 1525:65439, + 1525:65511, + 1525:65535 +end-set +! + +route-policy POLICY2 +end-policy +! +route-policy cust2bgp + set origin igp + set next-hop 137.1.16.12 +end-policy +! +rd-set ebpg-1 +end-set +! +rd-set EBGP_INCOMING_RD_SET + 172.16.0.0/16:*, + 172.17.0.0/16:100, + 192:*, + 192:100 +end-set +! +extcommunity-set rt EBGP_INCOMIG_RT_SET + 10:615, + 10:6150, + 15.15.15.15:15 +end-set +! +extcommunity-set rt ebpg-1 +end-set +! +route-policy static-to-bgp + if destination in cust-no-export then + apply cust2bgp + set community cust-no-export additive + elseif destination in cust-announce then + apply cust2bgp + set community cust-announce additive + elseif destination in cust-announce-backup then + apply cust2bgp + set local-preference 100 + set weight 0 + set community cust-announce additive + elseif destination in cust-no-export-backup then + apply cust2bgp + set local-preference 98 + set weight 0 + set community cust-no-export additive + else + drop + endif +end-policy +! +class-map match-any data + match precedence ipv4 0 1 + end-class-map +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/route_policy_change.j2 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/route_policy_change.j2 new file mode 100644 index 00000000..45448bae --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/route_policy_change.j2 @@ -0,0 +1,65 @@ +prefix-set EBGP-PEER-BOGONS + 192.0.2.0/24 le 32, + 192.168.0.0/16 le 32, + 198.18.0.0/16 le 32, + 224.0.0.0/4 le 32, + 240.0.0.0/4 le 32 +end-set +! +as-path-set EBGP-PEER-AS16509-403-PERMIT-PATHS + ios-regex '^11164_8075_', + ios-regex '^1164_16509$', + ios-regex '^1116_16409_[0-9]+$', + ios-regex '^8075_' +end-set +! +community-set cust-announce + 1525:65298, + 1525:6546, + 1525:6438, + 1525:65439, + 1525:65498 +end-set +! +rd-set EBGP_INCOMING_RD_SET + 172.16.0.0/16:*, + 172.14.0.0/16:100, + 192:*, + 192:100 +end-set +! +extcommunity-set rt EBGP_INCOMIG_RT_SET + 10:615, + 10:6120, + 15.15.15.15:15 +end-set +! +route-policy POLICY2 +end-policy +! +route-policy static-to-bgp + if destination in cust-no-export then + apply cust2bgp + set community cust-no-export additive + elseif destination in cust-announce then + apply cust2bgp + set community cust-announce additive + elseif destination in cust-announce-backup then + apply cust2bgp + set local-preference 100 + set weight 23 + set community cust-announce additive + elseif destination in cust-no-export-backup then + apply cust2bgp + set local-preference 98 + set weight 0 + set community cust-no-export additive + else + drop + endif +end-policy +! +class-map match-any data + match precedence ipv4 0 1 2 + end-class-map +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/route_policy_clean.j2 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/route_policy_clean.j2 new file mode 100644 index 00000000..08ba7686 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/basic/route_policy_clean.j2 @@ -0,0 +1,32 @@ +no router ospf 1 +! +no prefix-set EBGP-PEER-BOGONS +! +no prefix-set cust-ddos-DDOS +! +no prefix-set cust-no-export +! +no prefix-set acme_DC_Internal +! +no as-path-set EBGP-PEER-AS16509-403-PERMIT-PATHS +! +no community-set cust-announce +! +no community-set cust-no-export +! +no rd-set ebpg-1 +! +no rd-set EBGP_INCOMING_RD_SET +! +no extcommunity-set rt EBGP_INCOMIG_RT_SET +! +no extcommunity-set rt ebpg-1 +! +no route-policy POLICY2 +! +no route-policy cust2bgp +! +no route-policy static-to-bgp +! +no class-map match-any data +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/defaults/config.j2 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/templates/defaults/config.j2 new file mode 100644 index 00000000..1d4d9da8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_config/tests/cli/backup.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/backup.yaml new file mode 100644 index 00000000..f1c1a89c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/backup.yaml @@ -0,0 +1,124 @@ +--- +- debug: msg="START cli/backup.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.iosxr.iosxr_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*' + connection: local + register: backup_files + +- name: delete backup files + file: + path: '{{ item.path }}' + state: absent + with_items: '{{backup_files.files|default([])}}' + +- name: configure device with config + register: result + cisco.iosxr.iosxr_config: + src: basic/config.j2 + backup: true + +- assert: + that: + - result.changed == true + - result.updates is not defined + +- name: collect any backup files + find: + paths: '{{ role_path }}/backup' + pattern: '{{ inventory_hostname_short }}_config*' + connection: local + register: backup_files + +- 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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/backup.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/comment-too-long.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/comment-too-long.yaml new file mode 100644 index 00000000..39232f8b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/comment-too-long.yaml @@ -0,0 +1,28 @@ +--- +- debug: msg="START cli/comment-too-long.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: Commit message too long + register: result + ignore_errors: true + cisco.iosxr.iosxr_config: + src: basic/config.j2 + comment: this is a really long message aaaaabbbbbbcdde end-of-message + +- assert: + that: + - result.changed == false + - result.updates is not defined + - "'comment argument cannot be more than 60 characters' in result.msg" + +- debug: msg="END cli/comment-too-long.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/comment.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/comment.yaml new file mode 100644 index 00000000..a75784f8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/comment.yaml @@ -0,0 +1,36 @@ +--- +- debug: msg="START cli/comment.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: configure device with comment + register: result + cisco.iosxr.iosxr_config: + src: basic/config.j2 + comment: this is sensible commit message + exclusive: true + +- assert: + that: + - result.changed == true + - result.updates is not defined + +- name: check device with config + register: result + cisco.iosxr.iosxr_config: + src: basic/config.j2 + exclusive: true + +- assert: + that: + - result.changed == false + - result.updates is not defined + +- debug: msg="END cli/comment.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/commit_label.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/commit_label.yaml new file mode 100644 index 00000000..73f9924e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/commit_label.yaml @@ -0,0 +1,70 @@ +--- +- debug: msg="START cli/commit_label.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: get a unique and valid label + set_fact: + label: ansible_{{ 1001 | random | to_uuid | truncate(20, true, '_') }} + +- name: configure device with a label and a comment + register: result + cisco.iosxr.iosxr_config: + src: basic/config.j2 + comment: this is sensible commit message + label: '{{ label }}' + +- assert: + that: + - result.changed == true + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: Try to commit with old label, fail with a msg that label is alreay used + register: result + ignore_errors: true + cisco.iosxr.iosxr_config: + src: basic/config.j2 + label: '{{ label }}' + +- assert: + that: + - result.changed == false + - "'already used' in result.msg" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: Try to commit with invalid chars($) in label + register: result + ignore_errors: true + cisco.iosxr.iosxr_config: + src: basic/config.j2 + label: ansible_iosxr_config_$ + +- assert: + that: + - result.changed == false + - "'only contain alphabets' in result.msg" + +- debug: msg="END cli/commit_label.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/misplaced_sublevel.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/misplaced_sublevel.yaml new file mode 100644 index 00000000..3776cc52 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/misplaced_sublevel.yaml @@ -0,0 +1,29 @@ +--- +- debug: msg="START cli/misplaced_sublevel.yaml on connection={{ ansible_connection + }}" + +- name: setup + ignore_errors: true + cisco.iosxr.iosxr_config: + src: basic/init_prefix_set.j2 + +- name: Change prefix-set and new command after prefix-set + register: result + cisco.iosxr.iosxr_config: + src: basic/change_prefix_set.j2 + +- assert: + that: + - result.changed == true + +- name: Play same config again to verify no diff in prefix-set also works + register: result + cisco.iosxr.iosxr_config: + src: basic/change_prefix_set.j2 + +- assert: + that: + - result.changed == false + +- debug: msg="END cli/misplaced_sublevel.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/prefix_set_remark.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/prefix_set_remark.yaml new file mode 100644 index 00000000..48884a95 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/prefix_set_remark.yaml @@ -0,0 +1,29 @@ +--- +- debug: msg="START cli/prefix_set_remark.yaml on connection={{ ansible_connection }}" + +- name: pre-setup cleanup + cisco.iosxr.iosxr_config: + commands: + - no prefix-set test_set + +- name: setup + register: result + cisco.iosxr.iosxr_config: + lines: + - '#testremark' + - 192.168.1.0/20 le 24 + - end-set + parents: prefix-set test_set + +- assert: + that: + - result.changed == true + - "'#testremark' in result.commands" + +- name: post-setup cleanup + cisco.iosxr.iosxr_config: + commands: + - no prefix-set test_set + + +- debug: msg="END cli/prefix_set_remark.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_config.yaml new file mode 100644 index 00000000..4ce326a2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/replace_config.yaml @@ -0,0 +1,44 @@ +--- +- debug: msg="START cli/replace_config.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no interface GigabitEthernet0/0/0/3 + +- name: replace config (add preconfigured interface) + register: result + cisco.iosxr.iosxr_config: &id001 + src: '{{ role_path }}/fixtures/config_add_interface.txt' + replace: config + +- assert: + that: + - '"load harddisk:/ansible_config.txt" in result.commands' + +- name: replace config (add preconfigured interface)(idempotence) + register: result + cisco.iosxr.iosxr_config: *id001 + +- assert: &id003 + that: + - result.changed == false + +- name: replace config (del preconfigured interface) + register: result + cisco.iosxr.iosxr_config: &id002 + src: '{{ role_path }}/fixtures/config_del_interface.txt' + replace: config + +- assert: + that: + - '"load harddisk:/ansible_config.txt" in result.commands' + +- name: replace config (del preconfigured interface)(idempotence) + register: result + cisco.iosxr.iosxr_config: *id002 + +- assert: *id003 + +- debug: msg="END cli/replace_config.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/route_policy.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/route_policy.yaml new file mode 100644 index 00000000..a3cb79aa --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/route_policy.yaml @@ -0,0 +1,53 @@ +--- +- debug: msg="START cli/route_policy.yaml on connection={{ ansible_connection }}" + +- name: Cleanup + cisco.iosxr.iosxr_config: + src: basic/route_policy_clean.j2 + +- name: config setup route-policy/prefix-set/as-path-set/community-set + register: result + cisco.iosxr.iosxr_config: + src: basic/route_policy.j2 + +- assert: + that: + - result.changed == true + +- name: Configure same route-policy/prefix-set ... verify change=0 + register: result + cisco.iosxr.iosxr_config: + src: basic/route_policy.j2 + +- assert: + that: + - result.changed == false + +- name: Do a change in multi-sublevel route-policy/prefix-set/community-set + register: result + cisco.iosxr.iosxr_config: + src: basic/route_policy_change.j2 + +- assert: + that: + - result.changed == true + +- name: Configure same route-policy/prefix-set ... verify change=0 + register: result + cisco.iosxr.iosxr_config: + src: basic/route_policy_change.j2 + +- assert: + that: + - result.changed == false + +- name: Cleanup + register: result + cisco.iosxr.iosxr_config: + src: basic/route_policy_clean.j2 + +- assert: + that: + - result.changed == true + +- debug: msg="END cli/route_policy.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/src_basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/src_basic.yaml new file mode 100644 index 00000000..34a6a430 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/src_basic.yaml @@ -0,0 +1,33 @@ +--- +- debug: msg="START cli/src_basic.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: configure device with config + register: result + cisco.iosxr.iosxr_config: + src: basic/config.j2 + +- assert: + that: + - result.changed == true + - result.updates is not defined + +- name: check device with config + register: result + cisco.iosxr.iosxr_config: + src: basic/config.j2 + +- assert: + that: + - result.changed == false + - result.updates is not defined + +- debug: msg="END cli/src_basic.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/src_invalid.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/src_invalid.yaml new file mode 100644 index 00000000..688f5e13 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_config/tests/cli/src_match_none.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/src_match_none.yaml new file mode 100644 index 00000000..298136ad --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/src_match_none.yaml @@ -0,0 +1,35 @@ +--- +- debug: msg="START cli/src_match_none.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no description + - no shutdown + parents: + - interface Loopback999 + match: none + +- name: configure device with config + register: result + cisco.iosxr.iosxr_config: + src: basic/config.j2 + match: none + +- assert: + that: + - result.changed == true + - result.updates is not defined + +- name: check device with config + register: result + cisco.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel.yaml new file mode 100644 index 00000000..f01a525b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel.yaml @@ -0,0 +1,43 @@ +--- +- debug: msg="START cli/sublevel.yaml on connection={{ ansible_connection }}" + +- name: setup + ignore_errors: true + cisco.iosxr.iosxr_config: + commands: + - no ipv4 access-list test + match: none + +- name: configure sub level command + register: result + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 any any log + parents: + - ipv4 access-list test + +- assert: + that: + - result.changed == true + - "'ipv4 access-list test' in result.commands" + - "'10 permit ipv4 any any log' in result.commands" + +- name: configure sub level command idempotent check + register: result + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 any any log + parents: + - ipv4 access-list test + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + commands: + - no ipv4 access-list test + match: none + +- debug: msg="END cli/sublevel.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_block.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_block.yaml new file mode 100644 index 00000000..1c0a84e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_block.yaml @@ -0,0 +1,60 @@ +--- +- debug: msg="START cli/sublevel_block.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + parents: + - ipv4 access-list test + before: + - no ipv4 access-list test + match: none + +- name: configure sub level command using block resplace + register: result + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + - 40 permit ipv4 host 192.0.2.4 any log + parents: + - ipv4 access-list test + replace: block + +- assert: + that: + - result.changed == true + - "'ipv4 access-list test' in result.commands" + - "'10 permit ipv4 host 192.0.2.1 any log' in result.commands" + - "'20 permit ipv4 host 192.0.2.2 any log' in result.commands" + - "'30 permit ipv4 host 192.0.2.3 any log' in result.commands" + - "'40 permit ipv4 host 192.0.2.4 any log' in result.commands" + +- name: check sub level command using block replace + register: result + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + - 40 permit ipv4 host 192.0.2.4 any log + parents: + - ipv4 access-list test + replace: block + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + commands: + - no ipv4 access-list test + match: none + +- debug: msg="END cli/sublevel_block.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_exact.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_exact.yaml new file mode 100644 index 00000000..29648c9a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_exact.yaml @@ -0,0 +1,64 @@ +--- +- debug: msg="START cli/sublevel_exact.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + - 40 permit ipv4 host 192.0.2.4 any log + - 50 permit ipv4 host 192.0.2.5 any log + parents: + - ipv4 access-list test + before: + - no ipv4 access-list test + match: none + +- name: configure sub level command using exact match + register: result + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + - 40 permit ipv4 host 192.0.2.4 any log + parents: + - ipv4 access-list test + match: exact + +- assert: + that: + - result.changed == true + - "'ipv4 access-list test' in result.commands" + - "'10 permit ipv4 host 192.0.2.1 any log' in result.commands" + - "'20 permit ipv4 host 192.0.2.2 any log' in result.commands" + - "'30 permit ipv4 host 192.0.2.3 any log' in result.commands" + - "'40 permit ipv4 host 192.0.2.4 any log' in result.commands" + - "'50 permit ipv4 host 192.0.2.5 any log' not in result.commands" + +- name: check sub level command using exact match + register: result + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + - 40 permit ipv4 host 192.0.2.4 any log + - 50 permit ipv4 host 192.0.2.5 any log + parents: + - ipv4 access-list test + match: exact + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + commands: + - no ipv4 access-list test + match: none + +- debug: msg="END cli/sublevel_exact.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_strict.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_strict.yaml new file mode 100644 index 00000000..0ed1155e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_strict.yaml @@ -0,0 +1,66 @@ +--- +- debug: msg="START cli/sublevel_strict.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.3 any log + - 30 permit ipv4 host 192.0.2.2 any log + - 40 permit ipv4 host 192.0.2.4 any log + - 50 permit ipv4 host 192.0.2.5 any log + parents: + - ipv4 access-list test + before: + - no ipv4 access-list test + match: none + +- name: configure sub level command using strict match + register: result + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + - 40 permit ipv4 host 192.0.2.4 any log + parents: + - ipv4 access-list test + before: + - no ipv4 access-list test + match: strict + replace: block + +- assert: + that: + - result.changed == true + - "'ipv4 access-list test' in result.commands" + - "'10 permit ipv4 host 192.0.2.1 any log' in result.commands" + - "'20 permit ipv4 host 192.0.2.2 any log' in result.commands" + - "'30 permit ipv4 host 192.0.2.3 any log' in result.commands" + - "'40 permit ipv4 host 192.0.2.4 any log' in result.commands" + - "'50 permit ipv4 host 192.0.2.5 any log' not in result.commands" + +- name: check sub level command using strict match + register: result + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + - 40 permit ipv4 host 192.0.2.4 any log + parents: + - ipv4 access-list test + match: strict + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + commands: + - no ipv4 access-list test + match: none + +- debug: msg="END cli/sublevel_strict.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_strict_mul_parents.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_strict_mul_parents.yaml new file mode 100644 index 00000000..e7dc8a4d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/sublevel_strict_mul_parents.yaml @@ -0,0 +1,75 @@ +--- +- debug: msg="START cli/sublevel_strict_mul_parents.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + lines: + - class-map match-any c1 + - match precedence 7 + - policy-map p1 + - class c1 + - set precedence 2 + before: + - no policy-map p1 + - no class-map match-any c1 + match: none + +- name: configure sub level command using strict match + register: result + cisco.iosxr.iosxr_config: + lines: + - set precedence 5 + - police rate percent 10 + parents: + - policy-map p1 + - class c1 + match: strict + +- assert: + that: + - result.changed == true + - "'set precedence 5' in result.commands" + - "'police rate percent 10' in result.commands" + +- name: change sub level command order and config with strict match + register: result + cisco.iosxr.iosxr_config: + lines: + - police rate percent 10 + - set precedence 5 + parents: + - policy-map p1 + - class c1 + match: strict + +- assert: + that: + - result.changed == true + - "'set precedence 5' in result.commands" + - "'police rate percent 10' in result.commands" + +- name: Config sub level command with strict match (Idempotency) + register: result + cisco.iosxr.iosxr_config: + lines: + - set precedence 5 + - police rate percent 10 + parents: + - policy-map p1 + - class c1 + match: strict + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + lines: + - no policy-map p1 + - no class-map match-any 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/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel.yaml new file mode 100644 index 00000000..eb7d8185 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel.yaml @@ -0,0 +1,37 @@ +--- +- debug: msg="START cli/toplevel.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - hostname {{ inventory_hostname_short }} + match: none + +- name: configure top level command + register: result + cisco.iosxr.iosxr_config: + commands: + - hostname foo + +- assert: + that: + - result.changed == true + - "'hostname foo' in result.commands" + +- name: configure top level command idempotent check + register: result + cisco.iosxr.iosxr_config: + commands: + - hostname foo + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + commands: + - hostname {{ inventory_hostname_short }} + match: none + +- debug: msg="END cli/toplevel.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel_after.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel_after.yaml new file mode 100644 index 00000000..73a2a17b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel_after.yaml @@ -0,0 +1,45 @@ +--- +- debug: msg="START cli/toplevel_after.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no cdp + - hostname {{ inventory_hostname_short }} + match: none + +- name: configure top level command with before + register: result + cisco.iosxr.iosxr_config: + commands: + - hostname foo + after: + - cdp + +- assert: + that: + - result.changed == true + - "'hostname foo' in result.commands" + - "'cdp' in result.commands" + +- name: configure top level command with before idempotent check + register: result + cisco.iosxr.iosxr_config: + commands: + - hostname foo + after: + - no cdp + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + commands: + - no cdp + - hostname {{ inventory_hostname_short }} + match: none + +- debug: msg="END cli/toplevel_after.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel_before.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel_before.yaml new file mode 100644 index 00000000..70ac2462 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel_before.yaml @@ -0,0 +1,45 @@ +--- +- debug: msg="START cli/toplevel_before.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - no cdp + - hostname {{ inventory_hostname_short }} + match: none + +- name: configure top level command with before + register: result + cisco.iosxr.iosxr_config: + commands: + - hostname foo + before: + - cdp + +- assert: + that: + - result.changed == true + - "'hostname foo' in result.commands" + - "'cdp' in result.commands" + +- name: configure top level command with before idempotent check + register: result + cisco.iosxr.iosxr_config: + commands: + - hostname foo + before: + - cdp + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + commands: + - no cdp + - hostname {{ inventory_hostname_short }} + match: none + +- debug: msg="END cli/toplevel_before.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel_nonidempotent.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel_nonidempotent.yaml new file mode 100644 index 00000000..a6c2a1ff --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli/toplevel_nonidempotent.yaml @@ -0,0 +1,44 @@ +--- +- debug: msg="START cli/toplevel_nonidempotent.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + commands: + - hostname {{ inventory_hostname_short }} + match: none + +- name: configure top level command + register: result + cisco.iosxr.iosxr_config: + commands: + - banner motd "hello world" + - hostname foo + match: strict + +- assert: + that: + - result.changed == true + - "'hostname foo' in result.commands" + - "'banner motd \"hello world\"' in result.commands" + +- name: configure top level command idempotent check + register: result + cisco.iosxr.iosxr_config: + commands: + - banner motd "hello world" + - hostname foo + match: strict + +- assert: + that: + - result.changed == true + +- name: teardown + cisco.iosxr.iosxr_config: + commands: + - hostname {{ inventory_hostname_short }} + match: none + +- debug: msg="END cli/toplevel_nonidempotent.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli_config/cli_backup.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli_config/cli_backup.yaml new file mode 100644 index 00000000..3880a040 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_config/tests/cli_config/cli_basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli_config/cli_basic.yaml new file mode 100644 index 00000000..21c0db45 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/cli_config/cli_basic.yaml @@ -0,0 +1,32 @@ +--- +- debug: msg="START cli_config/cli_basic.yaml on connection={{ ansible_connection + }}" + +- name: setup + become: true + ansible.netcommon.cli_config: &id002 + config: "interface Loopback999\n no description\n no shutdown\n" + +- name: configure device with config + register: result + become: true + 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: 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/iosxr/tests/integration/targets/iosxr_config/tests/redirection/shortname.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/redirection/shortname.yaml new file mode 100644 index 00000000..d1c67fe2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_config/tests/redirection/shortname.yaml @@ -0,0 +1,37 @@ +--- +- debug: msg="START redirection/shortname.yaml on connection={{ ansible_connection }}" + +- name: Use src with module alias + register: result + cisco.iosxr.config: + src: basic/configuration.j2 + +- assert: + that: + # make sure that the template content was read and not the path + - result.changed == true + - '"description test for ansible automation" in result.diff["prepared"]' + +- name: use module alias to take configuration backup + register: result + cisco.iosxr.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 redirection/shortname.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/meta/main.yml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tasks/cli.yaml new file mode 100644 index 00000000..163934f5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/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 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/iosxr/tests/integration/targets/iosxr_facts/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/all_facts.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/all_facts.yaml new file mode 100644 index 00000000..d41e7ae2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/all_facts.yaml @@ -0,0 +1,21 @@ +--- +- debug: msg="START cli/all_facts.yaml on connection={{ ansible_connection }}" + +- name: test getting all facts + register: result + cisco.iosxr.iosxr_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_model == 'IOS XRv' + - result.ansible_facts.ansible_net_filesystems is defined + +- debug: msg="END cli/all_facts.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/default_facts.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/default_facts.yaml new file mode 100644 index 00000000..7f472779 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/default_facts.yaml @@ -0,0 +1,21 @@ +--- +- debug: msg="START cli/default_facts.yaml on connection={{ ansible_connection }}" + +- name: test getting default facts + register: result + cisco.iosxr.iosxr_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_interfaces | length > 1 + - result.ansible_facts.ansible_net_config is not defined + +- debug: msg="END cli/default.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/invalid_subset.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/invalid_subset.yaml new file mode 100644 index 00000000..9deb3b13 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_facts/tests/cli/not_hardware.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/not_hardware.yaml new file mode 100644 index 00000000..2f8e9679 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_facts/tests/cli/not_hardware.yaml @@ -0,0 +1,23 @@ +--- +- debug: msg="START cli/not_hardware_facts.yaml on connection={{ ansible_connection + }}" + +- name: test not hardware + register: result + cisco.iosxr.iosxr_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 + +- debug: msg="END cli/not_hardware_facts.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/meta/main.yaml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tasks/cli.yaml new file mode 100644 index 00000000..8f7b62f9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tasks/cli.yaml @@ -0,0 +1,18 @@ +--- +- 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 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 + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tasks/main.yaml new file mode 100644 index 00000000..5d082a6f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- include: cli.yaml +- include: netconf.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tasks/netconf.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tasks/netconf.yaml new file mode 100644 index 00000000..e4754dcb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tasks/netconf.yaml @@ -0,0 +1,26 @@ +--- +- name: collect all netconf test cases + find: + paths: '{{ role_path }}/tests/netconf' + 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.netconf) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.netconf' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: + - netconf + +- 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 + tags: + - local diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/cli/basic.yaml new file mode 100644 index 00000000..c075035c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/cli/basic.yaml @@ -0,0 +1,296 @@ +--- +- debug: msg="START iosxr_interface cli/basic.yaml on connection={{ ansible_connection + }}" + +- name: Setup interface + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/2 + state: absent + provider: '{{ cli }}' + +- name: Confgure interface + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/2 + description: test-interface-initial + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/2 description test-interface-initial" in + result.commands' + +- name: Confgure interface (idempotent) + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/2 + description: test-interface-initial + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: Confgure interface parameters + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/2 + description: test-interface + speed: 100 + duplex: half + mtu: 512 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/2 description test-interface" in result.commands' + - '"interface GigabitEthernet0/0/0/2 speed 100" in result.commands' + - '"interface GigabitEthernet0/0/0/2 duplex half" in result.commands' + - '"interface GigabitEthernet0/0/0/2 mtu 512" in result.commands' + +- name: Change interface parameters + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/2 + description: test-interface-1 + speed: 10 + duplex: full + mtu: 256 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/2 description test-interface-1" in result.commands' + - '"interface GigabitEthernet0/0/0/2 speed 10" in result.commands' + - '"interface GigabitEthernet0/0/0/2 duplex full" in result.commands' + - '"interface GigabitEthernet0/0/0/2 mtu 256" in result.commands' + +- name: Change interface parameters (idempotent) + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/2 + description: test-interface-1 + speed: 10 + duplex: full + mtu: 256 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: Disable interface + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/2 + enabled: false + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/2 shutdown" in result.commands' + +- name: Enable interface + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/2 + enabled: true + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"no interface GigabitEthernet0/0/0/2 shutdown" in result.commands' + +- name: Confgure second interface (setup) + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/3 + description: test-interface-initial + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/3 description test-interface-initial" in + result.commands' + +- name: Delete interface aggregate (setup) + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/3 + + - name: GigabitEthernet0/0/0/2 + state: absent + provider: '{{ cli }}' + +- name: Add interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/3 + mtu: 256 + description: test-interface-1 + + - name: GigabitEthernet0/0/0/2 + mtu: 516 + description: test-interface-2 + speed: 100 + duplex: full + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/3 speed 100" in result.commands' + - '"interface GigabitEthernet0/0/0/3 description test-interface-1" in result.commands' + - '"interface GigabitEthernet0/0/0/3 duplex full" in result.commands' + - '"interface GigabitEthernet0/0/0/3 mtu 256" in result.commands' + - '"interface GigabitEthernet0/0/0/2 speed 100" in result.commands' + - '"interface GigabitEthernet0/0/0/2 description test-interface-2" in result.commands' + - '"interface GigabitEthernet0/0/0/2 duplex full" in result.commands' + - '"interface GigabitEthernet0/0/0/2 mtu 516" in result.commands' + +- name: Add interface aggregate (idempotent) + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/3 + mtu: 256 + description: test-interface-1 + + - name: GigabitEthernet0/0/0/2 + mtu: 516 + description: test-interface-2 + speed: 100 + duplex: full + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: Disable interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/3 + + - name: GigabitEthernet0/0/0/2 + enabled: false + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/3 shutdown" in result.commands' + - '"interface GigabitEthernet0/0/0/2 shutdown" in result.commands' + +- name: Enable interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/3 + + - name: GigabitEthernet0/0/0/2 + enabled: true + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"no interface GigabitEthernet0/0/0/3 shutdown" in result.commands' + - '"no interface GigabitEthernet0/0/0/2 shutdown" in result.commands' + +- name: interface aggregate (setup) + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/4 + + - name: GigabitEthernet0/0/0/5 + description: test-interface-initial + provider: '{{ cli }}' + +- name: Create interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/4 + description: test_interface_1 + + - name: GigabitEthernet0/0/0/5 + description: test_interface_2 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/4 description test_interface_1" in result.commands' + - '"interface GigabitEthernet0/0/0/5 description test_interface_2" in result.commands' + +- name: Delete interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/2 + + - name: GigabitEthernet0/0/0/3 + + - name: GigabitEthernet0/0/0/4 + + - name: GigabitEthernet0/0/0/5 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"no interface GigabitEthernet0/0/0/4" in result.commands' + - '"no interface GigabitEthernet0/0/0/5" in result.commands' + +- name: Delete interface aggregate (idempotent) + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/2 + + - name: GigabitEthernet0/0/0/3 + + - name: GigabitEthernet0/0/0/4 + + - name: GigabitEthernet0/0/0/5 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- debug: msg="END iosxr_interface cli/basic.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/cli/intent.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/cli/intent.yaml new file mode 100644 index 00000000..0ec81ba1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/cli/intent.yaml @@ -0,0 +1,80 @@ +--- +- debug: msg="START iosxr_interface cli/intent.yaml on connection={{ ansible_connection + }}" + +- name: Setup (interface is up) + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + description: test_interface_1 + enabled: true + state: present + provider: '{{ cli }}' + +- name: Check intent arguments + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: up + delay: 20 + provider: '{{ cli }}' + +- assert: + that: + - result.failed == false + +- name: Check intent arguments (failed condition) + ignore_errors: true + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: down + provider: '{{ cli }}' + +- assert: + that: + - result.failed == true + - "'state eq(down)' in result.failed_conditions" + +- name: Config + intent + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + enabled: false + state: down + delay: 20 + provider: '{{ cli }}' + +- assert: + that: + - result.failed == false + +- name: Config + intent (fail) + ignore_errors: true + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + enabled: false + state: up + provider: '{{ cli }}' + +- assert: + that: + - result.failed == true + - "'state eq(up)' in result.failed_conditions" + +- name: Aggregate config + intent (pass) + ignore_errors: true + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/1 + enabled: true + state: up + delay: 20 + provider: '{{ cli }}' + +- assert: + that: + - result.failed == false diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/cli/net_interface.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/cli/net_interface.yaml new file mode 100644 index 00000000..7ac652cb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/cli/net_interface.yaml @@ -0,0 +1,53 @@ +--- +- debug: msg="START iosxr cli/net_interface.yaml on connection={{ ansible_connection + }}" + +- name: Setup interface + register: result + ansible.netcommon.net_interface: + name: GigabitEthernet0/0/0/2 + state: absent + provider: '{{ cli }}' + +- name: Confgure interface using platform agnostic module + register: result + ansible.netcommon.net_interface: + name: GigabitEthernet0/0/0/2 + description: test-interface-initial + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/2 description test-interface-initial" in + result.commands' + +- name: Confgure interface parameters using platform agnostic module + register: result + ansible.netcommon.net_interface: + name: GigabitEthernet0/0/0/2 + description: test-interface + speed: 100 + duplex: half + mtu: 512 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"interface GigabitEthernet0/0/0/2 description test-interface" in result.commands' + - '"interface GigabitEthernet0/0/0/2 speed 100" in result.commands' + - '"interface GigabitEthernet0/0/0/2 duplex half" in result.commands' + - '"interface GigabitEthernet0/0/0/2 mtu 512" in result.commands' + +- name: Teardown interface + register: result + ansible.netcommon.net_interface: + name: GigabitEthernet0/0/0/2 + state: absent + provider: '{{ cli }}' + +- debug: msg="END iosxr cli/net_interface.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/netconf/basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/netconf/basic.yaml new file mode 100644 index 00000000..4731525d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/netconf/basic.yaml @@ -0,0 +1,308 @@ +--- +- debug: msg="START iosxr_interface netconf/basic.yaml" + +- name: Setup interface + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/1 + state: absent + provider: '{{ netconf }}' + +- name: Confgure interface + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + description: test-interface-initial + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"GigabitEthernet0/0/0/1" in result.xml[0]' + +- name: Confgure interface (idempotent) + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + description: test-interface-initial + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- name: Confgure interface parameters + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + description: test-interface + speed: 100 + duplex: half + mtu: 512 + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"GigabitEthernet0/0/0/1" in result.xml[0]' + - '"test-interface" in result.xml[0]' + - '"100" in result.xml[0]' + - '"512" in result.xml[0]' + +- name: Change interface parameters + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + description: test-interface-1 + speed: 10 + duplex: full + mtu: 256 + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"GigabitEthernet0/0/0/1" in result.xml[0]' + - '"test-interface-1" in result.xml[0]' + - '"10" in result.xml[0]' + - '"256" in result.xml[0]' + +- name: Change interface parameters (idempotent) + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + description: test-interface-1 + speed: 10 + duplex: full + mtu: 256 + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- name: Disable interface + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + enabled: false + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + +- name: Enable interface + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + enabled: true + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + +- name: Confgure second interface (setup) + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/0 + description: test-interface-initial + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"GigabitEthernet0/0/0/0" in result.xml[0]' + +- name: Delete interface aggregate (setup) + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/1 + state: absent + provider: '{{ netconf }}' + +- name: Add interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + mtu: 256 + description: test-interface-1 + + - name: GigabitEthernet0/0/0/1 + mtu: 516 + description: test-interface-2 + speed: 100 + duplex: full + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"GigabitEthernet0/0/0/1" in result.xml[0]' + - '"GigabitEthernet0/0/0/0" in result.xml[0]' + +- name: Add interface aggregate (idempotent) + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + mtu: 256 + description: test-interface-1 + + - name: GigabitEthernet0/0/0/1 + mtu: 516 + description: test-interface-2 + speed: 100 + duplex: full + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- name: Disable interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/1 + enabled: false + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + +- name: Disable interface aggregate (idempotent) + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/1 + enabled: false + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- name: Enable interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/1 + enabled: true + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + +- name: Enable interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/1 + enabled: true + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- name: interface aggregate (setup) + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/1 + description: test-interface-initial + provider: '{{ netconf }}' + +- name: Create interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + description: test_interface_1 + + - name: GigabitEthernet0/0/0/1 + description: test_interface_2 + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"GigabitEthernet0/0/0/0" in result.xml[0]' + - '"GigabitEthernet0/0/0/1" in result.xml[0]' + - '"test_interface_1" in result.xml[0]' + - '"test_interface_2" in result.xml[0]' + +- name: Delete interface aggregate + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/1 + state: absent + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + +- name: Delete interface aggregate (idempotent) + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/1 + state: absent + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- debug: msg="END iosxr_interface netconf/basic.yaml" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/netconf/intent.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/netconf/intent.yaml new file mode 100644 index 00000000..0a269cd1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/netconf/intent.yaml @@ -0,0 +1,79 @@ +--- +- debug: msg="START iosxr_interface netconf/intent.yaml" + +- name: Setup (interface is up) + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + description: test_interface_1 + enabled: true + state: present + provider: '{{ netconf }}' + +- name: Check intent arguments + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: up + delay: 10 + provider: '{{ netconf }}' + +- assert: + that: + - result.failed == false + +- name: Check intent arguments (failed condition) + ignore_errors: true + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: down + provider: '{{ netconf }}' + +- assert: + that: + - result.failed == true + - "'state eq(down)' in result.failed_conditions" + +- name: Config + intent + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + enabled: false + state: down + delay: 10 + provider: '{{ netconf }}' + +- assert: + that: + - result.failed == false + +- name: Config + intent (fail) + ignore_errors: true + register: result + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + enabled: false + state: up + provider: '{{ netconf }}' + +- assert: + that: + - result.failed == true + - "'state eq(up)' in result.failed_conditions" + +- name: Aggregate config + intent (pass) + ignore_errors: true + register: result + cisco.iosxr.iosxr_interface: + aggregate: + + - name: GigabitEthernet0/0/0/1 + enabled: true + state: up + delay: 10 + provider: '{{ netconf }}' + +- assert: + that: + - result.failed == false diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/netconf/net_interface.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/netconf/net_interface.yaml new file mode 100644 index 00000000..9257dac3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interface/tests/netconf/net_interface.yaml @@ -0,0 +1,45 @@ +--- +- debug: msg="START iosxr netconf/net_interface.yaml on connection={{ ansible_connection + }}" + +- name: Setup interface + register: result + ansible.netcommon.net_interface: + name: GigabitEthernet0/0/0/1 + state: absent + provider: '{{ netconf }}' + +- name: Confgure interface using platform agnostic module + register: result + ansible.netcommon.net_interface: + name: GigabitEthernet0/0/0/1 + description: test-interface-initial + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"GigabitEthernet0/0/0/1" in result.xml[0]' + +- name: Confgure interface parameters using platform agnostic module + register: result + ansible.netcommon.net_interface: + name: GigabitEthernet0/0/0/1 + description: test-interface + speed: 100 + duplex: half + mtu: 512 + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"GigabitEthernet0/0/0/1" in result.xml[0]' + - '"test-interface" in result.xml[0]' + - '"100" in result.xml[0]' + - '"512" in result.xml[0]' + +- debug: msg="END iosxr netconf/net_interface.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..ae8935a1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/0/0/0\ndescription this is interface0\n\ + mtu 65\nspeed 10\nno shutdown\ninterface GigabitEthernet 0/0/0/1\ndescription\ + \ this is interface1\nmtu 65\nspeed 10\nno shutdown\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..08046d69 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,18 @@ +--- +- name: Remove Config + vars: + lines: "interface loopback888\nno description\nno shutdown\ninterface loopback999\n\ + no description\nno shutdown\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' + +- name: Remove interfaces from config before actual testing + loop: + - GigabitEthernet 0/0/0/0 + - GigabitEthernet 0/0/0/1 + - GigabitEthernet 0/0/0/2 + - GigabitEthernet 0/0/0/3 + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no interface {{ item }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..94c2607e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,45 @@ +--- +- debug: + msg: Start Deleted integration state for iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..9eeffb56 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_interfaces empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..08619b40 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,19 @@ +interface Loopback888 + description test for ansible + shutdown +! +interface MgmtEth0/0/CPU0/0 + ipv4 address 10.8.38.70 255.255.255.0 +! +interface GigabitEthernet0/0/0/0 + description Configured and Merged by Ansible-Network + mtu 110 + ipv4 address 172.31.1.1 255.255.255.0 + duplex half +! +interface GigabitEthernet0/0/0/3 + shutdown +! +interface GigabitEthernet0/0/0/4 + shutdown +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..607041bd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,42 @@ +--- +- debug: + msg: START iosxr_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.iosxr.iosxr_interfaces: + config: + - name: GigabitEthernet0/0/0/0 + description: This interface is Configured and Merged by Ansible-Network + mtu: 110 + enabled: true + duplex: half + + - name: GigabitEthernet0/0/0/1 + description: Configured and Merged by Ansible-Network + mtu: 2800 + enabled: false + speed: 100 + duplex: full + state: merged + + - name: Gather interfaces facts using gathered state + register: result + cisco.iosxr.iosxr_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: "{{ gathered['after'] | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..10aa7090 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/merged.yaml @@ -0,0 +1,59 @@ +--- +- debug: + msg: START Merged iosxr_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Merge provided configuration with device configuration + register: result + cisco.iosxr.iosxr_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + description: Configured and Merged by Ansible-Network + mtu: 110 + enabled: true + duplex: half + + - name: GigabitEthernet0/0/0/1 + 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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..8c44ce17 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,54 @@ +--- +- debug: + msg: START Overridden iosxr_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.iosxr.iosxr_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/1 + description: Configured and Overridden by Ansible-Network + enabled: false + duplex: full + mtu: 2000 + speed: 100 + 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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..cffa8232 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START iosxr_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided interfaces config to agnostic model + register: result + cisco.iosxr.iosxr_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ parsed['after'] | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..8a076f9b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,29 @@ +--- +- debug: + msg: START iosxr_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- name: Render platform specific commands from task input using rendered state + register: result + cisco.iosxr.iosxr_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + description: Configured and Merged by Ansible-Network + mtu: 110 + enabled: true + duplex: half + + - name: GigabitEthernet0/0/0/1 + description: Configured and Merged by Ansible-Network + mtu: 2800 + enabled: false + speed: 100 + duplex: full + state: rendered + +- name: Assert that correct set of commands were rendered + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..ff0f9753 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START Replaced iosxr_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.iosxr.iosxr_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + description: Configured and Replaced by Ansible-Network + mtu: 110 + + - name: GigabitEthernet0/0/0/1 + description: Configured and Replaced by Ansible-Network + speed: 100 + 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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/vars/main.yaml new file mode 100644 index 00000000..5f1088d6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_interfaces/vars/main.yaml @@ -0,0 +1,196 @@ +--- +merged: + before: + - enabled: true + name: Loopback888 + - enabled: true + name: Loopback999 + - description: this is interface0 + enabled: true + mtu: 65 + name: GigabitEthernet0/0/0/0 + speed: 10 + - description: this is interface1 + enabled: true + mtu: 65 + name: GigabitEthernet0/0/0/1 + speed: 10 + commands: + - interface GigabitEthernet0/0/0/0 + - description Configured and Merged by Ansible-Network + - mtu 110 + - duplex half + - interface GigabitEthernet0/0/0/1 + - description Configured and Merged by Ansible-Network + - mtu 2800 + - speed 100 + - duplex full + - shutdown + after: + - enabled: true + name: Loopback888 + - enabled: true + name: Loopback999 + - description: Configured and Merged by Ansible-Network + duplex: half + enabled: true + mtu: 110 + name: GigabitEthernet0/0/0/0 + speed: 10 + - description: Configured and Merged by Ansible-Network + duplex: full + enabled: false + mtu: 2800 + name: GigabitEthernet0/0/0/1 + speed: 100 +parsed: + after: + - description: test for ansible + enabled: false + name: Loopback888 + - description: Configured and Merged by Ansible-Network + duplex: half + enabled: true + mtu: 110 + name: GigabitEthernet0/0/0/0 + - enabled: false + name: GigabitEthernet0/0/0/3 + - enabled: false + name: GigabitEthernet0/0/0/4 +replaced: + before: + - enabled: true + name: Loopback888 + - enabled: true + name: Loopback999 + - description: this is interface0 + enabled: true + mtu: 65 + name: GigabitEthernet0/0/0/0 + speed: 10 + - description: this is interface1 + enabled: true + mtu: 65 + name: GigabitEthernet0/0/0/1 + speed: 10 + commands: + - interface GigabitEthernet0/0/0/0 + - no speed + - description Configured and Replaced by Ansible-Network + - mtu 110 + - interface GigabitEthernet0/0/0/1 + - no mtu + - description Configured and Replaced by Ansible-Network + - speed 100 + after: + - enabled: true + name: Loopback888 + - enabled: true + name: Loopback999 + - description: Configured and Replaced by Ansible-Network + enabled: true + mtu: 110 + name: GigabitEthernet0/0/0/0 + - description: Configured and Replaced by Ansible-Network + enabled: true + name: GigabitEthernet0/0/0/1 + speed: 100 +rendered: + commands: + - interface GigabitEthernet0/0/0/0 + - description Configured and Merged by Ansible-Network + - mtu 110 + - duplex half + - no shutdown + - interface GigabitEthernet0/0/0/1 + - description Configured and Merged by Ansible-Network + - mtu 2800 + - speed 100 + - duplex full + - shutdown +overridden: + before: + - enabled: true + name: Loopback888 + - enabled: true + name: Loopback999 + - description: this is interface0 + enabled: true + mtu: 65 + name: GigabitEthernet0/0/0/0 + speed: 10 + - description: this is interface1 + enabled: true + mtu: 65 + name: GigabitEthernet0/0/0/1 + speed: 10 + commands: + - interface GigabitEthernet0/0/0/0 + - no description + - no speed + - no mtu + - interface GigabitEthernet0/0/0/1 + - description Configured and Overridden by Ansible-Network + - mtu 2000 + - duplex full + - speed 100 + - shutdown + after: + - enabled: true + name: Loopback888 + - enabled: true + name: Loopback999 + - description: Configured and Overridden by Ansible-Network + duplex: full + enabled: false + mtu: 2000 + name: GigabitEthernet0/0/0/1 + speed: 100 +gathered: + after: + - enabled: true + name: Loopback888 + - enabled: true + name: Loopback999 + - description: This interface is Configured and Merged by Ansible-Network + duplex: half + enabled: true + mtu: 110 + name: GigabitEthernet0/0/0/0 + speed: 10 + - description: Configured and Merged by Ansible-Network + duplex: full + enabled: false + mtu: 2800 + name: GigabitEthernet0/0/0/1 + speed: 100 +deleted: + before: + - enabled: true + name: Loopback888 + - enabled: true + name: Loopback999 + - description: this is interface0 + enabled: true + mtu: 65 + name: GigabitEthernet0/0/0/0 + speed: 10 + - description: this is interface1 + enabled: true + mtu: 65 + name: GigabitEthernet0/0/0/1 + speed: 10 + commands: + - interface GigabitEthernet0/0/0/0 + - no description + - no speed + - no mtu + - interface GigabitEthernet0/0/0/1 + - no description + - no speed + - no mtu + after: + - enabled: true + name: Loopback888 + - enabled: true + name: Loopback999 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_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/iosxr/tests/integration/targets/iosxr_l2_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..0d451071 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,9 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/0/0/1\ndot1q native vlan 10\nl2transport\ + \ l2protocol cdp forward\nl2transport propagate remote-status\ninterface GigabitEthernet\ + \ 0/0/0/4\ndot1q native vlan 20\nl2transport l2protocol vtp tunnel\ninterface\ + \ GigabitEthernet 0/0/0/3.900\ndot1q vlan 40 60\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..ac4b7a65 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Remove Config + vars: + lines: "interface GigabitEthernet 0/0/0/1\nno dot1q native vlan\nno l2transport\n\ + no interface GigabitEthernet 0/0/0/2\nno interface GigabitEthernet 0/0/0/3\n\ + no interface GigabitEthernet 0/0/0/3.900\nno interface GigabitEthernet 0/0/0/4\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..41d20e08 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,45 @@ +--- +- 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 interfaces attributes of all configured interfaces + register: result + cisco.iosxr.iosxr_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 L2 interfaces attributes of all configured interfaces (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_l2_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/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..23ce54bd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_l2_interfaces empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..129742c7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,31 @@ +interface Loopback888 + description test for ansible + shutdown +! +interface MgmtEth0/0/CPU0/0 + ipv4 address 10.8.38.70 255.255.255.0 +! +interface GigabitEthernet0/0/0/0 + description Configured and Merged by Ansible-Network + mtu 110 + ipv4 address 172.31.1.1 255.255.255.0 + duplex half +! +interface GigabitEthernet0/0/0/1 + dot1q native vlan 10 + l2transport + l2protocol cdp forward + l2protocol pvst tunnel + propagate remote-status + ! +! +interface GigabitEthernet0/0/0/3 + shutdown +! +interface GigabitEthernet0/0/0/3.900 + encapsulation dot1q 20 second-dot1q 40 +! +interface GigabitEthernet0/0/0/4 + shutdown + dot1q native vlan 40 +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..974ca3d2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,45 @@ +--- +- debug: + msg: START iosxr_l2_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the existing running configuration + register: result + cisco.iosxr.iosxr_l2_interfaces: + config: + + - name: GigabitEthernet0/0/0/1 + native_vlan: 10 + l2transport: true + l2protocol: + + - pvst: tunnel + + - cdp: forward + propagate: true + + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 20 + - 40 + + - name: GigabitEthernet0/0/0/4 + native_vlan: 40 + state: merged + + - name: Gather l2 interfaces facts using gathered state + register: result + cisco.iosxr.iosxr_l2_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: "{{ merged['after'] | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..89765611 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/merged.yaml @@ -0,0 +1,62 @@ +--- +- debug: + msg: START Merged ios_l2_interfaces state for integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge provided L2 configuration with device configuration + register: result + cisco.iosxr.iosxr_l2_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/1 + native_vlan: 10 + l2transport: true + l2protocol: + + - pvst: tunnel + + - cdp: forward + propagate: true + + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 20 + - 40 + + - name: GigabitEthernet0/0/0/4 + native_vlan: 40 + 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 L2 configuration with device configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_l2_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/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..46529a50 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,59 @@ +--- +- 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 of all interfaces with provided configuration + register: result + cisco.iosxr.iosxr_l2_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/4 + native_vlan: 40 + l2transport: true + l2protocol: + + - stp: forward + + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 20 + - 40 + 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 of all interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_l2_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/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..3c66ac27 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START iosxr_l2_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided L2 interfaces config to agnostic model + register: result + cisco.iosxr.iosxr_l2_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ parsed['after'] | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..57f0cb61 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,34 @@ +--- +- debug: + msg: START iosxr_l2_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- name: Render platform specific commands from task input using rendered state + register: result + cisco.iosxr.iosxr_l2_interfaces: + config: + + - name: GigabitEthernet0/0/0/1 + native_vlan: 10 + l2transport: true + l2protocol: + + - pvst: tunnel + + - cdp: forward + propagate: true + + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 20 + - 40 + + - name: GigabitEthernet0/0/0/4 + native_vlan: 40 + state: rendered + +- name: Assert that correct set of commands were rendered + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..fcc40107 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,55 @@ +--- +- 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 of listed interfaces with provided + configuration + register: result + cisco.iosxr.iosxr_l2_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/1 + native_vlan: 40 + l2transport: true + l2protocol: + + - vtp: tunnel + 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 of listed interfaces with provided + configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_l2_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/iosxr/tests/integration/targets/iosxr_l2_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/vars/main.yaml new file mode 100644 index 00000000..481495f3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l2_interfaces/vars/main.yaml @@ -0,0 +1,147 @@ +--- +merged: + before: [] + commands: + - interface GigabitEthernet0/0/0/1 + - dot1q native vlan 10 + - l2transport l2protocol pvst tunnel + - l2transport l2protocol cdp forward + - l2transport propagate remote-status + - interface GigabitEthernet0/0/0/3.900 + - dot1q vlan 20 40 + - interface GigabitEthernet0/0/0/4 + - dot1q native vlan 40 + after: + - l2protocol: + - cdp: forward + - pvst: tunnel + l2transport: true + name: GigabitEthernet0/0/0/1 + native_vlan: 10 + propagate: true + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 20 + - 40 + - name: GigabitEthernet0/0/0/4 + native_vlan: 40 +replaced: + before: + - l2protocol: + - cdp: forward + l2transport: true + name: GigabitEthernet0/0/0/1 + native_vlan: 10 + propagate: true + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 40 + - 60 + - l2protocol: + - vtp: tunnel + l2transport: true + name: GigabitEthernet0/0/0/4 + native_vlan: 20 + commands: + - interface GigabitEthernet0/0/0/1 + - no l2transport + - dot1q native vlan 40 + - l2transport l2protocol vtp tunnel + after: + - l2protocol: + - vtp: tunnel + l2transport: true + name: GigabitEthernet0/0/0/1 + native_vlan: 40 + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 40 + - 60 + - l2protocol: + - vtp: tunnel + l2transport: true + name: GigabitEthernet0/0/0/4 + native_vlan: 20 +overridden: + before: + - l2protocol: + - cdp: forward + l2transport: true + name: GigabitEthernet0/0/0/1 + native_vlan: 10 + propagate: true + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 40 + - 60 + - l2protocol: + - vtp: tunnel + l2transport: true + name: GigabitEthernet0/0/0/4 + native_vlan: 20 + commands: + - interface GigabitEthernet0/0/0/1 + - no dot1q native vlan + - no l2transport + - interface GigabitEthernet0/0/0/3.900 + - dot1q vlan 20 40 + - interface GigabitEthernet0/0/0/4 + - no l2transport + - dot1q native vlan 40 + - l2transport l2protocol stp forward + after: + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 20 + - 40 + - l2protocol: + - stp: forward + l2transport: true + name: GigabitEthernet0/0/0/4 + native_vlan: 40 +parsed: + after: + - name: GigabitEthernet0/0/0/0 + - l2protocol: + - cdp: forward + - pvst: tunnel + native_vlan: 10 + l2transport: true + name: GigabitEthernet0/0/0/1 + propagate: true + - name: GigabitEthernet0/0/0/3 + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 20 + - 40 + - name: GigabitEthernet0/0/0/4 + native_vlan: 40 +deleted: + before: + - l2protocol: + - cdp: forward + l2transport: true + name: GigabitEthernet0/0/0/1 + native_vlan: 10 + propagate: true + - name: GigabitEthernet0/0/0/3.900 + q_vlan: + - 40 + - 60 + - l2protocol: + - vtp: tunnel + l2transport: true + name: GigabitEthernet0/0/0/4 + native_vlan: 20 + commands: + - interface GigabitEthernet0/0/0/1 + - no dot1q native vlan + - no l2transport + - interface GigabitEthernet0/0/0/3.900 + - no encapsulation dot1q + - interface GigabitEthernet0/0/0/4 + - no dot1q native vlan + - no l2transport + after: + - name: GigabitEthernet0/0/0/4 + - name: GigabitEthernet0/0/0/3.900 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/meta/main.yaml new file mode 100644 index 00000000..23d65c7e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_l3_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..1dad55ad --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Populate Config + vars: + lines: "interface GigabitEthernet 0/0/0/0\nipv4 address 198.51.100.1 255.255.255.0\n\ + ipv6 address 2001:db8::/32\ninterface GigabitEthernet 0/0/0/1\nipv4 address\ + \ 192.0.2.1 255.255.255.0\nipv4 address 192.0.2.2 255.255.255.0 secondary\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..d99f4db7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,7 @@ +--- +- name: Remove Config + vars: + lines: "interface GigabitEthernet 0/0/0/0\nno ipv4 address\nno ipv6 address\n\ + interface GigabitEthernet 0/0/0/1\nno ipv4 address\nno ipv6 address\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..777596cd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,50 @@ +--- +- debug: + msg: Start Deleted integration state for iosxr_l3_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.iosxr.iosxr_l3_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + + - name: GigabitEthernet0/0/0/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: + - "{{ 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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..1ae1f2d8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_l3_interfaces empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..d4fac24a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,31 @@ +interface Loopback888 + description test for ansible + shutdown +! +interface MgmtEth0/0/CPU0/0 + ipv4 address 10.8.38.70 255.255.255.0 +! +interface GigabitEthernet0/0/0/0 + description Configured and Merged by Ansible-Network + mtu 66 + ipv4 address 192.0.2.1 255.255.255.0 + ipv4 address 192.0.2.2 255.255.255.0 secondary + ipv6 address 2001:db8:0:3::/64 + duplex half +! +interface GigabitEthernet0/0/0/1 + description Configured and Merged by Ansible-Network + mtu 66 + speed 100 + duplex full + dot1q native vlan 10 + l2transport + l2protocol cdp forward + l2protocol pvst tunnel + propagate remote-status + ! +! +interface GigabitEthernet0/0/0/3 + ipv4 address 192.0.22.1 255.255.255.0 + ipv4 address 192.0.23.1 255.255.255.0 +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..11284fb5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,43 @@ +--- +- debug: + msg: START iosxr_l3_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Gather the provided configuration with the existing running configuration + register: result + cisco.iosxr.iosxr_l3_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + ipv4: + + - address: 198.51.100.1/24 + + - name: GigabitEthernet0/0/0/1 + ipv6: + + - address: 2001:db8:0:3::/64 + ipv4: + + - address: 192.0.2.1/24 + + - address: 192.0.2.2/24 + secondary: true + state: merged + + - name: Gather L3 interfaces facts using gathered state + register: result + cisco.iosxr.iosxr_l3_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: "{{ merged['after'] | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..593acf32 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/merged.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START Merged iosxr_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.iosxr.iosxr_l3_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + ipv4: + + - address: 198.51.100.1/24 + + - name: GigabitEthernet0/0/0/1 + ipv6: + + - address: 2001:db8:0:3::/64 + ipv4: + + - address: 192.0.2.1/24 + + - address: 192.0.2.2/24 + secondary: true + 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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..38dd93e3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START Overridden iosxr_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.iosxr.iosxr_l3_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/1 + ipv4: + + - address: 198.51.102.1/24 + ipv6: + + - address: 2001:db8:1::/64 + 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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..9a4776b6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START iosxr_l3_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided L3 interfaces config to agnostic model + register: result + cisco.iosxr.iosxr_l3_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ parsed['after'] | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..03a330f5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,32 @@ +--- +- debug: + msg: START iosxr_l3_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- name: Render platform specific commands from task input using rendered state + register: result + cisco.iosxr.iosxr_l3_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + ipv4: + + - address: 198.51.100.1/24 + + - name: GigabitEthernet0/0/0/1 + ipv6: + + - address: 2001:db8:0:3::/64 + ipv4: + + - address: 192.0.2.1/24 + + - address: 192.0.2.2/24 + secondary: true + state: rendered + +- name: Assert that correct set of commands were rendered + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..f14e68a0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START Replaced iosxr_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.iosxr.iosxr_l3_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + ipv4: + + - address: 203.0.113.27/24 + + - address: 203.0.114.1/24 + secondary: 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 interfaces with provided configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..eea8ba23 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,47 @@ +--- +- debug: + msg: START iosxr_l3_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Round Trip test by applying the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_l3_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + ipv4: + + - address: 198.51.100.1/24 + + - name: GigabitEthernet0/0/0/1 + ipv6: + + - address: 2001:db8:0:3::/64 + ipv4: + + - address: 192.0.2.1/24 + + - secondary: true + address: 192.0.2.2/24 + state: merged + + - name: Gather interfaces facts + register: l3facts_config + cisco.iosxr.iosxr_facts: + gather_subset: + - default + gather_network_resources: + - l3_interfaces + + - name: Apply config from l3_interfaces facts generated (IDEMPOTENT) + cisco.iosxr.iosxr_l3_interfaces: + config: "{{ l3facts_config['ansible_facts']['ansible_network_resources']['l3_interfaces']\ + \ }}" + state: merged + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/vars/main.yaml new file mode 100644 index 00000000..c144276d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_l3_interfaces/vars/main.yaml @@ -0,0 +1,133 @@ +--- +merged: + before: + - name: Loopback888 + - name: Loopback999 + commands: + - interface GigabitEthernet0/0/0/0 + - ipv4 address 198.51.100.1 255.255.255.0 + - interface GigabitEthernet0/0/0/1 + - ipv4 address 192.0.2.2 255.255.255.0 secondary + - ipv4 address 192.0.2.1 255.255.255.0 + - ipv6 address 2001:db8:0:3::/64 + after: + - name: Loopback888 + - name: Loopback999 + - ipv4: + - address: 198.51.100.1 255.255.255.0 + name: GigabitEthernet0/0/0/0 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + - address: 192.0.2.2 255.255.255.0 + secondary: true + ipv6: + - address: 2001:db8:0:3::/64 + name: GigabitEthernet0/0/0/1 +replaced: + before: + - name: Loopback888 + - name: Loopback999 + - ipv4: + - address: 198.51.100.1 255.255.255.0 + ipv6: + - address: 2001:db8::/32 + name: GigabitEthernet0/0/0/0 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + - address: 192.0.2.2 255.255.255.0 + secondary: true + name: GigabitEthernet0/0/0/1 + commands: + - interface GigabitEthernet0/0/0/0 + - no ipv6 address + - ipv4 address 203.0.113.27 255.255.255.0 + - ipv4 address 203.0.114.1 255.255.255.0 secondary + after: + - name: Loopback888 + - name: Loopback999 + - ipv4: + - address: 203.0.113.27 255.255.255.0 + - address: 203.0.114.1 255.255.255.0 + secondary: true + name: GigabitEthernet0/0/0/0 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + - address: 192.0.2.2 255.255.255.0 + secondary: true + name: GigabitEthernet0/0/0/1 +overridden: + before: + - name: Loopback888 + - name: Loopback999 + - ipv4: + - address: 198.51.100.1 255.255.255.0 + ipv6: + - address: 2001:db8::/32 + name: GigabitEthernet0/0/0/0 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + - address: 192.0.2.2 255.255.255.0 + secondary: true + name: GigabitEthernet0/0/0/1 + commands: + - interface GigabitEthernet0/0/0/0 + - no ipv4 address + - no ipv6 address + - interface GigabitEthernet0/0/0/1 + - no ipv4 address + - ipv4 address 198.51.102.1 255.255.255.0 + - ipv6 address 2001:db8:1::/64 + after: + - name: Loopback888 + - name: Loopback999 + - ipv4: + - address: 198.51.102.1 255.255.255.0 + ipv6: + - address: 2001:db8:1::/64 + name: GigabitEthernet0/0/0/1 +rendered: + commands: + - interface GigabitEthernet0/0/0/0 + - ipv4 address 198.51.100.1 255.255.255.0 + - interface GigabitEthernet0/0/0/1 + - ipv4 address 192.0.2.2 255.255.255.0 secondary + - ipv4 address 192.0.2.1 255.255.255.0 + - ipv6 address 2001:db8:0:3::/64 +parsed: + after: + - name: Loopback888 + - ipv6: + - address: 2001:db8:0:3::/64 + ipv4: + - address: 192.0.2.1 255.255.255.0 + - address: 192.0.2.2 255.255.255.0 + secondary: true + name: GigabitEthernet0/0/0/0 + - name: GigabitEthernet0/0/0/1 + - ipv4: + - address: 192.0.22.1 255.255.255.0 + - address: 192.0.23.1 255.255.255.0 + name: GigabitEthernet0/0/0/3 +deleted: + before: + - name: Loopback888 + - name: Loopback999 + - ipv4: + - address: 198.51.100.1 255.255.255.0 + ipv6: + - address: 2001:db8::/32 + name: GigabitEthernet0/0/0/0 + - ipv4: + - address: 192.0.2.1 255.255.255.0 + - address: 192.0.2.2 255.255.255.0 + secondary: true + name: GigabitEthernet0/0/0/1 + commands: + - interface GigabitEthernet0/0/0/0 + - no ipv4 address + - no ipv6 address + - interface GigabitEthernet0/0/0/1 + - no ipv4 address + after: + - name: Loopback888 + - name: Loopback999 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/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/iosxr/tests/integration/targets/iosxr_lacp/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/_populate.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/_populate.yaml new file mode 100644 index 00000000..f93c2307 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/_populate.yaml @@ -0,0 +1,6 @@ +--- +- name: Setup + vars: + lines: "lacp system priority 12\nlacp system mac 00c1.4c00.bd16\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..a8234e82 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/_remove_config.yaml @@ -0,0 +1,6 @@ +--- +- name: Remove Config + vars: + lines: "no lacp system priority\nno lacp system mac\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/deleted.yaml new file mode 100644 index 00000000..f8824124 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/deleted.yaml @@ -0,0 +1,48 @@ +--- +- debug: + msg: Start iosxr_lacp deleted integration tests ansible_connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Delete LACP attributes + register: result + cisco.iosxr.iosxr_lacp: &id001 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ populate == result['before'] }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['after'] }}" + + - name: Delete attributes of given interfaces (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lacp: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/empty_config.yaml new file mode 100644 index 00000000..66504e22 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/empty_config.yaml @@ -0,0 +1,49 @@ +--- +- debug: + msg: START iosxr_lacp empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_lacp: + 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/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..5b16c0e8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,2 @@ +lacp system mac 00c1.4c00.bd15 +lacp system priority 11 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/gathered.yaml new file mode 100644 index 00000000..2d952cf2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/gathered.yaml @@ -0,0 +1,30 @@ +--- +- debug: + msg: START iosxr_lacp gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Gather the provided configuration with the existing running configuration + register: result + cisco.iosxr.iosxr_lacp: + config: + system: + priority: 11 + mac: + address: 00c1.4c00.bd15 + state: merged + + - name: Gather LACP facts using gathered state + register: result + cisco.iosxr.iosxr_lacp: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: "{{ merged['after'] == result['gathered'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/merged.yaml new file mode 100644 index 00000000..33859d9f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/merged.yaml @@ -0,0 +1,51 @@ +--- +- debug: + msg: START iosxr_lacp merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_lacp: &id001 + config: + system: + priority: 11 + mac: + address: 00c1.4c00.bd15 + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lacp: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] == result['before']}}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/parsed.yaml new file mode 100644 index 00000000..5e530a2e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/parsed.yaml @@ -0,0 +1,15 @@ +--- +- debug: + msg: START iosxr_lacp parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided LACP config to agnostic model + register: result + cisco.iosxr.iosxr_lacp: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ parsed['after'] == result['parsed'] }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/rendered.yaml new file mode 100644 index 00000000..ce760898 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/rendered.yaml @@ -0,0 +1,20 @@ +--- +- debug: + msg: START iosxr_lacp rendered integration tests on connection={{ + ansible_connection }} + +- name: Render platform specific commands from task input using rendered state + register: result + cisco.iosxr.iosxr_lacp: + config: + system: + priority: 11 + mac: + address: 00c1.4c00.bd15 + state: rendered + +- name: Assert that correct set of commands were rendered + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/replaced.yaml new file mode 100644 index 00000000..6076b5cd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/replaced.yaml @@ -0,0 +1,52 @@ +--- +- debug: + msg: START iosxr_lacp replaced integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Replace LACP configuration with provided configurations + register: result + cisco.iosxr.iosxr_lacp: &id001 + config: + system: + priority: 11 + 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: + - "{{ populate == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] == result['after'] }}" + + - name: Replace device configurations of listed interfaces with provided configurarions + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lacp: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/rtt.yaml new file mode 100644 index 00000000..88e1de92 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/tests/cli/rtt.yaml @@ -0,0 +1,53 @@ +--- +- debug: + msg: START isoxr_lacp round trip integration tests on connection={{ ansible_connection + }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_lacp: + config: + system: + priority: 15 + mac: + address: 00c1.4c00.bd16 + state: merged + + - name: Gather interfaces facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - lacp + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_lacp: + config: + system: + priority: 10 + mac: + address: 00c1.4c00.bd10 + state: merged + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] == result['after'] }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_lacp: + config: "{{ ansible_facts['network_resources']['lacp'] }}" + state: replaced + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] == revert['after'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/vars/main.yaml new file mode 100644 index 00000000..dc7a5246 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp/vars/main.yaml @@ -0,0 +1,44 @@ +--- +merged: + before: {} + commands: + - lacp system priority 11 + - lacp system mac 00c1.4c00.bd15 + after: + system: + priority: 11 + mac: + address: 00c1.4c00.bd15 +populate: + system: + priority: 12 + mac: + address: 00c1.4c00.bd16 +replaced: + commands: + - no lacp system mac + - lacp system priority 11 + after: + system: + priority: 11 +rendered: + commands: + - lacp system priority 11 + - lacp system mac 00c1.4c00.bd15 +parsed: + after: + system: + priority: 11 + mac: + address: 00c1.4c00.bd15 +deleted: + commands: + - no lacp system priority + - no lacp system mac + after: {} +round_trip: + after: + system: + priority: 10 + mac: + address: 00c1.4c00.bd10 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_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/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/_populate.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/_populate.yaml new file mode 100644 index 00000000..86d3e64e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/_populate.yaml @@ -0,0 +1,26 @@ +--- +- name: Setup Bundle-Ether10 + cisco.iosxr.iosxr_config: + lines: + - lacp churn logging actor + - lacp switchover suppress-flaps 500 + - lacp collector-max-delay 100 + parents: interface Bundle-Ether10 + +- name: Setup Bundle-Ether11 + cisco.iosxr.iosxr_config: + lines: + - lacp system mac 00c2.4c00.bd15 + parents: interface Bundle-Ether11 + +- name: Setup GigE0 + cisco.iosxr.iosxr_config: + lines: + - lacp period 100 + parents: interface GigabitEthernet0/0/0/0 + +- name: Setup GigE1 + cisco.iosxr.iosxr_config: + lines: + - lacp period 200 + parents: interface GigabitEthernet0/0/0/1 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..8d3c4fcb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,28 @@ +--- +- name: Remove Bundles + vars: + lines: "no interface Bundle-Ether10\nno interface Bundle-Ether11\nno interface\ + \ Bundle-Ether12\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' + +- name: Remove LACP interface config + loop: + - 0/0/0/0 + - 0/0/0/1 + cisco.iosxr.iosxr_config: + lines: + - no lacp period + - shutdown + parents: interface GigabitEthernet{{ item }} + +- name: Remove unwanted interfaces from config + loop: + - 0/0/0/2 + - 0/0/0/3 + - 0/0/0/4 + - 0/0/0/5 + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no interface GigabitEthernet{{ item }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..cb3daa43 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,51 @@ +--- +- debug: + msg: Start iosxr_lacp_interfaces deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Delete LACP attributes of all interfaces + register: result + cisco.iosxr.iosxr_lacp_interfaces: &id001 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete LACP attributes of all interfaces (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lacp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + - result.commands|length == 0 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..166f5943 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_lacp_interfaces empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_lacp_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/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..0595831e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,14 @@ +interface Bundle-Ether10 + lacp churn logging actor + lacp switchover suppress-flaps 500 + lacp collector-max-delay 100 +! +interface Bundle-Ether11 + lacp system mac 00c2.4c00.bd15 +! +interface MgmtEth0/0/CPU0/0 + ipv4 address 192.0.2.11 255.255.255.0 +! +interface GigabitEthernet0/0/0/1 + lacp period 200 +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..adc671e9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,39 @@ +--- +- debug: + msg: START iosxr_lacp_interfaces gathered 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.iosxr.iosxr_lacp_interfaces: + config: + + - name: Bundle-Ether10 + churn_logging: actor + collector_max_delay: 100 + switchover_suppress_flaps: 500 + + - name: Bundle-Ether11 + system: + mac: 00c2.4c00.bd15 + + - name: GigabitEthernet0/0/0/1 + period: 100 + state: merged + + - name: Gather interfaces facts using gathered state + register: result + cisco.iosxr.iosxr_lacp_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: "{{ merged['after'] | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..5642722c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/merged.yaml @@ -0,0 +1,63 @@ +--- +- debug: + msg: START iosxr_lacp_interfaces merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_lacp_interfaces: &id001 + config: + + - name: Bundle-Ether10 + churn_logging: actor + collector_max_delay: 100 + switchover_suppress_flaps: 500 + + - name: Bundle-Ether11 + system: + mac: 00c2.4c00.bd15 + + - name: GigabitEthernet0/0/0/1 + period: 100 + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lacp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..b83726ed --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,61 @@ +--- +- debug: + msg: START iosxr_lacp_interfaces overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Overridde all interface LACP configuration with provided configuration + register: result + cisco.iosxr.iosxr_lacp_interfaces: &id001 + config: + + - name: Bundle-Ether12 + churn_logging: both + collector_max_delay: 100 + switchover_suppress_flaps: 500 + + - name: GigabitEthernet0/0/0/1 + period: 300 + 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: + - "{{ populate | 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: Overridde all interface LACP configuration with provided configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lacp_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..10f6c447 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,15 @@ +--- +- debug: + msg: START iosxr_lacp_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided LACP config to agnostic model + register: result + cisco.iosxr.iosxr_lacp_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ parsed['after'] == result['parsed'] }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..7f259f30 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,27 @@ +--- +- debug: + msg: START iosxr_lacp_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- name: Render platform specific commands from task input using rendered state + register: result + cisco.iosxr.iosxr_lacp_interfaces: + config: + - name: Bundle-Ether10 + churn_logging: actor + collector_max_delay: 100 + switchover_suppress_flaps: 500 + + - name: Bundle-Ether11 + system: + mac: 00c2.4c00.bd15 + + - name: GigabitEthernet0/0/0/1 + period: 200 + state: rendered + +- name: Assert that correct set of commands were rendered + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..d0f25d10 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,59 @@ +--- +- debug: + msg: START iosxr_lacp_interfaces replaced integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Replace device configurations of listed interfaces with provided configurations + register: result + cisco.iosxr.iosxr_lacp_interfaces: &id001 + config: + + - name: Bundle-Ether10 + churn_logging: partner + + - name: GigabitEthernet0/0/0/1 + period: 300 + 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: + - "{{ populate | 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: Replace device configurations of listed interfaces with provided configurarions + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lacp_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..41315301 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,66 @@ +--- +- debug: + msg: START isoxr_lacp_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_lacp_interfaces: + config: + + - name: Bundle-Ether10 + churn_logging: actor + collector_max_delay: 200 + + - name: Bundle-Ether11 + period: 100 + + - name: GigabitEthernet0/0/0/0 + period: 200 + state: merged + + - name: Gather interfaces facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - lacp_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_lacp_interfaces: + config: + + - name: Bundle-Ether10 + churn_logging: partner + + - name: Bundle-Ether11 + period: 200 + + - name: GigabitEthernet0/0/0/0 + period: 300 + state: overridden + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_lacp_interfaces: + config: "{{ ansible_facts['network_resources']['lacp_interfaces'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/vars/main.yaml new file mode 100644 index 00000000..1f1f5cf9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lacp_interfaces/vars/main.yaml @@ -0,0 +1,130 @@ +--- +merged: + before: + - name: GigabitEthernet0/0/0/0 + - name: GigabitEthernet0/0/0/1 + commands: + - interface Bundle-Ether10 + - lacp churn logging actor + - lacp switchover suppress-flaps 500 + - lacp collector-max-delay 100 + - interface Bundle-Ether11 + - lacp system mac 00c2.4c00.bd15 + - interface GigabitEthernet0/0/0/1 + - lacp period 100 + after: + - name: Bundle-Ether10 + churn_logging: actor + switchover_suppress_flaps: 500 + collector_max_delay: 100 + - name: Bundle-Ether11 + system: + mac: 00c2.4c00.bd15 + - name: GigabitEthernet0/0/0/0 + - name: GigabitEthernet0/0/0/1 + period: 100 +populate: + - name: Bundle-Ether10 + churn_logging: actor + switchover_suppress_flaps: 500 + collector_max_delay: 100 + - name: Bundle-Ether11 + system: + mac: 00c2.4c00.bd15 + - name: GigabitEthernet0/0/0/0 + period: 100 + - name: GigabitEthernet0/0/0/1 + period: 200 +replaced: + commands: + - interface Bundle-Ether10 + - no lacp switchover suppress-flaps 500 + - no lacp collector-max-delay 100 + - lacp churn logging partner + - interface GigabitEthernet0/0/0/1 + - lacp period 300 + after: + - name: Bundle-Ether10 + churn_logging: partner + - name: Bundle-Ether11 + system: + mac: 00c2.4c00.bd15 + - name: GigabitEthernet0/0/0/0 + period: 100 + - name: GigabitEthernet0/0/0/1 + period: 300 +overridden: + commands: + - interface Bundle-Ether10 + - no lacp switchover suppress-flaps 500 + - no lacp collector-max-delay 100 + - no lacp churn logging actor + - interface Bundle-Ether11 + - no lacp system mac 00c2.4c00.bd15 + - interface GigabitEthernet0/0/0/0 + - no lacp period 100 + - interface Bundle-Ether12 + - lacp churn logging both + - lacp collector-max-delay 100 + - lacp switchover suppress-flaps 500 + - interface GigabitEthernet0/0/0/1 + - lacp period 300 + after: + - name: Bundle-Ether10 + - name: Bundle-Ether11 + - name: Bundle-Ether12 + churn_logging: both + collector_max_delay: 100 + switchover_suppress_flaps: 500 + - name: GigabitEthernet0/0/0/0 + - name: GigabitEthernet0/0/0/1 + period: 300 +deleted: + commands: + - interface Bundle-Ether10 + - no lacp switchover suppress-flaps 500 + - no lacp collector-max-delay 100 + - no lacp churn logging actor + - interface Bundle-Ether11 + - no lacp system mac 00c2.4c00.bd15 + - interface GigabitEthernet0/0/0/0 + - no lacp period 100 + - interface GigabitEthernet0/0/0/1 + - no lacp period 200 + after: + - name: Bundle-Ether10 + - name: Bundle-Ether11 + - name: GigabitEthernet0/0/0/0 + - name: GigabitEthernet0/0/0/1 +round_trip: + after: + - name: Bundle-Ether10 + churn_logging: partner + - name: Bundle-Ether11 + period: 200 + - name: GigabitEthernet0/0/0/0 + period: 300 + - name: GigabitEthernet0/0/0/1 +parsed: + after: + - name: Bundle-Ether10 + churn_logging: actor + collector_max_delay: 100 + switchover_suppress_flaps: 500 + + - name: Bundle-Ether11 + system: + mac: 00c2.4c00.bd15 + + - name: GigabitEthernet0/0/0/1 + period: 200 +rendered: + commands: + - "interface Bundle-Ether10" + - "lacp churn logging actor" + - "lacp switchover suppress-flaps 500" + - "lacp collector-max-delay 100" + - "interface Bundle-Ether11" + - "lacp system mac 00c2.4c00.bd15" + - "interface GigabitEthernet0/0/0/1" + - "lacp period 200" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_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/iosxr/tests/integration/targets/iosxr_lag_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..37982f9a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,29 @@ +--- +- name: Setup + cisco.iosxr.iosxr_lag_interfaces: + config: + + - name: Bundle-Ether10 + mode: active + members: + + - member: GigabitEthernet0/0/0/0 + mode: inherit + + - member: GigabitEthernet0/0/0/1 + mode: passive + load_balancing_hash: src-ip + links: + max_active: 10 + min_active: 2 + + - name: Bundle-Ether11 + load_balancing_hash: dst-ip + members: + + - member: GigabitEthernet0/0/0/8 + mode: passive + + - member: GigabitEthernet0/0/0/9 + mode: passive + state: merged diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..e9566f34 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,32 @@ +--- +- name: Remove Bundles + vars: + lines: "no interface Bundle-Ether10\nno interface Bundle-Ether11\nno interface\ + \ Bundle-Ether12\n" + ignore_errors: true + ansible.netcommon.cli_config: + config: '{{ lines }}' + +- name: Remove LAG interface config + loop: + - 0/0/0/0 + - 0/0/0/1 + - 0/0/0/2 + - 0/0/0/8 + - 0/0/0/9 + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no bundle id + - shutdown + parents: interface GigabitEthernet{{ item }} + +- name: Remove unwanted interfaces from config + loop: + - 0/0/0/2 + - 0/0/0/8 + - 0/0/0/9 + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no interface GigabitEthernet{{ item }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..6aed8ce5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,52 @@ +--- +- debug: + msg: Start iosxr_lag_interfaces deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete LAG interfaces configuration + register: result + cisco.iosxr.iosxr_lag_interfaces: &id001 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete LACP attributes of all interfaces (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lag_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + - result.commands|length == 0 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..5992de5b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_lag_interfaces empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_lag_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/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..a67b7f9a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,33 @@ +interface Bundle-Ether10 + lacp mode active + bundle load-balancing hash src-ip + bundle maximum-active links 5 + bundle minimum-active links 2 +! +interface Bundle-Ether12 + bundle load-balancing hash dst-ip +! +interface Loopback888 + description test for ansible + shutdown +! +interface MgmtEth0/0/CPU0/0 + ipv4 address 192.0.2.11 255.255.255.0 +! +interface GigabitEthernet0/0/0/1 + description 'GigabitEthernet - 1" + bundle id 10 mode inherit +! +interface GigabitEthernet0/0/0/2 + description "GigabitEthernet - 2" + bundle id 12 mode passive +! +interface GigabitEthernet0/0/0/3 + description "GigabitEthernet - 3" + bundle id 10 mode inherit +! +interface GigabitEthernet0/0/0/4 + description "GigabitEthernet - 4" + bundle id 12 mode passive +! + diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..50c13507 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,49 @@ +--- +- debug: + msg: START iosxr_lag_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Gather the provided configuration with the existing running configuration + register: result + cisco.iosxr.iosxr_lag_interfaces: + config: + - name: Bundle-Ether10 + mode: active + members: + + - member: GigabitEthernet0/0/0/0 + mode: inherit + + - member: GigabitEthernet0/0/0/1 + mode: passive + load_balancing_hash: src-ip + links: + max_active: 10 + min_active: 2 + + - name: Bundle-Ether11 + load_balancing_hash: dst-ip + members: + + - member: GigabitEthernet0/0/0/8 + mode: passive + + - member: GigabitEthernet0/0/0/9 + mode: passive + state: merged + + - name: Gather LACP facts using gathered state + register: result + cisco.iosxr.iosxr_lag_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: "{{ merged['after'] == result['gathered'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..73aee044 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/merged.yaml @@ -0,0 +1,75 @@ +--- +- debug: + msg: START iosxr_lag_interfaces merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_lag_interfaces: &id001 + config: + + - name: Bundle-Ether10 + mode: active + members: + + - member: GigabitEthernet0/0/0/0 + mode: inherit + + - member: GigabitEthernet0/0/0/1 + mode: passive + load_balancing_hash: src-ip + links: + max_active: 10 + min_active: 2 + + - name: Bundle-Ether11 + load_balancing_hash: dst-ip + members: + + - member: GigabitEthernet0/0/0/8 + mode: passive + + - member: GigabitEthernet0/0/0/9 + mode: passive + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lag_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..0c6ac8c3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,68 @@ +--- +- debug: + msg: START iosxr_lag_interfaces overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Overridde all LAG interface configuration with provided configuration + register: result + cisco.iosxr.iosxr_lag_interfaces: &id001 + config: + + - name: Bundle-Ether11 + mode: active + members: + + - member: GigabitEthernet0/0/0/0 + mode: active + + - member: GigabitEthernet0/0/0/1 + mode: active + load_balancing_hash: src-ip + links: + max_active: 10 + min_active: 5 + 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: Overridde all interface LAG interface configuration with provided configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lag_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..310c4d79 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,15 @@ +--- +- debug: + msg: START iosxr_lag_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided lag interfaces config to agnostic model + register: result + cisco.iosxr.iosxr_lag_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ parsed['after'] == result['parsed'] }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..cec9e7db --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,34 @@ +--- +- debug: + msg: START iosxr_lag_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- name: Render platform specific commands from task input using rendered state + register: result + cisco.iosxr.iosxr_lag_interfaces: + config: + - name: Bundle-Ether10 + members: + - member: GigabitEthernet0/0/0/1 + mode: inherit + - member: GigabitEthernet0/0/0/3 + mode: inherit + mode: active + links: + max_active: 5 + min_active: 2 + load_balancing_hash: src-ip + + - name: Bundle-Ether12 + members: + - member: GigabitEthernet0/0/0/2 + mode: passive + - member: GigabitEthernet0/0/0/4 + mode: passive + load_balancing_hash: dst-ip + state: rendered + +- name: Assert that correct set of commands were rendered + assert: + that: + - rendered['commands'].sort() == result['rendered'].sort() diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..2f8ad1e7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,65 @@ +--- +- debug: + msg: START iosxr_lag_interfaces replaced integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replace device configurations of listed interfaces with provided configurations + register: result + cisco.iosxr.iosxr_lag_interfaces: &id001 + config: + + - name: Bundle-Ether10 + mode: passive + members: + + - member: GigabitEthernet0/0/0/0 + mode: passive + load_balancing_hash: dst-ip + + - name: Bundle-Ether12 + mode: active + 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: Replace device configurations of listed interfaces with provided configurarions + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lag_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..0be9e147 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,71 @@ +--- +- debug: + msg: START isoxr_lag_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_lag_interfaces: + config: + + - name: Bundle-Ether10 + members: + + - member: GigabitEthernet0/0/0/1 + mode: passive + links: + max_active: 10 + min_active: 2 + + - name: Bundle-Ether11 + mode: passive + state: merged + + - name: Gather interfaces facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - lag_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_lag_interfaces: + config: + + - name: Bundle-Ether10 + members: + + - member: GigabitEthernet0/0/0/9 + mode: active + + - member: GigabitEthernet0/0/0/8 + mode: passive + + - name: Bundle-Ether11 + mode: active + state: overridden + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_lag_interfaces: + config: "{{ ansible_facts['network_resources']['lag_interfaces'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/vars/main.yaml new file mode 100644 index 00000000..5f4c7722 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lag_interfaces/vars/main.yaml @@ -0,0 +1,181 @@ +--- +merged: + before: [] + commands: + - interface Bundle-Ether10 + - bundle load-balancing hash src-ip + - bundle minimum-active links 2 + - bundle maximum-active links 10 + - lacp mode active + - interface GigabitEthernet0/0/0/1 + - bundle id 10 mode passive + - interface GigabitEthernet0/0/0/0 + - bundle id 10 mode inherit + - interface Bundle-Ether11 + - bundle load-balancing hash dst-ip + - interface GigabitEthernet0/0/0/8 + - bundle id 11 mode passive + - interface GigabitEthernet0/0/0/9 + - bundle id 11 mode passive + after: + - name: Bundle-Ether10 + links: + max_active: 10 + min_active: 2 + load_balancing_hash: src-ip + members: + - member: GigabitEthernet0/0/0/0 + mode: inherit + - member: GigabitEthernet0/0/0/1 + mode: passive + mode: active + - name: Bundle-Ether11 + load_balancing_hash: dst-ip + members: + - member: GigabitEthernet0/0/0/8 + mode: passive + - member: GigabitEthernet0/0/0/9 + mode: passive +replaced: + commands: + - interface Bundle-Ether10 + - no bundle maximum-active links 10 + - no bundle minimum-active links 2 + - bundle load-balancing hash dst-ip + - lacp mode passive + - interface GigabitEthernet0/0/0/1 + - no bundle id + - interface GigabitEthernet0/0/0/0 + - bundle id 10 mode passive + - interface Bundle-Ether12 + - lacp mode active + after: + - load_balancing_hash: dst-ip + members: + - member: GigabitEthernet0/0/0/0 + mode: passive + mode: passive + name: Bundle-Ether10 + - load_balancing_hash: dst-ip + members: + - member: GigabitEthernet0/0/0/8 + mode: passive + - member: GigabitEthernet0/0/0/9 + mode: passive + name: Bundle-Ether11 + - mode: active + name: Bundle-Ether12 +overridden: + commands: + - interface Bundle-Ether10 + - no bundle maximum-active links 10 + - no bundle minimum-active links 2 + - no bundle load-balancing hash src-ip + - no lacp mode active + - interface GigabitEthernet0/0/0/0 + - no bundle id + - interface GigabitEthernet0/0/0/1 + - no bundle id + - interface Bundle-Ether11 + - bundle load-balancing hash src-ip + - bundle minimum-active links 5 + - bundle maximum-active links 10 + - lacp mode active + - interface GigabitEthernet0/0/0/8 + - no bundle id + - interface GigabitEthernet0/0/0/9 + - no bundle id + - interface GigabitEthernet0/0/0/0 + - bundle id 11 mode active + - interface GigabitEthernet0/0/0/1 + - bundle id 11 mode active + after: + - name: Bundle-Ether10 + - links: + max_active: 10 + min_active: 5 + load_balancing_hash: src-ip + members: + - member: GigabitEthernet0/0/0/0 + mode: active + - member: GigabitEthernet0/0/0/1 + mode: active + mode: active + name: Bundle-Ether11 +deleted: + commands: + - interface Bundle-Ether10 + - no bundle maximum-active links 10 + - no bundle minimum-active links 2 + - no bundle load-balancing hash src-ip + - no lacp mode active + - interface GigabitEthernet0/0/0/0 + - no bundle id + - interface GigabitEthernet0/0/0/1 + - no bundle id + - interface Bundle-Ether11 + - no bundle load-balancing hash dst-ip + - interface GigabitEthernet0/0/0/8 + - no bundle id + - interface GigabitEthernet0/0/0/9 + - no bundle id + after: + - name: Bundle-Ether10 + - name: Bundle-Ether11 +round_trip: + after: + - members: + - member: GigabitEthernet0/0/0/8 + mode: passive + - member: GigabitEthernet0/0/0/9 + mode: active + name: Bundle-Ether10 + - mode: active + name: Bundle-Ether11 +rendered: + commands: + - "interface Bundle-Ether10" + - "lacp mode active" + - "bundle load-balancing hash src-ip" + - "bundle maximum-active links 5" + - "bundle minimum-active links 2" + - "interface Bundle-Ether12" + - "bundle load-balancing hash dst-ip" + - "interface Loopback888" + - "description test for ansible" + - "shutdown" + - "interface MgmtEth0/0/CPU0/0" + - "ipv4 address 192.0.2.11 255.255.255.0" + - "interface GigabitEthernet0/0/0/1" + - "description 'GigabitEthernet - 1'" + - "bundle id 10 mode inherit" + - "interface GigabitEthernet0/0/0/2" + - "description 'GigabitEthernet - 2'" + - "bundle id 12 mode passive" + - "interface GigabitEthernet0/0/0/3" + - "description 'GigabitEthernet - 3'" + - "bundle id 10 mode inherit" + - "interface GigabitEthernet0/0/0/4" + - "description 'GigabitEthernet - 4'" + - "bundle id 12 mode passive" +parsed: + after: + - name: Bundle-Ether10 + members: + - member: GigabitEthernet0/0/0/1 + mode: inherit + - member: GigabitEthernet0/0/0/3 + mode: inherit + mode: active + links: + max_active: 5 + min_active: 2 + load_balancing_hash: src-ip + + - name: Bundle-Ether12 + members: + - member: GigabitEthernet0/0/0/2 + mode: passive + - member: GigabitEthernet0/0/0/4 + mode: passive + load_balancing_hash: dst-ip diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_lldp_global/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/_populate.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/_populate.yaml new file mode 100644 index 00000000..3f44e711 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/_populate.yaml @@ -0,0 +1,8 @@ +--- +- name: Setup + vars: + lines: "lldp reinit 2\nlldp holdtime 100\nlldp timer 3000\nlldp subinterfaces\ + \ enable\nlldp tlv-select system-description disable\nlldp tlv-select management-address\ + \ disable\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..34140d91 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/_remove_config.yaml @@ -0,0 +1,6 @@ +--- +- name: Remove Config + vars: + lines: "no lldp\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/deleted.yaml new file mode 100644 index 00000000..5a53c74b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/deleted.yaml @@ -0,0 +1,48 @@ +--- +- debug: + msg: Start iosxr_lldp_global deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Delete global LLDP attributes + register: result + cisco.iosxr.iosxr_lldp_global: &id001 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ merged['after'] == result['before'] }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['after'] }}" + + - name: Delete attributes of given interfaces (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lldp_global: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/empty_config.yaml new file mode 100644 index 00000000..8043e582 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/empty_config.yaml @@ -0,0 +1,49 @@ +--- +- debug: + msg: START iosxr_lldp_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..9e05883e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,11 @@ +lldp + timer 3000 + reinit 2 + subinterfaces enable + holdtime 100 + tlv-select + management-address disable + system-description disable + ! +! + diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/gathered.yaml new file mode 100644 index 00000000..5c02e7e8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/gathered.yaml @@ -0,0 +1,34 @@ +--- +- debug: + msg: START iosxr_lldp_global gathered 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.iosxr.iosxr_lldp_global: + config: + holdtime: 100 + reinit: 2 + timer: 3000 + subinterfaces: true + tlv_select: + management_address: false + system_description: false + state: merged + + - name: Gather interfaces facts using gathered state + register: result + cisco.iosxr.iosxr_lldp_global: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: merged['after'] == result['gathered'] + + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/merged.yaml new file mode 100644 index 00000000..37effc81 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/merged.yaml @@ -0,0 +1,54 @@ +--- +- debug: + msg: START iosxr_lldp_global merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_lldp_global: &id001 + config: + holdtime: 100 + reinit: 2 + timer: 3000 + subinterfaces: true + tlv_select: + management_address: false + system_description: false + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lldp_global: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] == result['before']}}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/parsed.yaml new file mode 100644 index 00000000..c2e76075 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/parsed.yaml @@ -0,0 +1,15 @@ +--- +- debug: + msg: START iosxr_lldp_global parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided LACP config to agnostic model + register: result + cisco.iosxr.iosxr_lldp_global: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ parsed['after'] == result['parsed'] }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/rendered.yaml new file mode 100644 index 00000000..0eff0cdc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/rendered.yaml @@ -0,0 +1,23 @@ +--- +- debug: + msg: START iosxr_lldp_global rendered integration tests on connection={{ ansible_connection + }} + +- name: Render platform specific commands from task input using rendered stateion + register: result + cisco.iosxr.iosxr_lldp_global: + config: + holdtime: 100 + reinit: 2 + timer: 3000 + subinterfaces: true + tlv_select: + management_address: false + system_description: false + state: rendered + +- name: Assert that correct set of commands were rendered + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/replaced.yaml new file mode 100644 index 00000000..8ef44209 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/replaced.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: START iosxr_lldp_global replaced integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Replace global LLDP configuration with provided configurations + register: result + cisco.iosxr.iosxr_lldp_global: &id001 + config: + holdtime: 100 + tlv_select: + port_description: false + system_description: false + management_address: 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: + - "{{ merged['after'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] == result['after'] }}" + + - name: Replace device global LLDP configurations with provided configurarions + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lldp_global: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/rtt.yaml new file mode 100644 index 00000000..e8e99f54 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/tests/cli/rtt.yaml @@ -0,0 +1,51 @@ +--- +- debug: + msg: START isoxr_lldp_global round trip integration tests on connection={{ ansible_connection + }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_lldp_global: + config: + holdtime: 200 + timer: 500 + state: merged + + - name: Gather interfaces facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - lldp_global + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_lldp_global: + config: + holdtime: 200 + reinit: 4 + subinterfaces: true + timer: 3000 + state: merged + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] == result['after'] }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_lldp_global: + config: "{{ ansible_facts['network_resources']['lldp_global'] }}" + state: replaced + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] == revert['after'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/vars/main.yaml new file mode 100644 index 00000000..8d6f0928 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_global/vars/main.yaml @@ -0,0 +1,63 @@ +--- +merged: + before: {} + commands: + - lldp reinit 2 + - lldp holdtime 100 + - lldp timer 3000 + - lldp subinterfaces enable + - lldp tlv-select system-description disable + - lldp tlv-select management-address disable + after: + holdtime: 100 + reinit: 2 + subinterfaces: true + timer: 3000 + tlv_select: + management_address: false + system_description: false +replaced: + commands: + - no lldp reinit 2 + - no lldp subinterfaces enable + - no lldp timer 3000 + - lldp tlv-select port-description disable + after: + holdtime: 100 + tlv_select: + management_address: false + port_description: false + system_description: false +deleted: + commands: + - no lldp holdtime 100 + - no lldp reinit 2 + - no lldp subinterfaces enable + - no lldp timer 3000 + - no lldp tlv-select management-address disable + - no lldp tlv-select system-description disable + after: {} +round_trip: + after: + holdtime: 200 + reinit: 4 + subinterfaces: true + timer: 3000 + +parsed: + after: + holdtime: 100 + reinit: 2 + timer: 3000 + subinterfaces: true + tlv_select: + management_address: false + system_description: false +rendered: + commands: + - "lldp subinterfaces enable" + - "lldp holdtime 100" + - "lldp reinit 2" + - "lldp tlv-select system-description disable" + - "lldp tlv-select management-address disable" + - "lldp timer 3000" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/_populate.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/_populate.yaml new file mode 100644 index 00000000..e499c1bd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/_populate.yaml @@ -0,0 +1,12 @@ +--- +- name: Setup GigE1 + cisco.iosxr.iosxr_config: + lines: + - lldp receive disable + parents: interface GigabitEthernet0/0/0/1 + +- name: Setup GigE0 + cisco.iosxr.iosxr_config: + lines: + - lldp transmit disable + parents: interface GigabitEthernet0/0/0/0 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..004cdb88 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,22 @@ +--- +- name: Remove LLDP interface config + loop: + - 0/0/0/0 + - 0/0/0/1 + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no lldp + - shutdown + parents: interface GigabitEthernet{{ item }} + +- name: Remove unwanted interfaces from config + loop: + - 0/0/0/2 + - 0/0/0/3 + - 0/0/0/4 + - 0/0/0/5 + ignore_errors: true + cisco.iosxr.iosxr_config: + lines: + - no interface GigabitEthernet{{ item }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..933e188a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,51 @@ +--- +- debug: + msg: Start iosxr_lldp_interfaces deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Delete LLDP attributes of all interfaces + register: result + cisco.iosxr.iosxr_lldp_interfaces: &id001 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete LACP attributes of all interfaces (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lldp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + - result.commands|length == 0 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..e7fb55b5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_lldp_interfaces empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/fixtures/parsed.cfg new file mode 100644 index 00000000..8fbe03d5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/fixtures/parsed.cfg @@ -0,0 +1,16 @@ +interface TenGigE0/0/0/0 + ipv4 address 192.0.2.11 255.255.255.192 +! +interface preconfigure GigabitEthernet0/0/0/1 + lldp + receive disable + destination mac-address + ieee-nearest-bridge + ! + ! +! +interface preconfigure GigabitEthernet0/0/0/2 + lldp + transmit disable + destination mac-address + ieee-nearest-non-tmpr-bridge diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..da2c148e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: START iosxr_lldp_interfaces gathered 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.iosxr.iosxr_lldp_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + transmit: false + + - name: GigabitEthernet0/0/0/1 + receive: false + state: merged + + - name: Gather interfaces facts using gathered state + register: result + cisco.iosxr.iosxr_lldp_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + assert: + that: "{{ merged['after'] | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..28713969 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/merged.yaml @@ -0,0 +1,57 @@ +--- +- debug: + msg: START iosxr_lldp_interfaces merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_lldp_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + transmit: false + + - name: GigabitEthernet0/0/0/1 + receive: false + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lldp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..8cfb3a5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: START iosxr_lldp_interfaces overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Overridde all interface LLDP configuration with provided configuration + register: result + cisco.iosxr.iosxr_lldp_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/0 + transmit: false + 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: + - "{{ populate | 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: Overridde all interface LACP configuration with provided configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lldp_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..277a2778 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START iosxr_lldp_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided Lldp interfaces config to agnostic model + register: result + cisco.iosxr.iosxr_lldp_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that correct set of commands were rendered + assert: + that: + - "{{ parsed['config'] | symmetric_difference(result['parsed']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..c8a2c7de --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,27 @@ +--- +- debug: + msg: START iosxr_lldp_interfaces rendered integration tests on connection={{ ansible_connection + }} + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_lldp_interfaces: + config: + - name: GigabitEthernet0/0/0/1 + destination: + mac_address: ieee-nearest-non-tmpr-bridge + transmit: false + + - name: GigabitEthernet0/0/0/2 + destination: + mac_address: ieee-nearest-bridge + receive: false + state: rendered + + - name: Assert that correct set of commands were rendered + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..005d14d9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: START iosxr_lldp_interfaces replaced integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Replace device configurations of listed interfaces with provided configurations + register: result + cisco.iosxr.iosxr_lldp_interfaces: &id001 + config: + + - name: GigabitEthernet0/0/0/1 + 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: + - "{{ populate | 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: Replace device configurations of listed interfaces with provided configurarions + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_lldp_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..10a31cc4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: START iosxr_lldp_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_lldp_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + transmit: false + state: merged + + - name: Gather interfaces facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - lldp_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_lldp_interfaces: + config: + + - name: GigabitEthernet0/0/0/0 + receive: false + + - name: GigabitEthernet0/0/0/1 + transmit: false + state: overridden + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_lldp_interfaces: + config: "{{ ansible_facts['network_resources']['lldp_interfaces'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/vars/main.yaml new file mode 100644 index 00000000..403548b5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_lldp_interfaces/vars/main.yaml @@ -0,0 +1,73 @@ +--- +merged: + before: + - name: GigabitEthernet0/0/0/0 + - name: GigabitEthernet0/0/0/1 + commands: + - interface GigabitEthernet0/0/0/0 + - lldp transmit disable + - interface GigabitEthernet0/0/0/1 + - lldp receive disable + after: + - name: GigabitEthernet0/0/0/0 + transmit: false + - name: GigabitEthernet0/0/0/1 + receive: false +populate: + - name: GigabitEthernet0/0/0/0 + transmit: false + - name: GigabitEthernet0/0/0/1 + receive: false +replaced: + commands: + - interface GigabitEthernet0/0/0/1 + - no lldp receive disable + - lldp transmit disable + after: + - name: GigabitEthernet0/0/0/0 + transmit: false + - name: GigabitEthernet0/0/0/1 + transmit: false +overridden: + commands: + - interface GigabitEthernet0/0/0/1 + - no lldp receive disable + after: + - name: GigabitEthernet0/0/0/0 + transmit: false + - name: GigabitEthernet0/0/0/1 +deleted: + commands: + - interface GigabitEthernet0/0/0/0 + - no lldp transmit disable + - interface GigabitEthernet0/0/0/1 + - no lldp receive disable + after: + - name: GigabitEthernet0/0/0/0 + - name: GigabitEthernet0/0/0/1 +round_trip: + after: + - name: GigabitEthernet0/0/0/0 + receive: false + - name: GigabitEthernet0/0/0/1 + transmit: false +parsed: + config: + - name: TenGigE0/0/0/0 + - name: GigabitEthernet0/0/0/2 + destination: + mac_address: ieee-nearest-non-tmpr-bridge + transmit: false + + - name: GigabitEthernet0/0/0/1 + destination: + mac_address: ieee-nearest-bridge + receive: false +rendered: + commands: + - "interface GigabitEthernet0/0/0/2" + - "lldp destination mac-address ieee-nearest-non-tmpr-bridge" + - "lldp transmit disable" + - "interface GigabitEthernet0/0/0/1" + - "lldp receive disable" + - "lldp destination mac-address ieee-nearest-bridge" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/meta/main.yaml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/cli.yaml new file mode 100644 index 00000000..3358b7af --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/cli.yaml @@ -0,0 +1,21 @@ +--- +- 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 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 + tags: + - network_cli + +- name: reset connection + meta: reset_connection diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/main.yaml new file mode 100644 index 00000000..5d082a6f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- include: cli.yaml +- include: netconf.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/netconf.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/netconf.yaml new file mode 100644 index 00000000..cdbe47e3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tasks/netconf.yaml @@ -0,0 +1,29 @@ +--- +- name: collect all netconf test cases + find: + paths: '{{ role_path }}/tests/netconf' + 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 case (connection=ansible.netcommon.netconf) + include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.netconf' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: + - netconf + +- 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 + +- name: reset connection + meta: reset_connection diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tests/cli/basic.yaml new file mode 100644 index 00000000..2467557e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tests/cli/basic.yaml @@ -0,0 +1,161 @@ +--- +- name: remove host logging + cisco.iosxr.iosxr_logging: + dest: host + name: 172.16.0.1 + state: absent + provider: '{{ cli }}' + +- name: remove console logging + register: result + cisco.iosxr.iosxr_logging: + dest: console + state: absent + provider: '{{ cli }}' + +- name: remove buffered logging + register: result + cisco.iosxr.iosxr_logging: + dest: buffered + size: 2097155 + state: absent + provider: '{{ cli }}' + +- name: set up syslog host logging + register: result + cisco.iosxr.iosxr_logging: &id001 + dest: host + name: 172.16.0.1 + level: errors + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging 172.16.0.1 vrf default severity error" in result.commands' + +- name: set up syslog host logging (idempotent) + register: result + cisco.iosxr.iosxr_logging: *id001 + +- assert: &id003 + that: + - result.changed == false + +- name: delete/disable syslog host logging + register: result + cisco.iosxr.iosxr_logging: &id002 + dest: host + name: 172.16.0.1 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"no logging 172.16.0.1 vrf default" in result.commands' + +- name: delete/disable syslog host logging (idempotent) + register: result + cisco.iosxr.iosxr_logging: *id002 + +- assert: *id003 + +- name: add console logging with level warning + register: result + cisco.iosxr.iosxr_logging: &id004 + dest: console + level: warning + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging console warning" in result.commands' + +- name: console logging with level warning (idempotent) + register: result + cisco.iosxr.iosxr_logging: *id004 + +- assert: *id003 + +- name: remove console logging with level warning + register: result + cisco.iosxr.iosxr_logging: + dest: console + level: warning + state: absent + provider: '{{ cli }}' + +- assert: &id006 + that: + - result.changed == true + +- name: configure buffered logging size + register: result + cisco.iosxr.iosxr_logging: &id005 + dest: buffered + size: 4800000 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging buffered 4800000" in result.commands' + +- name: configure buffered logging size (idempotence) + register: result + cisco.iosxr.iosxr_logging: *id005 + +- assert: *id003 + +- name: remove buffered logging size + register: result + cisco.iosxr.iosxr_logging: + dest: buffered + size: 4800000 + state: absent + provider: '{{ cli }}' + +- assert: *id006 + +- name: change logging parameters using aggregate + register: result + cisco.iosxr.iosxr_logging: + aggregate: + + - dest: console + level: notifications + + - dest: buffered + size: 4700000 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging buffered 4700000" in result.commands' + - '"logging console notifications" in result.commands' + +- name: remove logging parameters using aggregate + register: result + cisco.iosxr.iosxr_logging: + aggregate: + + - dest: console + level: notifications + + - dest: buffered + size: 4700000 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"no logging console" in result.commands' + - '"no logging buffered" in result.commands' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tests/cli/net_logging.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tests/cli/net_logging.yaml new file mode 100644 index 00000000..94d057b4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tests/cli/net_logging.yaml @@ -0,0 +1,33 @@ +--- +- debug: msg="START iosxr 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 + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"logging 172.16.0.1 vrf default severity debugging" 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 iosxr cli/net_logging.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tests/netconf/basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tests/netconf/basic.yaml new file mode 100644 index 00000000..57bc6de9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_logging/tests/netconf/basic.yaml @@ -0,0 +1,227 @@ +--- +- name: remove host logging + cisco.iosxr.iosxr_logging: + dest: host + name: 172.16.0.1 + state: absent + provider: '{{ netconf }}' + +- name: remove console logging + register: result + cisco.iosxr.iosxr_logging: + dest: console + level: warning + state: absent + provider: '{{ netconf }}' + +- name: remove buffered logging + register: result + cisco.iosxr.iosxr_logging: + dest: buffered + size: 2097155 + state: absent + provider: '{{ netconf }}' + +- name: set up syslog host logging + register: result + cisco.iosxr.iosxr_logging: &id001 + dest: host + name: 172.16.0.1 + level: errors + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"172.16.0.1" in result.xml[0]' + +- name: set up syslog host logging (idempotent) + register: result + cisco.iosxr.iosxr_logging: *id001 + +- assert: &id003 + that: + - result.changed == false + +- name: delete/disable syslog host logging + register: result + cisco.iosxr.iosxr_logging: &id002 + dest: host + name: 172.16.0.1 + state: absent + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"172.16.0.1" in result.xml[0]' + - '"delete" in result.xml[0]' + +- name: delete/disable syslog host logging (idempotent) + register: result + cisco.iosxr.iosxr_logging: *id002 + +- assert: *id003 + +- name: add console logging with level warning + register: result + cisco.iosxr.iosxr_logging: &id004 + dest: console + level: warning + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"console" in result.xml[0]' + - '"warning" in result.xml[0]' + +- name: console logging with level warning (idempotent) + register: result + cisco.iosxr.iosxr_logging: *id004 + +- assert: *id003 + +- name: remove console logging with level warning + register: result + cisco.iosxr.iosxr_logging: + dest: console + level: warning + state: absent + provider: '{{ netconf }}' + +- assert: &id006 + that: + - result.changed == true + +- name: configure buffered logging size + register: result + cisco.iosxr.iosxr_logging: &id005 + dest: buffered + size: 4800000 + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"buffered" in result.xml[0]' + - '"4800000" in result.xml[0]' + +- name: configure buffered logging size (idempotence) + register: result + cisco.iosxr.iosxr_logging: *id005 + +- assert: *id003 + +- name: remove buffered logging size + register: result + cisco.iosxr.iosxr_logging: + dest: buffered + size: 4800000 + state: absent + provider: '{{ netconf }}' + +- assert: *id006 + +- name: change logging parameters using aggregate + register: result + cisco.iosxr.iosxr_logging: + aggregate: + + - dest: console + level: notifications + + - dest: buffered + size: 4700000 + + - dest: monitor + level: alerts + + - dest: host + name: 10.10.10.1 + level: errors + + - dest: host + name: 10.10.10.2 + + - dest: file + name: file1 + size: 2048 + level: critical + + - dest: file + name: file2 + size: 2048 + + - facility: local3 + + - hostnameprefix: host3 + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"file1" in result.xml[0]' + - '"file2" in result.xml[0]' + - '"10.10.10.1" in result.xml[1]' + - '"10.10.10.2" in result.xml[1]' + - '"notice" in result.xml[2]' + - '"alert" in result.xml[3]' + - '"4700000" in result.xml[4]' + - '"debug" in result.xml[5]' + - '"local3" in result.xml[6]' + - '"host3" in result.xml[7]' + +- name: remove logging parameters using aggregate + register: result + cisco.iosxr.iosxr_logging: + aggregate: + + - dest: console + level: notifications + + - dest: buffered + size: 4700000 + + - dest: monitor + level: alerts + + - dest: host + name: 10.10.10.1 + level: errors + + - dest: host + name: 10.10.10.2 + + - dest: file + name: file1 + size: 2048 + level: critical + + - dest: file + name: file2 + size: 2048 + + - facility: local3 + + - hostnameprefix: host3 + state: absent + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"file1" in result.xml[0]' + - '"file2" in result.xml[0]' + - '"10.10.10.1" in result.xml[1]' + - '"10.10.10.2" in result.xml[1]' + - '"notice" in result.xml[2]' + - '"alert" in result.xml[3]' + - '"4700000" in result.xml[4]' + - '"debug" in result.xml[5]' + - '"local3" in result.xml[6]' + - '"host3" in result.xml[7]' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/meta/main.yaml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tasks/cli.yaml new file mode 100644 index 00000000..163934f5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/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 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/iosxr/tests/integration/targets/iosxr_netconf/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tests/cli/basic.yaml new file mode 100644 index 00000000..1cf4a019 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_netconf/tests/cli/basic.yaml @@ -0,0 +1,72 @@ +--- +- debug: msg="START iosxr_netconf cli/basic.yaml on connection={{ ansible_connection + }}" + +- name: Disable NetConf service + cisco.iosxr.iosxr_netconf: &id003 + state: absent + +- block: + + - name: Enable Netconf service + register: result + cisco.iosxr.iosxr_netconf: + netconf_port: 830 + netconf_vrf: default + state: present + + - assert: &id001 + that: + - result.changed == true + + - name: Check idempotence of Enable Netconf service + register: result + cisco.iosxr.iosxr_netconf: + netconf_port: 830 + netconf_vrf: default + state: present + + - assert: &id002 + that: + - result.changed == false + + - name: Change Netconf port + register: result + cisco.iosxr.iosxr_netconf: + netconf_port: 9000 + state: present + + - assert: *id001 + + - name: Check idempotent of change Netconf port + register: result + cisco.iosxr.iosxr_netconf: + netconf_port: 9000 + state: present + + - assert: *id002 + + - name: Add Netconf vrf + register: result + cisco.iosxr.iosxr_netconf: + netconf_port: 9000 + netconf_vrf: new_default + state: present + + - assert: *id001 + + - name: Check idempotent of add Netconf vrf + register: result + cisco.iosxr.iosxr_netconf: + netconf_port: 9000 + netconf_vrf: new_default + state: present + + - assert: *id002 + always: + + - name: Disable Netconf service + cisco.iosxr.iosxr_netconf: *id003 + +- debug: msg="END iosxr_netconf cli/basic.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/fixtures/parsed.cfg new file mode 100644 index 00000000..b2677113 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/fixtures/parsed.cfg @@ -0,0 +1,51 @@ +router ospf LAB3 + area 0.0.0.3 + interface GigabitEthernet0/0/0/0 + cost 20 + authentication message-digest keychain cisco + ! + ! +! +router ospfv3 10 + area 11 + cost 11 + default-cost 5 + ! + area 22 + default-cost 6 + ! +! +router ospfv3 26 + authentication disable +! +router ospfv3 27 + area 10 + hello-interval 2 + ! +! +router ospfv3 30 + cost 2 + priority 1 + mtu-ignore + packet-size 577 + dead-interval 2 + retransmit-interval 2 + demand-circuit + hello-interval 1 + transmit-delay 2 + router-id 2.2.2.2 + default-metric 10 + area 11 + default-cost 5 + ! + area 22 + default-cost 6 + ! +! +router ospfv3 LAB3 + area 0.0.0.2 + interface GigabitEthernet0/0/0/0 + cost 30 + ! + ! +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..ec4c4b37 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/_populate_config.yaml @@ -0,0 +1,23 @@ +--- +- name: Setup (Populate OSPF interfaces config) + cisco.iosxr.iosxr_ospf_interfaces: + config: + - name: GigabitEthernet0/0/0/0 + type: gigabitethernet + address_family: + - afi: ipv4 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.3 + cost: 20 + authentication: + message_digest: + keychain: cisco + - afi: ipv6 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.2 + cost: 30 + state: merged diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..2ddf6416 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,12 @@ +--- +- name: Remove OSPFv3 Routes + vars: + lines: "no router ospf LAB3 \n + no router ospfv3 LAB3 \n + no router ospfv3 LAB \n + no router ospf LAB \n + no router ospf LAB1 \n + no router ospfv3 LAB1 " + ignore_errors: true + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..20a56fcd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,86 @@ +--- +- debug: + msg: Start iosxr_ospf_interfaces deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete single ospf interface + register: result + cisco.iosxr.iosxr_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/0/0/0 + type: gigabitethernet + + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete a single ospf process (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospf_interfaces: *id001 + + - assert: &id003 + that: + - result.changed == false + - result.commands|length == 0 + + - include_tasks: _populate_config.yaml + + - name: Delete all ospf processes + register: result + cisco.iosxr.iosxr_ospf_interfaces: &id005 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete all ospf processes (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospf_interfaces: *id005 + + - name: Assert that the previous task was idempotent + assert: *id003 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000..fff02bf2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_ospf_interfaces empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_ospf_interfaces: + config: + state: replaced + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Parsed with empty running_config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_ospf_interfaces: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Overridden with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_ospf_interfaces: + config: + state: rendered + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..158c7e9a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,25 @@ +--- +- debug: + msg: START iosxr_ospf_interfaces gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather OSPF interfaces facts from the device using iosxr_ospf_interfaces + module + register: result + cisco.iosxr.iosxr_ospf_interfaces: + state: gathered + + - assert: + that: + - "{{ merged['after'] | symmetric_difference(result['gathered']) | length\ + \ == 0 }}" + - "result.changed == false" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..e380f704 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/merged.yaml @@ -0,0 +1,121 @@ +--- +- debug: + msg: START iosxr_ospf interfaces merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/0/0/0 + type: gigabitethernet + address_family: + - afi: ipv4 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.3 + cost: 20 + authentication: + message_digest: + keychain: cisco + - afi: ipv6 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.2 + cost: 30 + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['before'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospf_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Update existing configuration using merged + register: result + cisco.iosxr.iosxr_ospf_interfaces: &id002 + config: + - name: GigabitEthernet0/0/0/1 + type: gigabitethernet + address_family: + - afi: ipv4 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.1 + cost: 10 + authentication: + message_digest: + keychain: lab1 + - afi: ipv6 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.4 + cost: 40 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) | length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['update_commands'] | symmetric_difference(result['commands'])\ + \ |length == 0 }}" + + - name: Assert that after dicts were correctly generated + assert: + that: + - "{{ merged['update_after'] | symmetric_difference(result['after']) | length\ + \ == 0 }}" + + - name: Update existing ospf interfaces configuration using merged (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospf_interfaces: *id002 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..8fa3878c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,65 @@ +--- +- debug: + msg: START iosxr_ospf_interfaces overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Overridde all ospf_interfaces configuration with provided configuration + register: result + cisco.iosxr.iosxr_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/0/0/1 + type: gigabitethernet + address_family: + - afi: ipv4 + processes: + - process_id: "LAB1" + area: + area_id: 0.0.0.3 + cost: 10 + authentication: + message_digest: + keychain: iosxr + 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: Overridde all ospf_interfaces configuration with given configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospf_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before'])\ + \ |length == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..5943066b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,19 @@ +--- +- debug: + msg: START iosxr_ospf_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- block: + + - name: Use parsed state to convert externally supplied device specific ospf_interfaces + commands to structured format + register: result + cisco.iosxr.iosxr_ospf_interfaces: + running_config: "{{ lookup('file', '../../fixtures/parsed.cfg') }}" + state: parsed + + - assert: + that: + - "{{ merged['after'] | symmetric_difference(result['parsed']) | length\ + \ == 0 }}" + - "result.changed == false" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..db25ec00 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,51 @@ +--- +- debug: + msg: START iosxr_ospf_interfaces rendered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Use rendered state to convert task input to device specific commands + register: result + cisco.iosxr.iosxr_ospf_interfaces: + config: + - name: GigabitEthernet0/0/0/0 + type: gigabitethernet + address_family: + - afi: ipv4 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.3 + cost: 20 + authentication: + message_digest: + keychain: cisco + - afi: ipv6 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.2 + cost: 30 + state: rendered + + - assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['rendered'])\ + \ |length==0 }}" + - "result.changed == false" + + - name: Gather Ospf interfaces facts from the device and assert that its empty + register: result + cisco.iosxr.iosxr_ospf_interfaces: + state: gathered + + - name: Make sure that rendered task actually did not make any changes to the + device + assert: + that: "{{ result['gathered'] == [] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..1527126b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,72 @@ +--- +- debug: + msg: START iosxr_ospf_interfaces replaced integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replace device configurations of ospf_interfaces with provided configurations + register: result + cisco.iosxr.iosxr_ospf_interfaces: &id001 + config: + - name: GigabitEthernet0/0/0/0 + type: gigabitethernet + address_family: + - afi: ipv4 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.3 + cost: 30 + authentication: + message_digest: + keychain: ciscoiosxr + - afi: ipv6 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.2 + cost: 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: Replace device configurations of listed vrfs/global entry with provided + configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospf_interfaces: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['before'])\ + \ |length == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..64f73189 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,79 @@ +--- +- debug: + msg: START iosxr_ospf_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_ospf_interfaces: + config: + - name: GigabitEthernet0/0/0/0 + type: gigabitethernet + address_family: + - afi: ipv4 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.3 + cost: 20 + authentication: + message_digest: + keychain: cisco + - afi: ipv6 + processes: + - process_id: "LAB3" + area: + area_id: 0.0.0.2 + cost: 30 + state: merged + + - name: Gather ospf_interfaces facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - ospf_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_ospf_interfaces: + config: + - name: GigabitEthernet0/0/0/1 + type: gigabitethernet + address_family: + - afi: ipv4 + processes: + - process_id: "LAB1" + area: + area_id: 0.0.0.3 + cost: 10 + authentication: + message_digest: + keychain: iosxr + state: overridden + + - name: Assert that changes were applied + assert: + that: + - "{{ round_trip['after'] | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_ospf_interfaces: + config: "{{ ansible_facts['network_resources']['ospf_interfaces'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: + - "{{ base_config['after'] | symmetric_difference(revert['after'])\ + \ |length == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/vars/main.yaml new file mode 100644 index 00000000..95f5e7bf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospf_interfaces/vars/main.yaml @@ -0,0 +1,138 @@ +--- +merged: + before: [] + commands: + - router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 cost 20 + - router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 authentication message-digest + - router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 authentication message-digest keychain cisco + - router ospfv3 LAB3 area 0.0.0.2 interface GigabitEthernet 0/0/0/0 cost 30 + + update_commands: + - router ospf LAB3 area 0.0.0.1 interface GigabitEthernet 0/0/0/1 cost 10 + - router ospf LAB3 area 0.0.0.1 interface GigabitEthernet 0/0/0/1 authentication message-digest + - router ospf LAB3 area 0.0.0.1 interface GigabitEthernet 0/0/0/1 authentication message-digest keychain lab1 + - router ospfv3 LAB3 area 0.0.0.4 interface GigabitEthernet 0/0/0/1 cost 40 + after: + - address_family: + - afi: ipv4 + authentication: + message_digest: + keychain: cisco + cost: 20 + processes: + - area: + area_id: 0.0.0.3 + process_id: "LAB3" + - afi: ipv6 + cost: 30 + processes: + - area: + area_id: 0.0.0.2 + process_id: "LAB3" + name: GigabitEthernet0/0/0/0 + type: gigabitethernet + + update_after: + - address_family: + - afi: ipv4 + authentication: + message_digest: + keychain: lab1 + cost: 10 + processes: + - area: + area_id: 0.0.0.1 + process_id: "LAB3" + - afi: ipv6 + cost: 40 + processes: + - area: + area_id: 0.0.0.4 + process_id: "LAB3" + name: GigabitEthernet0/0/0/1 + type: gigabitethernet + - address_family: + - afi: ipv4 + authentication: + message_digest: + keychain: cisco + cost: 20 + processes: + - area: + area_id: 0.0.0.3 + process_id: "LAB3" + - afi: ipv6 + cost: 30 + processes: + - area: + area_id: 0.0.0.2 + process_id: "LAB3" + name: GigabitEthernet0/0/0/0 + type: gigabitethernet +replaced: + commands: + - router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 cost 30 + - router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 authentication message-digest + - router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 authentication message-digest keychain ciscoiosxr + + after: + - address_family: + - afi: ipv4 + authentication: + message_digest: + keychain: ciscoiosxr + cost: 30 + processes: + - area: + area_id: 0.0.0.3 + process_id: "LAB3" + - afi: ipv6 + cost: 30 + processes: + - area: + area_id: 0.0.0.2 + process_id: "LAB3" + name: GigabitEthernet0/0/0/0 + type: gigabitethernet + +overridden: + commands: + - no router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 + - no router ospfv3 LAB3 area 0.0.0.2 interface GigabitEthernet 0/0/0/0 + - router ospf LAB1 area 0.0.0.3 interface GigabitEthernet 0/0/0/1 cost 10 + - router ospf LAB1 area 0.0.0.3 interface GigabitEthernet 0/0/0/1 authentication message-digest + - router ospf LAB1 area 0.0.0.3 interface GigabitEthernet 0/0/0/1 authentication message-digest keychain iosxr + + after: + - address_family: + - afi: ipv4 + authentication: + message_digest: + keychain: iosxr + cost: 10 + processes: + - area: + area_id: 0.0.0.3 + process_id: "LAB1" + name: GigabitEthernet0/0/0/1 + type: gigabitethernet +deleted: + commands: + - no router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 + - no router ospfv3 LAB3 area 0.0.0.2 interface GigabitEthernet 0/0/0/0 + + after: [] +round_trip: + after: + - name: GigabitEthernet0/0/0/1 + type: gigabitethernet + address_family: + - afi: ipv4 + processes: + - process_id: "LAB1" + area: + area_id: 0.0.0.3 + cost: 10 + authentication: + message_digest: + keychain: iosxr diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/fixtures/parsed.cfg new file mode 100644 index 00000000..f3861f84 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/fixtures/parsed.cfg @@ -0,0 +1,42 @@ +Thu Jun 4 12:15:08.448 UTC +router ospf 10 + area 11 + cost 11 + default-cost 5 + ! + area 22 + default-cost 6 + ! +! +router ospf 26 + authentication message-digest keychain ansible1101pass + adjacency stagger 10 20 +! +router ospf 27 + area 10 + hello-interval 2 + ! +! +router ospf 30 + router-id 2.2.2.2 + summary-in enable + external-out disable + cost 2 + packet-size 577 + passive disable + priority 1 + mtu-ignore enable + flood-reduction disable + dead-interval 2 + retransmit-interval 2 + demand-circuit enable + hello-interval 1 + transmit-delay 2 + default-metric 10 + area 11 + default-cost 5 + ! + area 22 + default-cost 6 + ! +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_ospfv2/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..c7821e00 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/_populate_config.yaml @@ -0,0 +1,47 @@ +--- +- name: Setup (Populate OSPFv2 routes) + cisco.iosxr.iosxr_ospfv2: + config: + + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - process_id: 26 + adjacency_stagger: + min_adjacency: 10 + max_adjacency: 20 + authentication: + message_digest: + keychain: 'ansible1101pass' + - process_id: 10 + areas: + - area_id: 11 + default_cost: 5 + cost: 11 + - area_id: 22 + default_cost: 6 + - process_id: 30 + areas: + - area_id: 11 + default_cost: 5 + - area_id: 22 + default_cost: 6 + + cost: 2 + default_metric: 10 + transmit_delay: 2 + hello_interval: 1 + dead_interval: 2 + retransmit_interval: 2 + packet_size: 577 + priority: 1 + router_id: '2.2.2.2' + demand_circuit: enable + passive: disable + summary_in: enable + flood_reduction: disable + mtu_ignore: enable + external_out: disable + state: merged diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..80a2048c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/_remove_config.yaml @@ -0,0 +1,11 @@ +--- +- name: Remove OSPFv2 Routes + vars: + lines: "no router ospf 26\n + no router ospf 27\n + no router ospf 30\n + no router ospf 10\n + " + ignore_errors: true + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/deleted.yaml new file mode 100644 index 00000000..6f69ec1d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/deleted.yaml @@ -0,0 +1,84 @@ +--- +- debug: + msg: Start iosxr_ospfv2 deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete single ospf process network + register: result + cisco.iosxr.iosxr_ospfv2: &id001 + config: + processes: + - process_id: 10 + - process_id: 26 + - process_id: 27 + - process_id: 30 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ replaced['before'] == result['before'] }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['after'] }}" + + - name: Delete a single ospf process (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv2: *id001 + + - assert: &id003 + that: + - result.changed == false + - result.commands|length == 0 + + - include_tasks: _populate_config.yaml + + - name: Delete all ospf processes + register: result + cisco.iosxr.iosxr_ospfv2: &id005 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ replaced['before'] == result['before'] }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['after'] }}" + + - name: Delete all ospf processes (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv2: *id005 + + - name: Assert that the previous task was idempotent + assert: *id003 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/empty_config.yaml new file mode 100644 index 00000000..10b22621 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_ospfv2 empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_ospfv2: + config: + state: replaced + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Parsed with empty running_config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_ospfv2: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Overridden with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_ospfv2: + config: + state: rendered + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/gathered.yaml new file mode 100644 index 00000000..b09e2e3a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/gathered.yaml @@ -0,0 +1,22 @@ +--- +- debug: + msg: START iosxr_ospfv2 gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather static routes facts from the device using iosxr_ospfv2 + module + register: result + cisco.iosxr.iosxr_ospfv2: + state: gathered + + - assert: + that: "{{ replaced['before'] == result['gathered'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/merged.yaml new file mode 100644 index 00000000..3d5fdfda --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/merged.yaml @@ -0,0 +1,132 @@ +--- +- debug: + msg: START iosxr_ospfv2 merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_ospfv2: &id001 + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - process_id: 26 + adjacency_stagger: + min_adjacency: 10 + max_adjacency: 20 + authentication: + message_digest: + keychain: 'ansible1101pass' + - process_id: 10 + areas: + - area_id: 11 + default_cost: 5 + cost: 11 + - area_id: 22 + default_cost: 6 + - process_id: 30 + areas: + - area_id: 11 + default_cost: 5 + - area_id: 22 + default_cost: 6 + + cost: 2 + default_metric: 10 + transmit_delay: 2 + hello_interval: 1 + dead_interval: 2 + retransmit_interval: 2 + packet_size: 577 + priority: 1 + router_id: '2.2.2.2' + demand_circuit: enable + passive: disable + summary_in: enable + flood_reduction: disable + mtu_ignore: enable + external_out: disable + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv2: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] == result['before'] }}" + + - name: Update existing configuration using merged + register: result + cisco.iosxr.iosxr_ospfv2: &id002 + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - area_id: 30 + dead_interval: 4 + - process_id: 26 + adjacency_stagger: + min_adjacency: 11 + max_adjacency: 21 + authentication: + message_digest: + keychain: 'ansible1101pass' + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['update_commands'] | symmetric_difference(result['commands'])\ + \ |length == 0 }}" + + - name: Assert that after dicts were correctly generated + assert: + that: "{{ merged['update_after'] == result['after'] }}" + + - name: Update existing ospfv2 configuration using merged (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv2: *id002 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/overridden.yaml new file mode 100644 index 00000000..dcff31e8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/overridden.yaml @@ -0,0 +1,65 @@ +--- +- debug: + msg: START iosxr_ospfv2 overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Overridde all ospfv2 configuration with provided configuration + register: result + cisco.iosxr.iosxr_ospfv2: &id001 + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - area_id: 20 + cost: 2 + default_cost: 2 + - process_id: 26 + adjacency_stagger: + min_adjacency: 10 + max_adjacency: 20 + authentication: + message_digest: + keychain: 'ansible1101pass' + 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: + - "{{ replaced['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] == result['after'] }}" + + - name: Overridde all ospfv2 configuration with given configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv2: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ overridden['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/parsed.yaml new file mode 100644 index 00000000..19efa25f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START iosxr_ospfv2 parsed integration tests on connection={{ ansible_connection + }} + +- block: + + - name: Use parsed state to convert externally supplied device specific ospfv2 + routes commands to structured format + register: result + cisco.iosxr.iosxr_ospfv2: + running_config: "{{ lookup('file', '../../fixtures/parsed.cfg') }}" + state: parsed + + - assert: + that: "{{ merged['after'] == result['parsed'] }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/rendered.yaml new file mode 100644 index 00000000..96ee3c24 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/rendered.yaml @@ -0,0 +1,72 @@ +--- +- debug: + msg: START iosxr_ospfv2 rendered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Use rendered state to convert task input to device specific commands + register: result + cisco.iosxr.iosxr_ospfv2: + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - process_id: 26 + adjacency_stagger: + min_adjacency: 10 + max_adjacency: 20 + authentication: + message_digest: + keychain: 'ansible1101pass' + - process_id: 10 + areas: + - area_id: 11 + default_cost: 5 + cost: 11 + - area_id: 22 + default_cost: 6 + - process_id: 30 + areas: + - area_id: 11 + default_cost: 5 + - area_id: 22 + default_cost: 6 + + cost: 2 + default_metric: 10 + transmit_delay: 2 + hello_interval: 1 + dead_interval: 2 + retransmit_interval: 2 + packet_size: 577 + priority: 1 + router_id: '2.2.2.2' + demand_circuit: enable + passive: disable + summary_in: enable + flood_reduction: disable + mtu_ignore: enable + external_out: disable + state: rendered + + - assert: + that: "{{ merged['commands'] | symmetric_difference(result['rendered'])\ + \ |length==0 }}" + + - name: Gather static routes facts from the device and assert that its empty + register: result + cisco.iosxr.iosxr_ospfv2: + state: gathered + + - name: Make sure that rendered task actually did not make any changes to the + device + assert: + that: "{{ result['gathered'] == {} }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/replaced.yaml new file mode 100644 index 00000000..d62e34c8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/replaced.yaml @@ -0,0 +1,66 @@ +--- +- debug: + msg: START iosxr_ospfv2 replaced integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replace device configurations of ospfv2 routes with provided configurations + register: result + cisco.iosxr.iosxr_ospfv2: &id001 + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - area_id: 20 + cost: 2 + default_cost: 2 + - process_id: 26 + adjacency_stagger: + min_adjacency: 10 + max_adjacency: 20 + authentication: + message_digest: + keychain: 'ansible1101pass' + 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['after'] == result['after'] }}" + + - name: Replace device configurations of listed vrfs/global entry with provided + configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv2: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/rtt.yaml new file mode 100644 index 00000000..a5828181 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/tests/cli/rtt.yaml @@ -0,0 +1,101 @@ +--- +- debug: + msg: START iosxr_ospfv2 round trip integration tests on connection={{ + ansible_connection }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_ospfv2: + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - process_id: 26 + adjacency_stagger: + min_adjacency: 10 + max_adjacency: 20 + authentication: + message_digest: + keychain: 'ansible1101pass' + - process_id: 10 + areas: + - area_id: 11 + default_cost: 5 + cost: 11 + - area_id: 22 + default_cost: 6 + - process_id: 30 + areas: + - area_id: 11 + default_cost: 5 + - area_id: 22 + default_cost: 6 + + cost: 2 + default_metric: 10 + transmit_delay: 2 + hello_interval: 1 + dead_interval: 2 + retransmit_interval: 2 + packet_size: 577 + priority: 1 + router_id: '2.2.2.2' + demand_circuit: enable + passive: disable + summary_in: enable + flood_reduction: disable + mtu_ignore: enable + external_out: disable + state: merged + + - name: Gather ospfv2 facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - ospfv2 + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_ospfv2: + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - area_id: 20 + cost: 2 + default_cost: 2 + - process_id: 26 + adjacency_stagger: + min_adjacency: 10 + max_adjacency: 20 + authentication: + message_digest: + keychain: 'ansible1101pass' + state: overridden + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] == result['after'] }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_ospfv2: + config: "{{ ansible_facts['network_resources']['ospfv2'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] == revert['after'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/vars/main.yaml new file mode 100644 index 00000000..497a8c99 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv2/vars/main.yaml @@ -0,0 +1,316 @@ +--- +merged: + before: {} + commands: + - router ospf 10 + - area 11 default-cost 5 + - area 11 cost 11 + - area 22 default-cost 6 + - router ospf 27 + - area 10 hello-interval 2 + - router ospf 26 + - adjacency stagger 10 20 + - authentication message-digest keychain ansible1101pass + - router ospf 30 + - cost 2 + - passive disable + - priority 1 + - flood-reduction disable + - default-metric 10 + - router-id 2.2.2.2 + - demand-circuit enable + - packet-size 577 + - transmit-delay 2 + - summary-in enable + - external-out disable + - dead-interval 2 + - hello-interval 1 + - retransmit-interval 2 + - mtu-ignore enable + - area 11 default-cost 5 + - area 22 default-cost 6 + update_commands: + - router ospf 26 + - adjacency stagger 11 21 + - router ospf 27 + - area 30 dead-interval 4 + after: + processes: + - areas: + - area_id: "11" + cost: 11 + default_cost: 5 + - area_id: "22" + default_cost: 6 + process_id: "10" + + - adjacency_stagger: + max_adjacency: 20 + min_adjacency: 10 + authentication: + message_digest: + keychain: 'ansible1101pass' + process_id: "26" + - areas: + - area_id: "10" + hello_interval: 2 + process_id: "27" + - areas: + - area_id: "11" + default_cost: 5 + - area_id: "22" + default_cost: 6 + cost: 2 + dead_interval: 2 + default_metric: 10 + demand_circuit: "enable" + external_out: "disable" + flood_reduction: "disable" + hello_interval: 1 + mtu_ignore: "enable" + packet_size: 577 + passive: "disable" + priority: 1 + process_id: "30" + retransmit_interval: 2 + router_id: "2.2.2.2" + summary_in: "enable" + transmit_delay: 2 + + update_after: + processes: + - areas: + - area_id: "11" + cost: 11 + default_cost: 5 + - area_id: "22" + default_cost: 6 + process_id: '10' + - adjacency_stagger: + max_adjacency: 21 + min_adjacency: 11 + authentication: + message_digest: + keychain: 'ansible1101pass' + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + - area_id: '30' + dead_interval: 4 + process_id: '27' + - areas: + - area_id: '11' + default_cost: 5 + - area_id: '22' + default_cost: 6 + + cost: 2 + dead_interval: 2 + default_metric: 10 + demand_circuit: 'enable' + external_out: 'disable' + flood_reduction: 'disable' + hello_interval: 1 + mtu_ignore: 'enable' + packet_size: 577 + passive: 'disable' + priority: 1 + process_id: '30' + retransmit_interval: 2 + router_id: '2.2.2.2' + summary_in: 'enable' + transmit_delay: 2 +replaced: + before: + processes: + - areas: + - area_id: '11' + cost: 11 + default_cost: 5 + - area_id: '22' + default_cost: 6 + process_id: '10' + - adjacency_stagger: + max_adjacency: 20 + min_adjacency: 10 + authentication: + message_digest: + keychain: 'ansible1101pass' + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + process_id: '27' + - areas: + - area_id: '11' + default_cost: 5 + - area_id: '22' + default_cost: 6 + cost: 2 + dead_interval: 2 + default_metric: 10 + demand_circuit: 'enable' + external_out: 'disable' + flood_reduction: 'disable' + hello_interval: 1 + mtu_ignore: 'enable' + packet_size: 577 + passive: 'disable' + priority: 1 + process_id: '30' + retransmit_interval: 2 + router_id: '2.2.2.2' + summary_in: 'enable' + transmit_delay: 2 + + commands: + - router ospf 27 + - area 20 default-cost 2 + - area 20 cost 2 + + after: + processes: + - areas: + - area_id: '11' + cost: 11 + default_cost: 5 + - area_id: '22' + default_cost: 6 + process_id: '10' + - adjacency_stagger: + max_adjacency: 20 + min_adjacency: 10 + authentication: + message_digest: + keychain: 'ansible1101pass' + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + - area_id: '20' + cost: 2 + default_cost: 2 + process_id: '27' + - areas: + - area_id: '11' + default_cost: 5 + - area_id: '22' + default_cost: 6 + cost: 2 + dead_interval: 2 + default_metric: 10 + demand_circuit: 'enable' + external_out: 'disable' + flood_reduction: 'disable' + hello_interval: 1 + mtu_ignore: 'enable' + packet_size: 577 + passive: 'disable' + priority: 1 + process_id: '30' + retransmit_interval: 2 + router_id: '2.2.2.2' + summary_in: 'enable' + transmit_delay: 2 + +overridden: + commands: + - router ospf 10 + - no area 11 default-cost 5 + - no area 11 cost 11 + - no area 22 default-cost 6 + - router ospf 30 + - no cost 2 + - no passive disable + - no priority 1 + - no flood-reduction disable + - no default-metric 10 + - no router-id 2.2.2.2 + - no demand-circuit enable + - no packet-size 577 + - no transmit-delay 2 + - no summary-in enable + - no external-out disable + - no dead-interval 2 + - no hello-interval 1 + - no retransmit-interval 2 + - no mtu-ignore enable + - no area 11 default-cost 5 + - no area 22 default-cost 6 + - router ospf 27 + - area 20 default-cost 2 + - area 20 cost 2 + after: + processes: + - process_id: '10' + - adjacency_stagger: + max_adjacency: 20 + min_adjacency: 10 + authentication: + message_digest: + keychain: 'ansible1101pass' + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + - area_id: '20' + cost: 2 + default_cost: 2 + process_id: '27' + - process_id: '30' +deleted: + commands: + - router ospf 10 + - no area 11 default-cost 5 + - no area 11 cost 11 + - no area 22 default-cost 6 + - router ospf 26 + - no adjacency stagger 10 20 + - no authentication message-digest keychain ansible1101pass + - router ospf 27 + - no area 10 hello-interval 2 + - router ospf 30 + - no cost 2 + - no passive disable + - no priority 1 + - no flood-reduction disable + - no default-metric 10 + - no router-id 2.2.2.2 + - no demand-circuit enable + - no packet-size 577 + - no transmit-delay 2 + - no summary-in enable + - no external-out disable + - no dead-interval 2 + - no hello-interval 1 + - no retransmit-interval 2 + - no mtu-ignore enable + - no area 11 default-cost 5 + - no area 22 default-cost 6 + + after: + processes: + - process_id: '10' + - process_id: '26' + - process_id: '27' + - process_id: '30' +round_trip: + after: + processes: + - process_id: '10' + - adjacency_stagger: + max_adjacency: 20 + min_adjacency: 10 + authentication: + message_digest: + keychain: 'ansible1101pass' + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + - area_id: '20' + cost: 2 + default_cost: 2 + process_id: '27' + - process_id: '30' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/fixtures/parsed.cfg new file mode 100644 index 00000000..f0e69c9e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/fixtures/parsed.cfg @@ -0,0 +1,36 @@ +router ospfv3 10 + area 11 + cost 11 + default-cost 5 + ! + area 22 + default-cost 6 + ! +! +router ospfv3 26 + authentication disable +! +router ospfv3 27 + area 10 + hello-interval 2 + ! +! +router ospfv3 30 + router-id 2.2.2.2 + cost 2 + packet-size 577 + priority 1 + mtu-ignore + dead-interval 2 + retransmit-interval 2 + demand-circuit + hello-interval 1 + transmit-delay 2 + default-metric 10 + area 11 + default-cost 5 + ! + area 22 + default-cost 6 + ! +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_ospfv3/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..a795e39b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/_populate_config.yaml @@ -0,0 +1,39 @@ +--- +- name: Setup (Populate OSPFv3 routes) + cisco.iosxr.iosxr_ospfv3: + config: + + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - process_id: 26 + authentication: + disable: true + - process_id: 10 + areas: + - area_id: 11 + default_cost: 5 + cost: 11 + - area_id: 22 + default_cost: 6 + - process_id: 30 + areas: + - area_id: 11 + default_cost: 5 + - area_id: 22 + default_cost: 6 + + cost: 2 + default_metric: 10 + transmit_delay: 2 + hello_interval: 1 + dead_interval: 2 + retransmit_interval: 2 + packet_size: 577 + priority: 1 + router_id: '2.2.2.2' + demand_circuit: true + mtu_ignore: true + state: merged diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..d0632854 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/_remove_config.yaml @@ -0,0 +1,11 @@ +--- +- name: Remove OSPFv3 Routes + vars: + lines: "no router ospfv3 26\n + no router ospfv3 27\n + no router ospfv3 30\n + no router ospfv3 10\n + " + ignore_errors: true + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/deleted.yaml new file mode 100644 index 00000000..903fe46e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/deleted.yaml @@ -0,0 +1,84 @@ +--- +- debug: + msg: Start iosxr_ospfv3 deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Delete single ospf process network + register: result + cisco.iosxr.iosxr_ospfv3: &id001 + config: + processes: + - process_id: 10 + - process_id: 26 + - process_id: 27 + - process_id: 30 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ replaced['before'] == result['before'] }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['after'] }}" + + - name: Delete a single ospf process (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv3: *id001 + + - assert: &id003 + that: + - result.changed == false + - result.commands|length == 0 + + - include_tasks: _populate_config.yaml + + - name: Delete all ospf processes + register: result + cisco.iosxr.iosxr_ospfv3: &id005 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ replaced['before'] == result['before'] }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['after'] }}" + + - name: Delete all ospf processes (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv3: *id005 + + - name: Assert that the previous task was idempotent + assert: *id003 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/empty_config.yaml new file mode 100644 index 00000000..6c70f61f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START iosxr_ospfv3 empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_ospfv3: + config: + state: replaced + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Parsed with empty running_config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_ospfv3: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Overridden with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_ospfv3: + config: + state: rendered + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/gathered.yaml new file mode 100644 index 00000000..c9f82171 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START iosxr_ospfv3 gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather Ospfv3 facts from the device using iosxr_ospfv3 + module + register: result + cisco.iosxr.iosxr_ospfv3: + state: gathered + + - assert: + that: + - "{{ replaced['before'] == result['gathered'] }}" + - "result.changed == false" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/merged.yaml new file mode 100644 index 00000000..a9e3667f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/merged.yaml @@ -0,0 +1,120 @@ +--- +- debug: + msg: START iosxr_ospfv3 merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_ospfv3: &id001 + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - process_id: 26 + authentication: + disable: true + - process_id: 10 + areas: + - area_id: 11 + default_cost: 5 + cost: 11 + - area_id: 22 + default_cost: 6 + - process_id: 30 + areas: + - area_id: 11 + default_cost: 5 + - area_id: 22 + default_cost: 6 + + cost: 2 + default_metric: 10 + transmit_delay: 2 + hello_interval: 1 + dead_interval: 2 + retransmit_interval: 2 + packet_size: 577 + priority: 1 + router_id: '2.2.2.2' + demand_circuit: true + mtu_ignore: true + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv3: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] == result['before'] }}" + + - name: Update existing configuration using merged + register: result + cisco.iosxr.iosxr_ospfv3: &id002 + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - area_id: 30 + dead_interval: 4 + - process_id: 26 + authentication: + disable: true + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['update_commands'] | symmetric_difference(result['commands'])\ + \ |length == 0 }}" + + - name: Assert that after dicts were correctly generated + assert: + that: "{{ merged['update_after'] == result['after'] }}" + + - name: Update existing ospfv3 configuration using merged (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv3: *id002 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/overridden.yaml new file mode 100644 index 00000000..29b01e0f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/overridden.yaml @@ -0,0 +1,61 @@ +--- +- debug: + msg: START iosxr_ospfv3 overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Overridde all ospfv3 configuration with provided configuration + register: result + cisco.iosxr.iosxr_ospfv3: &id001 + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - area_id: 20 + cost: 2 + default_cost: 2 + - process_id: 26 + authentication: + disable: 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: + - "{{ replaced['before'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ overridden['after'] == result['after'] }}" + + - name: Overridde all ospfv3 configuration with given configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv3: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ overridden['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/parsed.yaml new file mode 100644 index 00000000..b1b17304 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/parsed.yaml @@ -0,0 +1,18 @@ +--- +- debug: + msg: START iosxr_ospfv3 parsed integration tests on connection={{ ansible_connection + }} + +- block: + + - name: Use parsed state to convert externally supplied device specific ospfv3 + routes commands to structured format + register: result + cisco.iosxr.iosxr_ospfv3: + running_config: "{{ lookup('file', '../../fixtures/parsed.cfg') }}" + state: parsed + + - assert: + that: + - "{{ merged['after'] == result['parsed'] }}" + - "result.changed == false" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/rendered.yaml new file mode 100644 index 00000000..369ff70b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/rendered.yaml @@ -0,0 +1,68 @@ +--- +- debug: + msg: START iosxr_ospfv3 rendered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Use rendered state to convert task input to device specific commands + register: result + cisco.iosxr.iosxr_ospfv3: + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - process_id: 26 + authentication: + disable: true + - process_id: 10 + areas: + - area_id: 11 + default_cost: 5 + cost: 11 + - area_id: 22 + default_cost: 6 + - process_id: 30 + areas: + - area_id: 11 + default_cost: 5 + - area_id: 22 + default_cost: 6 + + cost: 2 + default_metric: 10 + transmit_delay: 2 + hello_interval: 1 + dead_interval: 2 + retransmit_interval: 2 + packet_size: 577 + priority: 1 + router_id: '2.2.2.2' + demand_circuit: true + passive: false + flood_reduction: false + mtu_ignore: true + state: rendered + + - assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['rendered'])\ + \ |length==0 }}" + - "result.changed == false" + + - name: Gather Ospfv3 facts from the device and assert that its empty + register: result + cisco.iosxr.iosxr_ospfv3: + state: gathered + + - name: Make sure that rendered task actually did not make any changes to the + device + assert: + that: "{{ result['gathered'] == {} }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/replaced.yaml new file mode 100644 index 00000000..efc8a099 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/replaced.yaml @@ -0,0 +1,62 @@ +--- +- debug: + msg: START iosxr_ospfv3 replaced integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replace device configurations of ospfv3 routes with provided configurations + register: result + cisco.iosxr.iosxr_ospfv3: &id001 + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - area_id: 20 + cost: 2 + default_cost: 2 + - process_id: 26 + authentication: + disable: 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'] == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] == result['after'] }}" + + - name: Replace device configurations of listed vrfs/global entry with provided + configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_ospfv3: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/rtt.yaml new file mode 100644 index 00000000..a507d61a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/tests/cli/rtt.yaml @@ -0,0 +1,91 @@ +--- +- debug: + msg: START iosxr_ospfv3 round trip integration tests on connection={{ + ansible_connection }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_ospfv3: + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - process_id: 26 + authentication: + disable: true + - process_id: 10 + areas: + - area_id: 11 + default_cost: 5 + cost: 11 + - area_id: 22 + default_cost: 6 + - process_id: 30 + areas: + - area_id: 11 + default_cost: 5 + - area_id: 22 + default_cost: 6 + + cost: 2 + default_metric: 10 + transmit_delay: 2 + hello_interval: 1 + dead_interval: 2 + retransmit_interval: 2 + packet_size: 577 + priority: 1 + router_id: '2.2.2.2' + demand_circuit: true + passive: false + flood_reduction: false + mtu_ignore: true + state: merged + + - name: Gather ospfv3 facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - ospfv3 + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_ospfv3: + config: + processes: + - process_id: 27 + areas: + - area_id: 10 + hello_interval: 2 + - area_id: 20 + cost: 2 + default_cost: 2 + - process_id: 26 + authentication: + disable: true + state: overridden + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] == result['after'] }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_ospfv3: + config: "{{ ansible_facts['network_resources']['ospfv3'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] == revert['after'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/vars/main.yaml new file mode 100644 index 00000000..06aa7812 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_ospfv3/vars/main.yaml @@ -0,0 +1,260 @@ +--- +merged: + before: {} + commands: + - router ospfv3 10 + - area 11 default-cost 5 + - area 11 cost 11 + - area 22 default-cost 6 + - router ospfv3 27 + - area 10 hello-interval 2 + - router ospfv3 26 + - authentication disable + - router ospfv3 30 + - cost 2 + - priority 1 + - default-metric 10 + - router-id 2.2.2.2 + - demand-circuit + - packet-size 577 + - transmit-delay 2 + - dead-interval 2 + - hello-interval 1 + - retransmit-interval 2 + - mtu-ignore + - area 11 default-cost 5 + - area 22 default-cost 6 + update_commands: + - router ospfv3 27 + - area 30 dead-interval 4 + after: + processes: + - areas: + - area_id: "11" + cost: 11 + default_cost: 5 + - area_id: "22" + default_cost: 6 + process_id: "10" + + - authentication: + disable: true + process_id: "26" + - areas: + - area_id: "10" + hello_interval: 2 + process_id: "27" + - areas: + - area_id: "11" + default_cost: 5 + - area_id: "22" + default_cost: 6 + cost: 2 + dead_interval: 2 + default_metric: 10 + demand_circuit: true + hello_interval: 1 + mtu_ignore: true + packet_size: 577 + priority: 1 + process_id: "30" + retransmit_interval: 2 + router_id: "2.2.2.2" + transmit_delay: 2 + + update_after: + processes: + - areas: + - area_id: "11" + cost: 11 + default_cost: 5 + - area_id: "22" + default_cost: 6 + process_id: '10' + - authentication: + disable: true + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + - area_id: '30' + dead_interval: 4 + process_id: '27' + - areas: + - area_id: '11' + default_cost: 5 + - area_id: '22' + default_cost: 6 + + cost: 2 + dead_interval: 2 + default_metric: 10 + demand_circuit: true + hello_interval: 1 + mtu_ignore: true + packet_size: 577 + priority: 1 + process_id: '30' + retransmit_interval: 2 + router_id: '2.2.2.2' + transmit_delay: 2 +replaced: + before: + processes: + - areas: + - area_id: '11' + cost: 11 + default_cost: 5 + - area_id: '22' + default_cost: 6 + process_id: '10' + - authentication: + disable: true + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + process_id: '27' + - areas: + - area_id: '11' + default_cost: 5 + - area_id: '22' + default_cost: 6 + cost: 2 + dead_interval: 2 + default_metric: 10 + demand_circuit: true + hello_interval: 1 + mtu_ignore: true + packet_size: 577 + priority: 1 + process_id: '30' + retransmit_interval: 2 + router_id: '2.2.2.2' + transmit_delay: 2 + + commands: + - router ospfv3 27 + - area 20 default-cost 2 + - area 20 cost 2 + + after: + processes: + - areas: + - area_id: '11' + cost: 11 + default_cost: 5 + - area_id: '22' + default_cost: 6 + process_id: '10' + - authentication: + disable: true + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + - area_id: '20' + cost: 2 + default_cost: 2 + process_id: '27' + - areas: + - area_id: '11' + default_cost: 5 + - area_id: '22' + default_cost: 6 + cost: 2 + dead_interval: 2 + default_metric: 10 + demand_circuit: true + hello_interval: 1 + mtu_ignore: true + packet_size: 577 + priority: 1 + process_id: '30' + retransmit_interval: 2 + router_id: '2.2.2.2' + transmit_delay: 2 + +overridden: + commands: + - router ospfv3 10 + - no area 11 default-cost 5 + - no area 11 cost 11 + - no area 22 default-cost 6 + - router ospfv3 30 + - no cost 2 + - no priority 1 + - no default-metric 10 + - no router-id 2.2.2.2 + - no demand-circuit + - no packet-size 577 + - no transmit-delay 2 + - no dead-interval 2 + - no hello-interval 1 + - no retransmit-interval 2 + - no mtu-ignore + - no area 11 default-cost 5 + - no area 22 default-cost 6 + - router ospfv3 27 + - area 20 default-cost 2 + - area 20 cost 2 + after: + processes: + - process_id: '10' + - authentication: + disable: true + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + - area_id: '20' + cost: 2 + default_cost: 2 + process_id: '27' + - process_id: '30' +deleted: + commands: + - router ospfv3 10 + - no area 11 default-cost 5 + - no area 11 cost 11 + - no area 22 default-cost 6 + - router ospfv3 26 + - no authentication disable + - router ospfv3 27 + - no area 10 hello-interval 2 + - router ospfv3 30 + - no cost 2 + - no priority 1 + - no default-metric 10 + - no router-id 2.2.2.2 + - no demand-circuit + - no packet-size 577 + - no transmit-delay 2 + - no dead-interval 2 + - no hello-interval 1 + - no retransmit-interval 2 + - no mtu-ignore + - no area 11 default-cost 5 + - no area 22 default-cost 6 + + after: + processes: + - process_id: '10' + - process_id: '26' + - process_id: '27' + - process_id: '30' +round_trip: + after: + processes: + - process_id: '10' + - authentication: + disable: true + process_id: '26' + - areas: + - area_id: '10' + hello_interval: 2 + - area_id: '20' + cost: 2 + default_cost: 2 + process_id: '27' + - process_id: '30' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/meta/main.yaml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/cli.yaml new file mode 100644 index 00000000..e9103656 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/cli.yaml @@ -0,0 +1,26 @@ +--- +- 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 case (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" + 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_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + tags: + - local diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/main.yaml new file mode 100644 index 00000000..5d082a6f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- include: cli.yaml +- include: netconf.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/netconf.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/netconf.yaml new file mode 100644 index 00000000..18b257a0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tasks/netconf.yaml @@ -0,0 +1,26 @@ +--- +- name: collect all netconf test cases + find: + paths: "{{ role_path }}/tests/netconf" + 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=netconf) + include: "{{ test_case_to_run }} ansible_connection=netconf" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + tags: + - netconf + +- 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 + tags: + - local diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/cli/common_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/cli/common_config.yaml new file mode 100644 index 00000000..9eb7f703 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/cli/common_config.yaml @@ -0,0 +1,100 @@ +--- +- debug: msg="START cli/common_config.yaml on connection={{ ansible_connection }}" + +# Sublevel / Block +- name: setup + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + parents: ['ipv4 access-list test'] + before: ['no ipv4 access-list test'] + match: none + +- name: configure sub level command using block resplace + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + - 40 permit ipv4 host 192.0.2.4 any log + parents: ['ipv4 access-list test'] + replace: block + register: result + +- assert: + that: + - "result.changed == true" + - "'ipv4 access-list test' in result.commands" + - "'10 permit ipv4 host 192.0.2.1 any log' in result.commands" + - "'20 permit ipv4 host 192.0.2.2 any log' in result.commands" + - "'30 permit ipv4 host 192.0.2.3 any log' in result.commands" + - "'40 permit ipv4 host 192.0.2.4 any log' in result.commands" + +- name: check sub level command using block replace + cisco.iosxr.iosxr_config: + commands: + - 10 permit ipv4 host 192.0.2.1 any log + - 20 permit ipv4 host 192.0.2.2 any log + - 30 permit ipv4 host 192.0.2.3 any log + - 40 permit ipv4 host 192.0.2.4 any log + parents: ['ipv4 access-list test'] + replace: block + register: result + +- assert: + that: + - "result.changed == false" + +- name: teardown + cisco.iosxr.iosxr_config: + commands: ['no ipv4 access-list test'] + match: none + +# diff exact, strict, line +- name: setup + cisco.iosxr.iosxr_config: + commands: + - 'hostname {{ inventory_hostname_short }}' + register: result + +- name: set hostname + cisco.iosxr.iosxr_config: + commands: + - hostname testhost + match: strict + register: result + +- cisco.iosxr.iosxr_command: + commands: + - show configuration running-config hostname + register: configured_hostname + +- assert: + that: + - "'testhost' in configured_hostname.stdout[0]" + +- name: set hostname + cisco.iosxr.iosxr_config: + commands: + - hostname testhost2 + match: exact + register: result + +- cisco.iosxr.iosxr_command: + commands: + - show configuration running-config hostname + register: configured_hostname + +- assert: + that: + - "'testhost2' in configured_hostname.stdout[0]" + +- name: teardown + cisco.iosxr.iosxr_config: + commands: + - 'hostname {{ inventory_hostname_short }}' + register: result + +- debug: msg="END cli/common_config.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/cli/common_utils.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/cli/common_utils.yaml new file mode 100644 index 00000000..e04d1a75 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/cli/common_utils.yaml @@ -0,0 +1,37 @@ +--- +- debug: msg="START iosxr cli/common_utils.yaml on connection={{ ansible_connection }}" + +# Functions used by iosxr: conditional, remove_default_spec + +# hit conditional() and remove_default_spec() +- name: Check intent arguments + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: up + tx_rate: ge(0) + rx_rate: ge(0) + provider: "{{ cli }}" + register: result + +- assert: + that: + - "result.failed == false" + +- name: Check intent arguments (failed condition) + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: down + tx_rate: gt(0) + rx_rate: lt(0) + provider: "{{ cli }}" + ignore_errors: true + register: result + +- assert: + that: + - "result.failed == true" + - "'state eq(down)' in result.failed_conditions" + - "'tx_rate gt(0)' in result.failed_conditions" + - "'rx_rate lt(0)' in result.failed_conditions" + +- debug: msg="END iosxr cli/common_utils.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml new file mode 100644 index 00000000..79eaeea1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/netconf/common_netconf.yaml @@ -0,0 +1,53 @@ +--- +- debug: msg="START iosxr netconf/common_netconf.yaml on connection={{ ansible_connection }}" + +# hit general code +- name: setup - remove login + cisco.iosxr.iosxr_banner: + banner: login + provider: "{{ netconf }}" + state: absent + +- name: Set login + cisco.iosxr.iosxr_banner: + banner: login + text: | + this is my login banner + that has a multiline + string + provider: "{{ netconf }}" + state: present + register: result + +- debug: + msg: "{{ result }}" + +- assert: + that: + - "result.changed == true" + - "'this is my login banner' in result.xml" + - "'that has a multiline' in result.xml" + +# hit etree_findall() +- name: remove host logging + cisco.iosxr.iosxr_logging: + dest: host + name: 172.16.0.1 + state: absent + provider: "{{ netconf }}" + +- name: set up syslog host logging + cisco.iosxr.iosxr_logging: &addhostlog + dest: host + name: 172.16.0.1 + level: errors + state: present + provider: "{{ netconf }}" + register: result + +- assert: + that: + - 'result.changed == true' + - '"172.16.0.1" in result.xml[0]' + +- debug: msg="END iosxr netconf/common_netconf.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/netconf/misc_tests.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/netconf/misc_tests.yaml new file mode 100644 index 00000000..5a21fa0a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_smoke/tests/netconf/misc_tests.yaml @@ -0,0 +1,40 @@ +--- +- debug: msg="START iosxr netconf/misc_tests.yaml on connection={{ ansible_connection }}" + + +# hit module_utils.network.iosxr -> get_oper() +- name: Setup (interface is up) + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + description: test_interface_1 + enabled: true + state: present + provider: "{{ netconf }}" + register: result + +- name: Check intent arguments + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: up + delay: 10 + provider: "{{ netconf }}" + register: result + +- assert: + that: + - "result.failed == false" + +- name: Check intent arguments (failed condition) + cisco.iosxr.iosxr_interface: + name: GigabitEthernet0/0/0/1 + state: down + provider: "{{ netconf }}" + ignore_errors: true + register: result + +- assert: + that: + - "result.failed == true" + - "'state eq(down)' in result.failed_conditions" + +- debug: msg="END iosxr netconf/misc_tests.yaml on connection={{ ansible_connection }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/defaults/main.yaml new file mode 100644 index 00000000..852a6bee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/fixtures/parsed.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/fixtures/parsed.cfg new file mode 100644 index 00000000..35948336 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/fixtures/parsed.cfg @@ -0,0 +1,18 @@ +Fri Nov 29 21:10:41.896 UTC +router static + address-family ipv4 unicast + 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120 + 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1 + 192.0.2.32/28 192.0.2.11 100 + ! + address-family ipv6 unicast + 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC + 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1 + ! + vrf DEV_SITE + address-family ipv4 unicast + 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV + 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2 + ! + ! +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/cli.yaml new file mode 100644 index 00000000..f622cf94 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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/iosxr/tests/integration/targets/iosxr_static_routes/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/main.yaml new file mode 100644 index 00000000..b957d2f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/_populate_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/_populate_config.yaml new file mode 100644 index 00000000..1ca3ca3e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/_populate_config.yaml @@ -0,0 +1,69 @@ +--- +- name: Setup + cisco.iosxr.iosxr_static_routes: + config: + + - address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.16/28 + next_hops: + + - forward_router_address: 192.0.2.10 + interface: FastEthernet0/0/0/1 + description: LAB + metric: 120 + tag: 10 + + - interface: FastEthernet0/0/0/5 + track: ip_sla_1 + + - dest: 192.0.2.32/28 + next_hops: + + - forward_router_address: 192.0.2.11 + admin_distance: 100 + + - afi: ipv6 + safi: unicast + routes: + + - dest: 2001:db8:1000::/36 + next_hops: + + - interface: FastEthernet0/0/0/7 + description: DC + + - interface: FastEthernet0/0/0/8 + forward_router_address: 2001:db8:2000:2::1 + + - vrf: DEV_SITE + address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.48/28 + next_hops: + + - forward_router_address: 192.0.2.12 + description: DEV + dest_vrf: test_1 + + - forward_router_address: 192.0.3.24 + interface: GigabitEthernet0/0/0/1 + vrflabel: 2302 + + - dest: 192.0.2.80/28 + next_hops: + + - interface: FastEthernet0/0/0/2 + forward_router_address: 192.0.2.14 + dest_vrf: test_1 + track: ip_sla_2 + vrflabel: 124 + state: merged diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/_remove_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..f4e62ebe --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/_remove_config.yaml @@ -0,0 +1,7 @@ +--- +- name: Remove Static Routes + vars: + lines: "no router static\n" + ignore_errors: true + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/deleted.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/deleted.yaml new file mode 100644 index 00000000..803906c9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/deleted.yaml @@ -0,0 +1,79 @@ +--- +- debug: + msg: Start iosxr_static_routes deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + - name: Delete all destination network entries under a single AFI + register: result + cisco.iosxr.iosxr_static_routes: &id004 + config: + + - vrf: DEV_SITE + address_families: + + - afi: ipv4 + safi: unicast + state: deleted + + - assert: + that: + - '"router static" in result.commands' + - '"vrf DEV_SITE" in result.commands' + - '"no address-family ipv4 unicast" in result.commands' + - result.commands|length == 3 + + - name: Delete all destination network entries under a single AFI (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_static_routes: *id004 + + - name: Assert that the previous task was idempotent + assert: &id003 + that: + - result['changed'] == false + - result.commands|length == 0 + + - include_tasks: _populate_config.yaml + + - name: Delete static routes configuration + register: result + cisco.iosxr.iosxr_static_routes: &id005 + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ replaced['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete all static routes (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_static_routes: *id005 + + - name: Assert that the previous task was idempotent + assert: *id003 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/empty_config.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/empty_config.yaml new file mode 100644 index 00000000..c555e8fe --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/empty_config.yaml @@ -0,0 +1,49 @@ +--- +- debug: + msg: START iosxr_static_routes empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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.iosxr.iosxr_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.iosxr.iosxr_static_routes: + config: + state: overridden + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Parsed with empty running_config should give appropriate error message + register: result + ignore_errors: true + cisco.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/gathered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/gathered.yaml new file mode 100644 index 00000000..56211b19 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/gathered.yaml @@ -0,0 +1,23 @@ +--- +- debug: + msg: START iosxr_static_routes gathered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Gather static routes facts from the device using iosxr_static_routes + module + register: result + cisco.iosxr.iosxr_static_routes: + state: gathered + + - assert: + that: "{{ replaced['before'] | symmetric_difference(result['gathered'])\ + \ |length == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml new file mode 100644 index 00000000..d5e305a2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/merged.yaml @@ -0,0 +1,167 @@ +--- +- debug: + msg: START iosxr_static_routes merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + cisco.iosxr.iosxr_static_routes: &id001 + config: + + - address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.16/28 + next_hops: + + - forward_router_address: 192.0.2.10 + interface: FastEthernet0/0/0/1 + description: LAB + metric: 120 + tag: 10 + + - interface: FastEthernet0/0/0/5 + track: ip_sla_1 + + - dest: 192.0.2.32/28 + next_hops: + + - forward_router_address: 192.0.2.11 + admin_distance: 100 + + - afi: ipv6 + safi: unicast + routes: + + - dest: 2001:db8:1000::/36 + next_hops: + + - interface: FastEthernet0/0/0/7 + description: DC + + - interface: FastEthernet0/0/0/8 + forward_router_address: 2001:db8:2000:2::1 + + - vrf: DEV_SITE + address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.48/28 + next_hops: + + - forward_router_address: 192.0.2.12 + description: DEV + dest_vrf: test_1 + + - dest: 192.0.2.80/28 + next_hops: + + - interface: FastEthernet0/0/0/2 + forward_router_address: 192.0.2.14 + dest_vrf: test_1 + track: ip_sla_2 + vrflabel: 124 + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - set_fact: + diff: "{{ merged['after'] | symmetric_difference(result['after']) }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_static_routes: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Update existing configuration using merged + register: result + cisco.iosxr.iosxr_static_routes: &id002 + config: + + - vrf: DEV_SITE + address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.48/28 + next_hops: + + - forward_router_address: 192.0.2.12 + vrflabel: 2301 + dest_vrf: test_1 + + - dest: 192.0.2.80/28 + next_hops: + + - interface: FastEthernet0/0/0/2 + forward_router_address: 192.0.2.14 + dest_vrf: test_1 + description: rt_test_1 + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['update_commands'] | symmetric_difference(result['commands'])\ + \ |length == 0 }}" + + - name: Assert that after dicts were correctly generated + assert: + that: "{{ merged['update_after'] | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: Update existing static_routes configuration using merged (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_static_routes: *id002 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/overridden.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/overridden.yaml new file mode 100644 index 00000000..d9276037 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/overridden.yaml @@ -0,0 +1,79 @@ +--- +- debug: + msg: START iosxr_static_routes overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Overridde all static routes configuration with provided configuration + register: result + cisco.iosxr.iosxr_static_routes: &id001 + config: + + - vrf: DEV_NEW + address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.48/28 + next_hops: + + - forward_router_address: 192.0.2.15 + interface: FastEthernet0/0/0/3 + description: DEV1 + + - afi: ipv6 + safi: unicast + routes: + + - dest: 2001:db8:3000::/36 + next_hops: + + - interface: FastEthernet0/0/0/4 + forward_router_address: 2001:db8:2000:2::2 + description: PROD1 + track: ip_sla_1 + 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: + - "{{ replaced['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: Overridde all static routes configuration with given configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_static_routes: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/parsed.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/parsed.yaml new file mode 100644 index 00000000..0a4bc5c6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/parsed.yaml @@ -0,0 +1,17 @@ +--- +- debug: + msg: START iosxr_static_routes parsed integration tests on connection={{ ansible_connection + }} + +- block: + + - name: Use parsed state to convert externally supplied device specific static + routes commands to structured format + register: result + cisco.iosxr.iosxr_static_routes: + running_config: "{{ lookup('file', '../../fixtures/parsed.cfg') }}" + state: parsed + + - assert: + that: "{{ merged['after'] | symmetric_difference(result['parsed']) |length==0\ + \ }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/rendered.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/rendered.yaml new file mode 100644 index 00000000..164165f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/rendered.yaml @@ -0,0 +1,91 @@ +--- +- debug: + msg: START iosxr_static_routes rendered integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Use rendered state to convert task input to device specific commands + register: result + cisco.iosxr.iosxr_static_routes: + config: + + - vrf: DEV_SITE + address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.48/28 + next_hops: + + - forward_router_address: 192.0.2.12 + description: DEV + dest_vrf: test_1 + + - dest: 192.0.2.80/28 + next_hops: + + - interface: FastEthernet0/0/0/2 + forward_router_address: 192.0.2.14 + dest_vrf: test_1 + track: ip_sla_2 + vrflabel: 124 + + - address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.16/28 + next_hops: + + - forward_router_address: 192.0.2.10 + interface: FastEthernet0/0/0/1 + description: LAB + metric: 120 + tag: 10 + + - interface: FastEthernet0/0/0/5 + track: ip_sla_1 + + - dest: 192.0.2.32/28 + next_hops: + + - forward_router_address: 192.0.2.11 + admin_distance: 100 + + - afi: ipv6 + safi: unicast + routes: + + - dest: 2001:db8:1000::/36 + next_hops: + + - interface: FastEthernet0/0/0/7 + description: DC + + - interface: FastEthernet0/0/0/8 + forward_router_address: 2001:db8:2000:2::1 + state: rendered + + - assert: + that: "{{ merged['commands'] | symmetric_difference(result['rendered'])\ + \ |length==0 }}" + + - name: Gather static routes facts from the device and assert that its empty + register: result + cisco.iosxr.iosxr_static_routes: + state: gathered + + - name: Make sure that rendered task actually did not make any changes to the + device + assert: + that: "{{ result['gathered'] == [] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/replaced.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/replaced.yaml new file mode 100644 index 00000000..beef4034 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/replaced.yaml @@ -0,0 +1,69 @@ +--- +- debug: + msg: START iosxr_static_routes replaced integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_config.yaml + +- block: + + - name: Replace device configurations of static routes with provided configurations + register: result + cisco.iosxr.iosxr_static_routes: &id001 + config: + + - vrf: DEV_SITE + address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.48/28 + next_hops: + + - forward_router_address: 192.0.2.15 + interface: FastEthernet0/0/0/3 + description: DEV_NEW + dest_vrf: dev_test_2 + 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: Replace device configurations of listed vrfs/global entry with provided + configuration (IDEMPOTENT) + register: result + cisco.iosxr.iosxr_static_routes: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + - result.commands|length == 0 + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['before']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/rtt.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/rtt.yaml new file mode 100644 index 00000000..c1ddfe58 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/tests/cli/rtt.yaml @@ -0,0 +1,89 @@ +--- +- debug: + msg: START iosxr_static_routes round trip integration tests on connection={{ + ansible_connection }} + +- block: + + - include_tasks: _remove_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + cisco.iosxr.iosxr_static_routes: + config: + + - address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.48/28 + next_hops: + + - forward_router_address: 192.0.2.15 + admin_distance: 105 + track: ip_sla_2 + + - vrf: DEV_SITE + address_families: + + - afi: ipv6 + safi: unicast + routes: + + - dest: 2001:db8:3000::/36 + next_hops: + + - forward_router_address: 2001:db8:2000:2::2 + interface: FastEthernet0/0/0/11 + description: PROD1 + state: merged + + - name: Gather interfaces facts + cisco.iosxr.iosxr_facts: + gather_subset: + - '!all' + - '!min' + gather_network_resources: + - static_routes + + - name: Apply the provided configuration (config to be reverted) + register: result + cisco.iosxr.iosxr_static_routes: + config: + + - vrf: TEST_SITE + address_families: + + - afi: ipv4 + safi: unicast + routes: + + - dest: 192.0.2.80/28 + next_hops: + + - forward_router_address: 192.0.2.12 + interface: FastEthernet0/0/0/3 + description: DEV_MOVED + dest_vrf: dev_moved + state: overridden + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Revert back to base config using facts round trip + register: revert + cisco.iosxr.iosxr_static_routes: + config: "{{ ansible_facts['network_resources']['static_routes'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length\ + \ == 0 }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/vars/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/vars/main.yaml new file mode 100644 index 00000000..b12c6698 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_static_routes/vars/main.yaml @@ -0,0 +1,264 @@ +--- +merged: + before: [] + commands: + - router static + - address-family ipv4 unicast + - 192.0.2.16/28 192.0.2.10 FastEthernet0/0/0/1 description LAB metric 120 tag + 10 + - 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1 + - 192.0.2.32/28 192.0.2.11 100 + - address-family ipv6 unicast + - 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC + - 2001:db8:1000::/36 2001:db8:2000:2::1 FastEthernet0/0/0/8 + - vrf DEV_SITE + - address-family ipv4 unicast + - 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV + - 192.0.2.80/28 vrf test_1 192.0.2.14 FastEthernet0/0/0/2 track ip_sla_2 vrflabel + 124 + update_commands: + - router static + - vrf DEV_SITE + - address-family ipv4 unicast + - 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV vrflabel 2301 + - 192.0.2.80/28 vrf test_1 192.0.2.14 FastEthernet0/0/0/2 description rt_test_1 + track ip_sla_2 vrflabel 124 + after: + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/28 + next_hops: + - description: LAB + forward_router_address: 192.0.2.10 + interface: FastEthernet0/0/0/1 + metric: 120 + tag: 10 + - interface: FastEthernet0/0/0/5 + track: ip_sla_1 + - dest: 192.0.2.32/28 + next_hops: + - admin_distance: 100 + forward_router_address: 192.0.2.11 + safi: unicast + - afi: ipv6 + routes: + - dest: 2001:db8:1000::/36 + next_hops: + - description: DC + interface: FastEthernet0/0/0/7 + - forward_router_address: 2001:db8:2000:2::1 + interface: FastEthernet0/0/0/8 + safi: unicast + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.48/28 + next_hops: + - description: DEV + dest_vrf: test_1 + forward_router_address: 192.0.2.12 + - dest: 192.0.2.80/28 + next_hops: + - dest_vrf: test_1 + forward_router_address: 192.0.2.14 + interface: FastEthernet0/0/0/2 + track: ip_sla_2 + vrflabel: 124 + safi: unicast + vrf: DEV_SITE + update_after: + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/28 + next_hops: + - description: LAB + forward_router_address: 192.0.2.10 + interface: FastEthernet0/0/0/1 + metric: 120 + tag: 10 + - interface: FastEthernet0/0/0/5 + track: ip_sla_1 + - dest: 192.0.2.32/28 + next_hops: + - admin_distance: 100 + forward_router_address: 192.0.2.11 + safi: unicast + - afi: ipv6 + routes: + - dest: 2001:db8:1000::/36 + next_hops: + - description: DC + interface: FastEthernet0/0/0/7 + - forward_router_address: 2001:db8:2000:2::1 + interface: FastEthernet0/0/0/8 + safi: unicast + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.48/28 + next_hops: + - description: DEV + dest_vrf: test_1 + forward_router_address: 192.0.2.12 + vrflabel: 2301 + - dest: 192.0.2.80/28 + next_hops: + - dest_vrf: test_1 + forward_router_address: 192.0.2.14 + interface: FastEthernet0/0/0/2 + track: ip_sla_2 + vrflabel: 124 + description: rt_test_1 + safi: unicast + vrf: DEV_SITE +replaced: + before: + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/28 + next_hops: + - description: LAB + forward_router_address: 192.0.2.10 + interface: FastEthernet0/0/0/1 + metric: 120 + tag: 10 + - interface: FastEthernet0/0/0/5 + track: ip_sla_1 + - dest: 192.0.2.32/28 + next_hops: + - admin_distance: 100 + forward_router_address: 192.0.2.11 + safi: unicast + - afi: ipv6 + routes: + - dest: 2001:db8:1000::/36 + next_hops: + - description: DC + interface: FastEthernet0/0/0/7 + - forward_router_address: 2001:db8:2000:2::1 + interface: FastEthernet0/0/0/8 + safi: unicast + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.48/28 + next_hops: + - description: DEV + dest_vrf: test_1 + forward_router_address: 192.0.2.12 + - forward_router_address: 192.0.3.24 + interface: GigabitEthernet0/0/0/1 + vrflabel: 2302 + - dest: 192.0.2.80/28 + next_hops: + - dest_vrf: test_1 + forward_router_address: 192.0.2.14 + interface: FastEthernet0/0/0/2 + track: ip_sla_2 + vrflabel: 124 + safi: unicast + vrf: DEV_SITE + commands: + - router static + - vrf DEV_SITE + - address-family ipv4 unicast + - no 192.0.2.48/28 192.0.3.24 GigabitEthernet0/0/0/1 + - no 192.0.2.48/28 vrf test_1 192.0.2.12 + - 192.0.2.48/28 vrf dev_test_2 192.0.2.15 FastEthernet0/0/0/3 description DEV_NEW + after: + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.16/28 + next_hops: + - description: LAB + forward_router_address: 192.0.2.10 + interface: FastEthernet0/0/0/1 + metric: 120 + tag: 10 + - interface: FastEthernet0/0/0/5 + track: ip_sla_1 + - dest: 192.0.2.32/28 + next_hops: + - admin_distance: 100 + forward_router_address: 192.0.2.11 + safi: unicast + - afi: ipv6 + routes: + - dest: 2001:db8:1000::/36 + next_hops: + - description: DC + interface: FastEthernet0/0/0/7 + - forward_router_address: 2001:db8:2000:2::1 + interface: FastEthernet0/0/0/8 + safi: unicast + - address_families: + - afi: ipv4 + routes: + - dest: 192.0.2.48/28 + next_hops: + - forward_router_address: 192.0.2.15 + interface: FastEthernet0/0/0/3 + description: DEV_NEW + dest_vrf: dev_test_2 + - dest: 192.0.2.80/28 + next_hops: + - dest_vrf: test_1 + forward_router_address: 192.0.2.14 + interface: FastEthernet0/0/0/2 + track: ip_sla_2 + vrflabel: 124 + safi: unicast + vrf: DEV_SITE +overridden: + commands: + - router static + - no vrf DEV_SITE + - no address-family ipv4 unicast + - no address-family ipv6 unicast + - vrf DEV_NEW + - address-family ipv4 unicast + - 192.0.2.48/28 192.0.2.15 FastEthernet0/0/0/3 description DEV1 + - address-family ipv6 unicast + - 2001:db8:3000::/36 2001:db8:2000:2::2 FastEthernet0/0/0/4 description PROD1 + track ip_sla_1 + after: + - vrf: DEV_NEW + address_families: + - afi: ipv4 + safi: unicast + routes: + - dest: 192.0.2.48/28 + next_hops: + - forward_router_address: 192.0.2.15 + interface: FastEthernet0/0/0/3 + description: DEV1 + - afi: ipv6 + safi: unicast + routes: + - dest: 2001:db8:3000::/36 + next_hops: + - interface: FastEthernet0/0/0/4 + forward_router_address: 2001:db8:2000:2::2 + description: PROD1 + track: ip_sla_1 +deleted: + commands: + - no router static + after: [] +round_trip: + after: + - vrf: TEST_SITE + address_families: + - afi: ipv4 + safi: unicast + routes: + - dest: 192.0.2.80/28 + next_hops: + - forward_router_address: 192.0.2.12 + interface: FastEthernet0/0/0/3 + description: DEV_MOVED + dest_vrf: dev_moved diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/defaults/main.yaml new file mode 100644 index 00000000..10c0fabc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: '*' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/meta/main.yml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/meta/main.yml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/cli.yaml new file mode 100644 index 00000000..9d1857ab --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/cli.yaml @@ -0,0 +1,29 @@ +--- +- 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 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 + 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 + +- name: reset connection + meta: reset_connection diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/main.yaml new file mode 100644 index 00000000..5d082a6f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- include: cli.yaml +- include: netconf.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/netconf.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/netconf.yaml new file mode 100644 index 00000000..e984861a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tasks/netconf.yaml @@ -0,0 +1,29 @@ +--- +- name: collect all netconf test cases + find: + paths: '{{ role_path }}/tests/netconf' + 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 case (connection=ansible.netcommon.netconf) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: + - netconf + +- 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 + +- name: reset connection + meta: reset_connection diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/net_system.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/net_system.yaml new file mode 100644 index 00000000..83ca4801 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/net_system.yaml @@ -0,0 +1,36 @@ +--- +- debug: msg="START iosxr cli/net_system.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + lines: + - no domain list ansible.com + - no 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 + - "'domain list ansible.com' in result.commands" + - "'domain list redhat.com' in result.commands" + +- name: teardown + cisco.iosxr.iosxr_config: + lines: + - no domain list ansible.com + - no domain list redhat.com + match: none + provider: '{{ cli }}' + +- debug: msg="END iosxr cli/net_system.yaml on connection={{ ansible_connection + }}" diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_domain_list.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_domain_list.yaml new file mode 100644 index 00000000..7e4f8fe3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_domain_list.yaml @@ -0,0 +1,123 @@ +--- +- debug: msg="START cli/set_domain_search.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + lines: + - no domain list ansible.com + - no domain list redhat.com + match: none + provider: '{{ cli }}' + +- name: configure domain_search + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'domain list ansible.com' in result.commands" + - "'domain list redhat.com' in result.commands" + +- name: verify domain_search + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: remove one entry + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'no domain list redhat.com' in result.commands" + +- name: verify remove one entry + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: add one entry + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'domain list redhat.com' in result.commands" + +- name: verify add one entry + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: add and remove one entry + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - eng.ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'no domain list redhat.com' in result.commands" + - "'domain list eng.ansible.com' in result.commands" + - result.commands|length == 2 + +- name: verify add and remove one entry + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - eng.ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + lines: + - no domain list ansible.com + - no 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/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_domain_name.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_domain_name.yaml new file mode 100644 index 00000000..b6e080fa --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_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.iosxr.iosxr_config: + lines: no domain name + match: none + provider: '{{ cli }}' + +- name: configure domain_name + register: result + cisco.iosxr.iosxr_system: + domain_name: eng.ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + +- name: verify domain_name + register: result + cisco.iosxr.iosxr_system: + domain_name: eng.ansible.com + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + lines: no 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/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_hostname.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_hostname.yaml new file mode 100644 index 00000000..a23c09d5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_hostname.yaml @@ -0,0 +1,36 @@ +--- +- debug: msg="START cli/set_hostname.yaml on connection={{ ansible_connection }}" + +- name: setup + cisco.iosxr.iosxr_config: + lines: hostname switch + match: none + provider: '{{ cli }}' + +- name: configure hostname + register: result + cisco.iosxr.iosxr_system: + hostname: foo + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + +- name: verify hostname + register: result + cisco.iosxr.iosxr_system: + hostname: foo + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_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/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_lookup_source.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_lookup_source.yaml new file mode 100644 index 00000000..8fdf2824 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_lookup_source.yaml @@ -0,0 +1,40 @@ +--- +- debug: msg="START cli/set_lookup_source.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + lines: no domain lookup source-interface Loopback10 + match: none + provider: '{{ cli }}' + +- name: configure lookup_source + register: result + cisco.iosxr.iosxr_system: + lookup_source: Loopback10 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'domain lookup source-interface Loopback10' in result.commands" + +- name: verify lookup_source + register: result + cisco.iosxr.iosxr_system: + lookup_source: Loopback10 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + +- name: teardown + cisco.iosxr.iosxr_config: + lines: + - no domain lookup source-interface Loopback10 + 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/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_name_servers.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_name_servers.yaml new file mode 100644 index 00000000..20fd8120 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/cli/set_name_servers.yaml @@ -0,0 +1,66 @@ +--- +- debug: msg="START cli/set_name_servers.yaml on connection={{ ansible_connection + }}" + +- name: setup + cisco.iosxr.iosxr_config: + lines: + - no ip name-server 192.0.2.1 + - no ip name-server 192.0.2.2 + - no ip name-server 192.0.2.3 + match: none + provider: '{{ cli }}' + +- name: configure name_servers + register: result + cisco.iosxr.iosxr_system: + name_servers: + - 192.0.2.1 + - 192.0.2.2 + - 192.0.2.3 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - "'domain name-server 192.0.2.1' in result.commands" + - "'domain name-server 192.0.2.2' in result.commands" + - "'domain name-server 192.0.2.3' in result.commands" + +- name: verify name_servers + register: result + cisco.iosxr.iosxr_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.iosxr.iosxr_system: + name_servers: + - 192.0.2.1 + - 192.0.2.2 + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands|length == 1 + - "'no domain name-server 192.0.2.3' in result.commands" + +- name: setup + cisco.iosxr.iosxr_config: + lines: + - no ip name-server 192.0.2.1 + - no ip name-server 192.0.2.2 + 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/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_list.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_list.yaml new file mode 100644 index 00000000..d7e1a7b0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_list.yaml @@ -0,0 +1,179 @@ +--- +- debug: + msg: START netconf/set_domain_search.yaml on connection={{ ansible_connection + }} + +- name: setup + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: + - no domain list ansible.com + - no domain list redhat.com + - no domain list eng.ansible.com + - no domain vrf ansiblevrf list redhat.com + - no domain vrf ansiblevrf list ansible.com + match: none + provider: '{{ cli }}' + +- name: configure domain_search + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'ansible.com' in result.xml[0]" + - "'redhat.com' in result.xml[0]" + +- name: configure domain_search with vrf + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id001 + vrf: ansiblevrf + domain_search: + - redhat.com + - ansible.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'ansiblevrf' in result.xml[0]" + - "'ansible.com' in result.xml[0]" + - "'redhat.com' in result.xml[0]" + +- name: verify domain_search with vrf + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id001 + +- assert: + that: + - result.changed == false + +- name: delete domain_search with vrf + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id002 + vrf: ansiblevrf + domain_search: + - redhat.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'ansiblevrf' in result.xml[0]" + - "'ansible.com' in result.xml[0]" + +- name: verify delete domain_search with vrf + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id002 + +- assert: + that: + - result.changed == false + +- name: remove one entry + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'redhat.com' in result.xml[0]" + +- name: verify remove one entry + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- name: add one entry + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'redhat.com' in result.xml[0]" + +- name: verify add one entry + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - redhat.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- name: add and remove one entry + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - eng.ansible.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'redhat.com' in result.xml[1]" + - "'eng.ansible.com' in result.xml[0]" + - result.xml|length == 2 + +- name: verify add and remove one entry + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + domain_search: + - ansible.com + - eng.ansible.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- name: teardown + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: + - no domain list ansible.com + - no domain list redhat.com + - no domain list eng.ansible.com + - no domain vrf ansiblevrf list redhat.com + - no domain vrf ansiblevrf list ansible.com + - no domain vrf ansiblevrf list eng.ansible.com + match: none + provider: '{{ cli }}' + +- debug: + msg: END netconf/set_domain_search.yaml on connection={{ ansible_connection + }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_name.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_name.yaml new file mode 100644 index 00000000..98508c4e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_domain_name.yaml @@ -0,0 +1,78 @@ +--- +- debug: + msg: START netconf/set_domain_name.yaml on connection={{ ansible_connection + }} + +- name: setup + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: + - no domain name + - no domain vrf ansiblevrf name + match: none + provider: '{{ cli }}' + +- name: configure domain_name + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id001 + domain_name: eng.ansible.com + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + +- name: verify domain_name + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id001 + +- assert: + that: + - result.changed == false + +- name: configure domain_name + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id002 + domain_name: eng.ansible.com + provider: '{{ netconf }}' + state: absent + +- assert: + that: + - result.changed == true + +- name: verify domain_name + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id002 + +- assert: + that: + - result.changed == false + +- name: configure domain_name with vrf + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id003 + domain_name: eng.ansible.com + vrf: ansiblevrf + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + +- name: verify domain_name with vrf + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id003 + +- assert: + that: + - result.changed == false + +- debug: + msg: END netconf/set_domain_name.yaml on connection={{ ansible_connection }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_hostname.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_hostname.yaml new file mode 100644 index 00000000..0a4b76a2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_hostname.yaml @@ -0,0 +1,45 @@ +--- +- debug: + msg: START netconf/set_hostname.yaml on connection={{ ansible_connection }} + +- block: + + - name: setup + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: hostname switch + match: none + provider: '{{ cli }}' + + - name: configure hostname + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + hostname: foo + provider: '{{ netconf }}' + + - assert: + that: + - result.changed == true + + - name: verify hostname + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + hostname: foo + provider: '{{ netconf }}' + + - assert: + that: + - result.changed == false + always: + + - name: teardown + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: hostname {{ inventory_hostname }} + match: none + provider: '{{ cli }}' + +- debug: + msg: END netconf/set_hostname.yaml on connection={{ ansible_connection }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_lookup_source.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_lookup_source.yaml new file mode 100644 index 00000000..2045a8dc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_lookup_source.yaml @@ -0,0 +1,162 @@ +--- +- debug: + msg: START netconf/set_lookup_source.yaml on connection={{ ansible_connection + }} + +- name: setup + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: + - no domain lookup source-interface Loopback10 + - no domain vrf ansiblevrf lookup source-interface Loopback10 + - no domain lookup disable + - no domain vrf ansiblevrf lookup disable + match: none + provider: '{{ cli }}' + +- name: configure lookup_source + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id001 + lookup_source: Loopback10 + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'Loopback10' in result.xml[0]" + +- name: verify lookup_source + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id001 + +- assert: + that: + - result.changed == false + +- name: disable lookup + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id002 + lookup_enabled: false + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'lookup' in result.xml[0]" + +- name: verify disable lookup + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id002 + +- assert: + that: + - result.changed == false + +- name: delete lookup_source + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id003 + lookup_source: Loopback10 + provider: '{{ netconf }}' + state: absent + +- assert: + that: + - result.changed == true + - "'Loopback10' in result.xml[0]" + +- name: verify lookup_source + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id003 + +- assert: + that: + - result.changed == false + +- name: configure lookup_source with vrf + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id004 + lookup_source: Loopback10 + vrf: ansiblevrf + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'Loopback10' in result.xml[0]" + - "'ansiblevrf' in result.xml[0]" + +- name: verify lookup_source + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id004 + +- assert: + that: + - result.changed == false + +- name: disable lookup + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id005 + lookup_enabled: false + vrf: ansiblevrf + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - "'lookup' in result.xml[0]" + - "'ansiblevrf' in result.xml[0]" + +- name: verify disable lookup + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id005 + +- assert: + that: + - result.changed == false + +- name: delete lookup_source + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id006 + lookup_source: Loopback10 + vrf: ansiblevrf + provider: '{{ netconf }}' + state: absent + +- assert: + that: + - result.changed == true + - "'Loopback10' in result.xml[0]" + - "'ansiblevrf' in result.xml[0]" + +- name: verify lookup_source + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id006 + +- assert: + that: + - result.changed == false + +- name: teardown + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: + - no domain lookup disable + - no domain vrf ansiblevrf lookup disable + match: none + provider: '{{ cli }}' + +- debug: + msg: END netconf/set_lookup_source.yaml on connection={{ ansible_connection + }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_name_servers.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_name_servers.yaml new file mode 100644 index 00000000..c7a788a0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_system/tests/netconf/set_name_servers.yaml @@ -0,0 +1,138 @@ +--- +- debug: + msg: START netconf/set_name_servers.yaml on connection={{ ansible_connection + }} + +- name: setup + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: + - no domain name-server 192.0.2.1 + - no domain name-server 192.0.2.2 + - no domain name-server 192.0.2.3 + match: none + provider: '{{ cli }}' + +- name: setup + connection: ansible.netcommon.netconf + ignore_errors: true + register: result + cisco.iosxr.iosxr_system: + vrf: ansible + name_servers: + - 192.0.2.1 + - 192.0.2.2 + - 192.0.2.3 + provider: '{{ netconf }}' + state: absent + +- name: configure name_servers + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + name_servers: + - 192.0.2.1 + - 192.0.2.2 + - 192.0.2.3 + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - result.xml|length == 1 + - "'192.0.2.1' in result.xml[0]" + - "'192.0.2.2' in result.xml[0]" + - "'192.0.2.3' in result.xml[0]" + +- name: verify name_servers + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + name_servers: + - 192.0.2.1 + - 192.0.2.2 + - 192.0.2.3 + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + +- name: add name servers with vrf + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: &id001 + vrf: ansible + name_servers: + - 192.0.2.1 + - 192.0.2.2 + - 192.0.2.3 + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - result.xml|length == 1 + - "'ansible' in result.xml[0]" + - "'192.0.2.1' in result.xml[0]" + - "'192.0.2.2' in result.xml[0]" + - "'192.0.2.3' in result.xml[0]" + +- name: verify change to vrf + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: *id001 + +- assert: + that: + - result.changed == false + +- name: remove one + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_system: + name_servers: + - 192.0.2.1 + - 192.0.2.2 + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - result.xml|length == 1 + - "'192.0.2.3' in result.xml[0]" + +- name: remove one with vrf + connection: ansible.netcommon.netconf + ignore_errors: true + register: result + cisco.iosxr.iosxr_system: + vrf: ansible + name_servers: + - 192.0.2.1 + - 192.0.2.2 + provider: '{{ netconf }}' + +- name: teardown + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: + - no domain name-server 192.0.2.1 + - no domain name-server 192.0.2.2 + match: none + provider: '{{ cli }}' + +- name: teardown + connection: ansible.netcommon.netconf + ignore_errors: true + register: result + cisco.iosxr.iosxr_system: + vrf: ansible + name_servers: + - 192.0.2.1 + - 192.0.2.2 + provider: '{{ netconf }}' + state: absent + +- debug: + msg: END netconf/set_name_servers.yaml on connection={{ ansible_connection }} diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/defaults/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/defaults/main.yaml new file mode 100644 index 00000000..a845c24b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '*' +test_items: [] diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/private b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/private new file mode 100644 index 00000000..bf2425bb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/private @@ -0,0 +1,30 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,A823A6B5ED873917 + +mLZ1xM1+xwutkRy+K/c9QsstDPQ9F6UWtDpoYyIgs7n9VgMjhIMbWQC9CkTvnFJM +ey+iwGdQZZOThwxalm+k3pMibwRjhnF+PNFhiVkzWH8/K8QvXRQiW/vYmE/QB9pY +T0IWbMcC7/ktEfQn+6GLXoe/L7yH+aNv/2Flsa2jN2cfSXpzbneUA06/LVVOw6E+ +C74NKRWUmMPA39Zd4WOeBoWUdS5Kgwl57SOtrKs1LIGh33+TPu+Go8gJ7h/t/kaN +kverVSz+0eeX+exKumejfo1UfosplRhcjRG8YgiQ8l7SN3NBF/gXiiSrH3fLwmRJ +hbokJ8TmCozrYBs1MNe3LoU2iuIqVnJ5Sd6DJELs6vCuFz+v6J/s80NaaYMlBCbB +1lahelYqoyLb4uiDd4zQSpaxzO+Cx/d50Wpee8mFxbAL/YxacOzD3b/VCBgB+AZN +TTHr1ayd+ITd8gewXAyERKWyrDcC2beJI0fOil23PYowWvEncS6I1f4hKQY28sRf +vHSbwQdltky/xiib2/feQTaMSQFvsY67uTHipMwl5wJNOKcbeqDVMWPYST3XUsBg +LRlbT+VTUEehbOJAJ6Hh7Yv4nqu7fEh95HUQK7Ed56rMLKpmdorYO49JtewkEUsj +LJn7tcxMUuOcWKHMPu6vB/63f6Ulthqp1SEG8aNBaZMuPyLWAPAJc2okOmkiSbvO +0Hxe6BtAGn2fUo2jK6E3tD/dsIR2qqMlL09FkACGT8D5Lfh5d3z+lo9DxpXl281R +ablehPyHgHcIC6cD2/7FwwjzUuyj/kYcETnMs51agcWFAXTom/ehqD+IQ8jZ73zT +5O4FFgslnNmB/vddh9PeYpjDYdR4y5xMrlMxJ+qcZuQOq7dfaiodq8oj+XPmwgxA +audX/sHMutOpmOagrsQfaQXaPqRXdQTnuwHacQfwq+tBBhrft5gwt1HE7Ir2ulwD +Q19kefchkJu/0c1cAGg1VHtQic0a6tX6PrwqZOMDfpSywcImMCF4KHgD2EC5/8h6 +tq0PqPLNcwiM2NhpypCuYmkYZ0gnJ/xAwtM85Ck9nmPFptLSd0b7YB7dtGsFYY5A +rhIcq5lZhy06/RRAPluIkniscA50iEO/EXKwzYzovBJh6jQz7oYsbEUW5kwg0gm/ +YPSa6lqv2kTpXS+UiGyeNWdUkr5DpdwKe4lrAsN94HE9/SoLgFvz0X5/WyTssSzo +IO3WfLfBc7SOkZK1ibcleIqilzd+LSoIqqGrft2yonXgJD3p9xO+Hlldczx2kHmu +z4lZBq53AkVAQ4os5L7ZRnmxoqKn2XAQRwVH3M9ZFYFEqEyDmZhlFdJSGEnKws81 +Ej48t6KWwqml02cx675bSYI22tL3+RL7AGmlC0/Xh8wIVesgulsYmnhW4BtpBYf2 +fwv5esJJMjkh2LvLNG3edYChugudeZXtcBJdNr0GYRbBAhvO25bRcr6z8nYDusKX +e/+30vATOcBO/zaOYIwDGT5ZwMQAV1aQl8HyeyYESNjb0fBXQ3OYObOrTTs8MLyC +I4b6wr1vlbN+lMOm+RIXCDgmC3COdlgCHyo3qiIu2YNYQVoNF4NN4A== +-----END RSA PRIVATE KEY----- diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public.pub b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public.pub new file mode 100644 index 00000000..db1847f4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAkvLTTJdwZ0lg1cUCn13Hi3+ho2+G6/96XuAP7jA7Ghz9NPbC/eqXnjvb27BA8CxtFXYuXR5eZWSq2UN5zFcfrFb57XFxdAg2q21hGEX+FGiTUuRZh8+ByVEh0LUetFTwsEZ1iGv6GZiLBt7IJvClXbyNTJEt3DZncHfGwudyGFviV4dGrzusDAGAcoHqvD/5uXYl4PjMH9oSfraO3sG4Q7soQwxNeiM8qOLf3c1SabHBAtSewwnA0E/jhzpOLD2QUncU5s+Oa9PvEXXhGv5eZo9lp71brsgyWj32m2UuXx/n+EZg78GVJT5mFO7LG239n3gTnwkMVdr6zVBFNX5Mvw== rsa-key-20171025 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public2.pub b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public2.pub new file mode 100644 index 00000000..2fc64568 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/files/public2.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAhTxbibM8hKZn7xDURs15L3gkcsnpDoZ+tNm5zpP9dcboASnIyJzfC7J/RdRCQsO/pDmUY4y/tsTx18uenyfazxtNkyCHdANlp8XVF1fGNv5GM+QbsDqxe54sdG9csASX0/Ljvl538IbcLFVH0zxyKspbDOgkAkUSuKIAH5x+/GhkAoGQO2tOhYjqofNtUxLSvfRsf4Gm1M0WgdWmz3MW4NOdZhsL4S+STgRPU1jy1dKGj7BKY9cpnCWBFHa2wSaOXJEBZEKNaFVxlBBrFs5brjRQA0mVPmE+pz+/+IJeSNEEma9cXur0ONeb6OoXvkManxKfkaswT2ybOChAzJR8dQ== T-MOBILE
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/meta/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/meta/main.yaml new file mode 100644 index 00000000..be631e5d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_iosxr_tests diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/cli.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/cli.yaml new file mode 100644 index 00000000..36229e75 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/cli.yaml @@ -0,0 +1,29 @@ +--- +- name: collect all common test cases + find: + paths: '{{ role_path }}/tests/common' + patterns: '{{ testcase }}.yaml' + register: common_test_cases + delegate_to: localhost + +- name: collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- set_fact: + test_cases: + files: '{{ common_test_cases.files }} + {{ test_cases.files }}' + +- name: set test_items + set_fact: test_items="{{ 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 + tags: + - network_cli diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/main.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/main.yaml new file mode 100644 index 00000000..5d082a6f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- include: cli.yaml +- include: netconf.yaml diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/netconf.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/netconf.yaml new file mode 100644 index 00000000..49c17aff --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tasks/netconf.yaml @@ -0,0 +1,37 @@ +--- +- name: collect all common test cases + find: + paths: '{{ role_path }}/tests/common' + patterns: '{{ testcase }}.yaml' + register: common_test_cases + delegate_to: localhost + +- name: collect all netconf test cases + find: + paths: '{{ role_path }}/tests/netconf' + patterns: '{{ testcase }}.yaml' + register: test_cases + delegate_to: localhost + +- set_fact: + test_cases: + files: '{{ common_test_cases.files }} + {{ test_cases.files }}' + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case (connection=ansible.netcommon.netconf) + include: '{{ test_case_to_run }}' + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run + tags: + - netconf + +- 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/iosxr/tests/integration/targets/iosxr_user/tests/cli/basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/cli/basic.yaml new file mode 100644 index 00000000..e13fc7dc --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/cli/basic.yaml @@ -0,0 +1,182 @@ +--- +- name: Remove users prior to tests + cisco.iosxr.iosxr_config: + lines: + - no username ansibletest1 + - no username ansibletest2 + - no username ansibletest3 + provider: '{{ cli }}' + +- name: Create user (SetUp) + register: result + cisco.iosxr.iosxr_user: + name: ansibletest1 + configured_password: test + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"username" in result.commands[0]' + - '"secret" in result.commands[1]' + +- name: Create user with update_password always (not idempotent) + register: result + cisco.iosxr.iosxr_user: + name: ansibletest1 + configured_password: test + update_password: always + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"username" in result.commands[0]' + - '"secret" in result.commands[0]' + +- name: Create user again with update_password on_create (idempotent) + register: result + cisco.iosxr.iosxr_user: + name: ansibletest1 + configured_password: test + update_password: on_create + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 + +- name: Modify user group + register: result + cisco.iosxr.iosxr_user: + name: ansibletest1 + configured_password: test + update_password: on_create + group: sysadmin + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"username" in result.commands[0]' + - '"group" in result.commands[0]' + +- name: Modify user group again (idempotent) + register: result + cisco.iosxr.iosxr_user: + name: ansibletest1 + configured_password: test + update_password: on_create + group: sysadmin + state: present + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 + +- name: Collection of users (SetUp) + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansibletest2 + + - name: ansibletest3 + configured_password: test + state: present + group: sysadmin + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"username" in result.commands[0]' + - '"secret" in result.commands[1]' + - '"group sysadmin" in result.commands[2]' + - '"username" in result.commands[3]' + - '"secret" in result.commands[4]' + - '"group sysadmin" in result.commands[5]' + +- name: Add collection of users again with update_password always (not idempotent) + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansibletest2 + + - name: ansibletest3 + configured_password: test + state: present + group: sysadmin + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - '"username" in result.commands[0]' + - '"secret" in result.commands[0]' + - '"username" in result.commands[1]' + - '"secret" in result.commands[1]' + +- name: Add collection of users again with update_password on_create (idempotent) + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansibletest2 + + - name: ansibletest3 + configured_password: test + update_password: on_create + state: present + group: sysadmin + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 + +- name: Delete collection of users + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansibletest1 + + - name: ansibletest2 + + - name: ansibletest3 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == true + - result.commands == ["no username ansibletest1", "no username ansibletest2", + "no username ansibletest3"] + +- name: Delete collection of users again (idempotent) + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansibletest1 + + - name: ansibletest2 + + - name: ansibletest3 + state: absent + provider: '{{ cli }}' + +- assert: + that: + - result.changed == false + - result.commands | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/common/auth.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/common/auth.yaml new file mode 100644 index 00000000..adfb7c9a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/common/auth.yaml @@ -0,0 +1,121 @@ +--- +- block: + + - name: Create user with password + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_user: + name: auth_user + state: present + configured_password: pass123 + provider: '{{ cli }}' + + - name: test login + expect: + command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) + }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no show version + responses: + (?i)password: pass123 + connection: ansible.netcommon.network_cli + + - name: test login with invalid password (should fail) + expect: + command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) + }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no show version + responses: + (?i)password: badpass + ignore_errors: true + connection: ansible.netcommon.network_cli + register: results + + - name: check that attempt failed + assert: + that: + - results.failed + + - name: create user with private key (contents input) + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_user: + name: auth_user + state: present + public_key_contents: "{{ lookup('file', \"{{ role_path }}/files/public.pub\"\ + ) }}" + provider: '{{ cli }}' + + - name: test login with private key + expect: + command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) + }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path + }}/files/private show version + responses: + (?i)password: pass123 + connection: ansible.netcommon.network_cli + + - name: remove user and key + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_user: + name: auth_user + provider: '{{ cli }}' + state: absent + + - name: test login with private key (should fail, no user) + expect: + command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) + }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path + }}/files/private show version + responses: + (?i)password: pass123 + ignore_errors: true + connection: ansible.netcommon.network_cli + register: results + + - name: create user with private key (path input) + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_user: + name: auth_user + state: present + public_key: '{{ role_path }}/files/public.pub' + provider: '{{ cli }}' + + - name: test login with private key + expect: + command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) + }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path + }}/files/private show version + responses: + (?i)password: pass123 + ignore_errors: true + connection: ansible.netcommon.network_cli + + - name: change private key for user + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_user: + name: auth_user + state: present + public_key_contents: "{{ lookup('file', \"{{ role_path }}/files/public2.pub\"\ + ) }}" + provider: '{{ cli }}' + + - name: test login with invalid private key (should fail) + expect: + command: ssh auth_user@{{ ansible_ssh_host }} -p {{ ansible_ssh_port|default(22) + }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{ role_path + }}/files/private show version + responses: + (?i)password: pass123 + ignore_errors: true + connection: ansible.netcommon.network_cli + register: results + + - name: check that attempt failed + assert: + that: + - results.failed + always: + + - name: delete user + connection: ansible.netcommon.network_cli + register: result + cisco.iosxr.iosxr_user: + name: auth_user + state: absent + provider: '{{ cli }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/netconf/basic.yaml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/netconf/basic.yaml new file mode 100644 index 00000000..1d4e83d9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/iosxr_user/tests/netconf/basic.yaml @@ -0,0 +1,193 @@ +--- +- name: Remove users prior to tests + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + lines: + - no username ansible1 + - no username ansible2 + - no username ansible3 + provider: '{{ cli }}' + +- name: Create user (SetUp) + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + name: ansible1 + configured_password: password + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"ansible1" in result.xml[0]' + - '"secret" in result.xml[0]' + +- name: Create user with update_password always (not idempotent) + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + name: ansible1 + configured_password: password + update_password: always + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"ansible1" in result.xml[0]' + - '"secret" in result.xml[0]' + +- name: Create user again with update_password on_create (idempotent) + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + name: ansible1 + configured_password: password + update_password: on_create + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + - result.xml | length == 0 + +- name: Modify user group + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + name: ansible1 + configured_password: password + update_password: on_create + group: sysadmin + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"ansible1" in result.xml[0]' + - '"sysadmin" in result.xml[0]' + +- name: Modify user group again (idempotent) + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + name: ansible1 + configured_password: password + update_password: on_create + group: sysadmin + state: present + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + - result.xml | length == 0 + +- name: Collection of users (SetUp) + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansible2 + + - name: ansible3 + configured_password: password + state: present + group: sysadmin + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"ansible2" in result.xml[0]' + - '"secret" in result.xml[0]' + - '"sysadmin" in result.xml[1]' + - '"ansible2" in result.xml[0]' + - '"secret" in result.xml[0]' + - '"sysadmin" in result.xml[1]' + +- name: Add collection of users again with update_password always (not idempotent) + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansible2 + + - name: ansible3 + configured_password: password + state: present + group: sysadmin + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"ansible2" in result.xml[0]' + - '"ansible3" in result.xml[0]' + - '"secret" in result.xml[0]' + +- name: Add collection of users again with update_password on_create (idempotent) + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansible2 + + - name: ansible3 + configured_password: password + update_password: on_create + state: present + group: sysadmin + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + - result.xml | length == 0 + +- name: Delete collection of users + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansible1 + + - name: ansible2 + + - name: ansible3 + state: absent + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == true + - '"ansible1" in result.xml[0]' + - '"ansible2" in result.xml[0]' + - '"ansible3" in result.xml[0]' + +- name: Delete collection of users again (idempotent) + connection: ansible.netcommon.netconf + register: result + cisco.iosxr.iosxr_user: + aggregate: + + - name: ansible1 + + - name: ansible2 + + - name: ansible3 + state: absent + provider: '{{ netconf }}' + +- assert: + that: + - result.changed == false + - result.xml | length == 0 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/prepare_iosxr_tests/tasks/main.yml b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/prepare_iosxr_tests/tasks/main.yml new file mode 100644 index 00000000..8799387c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/prepare_iosxr_tests/tasks/main.yml @@ -0,0 +1,16 @@ +--- +- name: Ensure we have loopback 888 for testing + connection: ansible.netcommon.network_cli + cisco.iosxr.iosxr_config: + src: config.j2 + +- name: Enable Netconf service + connection: ansible.netcommon.network_cli + tags: netconf + cisco.iosxr.iosxr_netconf: + netconf_port: 830 + netconf_vrf: default + state: present + +- set_fact: + shorter_hostname: '{{ inventory_hostname_short| truncate(10, True, "") }}' diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/prepare_iosxr_tests/templates/config.j2 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/prepare_iosxr_tests/templates/config.j2 new file mode 100644 index 00000000..c8eb3457 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/integration/targets/prepare_iosxr_tests/templates/config.j2 @@ -0,0 +1,4 @@ +interface Loopback888 + description test for ansible + shutdown + diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.10.txt b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.10.txt new file mode 100644 index 00000000..195b00f6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.10.txt @@ -0,0 +1 @@ +plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.9.txt b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.9.txt new file mode 100644 index 00000000..89a6aac5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/sanity/ignore-2.9.txt @@ -0,0 +1,3 @@ +plugins/action/iosxr.py action-plugin-docs # base class for deprecated network platform modules using `connection: local +plugins/modules/iosxr_interface.py validate-modules:deprecation-mismatch # 2.9 expects METADATA +plugins/modules/iosxr_interface.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/sanity/requirements.txt b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/sanity/requirements.txt new file mode 100644 index 00000000..3e3a9669 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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/iosxr/tests/unit/__init__.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/compat/__init__.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/compat/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/compat/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/compat/builtins.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/compat/builtins.py new file mode 100644 index 00000000..bfc8adfb --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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/iosxr/tests/unit/compat/mock.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/compat/mock.py new file mode 100644 index 00000000..8d265c65 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/compat/mock.py @@ -0,0 +1,126 @@ +# (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 +import _io + +# 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: + 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/iosxr/tests/unit/compat/unittest.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/compat/unittest.py new file mode 100644 index 00000000..df3379b8 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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/iosxr/tests/unit/mock/__init__.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/mock/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/mock/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/mock/loader.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/mock/loader.py new file mode 100644 index 00000000..c21188ee --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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/iosxr/tests/unit/mock/path.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/mock/path.py new file mode 100644 index 00000000..8e9e368b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/mock/path.py @@ -0,0 +1,10 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type +from ansible_collections.cisco.iosxr.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/iosxr/tests/unit/mock/procenv.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/mock/procenv.py new file mode 100644 index 00000000..3c38a990 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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.iosxr.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/iosxr/tests/unit/mock/vault_helper.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/mock/vault_helper.py new file mode 100644 index 00000000..b34ae134 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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/iosxr/tests/unit/mock/yaml_helper.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/mock/yaml_helper.py new file mode 100644 index 00000000..5df30aae --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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/iosxr/tests/unit/modules/__init__.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/conftest.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/conftest.py new file mode 100644 index 00000000..e19a1e04 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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/iosxr/tests/unit/modules/network/__init__.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/__init__.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/__init__.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/__init__.py diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/dir_7all b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/dir_7all new file mode 100644 index 00000000..b992498c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/dir_7all @@ -0,0 +1,6 @@ +Directory of disk0: +file1 +file2 + +Directory of flash0: +file3 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_acls_config.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_acls_config.cfg new file mode 100644 index 00000000..d9c32dd6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_acls_config.cfg @@ -0,0 +1,5 @@ +ipv4 access-list acl_2 + 10 deny ipv4 any any + 20 permit tcp host 192.168.1.100 any +ipv6 access-list acl6_1 + 10 deny icmpv6 any any diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_config_config.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_config_config.cfg new file mode 100644 index 00000000..afad9d08 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_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/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_config_src.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_config_src.cfg new file mode 100644 index 00000000..b3d8961a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_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/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_ospf_interfaces.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_ospf_interfaces.cfg new file mode 100644 index 00000000..3f982bc1 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_ospf_interfaces.cfg @@ -0,0 +1,9 @@ +router ospf LAB3 + area 0.0.0.3 + interface GigabitEthernet0/0/0/0 + cost 20 + authentication message-digest keychain cisco + ! + ! +! + diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_ospfv2.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_ospfv2.cfg new file mode 100644 index 00000000..8645482e --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_ospfv2.cfg @@ -0,0 +1,8 @@ +Sun Jun 14 12:10:47.455 UTC +router ospf 30 + cost 2 + default-metric 10 + area 11 + default-cost 5 + ! +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_ospfv3.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_ospfv3.cfg new file mode 100644 index 00000000..b52c0ee0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_ospfv3.cfg @@ -0,0 +1,8 @@ +Sun Jun 14 12:10:47.455 UTC +router ospfv3 30 + cost 2 + default-metric 10 + area 11 + default-cost 5 + ! +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_static_routes_config.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_static_routes_config.cfg new file mode 100644 index 00000000..36c9eb23 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_static_routes_config.cfg @@ -0,0 +1,18 @@ +Fri Nov 29 21:10:41.896 UTC +router static + address-family ipv4 unicast + 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120 + 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1 + 192.0.2.32/28 192.0.2.11 100 + ! + address-family ipv6 unicast + 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC + 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1 + ! + vrf DEV_SITE + address-family ipv4 unicast + 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV + 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2 + ! + ! +!
\ No newline at end of file diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_system_config.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_system_config.cfg new file mode 100644 index 00000000..fc6fd2b7 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_system_config.cfg @@ -0,0 +1,8 @@ +hostname iosxr01 +domain name eng.ansible.com +domain lookup disable +domain lookup source-interface MgmtEth0/0/CPU0/0 +domain list redhat.com +domain list cisco.com +domain name-server 8.8.8.8 +domain name-server 8.8.4.4 diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_user_config.cfg b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_user_config.cfg new file mode 100644 index 00000000..0f0ab168 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/iosxr_user_config.cfg @@ -0,0 +1,8 @@ +username admin + secret 5 $1$mdQIUxjg$3t3lzBpfKfITKvFm1uEIY. + group sysadmin +! +username ansible + secret 5 $1$3yWSXiIi$VdzV59ChiurrNdGxlDeAW/ + group sysadmin +! diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_interfaces b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_interfaces new file mode 100644 index 00000000..d68907c0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_interfaces @@ -0,0 +1,41 @@ +Loopback0 is up, line protocol is up + Interface state transitions: 1 + Hardware is Loopback interface(s) + Description: Loopback + Internet address is 192.168.0.3/32 + MTU 1500 bytes, BW 0 Kbit + reliability Unknown, txload Unknown, rxload Unknown + Encapsulation Loopback, loopback not set, + Last link flapped 12w1d + Last input Unknown, output Unknown + Last clearing of "show interface" counters Unknown + Input/output data rate is disabled. + +GigabitEthernet0/0/0/0 is up, line protocol is up + Interface state transitions: 1 + Hardware is GigabitEthernet, address is fa16.3e6c.20bd (bia fa16.3e6c.20bd) + Description: to nxos01 + Internet address is 10.0.0.5/30 + MTU 1514 bytes, BW 1000000 Kbit (Max: 1000000 Kbit) + reliability 255/255, txload 0/255, rxload 0/255 + Encapsulation ARPA, + Full-duplex, 1000Mb/s, unknown, link type is force-up + output flow control is off, input flow control is off + Carrier delay (up) is 10 msec + loopback not set, + Last link flapped 12w1d + ARP type ARPA, ARP timeout 04:00:00 + Last input 00:00:44, output 00:12:45 + Last clearing of "show interface" counters never + 5 minute input rate 0 bits/sec, 0 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 150700 packets input, 36897055 bytes, 0 total input drops + 0 drops for unrecognized upper-level protocol + Received 1 broadcast packets, 150445 multicast packets + 0 runts, 0 giants, 0 throttles, 0 parity + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort + 11691 packets output, 2904632 bytes, 0 total output drops + Output 1 broadcast packets, 11436 multicast packets + 0 output errors, 0 underruns, 0 applique, 0 resets + 0 output buffer failures, 0 output buffers swapped out + 1 carrier transitions diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_ipv6_interface b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_ipv6_interface new file mode 100644 index 00000000..971d1f65 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_ipv6_interface @@ -0,0 +1,5 @@ +Loopback0 is Up, ipv6 protocol is Up, Vrfid is default (0x60000000) + IPv6 is disabled, link-local address unassigned + No global unicast address is configured +GigabitEthernet0/0/0/0 is Up, ipv6 protocol is Up, Vrfid is default (0x60000000) + IPv6 is disabled, link-local address unassigned diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_lldp b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_lldp new file mode 100644 index 00000000..60ab287f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_lldp @@ -0,0 +1 @@ +% LLDP is not enabled diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_lldp_neighbors_detail b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_lldp_neighbors_detail new file mode 100644 index 00000000..60ab287f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_lldp_neighbors_detail @@ -0,0 +1 @@ +% LLDP is not enabled diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_memory_summary b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_memory_summary new file mode 100644 index 00000000..b26abeae --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_memory_summary @@ -0,0 +1,5 @@ +Physical Memory: 3095M total (1499M available) + Application Memory : 2893M (1499M available) + Image: 73M (bootram: 73M) + Reserved: 128M, IOMem: 0, flashfsys: 0 + Total shared window: 23M diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_running-config b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_running-config new file mode 100644 index 00000000..085baef4 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_running-config @@ -0,0 +1,43 @@ +hostname iosxr01 +service timestamps log datetime msec +service timestamps debug datetime msec +telnet vrf default ipv4 server max-servers 10 +telnet vrf Mgmt-intf ipv4 server max-servers 10 +domain name eng.ansible.com +domain lookup disable +vrf Mgmt-intf + address-family ipv4 unicast + ! + address-family ipv6 unicast + ! +! +line template vty + timestamp + exec-timeout 720 0 +! +line console + exec-timeout 0 0 +! +line default + exec-timeout 720 0 +! +vty-pool default 0 50 +control-plane + management-plane + inband + interface all + allow all + ! + ! + ! +! +interface Loopback0 + description Loopback + ipv4 address 192.168.0.1 255.255.255.255 +! +interface GigabitEthernet0/0/0/0 + description to nxos01 + cdp + ipv4 address 10.0.0.1 255.255.255.252 +! +end diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_version b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_version new file mode 100644 index 00000000..faecfffd --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_version @@ -0,0 +1,84 @@ +Cisco IOS XR Software, Version 6.0.0[Default] +Copyright (c) 2015 by Cisco Systems, Inc. + +ROM: GRUB, Version 1.99(0), DEV RELEASE + +iosxr01 uptime is 11 weeks, 2 days, 5 hours, 48 minutes +System image file is "bootflash:disk0/xrvr-os-mbi-6.0.0/mbixrvr-rp.vm" + +cisco IOS XRv Series (Pentium Celeron Stepping 3) processor with 3169911K bytes of memory. +Pentium Celeron Stepping 3 processor at 3836MHz, Revision 2.174 +IOS XRv Chassis + +1 Management Ethernet +6 GigabitEthernet +97070k bytes of non-volatile configuration memory. +866M bytes of hard disk. +2321392k bytes of disk0: (Sector size 512 bytes). + +Configuration register on node 0/0/CPU0 is 0x2102 +Boot device on node 0/0/CPU0 is disk0: +Package active on node 0/0/CPU0: +iosxr-infra, V 6.0.0[Default], Cisco Systems, at disk0:iosxr-infra-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +iosxr-fwding, V 6.0.0[Default], Cisco Systems, at disk0:iosxr-fwding-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +iosxr-routing, V 6.0.0[Default], Cisco Systems, at disk0:iosxr-routing-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +iosxr-ce, V 6.0.0[Default], Cisco Systems, at disk0:iosxr-ce-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +xrvr-os-mbi, V 6.0.0[Default], Cisco Systems, at disk0:xrvr-os-mbi-6.0.0 + Built on Thu Dec 24 08:54:41 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +xrvr-base, V 6.0.0[Default], Cisco Systems, at disk0:xrvr-base-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +xrvr-fwding, V 6.0.0[Default], Cisco Systems, at disk0:xrvr-fwding-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +xrvr-mgbl-x, V 6.0.0[Default], Cisco Systems, at disk0:xrvr-mgbl-x-6.0.0 + Built on Thu Dec 24 08:53:57 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +iosxr-mpls, V 6.0.0[Default], Cisco Systems, at disk0:iosxr-mpls-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +iosxr-mgbl, V 6.0.0[Default], Cisco Systems, at disk0:iosxr-mgbl-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +iosxr-mcast, V 6.0.0[Default], Cisco Systems, at disk0:iosxr-mcast-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +xrvr-mcast-supp, V 6.0.0[Default], Cisco Systems, at disk0:xrvr-mcast-supp-6.0.0 + Built on Thu Dec 24 08:53:49 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +iosxr-bng, V 6.0.0[Default], Cisco Systems, at disk0:iosxr-bng-6.0.0 + Built on Thu Dec 24 08:53:47 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +xrvr-bng-supp, V 6.0.0[Default], Cisco Systems, at disk0:xrvr-bng-supp-6.0.0 + Built on Thu Dec 24 08:53:47 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +iosxr-security, V 6.0.0[Default], Cisco Systems, at disk0:iosxr-security-6.0.0 + Built on Thu Dec 24 08:53:41 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie + +xrvr-fullk9-x, V 6.0.0[Default], Cisco Systems, at disk0:xrvr-fullk9-x-6.0.0 + Built on Thu Dec 24 08:55:12 UTC 2015 + By iox-lnx-010 in /auto/srcarchive16/production/6.0.0/xrvr/workspace for pie diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_version___utility_head_-n_20 b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_version___utility_head_-n_20 new file mode 100644 index 00000000..7f82039f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_version___utility_head_-n_20 @@ -0,0 +1,18 @@ +Cisco IOS XR Software, Version 6.0.0[Default] +Copyright (c) 2015 by Cisco Systems, Inc. + +ROM: GRUB, Version 1.99(0), DEV RELEASE + +iosxr01 uptime is 11 weeks, 6 days, 2 hours, 2 minutes +System image file is "bootflash:disk0/xrvr-os-mbi-6.0.0/mbixrvr-rp.vm" + +cisco IOS XRv Series (Pentium Celeron Stepping 3) processor with 3169911K bytes +of memory. +Pentium Celeron Stepping 3 processor at 3836MHz, Revision 2.174 +IOS XRv Chassis + +1 Management Ethernet +6 GigabitEthernet +97070k bytes of non-volatile configuration memory. +866M bytes of hard disk. +2321392k bytes of disk0: (Sector size 512 bytes). diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_version_brief b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_version_brief new file mode 100644 index 00000000..7f82039f --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/fixtures/show_version_brief @@ -0,0 +1,18 @@ +Cisco IOS XR Software, Version 6.0.0[Default] +Copyright (c) 2015 by Cisco Systems, Inc. + +ROM: GRUB, Version 1.99(0), DEV RELEASE + +iosxr01 uptime is 11 weeks, 6 days, 2 hours, 2 minutes +System image file is "bootflash:disk0/xrvr-os-mbi-6.0.0/mbixrvr-rp.vm" + +cisco IOS XRv Series (Pentium Celeron Stepping 3) processor with 3169911K bytes +of memory. +Pentium Celeron Stepping 3 processor at 3836MHz, Revision 2.174 +IOS XRv Chassis + +1 Management Ethernet +6 GigabitEthernet +97070k bytes of non-volatile configuration memory. +866M bytes of hard disk. +2321392k bytes of disk0: (Sector size 512 bytes). diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/iosxr_module.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/iosxr_module.py new file mode 100644 index 00000000..728c071c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/iosxr_module.py @@ -0,0 +1,105 @@ +# (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.iosxr.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 TestIosxrModule(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/iosxr/tests/unit/modules/network/iosxr/test_iosxr_acls.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_acls.py new file mode 100644 index 00000000..ab265fbf --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_acls.py @@ -0,0 +1,361 @@ +# +# (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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_acls +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture + + +class TestIosxrAclsModule(TestIosxrModule): + module = iosxr_acls + + def setUp(self): + super(TestIosxrAclsModule, 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_execute_show_command = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.acls.acls.AclsFacts.get_device_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosxrAclsModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def _prepare(self): + def load_from_file(*args, **kwargs): + return load_fixture("iosxr_acls_config.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_iosxr_acls_merged(self): + self._prepare() + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="acl_1", + aces=[ + dict( + sequence="10", + grant="permit", + protocol="ospf", + source=dict(prefix="192.168.1.0/24"), + destination=dict(any="true"), + log="true", + ) + ], + ) + ], + ) + ], + state="merged", + ) + ) + commands = [ + "ipv4 access-list acl_1", + "10 permit ospf 192.168.1.0 0.0.0.255 any log", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_acls_merged_idempotent(self): + self._prepare() + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="acl_2", + aces=[ + dict( + sequence="10", + grant="deny", + protocol="ipv4", + destination=dict(any="true"), + source=dict(any="true"), + ) + ], + ) + ], + ) + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_acls_replaced(self): + self._prepare() + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="acl_2", + aces=[ + dict( + sequence="30", + grant="permit", + protocol="ospf", + source=dict(prefix="10.0.0.0/8"), + destination=dict(any="true"), + log="true", + ) + ], + ) + ], + ) + ], + state="replaced", + ) + ) + commands = [ + "ipv4 access-list acl_2", + "no 10", + "no 20", + "30 permit ospf 10.0.0.0 0.255.255.255 any log", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_acls_replaced_idempotent(self): + self._prepare() + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="acl_2", + aces=[ + dict( + sequence="10", + grant="deny", + protocol="ipv4", + destination=dict(any="true"), + source=dict(any="true"), + ), + dict( + sequence="20", + grant="permit", + protocol="tcp", + destination=dict(any="true"), + source=dict(host="192.168.1.100"), + ), + ], + ) + ], + ) + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_acls_overridden(self): + self._prepare() + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="acl_2", + aces=[ + dict( + sequence="40", + grant="permit", + protocol="ospf", + source=dict(any="true"), + destination=dict(any="true"), + log="true", + ) + ], + ) + ], + ) + ], + state="overridden", + ) + ) + commands = [ + "no ipv6 access-list acl6_1", + "ipv4 access-list acl_2", + "no 10", + "no 20", + "40 permit ospf any any log", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_acls_overridden_idempotent(self): + self._prepare() + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="acl_2", + aces=[ + dict( + sequence="10", + grant="deny", + protocol="ipv4", + destination=dict(any="true"), + source=dict(any="true"), + ), + dict( + sequence="20", + grant="permit", + protocol="tcp", + destination=dict(any="true"), + source=dict(host="192.168.1.100"), + ), + ], + ) + ], + ), + dict( + afi="ipv6", + acls=[ + dict( + name="acl6_1", + aces=[ + dict( + sequence="10", + grant="deny", + protocol="icmpv6", + destination=dict(any="true"), + source=dict(any="true"), + ) + ], + ) + ], + ), + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_acls_deletedacls(self): + self._prepare() + set_module_args( + dict( + config=[dict(afi="ipv6", acls=[dict(name="acl6_1")])], + state="deleted", + ) + ) + commands = ["no ipv6 access-list acl6_1"] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_acls_deletedafis(self): + self._prepare() + set_module_args(dict(config=[dict(afi="ipv4")], state="deleted")) + commands = ["no ipv4 access-list acl_2"] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_acls_rendered(self): + self._prepare() + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="acl_2", + aces=[ + dict( + grant="permit", + source=dict(any="true"), + destination=dict(any="true"), + protocol="igmp", + ) + ], + ) + ], + ) + ], + state="rendered", + ) + ) + commands = ["ipv4 access-list acl_2", "permit igmp any any"] + result = self.execute_module(changed=False) + self.assertEqual( + sorted(result["rendered"]), sorted(commands), result["rendered"] + ) + + def test_iosxr_acls_overridden_on_empty_config(self): + self.execute_show_command.return_value = "" + set_module_args( + dict( + config=[ + dict( + afi="ipv4", + acls=[ + dict( + name="acl_1", + aces=[ + dict( + sequence="10", + grant="deny", + source=dict(any=True), + destination=dict(any=True), + protocol="ip", + ) + ], + ) + ], + ) + ], + state="overridden", + ) + ) + cmds = ["ipv4 access-list acl_1", "10 deny ip any any"] + self.execute_module(changed=True, commands=cmds) diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_command.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_command.py new file mode 100644 index 00000000..8b149c5c --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_command.py @@ -0,0 +1,128 @@ +# (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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_command +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture + + +class TestIosxrCommandModule(TestIosxrModule): + + module = iosxr_command + + def setUp(self): + super(TestIosxrCommandModule, self).setUp() + + self.mock_run_commands = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_command.run_commands" + ) + self.run_commands = self.mock_run_commands.start() + + def tearDown(self): + super(TestIosxrCommandModule, 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: + command = item["command"] + except Exception: + command = item + filename = str(command).replace(" ", "_") + output.append(load_fixture(filename)) + return output + + self.run_commands.side_effect = load_from_file + + def test_iosxr_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 XR Software") + ) + + def test_iosxr_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 XR Software") + ) + + def test_iosxr_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_iosxr_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_iosxr_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_iosxr_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_iosxr_command_match_all(self): + wait_for = [ + 'result[0] contains "Cisco IOS"', + 'result[0] contains "XR Software"', + ] + set_module_args( + dict(commands=["show version"], wait_for=wait_for, match="all") + ) + self.execute_module() + + def test_iosxr_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) diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_config.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_config.py new file mode 100644 index 00000000..ee7499b5 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_config.py @@ -0,0 +1,308 @@ +# +# (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.iosxr.tests.unit.compat.mock import ( + patch, + MagicMock, +) +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_config +from ansible_collections.cisco.iosxr.plugins.cliconf.iosxr import Cliconf +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture + + +class TestIosxrConfigModule(TestIosxrModule): + + module = iosxr_config + + def setUp(self): + super(TestIosxrConfigModule, self).setUp() + + self.patcher_get_config = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_config.get_config" + ) + self.mock_get_config = self.patcher_get_config.start() + + self.patcher_exec_command = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_config.load_config" + ) + self.mock_exec_command = self.patcher_exec_command.start() + + self.mock_get_connection = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_config.get_connection" + ) + self.get_connection = self.mock_get_connection.start() + + self.conn = self.get_connection() + self.conn.edit_config = MagicMock() + + self.cliconf_obj = Cliconf(MagicMock()) + self.running_config = load_fixture("iosxr_config_config.cfg") + + def tearDown(self): + super(TestIosxrConfigModule, self).tearDown() + + self.patcher_get_config.stop() + self.patcher_exec_command.stop() + self.mock_get_connection.stop() + + def load_fixtures(self, commands=None): + config_file = "iosxr_config_config.cfg" + self.mock_get_config.return_value = load_fixture(config_file) + self.mock_exec_command.return_value = "dummy diff" + + def test_iosxr_config_unchanged(self): + src = load_fixture("iosxr_config_config.cfg") + set_module_args(dict(src=src)) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff(src, src) + ) + self.execute_module() + + def test_iosxr_config_src(self): + src = load_fixture("iosxr_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_iosxr_config_backup(self): + set_module_args(dict(backup=True)) + result = self.execute_module() + self.assertIn("__backup__", result) + + def test_iosxr_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_iosxr_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 = iosxr_config.get_candidate(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_iosxr_config_before(self): + lines = ["hostname foo"] + set_module_args(dict(lines=lines, before=["test1", "test2"])) + commands = ["test1", "test2", "hostname foo"] + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), self.running_config + ) + ) + self.execute_module(changed=True, commands=commands, sort=False) + + def test_iosxr_config_after(self): + lines = ["hostname foo"] + set_module_args(dict(lines=lines, after=["test1", "test2"])) + commands = ["hostname foo", "test1", "test2"] + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), self.running_config + ) + ) + self.execute_module(changed=True, commands=commands, sort=False) + + def test_iosxr_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_iosxr_config_config(self): + config = "hostname localhost" + lines = ["hostname router"] + set_module_args(dict(lines=["hostname router"], 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_iosxr_config_replace_block(self): + lines = ["description test string", "test string"] + parents = ["interface GigabitEthernet0/0"] + set_module_args(dict(lines=lines, replace="block", parents=parents)) + commands = parents + lines + + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = iosxr_config.get_candidate(module) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + diff_replace="block", + path=parents, + ) + ) + self.execute_module(changed=True, commands=commands) + + def test_iosxr_config_force(self): + lines = ["hostname router"] + set_module_args(dict(lines=lines, force=True)) + 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_iosxr_config_admin(self): + lines = ["username admin", "group root-system", "secret P@ssw0rd"] + set_module_args(dict(lines=lines, admin=True)) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), self.running_config + ) + ) + self.execute_module(changed=True, commands=lines) + + def test_iosxr_config_match_none(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")) + commands = parents + lines + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = iosxr_config.get_candidate(module) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + diff_match="none", + path=parents, + ) + ) + + self.execute_module(changed=True, commands=commands, sort=False) + + def test_iosxr_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")) + commands = parents + ["shutdown"] + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = iosxr_config.get_candidate(module) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + diff_match="strict", + path=parents, + ) + ) + + self.execute_module(changed=True, commands=commands, sort=False) + + def test_iosxr_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")) + commands = parents + lines + module = MagicMock() + module.params = {"lines": lines, "parents": parents, "src": None} + candidate_config = iosxr_config.get_candidate(module) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + diff_match="exact", + path=parents, + ) + ) + + self.execute_module(changed=True, commands=commands, sort=False) + + def test_iosxr_config_src_and_lines_fails(self): + args = dict(src="foo", lines="foo") + set_module_args(args) + self.execute_module(failed=True) + + def test_iosxr_config_src_and_parents_fails(self): + args = dict(src="foo", parents="foo") + set_module_args(args) + self.execute_module(failed=True) + + def test_iosxr_config_match_exact_requires_lines(self): + args = dict(match="exact") + set_module_args(args) + self.execute_module(failed=True) + + def test_iosxr_config_match_strict_requires_lines(self): + args = dict(match="strict") + set_module_args(args) + self.execute_module(failed=True) + + def test_iosxr_config_replace_block_requires_lines(self): + args = dict(replace="block") + set_module_args(args) + self.execute_module(failed=True) + + def test_iosxr_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/iosxr/tests/unit/modules/network/iosxr/test_iosxr_facts.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_facts.py new file mode 100644 index 00000000..95951850 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_facts.py @@ -0,0 +1,117 @@ +# (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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_facts + + +class TestIosxrFacts(TestIosxrModule): + + module = iosxr_facts + + def setUp(self): + super(TestIosxrFacts, self).setUp() + + self.mock_run_commands = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.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.iosxr.plugins.module_utils.network.iosxr.facts.legacy.base.get_capabilities" + ) + self.get_capabilities = self.mock_get_capabilities.start() + self.get_capabilities.return_value = { + "device_info": { + "network_os": "iosxr", + "network_os_hostname": "iosxr01", + "network_os_image": "bootflash:disk0/xrvr-os-mbi-6.1.3/mbixrvr-rp.vm", + "network_os_version": "6.1.3[Default]", + }, + "network_api": "cliconf", + } + + def tearDown(self): + super(TestIosxrFacts, self).tearDown() + + self.mock_run_commands.stop() + self.mock_get_capabilities.stop() + self.mock_get_resource_connection.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 = obj["command"] + except ValueError: + command = item + filename = str(command).replace(" ", "_") + filename = filename.replace("/", "7") + filename = filename.replace("|", "_") + output.append(load_fixture(filename)) + return output + + self.run_commands.side_effect = load_from_file + + def test_iosxr_facts_gather_subset_default(self): + set_module_args(dict()) + result = self.execute_module() + ansible_facts = result["ansible_facts"] + self.assertIn("hardware", ansible_facts["ansible_net_gather_subset"]) + self.assertIn("default", ansible_facts["ansible_net_gather_subset"]) + self.assertIn("interfaces", ansible_facts["ansible_net_gather_subset"]) + self.assertEqual("iosxr01", ansible_facts["ansible_net_hostname"]) + self.assertEqual( + ["disk0:", "flash0:"], ansible_facts["ansible_net_filesystems"] + ) + self.assertIn( + "GigabitEthernet0/0/0/0", + ansible_facts["ansible_net_interfaces"].keys(), + ) + self.assertEqual("3095", ansible_facts["ansible_net_memtotal_mb"]) + self.assertEqual("1499", ansible_facts["ansible_net_memfree_mb"]) + + def test_iosxr_facts_gather_subset_config(self): + set_module_args({"gather_subset": "config"}) + result = self.execute_module() + ansible_facts = result["ansible_facts"] + self.assertIn("default", ansible_facts["ansible_net_gather_subset"]) + self.assertIn("config", ansible_facts["ansible_net_gather_subset"]) + self.assertEqual("iosxr01", ansible_facts["ansible_net_hostname"]) + self.assertIn("ansible_net_config", ansible_facts) diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_netconf.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_netconf.py new file mode 100644 index 00000000..3e8a3473 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_netconf.py @@ -0,0 +1,114 @@ +# (c) 2017 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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_netconf +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule + + +class TestIosxrNetconfModule(TestIosxrModule): + + module = iosxr_netconf + + def setUp(self): + super(TestIosxrNetconfModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_netconf.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_netconf.load_config" + ) + self.load_config = self.mock_load_config.start() + + def tearDown(self): + super(TestIosxrNetconfModule, self).tearDown() + self.mock_get_config.stop() + self.mock_load_config.stop() + + def test_iosxr_disable_netconf_service(self): + self.get_config.return_value = """ + netconf-yang agent + ssh + ! + ssh server netconf vrf default + """ + self.load_config.return_value = "dummy diff" + set_module_args( + dict(netconf_port=830, netconf_vrf="default", state="absent") + ) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "no netconf-yang agent ssh", + "no ssh server netconf port 830", + "no ssh server netconf vrf default", + ], + ) + + def test_iosxr_enable_netconf_service(self): + self.get_config.return_value = "" + self.load_config.return_value = "dummy diff" + set_module_args( + dict(netconf_port=830, netconf_vrf="default", state="present") + ) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + [ + "netconf-yang agent ssh", + "ssh server netconf port 830", + "ssh server netconf vrf default", + ], + ) + + def test_iosxr_change_netconf_port(self): + self.get_config.return_value = """ + netconf-yang agent + ssh + ! + ssh server netconf vrf default + """ + self.load_config.return_value = "dummy diff" + set_module_args(dict(netconf_port=9000, state="present")) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["ssh server netconf port 9000"]) + + def test_iosxr_change_netconf_vrf(self): + self.get_config.return_value = """ + netconf-yang agent + ssh + ! + ssh server netconf vrf default + """ + self.load_config.return_value = "dummy diff" + set_module_args(dict(netconf_vrf="new_default", state="present")) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], ["ssh server netconf vrf new_default"] + ) diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py new file mode 100644 index 00000000..e5cc74ae --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospf_interfaces.py @@ -0,0 +1,358 @@ +# +# (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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.plugins.modules import ( + iosxr_ospf_interfaces, +) +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture + + +class TestIosxrOspf_InterfacesModule(TestIosxrModule): + module = iosxr_ospf_interfaces + + def setUp(self): + super(TestIosxrOspf_InterfacesModule, 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.iosxr.plugins.module_utils.network.iosxr.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.ospf_interfaces.ospf_interfaces." + "Ospf_interfacesFacts.get_ospf_interfaces" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosxrOspf_InterfacesModule, 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("iosxr_ospf_interfaces.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_iosxr_ospf_interfaces_merged(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/0/0/1", + type="gigabitethernet", + address_family=[ + dict( + afi="ipv4", + processes=[ + dict( + process_id="LAB1", + area=dict(area_id="0.0.0.3"), + ) + ], + cost=10, + authentication=dict( + message_digest=dict(keychain="iosxr") + ), + ) + ], + ) + ], + state="merged", + ) + ) + commands = [ + "router ospf LAB1 area 0.0.0.3 interface GigabitEthernet 0/0/0/1 cost 10", + "router ospf LAB1 area 0.0.0.3 interface GigabitEthernet 0/0/0/1 authentication message-digest", + "router ospf LAB1 area 0.0.0.3 interface GigabitEthernet 0/0/0/1 authentication message-digest keychain iosxr", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospf_interfaces_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/0/0/0", + type="gigabitethernet", + address_family=[ + dict( + afi="ipv4", + processes=[ + dict( + process_id="LAB3", + area=dict(area_id="0.0.0.3"), + ) + ], + cost=20, + authentication=dict( + message_digest=dict(keychain="cisco") + ), + ) + ], + ) + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospf_interfaces_replaced(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/0/0/0", + type="gigabitethernet", + address_family=[ + dict( + afi="ipv4", + processes=[ + dict( + process_id="LAB3", + area=dict(area_id="0.0.0.3"), + ) + ], + cost=40, + authentication=dict( + message_digest=dict(keychain="ciscoiosxr") + ), + ) + ], + ) + ], + state="replaced", + ) + ) + commands = [ + "router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 cost 40", + "router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 authentication message-digest", + "router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0 authentication message-digest keychain ciscoiosxr", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospf_interfaces_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/0/0/0", + type="gigabitethernet", + address_family=[ + dict( + afi="ipv4", + processes=[ + dict( + process_id="LAB3", + area=dict(area_id="0.0.0.3"), + ) + ], + cost=20, + authentication=dict( + message_digest=dict(keychain="cisco") + ), + ) + ], + ) + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospf_interfaces_overridden(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/0/0/4", + type="gigabitethernet", + address_family=[ + dict( + afi="ipv4", + processes=[ + dict( + process_id="LAB4", + area=dict(area_id="0.0.0.4"), + ) + ], + cost=40, + authentication=dict( + message_digest=dict(keychain="iosxr") + ), + ) + ], + ) + ], + state="overridden", + ) + ) + + commands = [ + "no router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0", + "router ospf LAB4 area 0.0.0.4 interface GigabitEthernet 0/0/0/4 cost 40", + "router ospf LAB4 area 0.0.0.4 interface GigabitEthernet 0/0/0/4 authentication message-digest", + "router ospf LAB4 area 0.0.0.4 interface GigabitEthernet 0/0/0/4 authentication message-digest keychain iosxr", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospf_interfaces_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/0/0/0", + type="gigabitethernet", + address_family=[ + dict( + afi="ipv4", + processes=[ + dict( + process_id="LAB3", + area=dict(area_id="0.0.0.3"), + ) + ], + cost=20, + authentication=dict( + message_digest=dict(keychain="cisco") + ), + ) + ], + ) + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospf_interfaces_deleted(self): + set_module_args( + dict( + config=[ + dict(name="GigabitEthernet0/0/0/0", type="gigabitethernet") + ], + state="deleted", + ) + ) + commands = [ + "no router ospf LAB3 area 0.0.0.3 interface GigabitEthernet 0/0/0/0" + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospf_interfaces_deleted_idempotent(self): + set_module_args( + dict( + config=[ + dict(name="GigabitEthernet0/0/0/1", type="gigabitethernet") + ], + state="deleted", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospf_interfaces_parsed(self): + set_module_args( + dict( + running_config="router ospf LAB3\n area 0.0.0.3\n interface GigabitEthernet0/0/0/0\n cost 20\n !\n !\n!", + state="parsed", + ) + ) + result = self.execute_module(changed=False) + parsed_list = [ + dict( + name="GigabitEthernet0/0/0/0", + type="gigabitethernet", + address_family=[ + dict( + afi="ipv4", + processes=[ + dict( + process_id="LAB3", area=dict(area_id="0.0.0.3") + ) + ], + cost=20, + ) + ], + ) + ] + self.assertEqual(parsed_list, result["parsed"]) + + def test_iosxr_ospf_interfaces_rendered(self): + set_module_args( + dict( + config=[ + dict( + name="GigabitEthernet0/0/0/1", + type="gigabitethernet", + address_family=[ + dict( + afi="ipv4", + processes=[ + dict( + process_id="LAB1", + area=dict(area_id="0.0.0.3"), + ) + ], + cost=10, + authentication=dict( + message_digest=dict(keychain="iosxr") + ), + ) + ], + ) + ], + state="rendered", + ) + ) + commands = [ + "router ospf LAB1 area 0.0.0.3 interface GigabitEthernet 0/0/0/1 cost 10", + "router ospf LAB1 area 0.0.0.3 interface GigabitEthernet 0/0/0/1 authentication message-digest", + "router ospf LAB1 area 0.0.0.3 interface GigabitEthernet 0/0/0/1 authentication message-digest keychain iosxr", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(commands)) diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py new file mode 100644 index 00000000..876cd3e2 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv2.py @@ -0,0 +1,275 @@ +# +# (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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_ospfv2 +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture + + +class TestIosxrOspfV2Module(TestIosxrModule): + module = iosxr_ospfv2 + + def setUp(self): + super(TestIosxrOspfV2Module, 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.iosxr.plugins.module_utils.network.iosxr.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.ospfv2.ospfv2." + "Ospfv2Facts.get_ospfv2_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosxrOspfV2Module, 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("iosxr_ospfv2.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_iosxr_ospfv2_merged(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="300", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="merged", + ) + ) + commands = [ + "router ospf 300", + "cost 2", + "default-metric 10", + "area 11 default-cost 5", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospfv2_merged_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="30", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospfv2_replaced(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="30", + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ), + dict( + process_id="40", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ), + ] + ), + state="replaced", + ) + ) + commands = [ + "router ospf 30", + "no default-metric 10", + "router ospf 40", + "cost 2", + "default-metric 10", + "area 11 default-cost 5", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospfv2_replaced_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="30", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospfv2_overridden(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="40", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="overridden", + ) + ) + + commands = [ + "router ospf 30", + "no cost 2", + "no default-metric 10", + "no area 11 default-cost 5", + "router ospf 40", + "cost 2", + "default-metric 10", + "area 11 default-cost 5", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospfv2_overridden_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="30", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospfv2_deleted(self): + set_module_args( + dict( + config=dict(processes=[dict(process_id="30", cost=2)]), + state="deleted", + ) + ) + commands = [ + "router ospf 30", + "no cost 2", + "no default-metric 10", + "no area 11 default-cost 5", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospfv2_parsed(self): + set_module_args( + dict( + running_config="router ospf 50\n cost 2\n area 11\n default-cost 5\n !\n!", + state="parsed", + ) + ) + result = self.execute_module(changed=False) + parsed_list = { + "processes": [ + dict( + process_id="50", + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + } + self.assertEqual(parsed_list, result["parsed"]) + + def test_iosxr_ospfv2_rendered(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="60", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="rendered", + ) + ) + commands = [ + "area 11 default-cost 5", + "cost 2", + "default-metric 10", + "router ospf 60", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), commands) diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py new file mode 100644 index 00000000..229fe68a --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_ospfv3.py @@ -0,0 +1,275 @@ +# +# (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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_ospfv3 +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture + + +class TestIosxrOspfV3Module(TestIosxrModule): + module = iosxr_ospfv3 + + def setUp(self): + super(TestIosxrOspfV3Module, 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.iosxr.plugins.module_utils.network.iosxr.providers.providers.CliProvider.edit_config" + ) + self.edit_config = self.mock_edit_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.ospfv3.ospfv3." + "Ospfv3Facts.get_ospfv3_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosxrOspfV3Module, 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("iosxr_ospfv3.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_iosxr_ospfv3_merged(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="300", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="merged", + ) + ) + commands = [ + "router ospfv3 300", + "cost 2", + "default-metric 10", + "area 11 default-cost 5", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospfv3_merged_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="30", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospfv3_replaced(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="30", + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ), + dict( + process_id="40", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ), + ] + ), + state="replaced", + ) + ) + commands = [ + "router ospfv3 30", + "no default-metric 10", + "router ospfv3 40", + "cost 2", + "default-metric 10", + "area 11 default-cost 5", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospfv3_replaced_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="30", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospfv3_overridden(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="40", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="overridden", + ) + ) + + commands = [ + "router ospfv3 30", + "no cost 2", + "no default-metric 10", + "no area 11 default-cost 5", + "router ospfv3 40", + "cost 2", + "default-metric 10", + "area 11 default-cost 5", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospfv3_overridden_idempotent(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="30", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_ospfv3_deleted(self): + set_module_args( + dict( + config=dict(processes=[dict(process_id="30", cost=2)]), + state="deleted", + ) + ) + commands = [ + "router ospfv3 30", + "no cost 2", + "no default-metric 10", + "no area 11 default-cost 5", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_iosxr_ospfv3_parsed(self): + set_module_args( + dict( + running_config="router ospfv3 50\n cost 2\n area 11\n default-cost 5\n !\n!", + state="parsed", + ) + ) + result = self.execute_module(changed=False) + parsed_list = { + "processes": [ + dict( + process_id="50", + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + } + self.assertEqual(parsed_list, result["parsed"]) + + def test_iosxr_ospfv3_rendered(self): + set_module_args( + dict( + config=dict( + processes=[ + dict( + process_id="60", + default_metric=10, + cost=2, + areas=[dict(area_id="11", default_cost=5)], + ) + ] + ), + state="rendered", + ) + ) + commands = [ + "area 11 default-cost 5", + "cost 2", + "default-metric 10", + "router ospfv3 60", + ] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), commands) diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py new file mode 100644 index 00000000..448078be --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_static_routes.py @@ -0,0 +1,338 @@ +# +# (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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_static_routes +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture + + +class TestIosxrStaticRoutesModule(TestIosxrModule): + module = iosxr_static_routes + + def setUp(self): + super(TestIosxrStaticRoutesModule, 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_execute_show_command = patch( + "ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.static_routes.static_routes.Static_routesFacts.get_device_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosxrStaticRoutesModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.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("iosxr_static_routes_config.cfg") + + self.execute_show_command.side_effect = load_from_file + + def test_iosxr_static_routes_merged(self): + set_module_args( + dict( + config=[ + dict( + vrf="dev_site", + address_families=[ + dict( + afi="ipv6", + safi="unicast", + routes=[ + dict( + dest="1200:10::/64", + next_hops=[ + dict( + interface="GigabitEthernet0/0/0/1", + admin_distance=55, + ) + ], + ) + ], + ) + ], + ) + ], + state="merged", + ) + ) + commands = [ + "router static", + "vrf dev_site", + "address-family ipv6 unicast", + "1200:10::/64 GigabitEthernet0/0/0/1 55", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_static_routes_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + vrf="DEV_SITE", + address_families=[ + dict( + afi="ipv4", + safi="unicast", + routes=[ + dict( + dest="192.0.2.48/28", + next_hops=[ + dict( + interface="192.0.2.12", + description="DEV", + dest_vrf="test_1", + ) + ], + ) + ], + ) + ], + ) + ], + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_static_routes_default(self): + set_module_args( + dict( + config=[ + dict( + address_families=[ + dict( + afi="ipv4", + safi="unicast", + routes=[ + dict( + dest="192.168.1.0/24", + next_hops=[ + dict( + interface="GigabitEthernet0/0/0/2", + track="ip_sla_2", + vrflabel=1200, + ) + ], + ) + ], + ) + ] + ) + ] + ) + ) + commands = [ + "router static", + "address-family ipv4 unicast", + "192.168.1.0/24 GigabitEthernet0/0/0/2 track ip_sla_2 vrflabel 1200", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_static_routes_default_idempotent(self): + set_module_args( + dict( + config=[ + dict( + address_families=[ + dict( + afi="ipv4", + safi="unicast", + routes=[ + dict( + dest="192.0.2.32/28", + next_hops=[ + dict( + forward_router_address="192.0.2.11", + admin_distance=100, + ) + ], + ) + ], + ) + ] + ) + ] + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_static_routes_replaced(self): + set_module_args( + dict( + config=[ + dict( + address_families=[ + dict( + afi="ipv4", + safi="unicast", + routes=[ + dict( + dest="192.0.2.16/28", + next_hops=[ + dict( + forward_router_address="192.0.2.11", + admin_distance=100, + ) + ], + ) + ], + ) + ] + ) + ], + state="replaced", + ) + ) + commands = [ + "router static", + "address-family ipv4 unicast", + "no 192.0.2.16/28 192.0.2.10 FastEthernet0/0/0/1", + "no 192.0.2.16/28 FastEthernet0/0/0/5", + "192.0.2.16/28 192.0.2.11 100", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_static_routes_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + address_families=[ + dict( + afi="ipv4", + safi="unicast", + routes=[ + dict( + dest="192.0.2.16/28", + next_hops=[ + dict( + interface="FastEthernet0/0/0/5", + track="ip_sla_1", + ), + dict( + interface="FastEthernet0/0/0/1", + forward_router_address="192.0.2.10", + tag=10, + description="LAB", + metric=120, + ), + ], + ) + ], + ) + ] + ) + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_iosxr_static_routes_overridden(self): + set_module_args( + dict( + config=[ + dict( + vrf="DEV_SITE_NEW", + address_families=[ + dict( + afi="ipv4", + safi="unicast", + routes=[ + dict( + dest="192.0.4.16/28", + next_hops=[ + dict( + interface="FastEthernet0/0/0/5", + track="ip_sla_1", + ), + dict( + interface="FastEthernet0/0/0/1", + forward_router_address="192.0.2.10", + tag=10, + description="LAB", + metric=120, + ), + ], + ) + ], + ) + ], + ) + ], + state="overridden", + ) + ) + commands = [ + "router static", + "no address-family ipv4 unicast", + "no address-family ipv6 unicast", + "no vrf DEV_SITE", + "vrf DEV_SITE_NEW", + "address-family ipv4 unicast", + "192.0.4.16/28 192.0.2.10 FastEthernet0/0/0/1 description LAB metric 120 tag 10", + "192.0.4.16/28 FastEthernet0/0/0/5 track ip_sla_1", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_static_routes_deleted_afi(self): + set_module_args( + dict( + config=[ + dict(address_families=[dict(afi="ipv4", safi="unicast")]) + ], + state="deleted", + ) + ) + + commands = ["router static", "no address-family ipv4 unicast"] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_static_routes_deleted_vrf(self): + set_module_args(dict(config=[dict(vrf="DEV_SITE")], state="deleted")) + + commands = ["router static", "no vrf DEV_SITE"] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_static_routes_deleted_all(self): + set_module_args(dict(state="deleted")) + + commands = ["no router static"] + self.execute_module(changed=True, commands=commands) diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_system.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_system.py new file mode 100644 index 00000000..60bdee83 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_system.py @@ -0,0 +1,123 @@ +# (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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_system + + +class TestIosxrSystemModule(TestIosxrModule): + + module = iosxr_system + + def setUp(self): + super(TestIosxrSystemModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_system.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_system.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_is_cliconf = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_system.is_cliconf" + ) + self.is_cliconf = self.mock_is_cliconf.start() + + def tearDown(self): + super(TestIosxrSystemModule, 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("iosxr_system_config.cfg") + self.load_config.return_value = dict(diff=None, session="session") + self.is_cliconf.return_value = True + + def test_iosxr_system_hostname_changed(self): + set_module_args(dict(hostname="foo")) + commands = ["hostname foo", "no domain lookup disable"] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_system_domain_name(self): + set_module_args(dict(domain_name="test.com")) + commands = ["domain name test.com", "no domain lookup disable"] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_system_domain_search(self): + set_module_args(dict(domain_search=["ansible.com", "redhat.com"])) + commands = [ + "domain list ansible.com", + "no domain list cisco.com", + "no domain lookup disable", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_system_lookup_source(self): + set_module_args(dict(lookup_source="Ethernet1")) + commands = [ + "domain lookup source-interface Ethernet1", + "no domain lookup disable", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_system_lookup_enabled(self): + set_module_args(dict(lookup_enabled=True)) + commands = ["no domain lookup disable"] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_system_name_servers(self): + name_servers = ["8.8.8.8", "8.8.4.4", "1.1.1.1"] + set_module_args(dict(name_servers=name_servers)) + self.execute_module(changed=True) + + def test_iosxr_system_state_absent(self): + set_module_args(dict(state="absent")) + commands = [ + "no hostname", + "no domain name", + "no domain lookup disable", + "no domain lookup source-interface MgmtEth0/0/CPU0/0", + "no domain list redhat.com", + "no domain list cisco.com", + "no domain name-server 8.8.8.8", + "no domain name-server 8.8.4.4", + ] + self.execute_module(changed=True, commands=commands) + + def test_iosxr_system_no_change(self): + set_module_args( + dict( + hostname="iosxr01", + domain_name="eng.ansible.com", + lookup_enabled=False, + ) + ) + self.execute_module() diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_user.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_user.py new file mode 100644 index 00000000..1f546c9d --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/network/iosxr/test_iosxr_user.py @@ -0,0 +1,129 @@ +# (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.iosxr.tests.unit.compat.mock import patch +from ansible_collections.cisco.iosxr.plugins.modules import iosxr_user +from ansible_collections.cisco.iosxr.tests.unit.modules.utils import ( + set_module_args, +) +from .iosxr_module import TestIosxrModule, load_fixture + + +class TestIosxrUserModule(TestIosxrModule): + + module = iosxr_user + + def setUp(self): + super(TestIosxrUserModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_user.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_user.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_is_cliconf = patch( + "ansible_collections.cisco.iosxr.plugins.modules.iosxr_user.is_cliconf" + ) + self.is_cliconf = self.mock_is_cliconf.start() + + def tearDown(self): + super(TestIosxrUserModule, self).tearDown() + + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_is_cliconf.stop() + + def load_fixtures(self, commands=None, transport="cli"): + self.get_config.return_value = load_fixture("iosxr_user_config.cfg") + self.load_config.return_value = dict(diff=None, session="session") + self.is_cliconf.return_value = True + + def test_iosxr_user_delete(self): + set_module_args(dict(name="ansible", state="absent")) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["no username ansible"]) + + def test_iosxr_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_iosxr_user_purge(self): + set_module_args(dict(purge=True)) + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], ["no username ansible"]) + + def test_iosxr_user_group(self): + set_module_args(dict(name="ansible", group="sysadmin")) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], ["username ansible group sysadmin"] + ) + + def test_iosxr_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", "username test secret test"] + ) + + def test_iosxr_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_iosxr_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_iosxr_user_admin_mode(self): + set_module_args( + dict(name="ansible-2", configured_password="test-2", admin=True) + ) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["username ansible-2", "username ansible-2 secret test-2"], + ) diff --git a/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/utils.py b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/modules/utils.py new file mode 100644 index 00000000..f6edc4b0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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.iosxr.tests.unit.compat import unittest +from ansible_collections.cisco.iosxr.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/iosxr/tests/unit/requirements.txt b/collections-debian-merged/ansible_collections/cisco/iosxr/tests/unit/requirements.txt new file mode 100644 index 00000000..a9772bea --- /dev/null +++ b/collections-debian-merged/ansible_collections/cisco/iosxr/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' |