diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:04:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:04:41 +0000 |
commit | 975f66f2eebe9dadba04f275774d4ab83f74cf25 (patch) | |
tree | 89bd26a93aaae6a25749145b7e4bca4a1e75b2be /ansible_collections/junipernetworks/junos/tests | |
parent | Initial commit. (diff) | |
download | ansible-975f66f2eebe9dadba04f275774d4ab83f74cf25.tar.xz ansible-975f66f2eebe9dadba04f275774d4ab83f74cf25.zip |
Adding upstream version 7.7.0+dfsg.upstream/7.7.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/junipernetworks/junos/tests')
628 files changed, 39869 insertions, 0 deletions
diff --git a/ansible_collections/junipernetworks/junos/tests/.gitignore b/ansible_collections/junipernetworks/junos/tests/.gitignore new file mode 100644 index 000000000..ea1472ec1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/.gitignore @@ -0,0 +1 @@ +output/ diff --git a/ansible_collections/junipernetworks/junos/tests/integration/target-prefixes.network b/ansible_collections/junipernetworks/junos/tests/integration/target-prefixes.network new file mode 100644 index 000000000..738c4ab49 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/target-prefixes.network @@ -0,0 +1 @@ +junos diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tasks/main.yaml new file mode 100644 index 000000000..d308b6d19 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Execute netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - "netconf" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..63ac8f93d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/_initial_config.yaml @@ -0,0 +1,20 @@ +--- +- name: Debug + ansible.builtin.debug: + msg: "START junipernetworks.junos.junos_acl_interfaces ACL interfaces initial config on connection={{ ansible_connection }}" + +- name: Set initial state for firewalls and interfaces + junipernetworks.junos.junos_acl_interfaces: + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + acls: + - name: initial_acl + direction: in + - name: second_acl + direction: out + +- name: Debug + ansible.builtin.debug: + msg: "END junipernetworks.junos.junos_acl_interfaces ACL interfaces initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..12fce836b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/_reset_config.yaml @@ -0,0 +1,18 @@ +--- +- name: Debug + ansible.builtin.debug: + msg: "START junipernetworks.junos.junos_acl_interfaces reset ACL and ACL interfaces config on connection={{ ansible_connection }}" + +- name: Set initial state for firewalls and interfaces + junipernetworks.junos.junos_config: + lines: + - delete firewall + - set firewall family inet filter initial_acl term ten_dot from source-port bgp protocol tcp source-address 10.0.0.0/8 + - set firewall family inet filter initial_acl term eleven_dot from source-port bgp protocol tcp source-address 11.0.0.0/8 + - set firewall family inet filter second_acl term twelve_dot from source-port bgp protocol tcp source-address 12.0.0.0/8 + - "delete interfaces ge-1/0/0" + - "delete interfaces ge-2/0/0" + +- name: Debug + ansible.builtin.debug: + msg: "END junipernetworks.junos.junos_acl_interfaces reset ACL and ACL interfaces config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/deleted.yaml new file mode 100644 index 000000000..2915e0071 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/deleted.yaml @@ -0,0 +1,64 @@ +--- +- name: Debug + ansible.builtin.debug: + msg: "START junipernetworks.junos.junos_acl_interfaces deleted integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Invoke initial config + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + acls: + - name: initial_acl + direction: in + + - name: Delete a single ACL + junipernetworks.junos.junos_acl_interfaces: + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + acls: + - name: second_acl + direction: out + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: &changed + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Set facts + ansible.builtin.set_fact: + config: [] + + - name: Delete all ACLs from the device + junipernetworks.junos.junos_acl_interfaces: + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: *changed + + tags: deleted + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug + ansible.builtin.debug: + msg: "END junipernetworks.junos.junos_acl_interfaces deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..204b3b7b2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/empty_config.yaml @@ -0,0 +1,55 @@ +--- +- name: Debug + ansible.builtin.debug: + msg: + START junipernetworks.junos.junos_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 + junipernetworks.junos.junos_acl_interfaces: + config: + state: merged + +- name: Assert result + ansible.builtin.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 + junipernetworks.junos.junos_acl_interfaces: + config: + state: replaced + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_acl_interfaces: + running_config: + state: parsed + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_acl_interfaces: + config: + state: rendered + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/merged.yaml new file mode 100644 index 000000000..d6a0a3533 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/merged.yaml @@ -0,0 +1,58 @@ +--- +- name: Debug + ansible.builtin.debug: + msg: "START junipernetworks.junos.junos_acl_interfaces merged integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + acls: + - name: second_acl + direction: in + - name: initial_acl + direction: out + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_acl_interfaces: &merged + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + acls: + - name: second_acl + direction: in + - name: initial_acl + direction: out + state: merged + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_acl_interfaces: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: merged + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junipernetworks.junos.junos_acl_interfaces merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/overridden.yaml new file mode 100644 index 000000000..ea1c6a1c6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/overridden.yaml @@ -0,0 +1,51 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junipernetworks.junos.junos_acl_interfaces overridden integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Initial configuration + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + acls: + - name: initial_acl + direction: in + + - name: Override configuration of ACL + junipernetworks.junos.junos_acl_interfaces: + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + acls: + - name: initial_acl + direction: in + state: overridden + register: result + + - name: Assert changed + ansible.builtin.assert: &changed + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Assert changed + ansible.builtin.assert: *changed + + tags: overridden + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junipernetworks.junos.junos_acl_interfaces overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/replaced.yaml new file mode 100644 index 000000000..2d63c95dd --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acl_interfaces/tests/netconf/replaced.yaml @@ -0,0 +1,51 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junipernetworks.junos.junos_acl_interfaces replaced integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Initial configuration + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + acls: + - name: initial_acl + direction: in + - name: second_acl + direction: out + - name: initial_acl + direction: out + + - name: Replace configuration of ACL + junipernetworks.junos.junos_acl_interfaces: + config: + - name: ge-1/0/0 + access_groups: + - afi: ipv4 + acls: + - name: initial_acl + direction: out + state: replaced + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - "{{ config|symmetric_difference(result.after) == [] }}" + + tags: replaced + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junipernetworks.junos.junos_acl_interfaces replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tasks/main.yaml new file mode 100644 index 000000000..7b18bda97 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: ["netconf"] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..436b450a0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/_reset_config.yaml @@ -0,0 +1,19 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_acls reset ACL config on connection={{ ansible_connection }}" + +- name: Set initial state + junipernetworks.junos.junos_config: + lines: + - delete firewall + - set firewall family inet filter initial_acl term ten_dot from source-port bgp protocol tcp source-address 10.0.0.0/8 + - set firewall family inet filter initial_acl term eleven_dot from source-port bgp protocol tcp source-address 11.0.0.0/8 + - set firewall family inet filter second_acl term twelve_dot from source-port bgp protocol tcp source-address 12.0.0.0/8 + - set firewall family inet filter third_acl term thirteen_dot from source-port bgp protocol tcp source-address 13.0.0.0/16 + - set firewall family inet filter third_acl term thirteen_dot from source-port bgp protocol tcp source-address 13.1.0.0/16 + - "set firewall family inet6 filter initial_acl6 term colon_eleven from source-port 631 source-address ::11" + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_acls reset ACL config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/config_policy.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/config_policy.yaml new file mode 100644 index 000000000..c425425c3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/config_policy.yaml @@ -0,0 +1,14 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_acls preconfig policy options config on connection={{ ansible_connection }}" + +- name: Set policy config + junipernetworks.junos.junos_config: + lines: + - set policy-options prefix-list ospf-all-routers + - set policy-options prefix-list ipv4-interfaces + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_acls preconfig policy options config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/deleted.yaml new file mode 100644 index 000000000..e44d37280 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/deleted.yaml @@ -0,0 +1,166 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_acls deleted integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset config + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + config: + - acls: + - aces: + - name: ten_dot + source: + address: 10.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: initial_acl + - aces: + - name: twelve_dot + source: + address: 12.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: second_acl + - aces: + - name: thirteen_dot + source: + address: + - 13.0.0.0/16 + - 13.1.0.0/16 + port_protocol: + eq: bgp + protocol: tcp + name: third_acl + afi: ipv4 + - acls: + - aces: + - name: colon_eleven + source: + address: ::11/128 + port_protocol: + eq: "631" + name: initial_acl6 + afi: ipv6 + + - name: Delete a single ACE + junipernetworks.junos.junos_acls: + config: + - afi: ipv4 + acls: + - name: initial_acl + aces: + - name: eleven_dot + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: &changed + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Set facts + ansible.builtin.set_fact: + config: + - acls: + - aces: + - name: ten_dot + source: + address: 10.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: initial_acl + - aces: + - name: thirteen_dot + source: + address: + - 13.0.0.0/16 + - 13.1.0.0/16 + port_protocol: + eq: bgp + protocol: tcp + name: third_acl + afi: ipv4 + - acls: + - aces: + - name: colon_eleven + source: + address: ::11/128 + port_protocol: + eq: "631" + name: initial_acl6 + afi: ipv6 + + - name: Delete a whole ACL + junipernetworks.junos.junos_acls: + config: + - afi: ipv4 + acls: + - name: second_acl + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: *changed + + - name: Set facts + ansible.builtin.set_fact: + config: + - acls: + - aces: + - name: ten_dot + source: + address: 10.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: initial_acl + - aces: + - name: thirteen_dot + source: + address: + - 13.0.0.0/16 + - 13.1.0.0/16 + port_protocol: + eq: bgp + protocol: tcp + name: third_acl + afi: ipv4 + + - name: Delete all ACLs under one AFI + junipernetworks.junos.junos_acls: + config: + - afi: ipv6 + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: *changed + + - name: Set facts + ansible.builtin.set_fact: + config: [] + + - name: Delete all ACLs from the device + junipernetworks.junos.junos_acls: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: *changed + + tags: deleted + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_acls deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..99878acf4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/empty_config.yaml @@ -0,0 +1,66 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_acls empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_acls: + config: + state: merged + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_acls: + config: + state: replaced + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_acls: + config: + state: overridden + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_acls: + running_config: + state: parsed + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_acls: + config: + state: rendered + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..c5e52190c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <firewall> + <family> + <inet> + <filter> + <name>from-cisco</name> + <term> + <name>1</name> + <from> + <source-address> + <name>10.0.0.0/8</name> + </source-address> + <destination-address> + <name>11.0.0.0/8</name> + </destination-address> + <packet-length>1000</packet-length> + <is-fragment/> + <protocol>udp</protocol> + <protocol>vrrp</protocol> + <ttl>100</ttl> + <destination-port>who</destination-port> + <destination-port>radius</destination-port> + </from> + <then> + <count>icmp_deny</count> + <reject> + </reject> + </then> + </term> + <term> + <name>2</name> + <from> + <destination-port>radius</destination-port> + </from> + </term> + </filter> + </inet> + </family> + </firewall> + + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/idempotent.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/idempotent.yaml new file mode 100644 index 000000000..e944f5de5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/idempotent.yaml @@ -0,0 +1,79 @@ +--- +- ansible.builtin.debug: + msg: "START junos_acls idempotence integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + config: + - acls: + - aces: + - name: ten_dot + source: + address: 10.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + - name: eleven_dot + source: + address: 11.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: initial_acl + - aces: + - name: twelve_dot + source: + address: 12.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: second_acl + - aces: + - name: thirteen_dot + source: + address: + - 13.0.0.0/16 + - 13.1.0.0/16 + port_protocol: + eq: bgp + protocol: tcp + name: third_acl + afi: ipv4 + - acls: + - aces: + - name: colon_eleven + source: + address: ::11/128 + port_protocol: + eq: 631 + name: initial_acl6 + afi: ipv6 + + - name: Test equivalence + junipernetworks.junos.junos_acls: + config: "{{ config }}" + state: merged + register: result + + - ansible.builtin.assert: + that: + - result.changed == False + + - name: Test idempotence + junipernetworks.junos.junos_acls: + config: "{{ config }}" + state: overridden + register: result + + - ansible.builtin.assert: + that: + - result.changed == False + + tags: idempotence + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_acls idempotence integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/merged.yaml new file mode 100644 index 000000000..4f360ead8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/merged.yaml @@ -0,0 +1,106 @@ +--- +- ansible.builtin.debug: + msg: "START junos_acls merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.include_tasks: config_policy.yaml + + - ansible.builtin.set_fact: + config: + - acls: + - aces: + - name: ten_dot + source: + address: 10.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + - name: eleven_dot + source: + address: 11.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: initial_acl + - aces: + - name: twelve_dot + source: + address: 12.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: second_acl + - aces: + - name: thirteen_dot + source: + address: + - 13.0.0.0/16 + - 13.1.0.0/16 + port_protocol: + eq: bgp + protocol: tcp + name: third_acl + - aces: + - name: ssh_rule + source: + prefix_list: + - name: "ipv4-interfaces" + - name: "ospf-all-routers" + port_protocol: + eq: ssh + protocol: tcp + name: allow_ssh_acl + afi: ipv4 + - acls: + - aces: + - name: colon_eleven + source: + address: ::11/128 + port_protocol: + eq: "631" + name: initial_acl6 + afi: ipv6 + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_acls: &merged + config: + - afi: ipv4 + acls: + - name: allow_ssh_acl + aces: + - name: ssh_rule + source: + prefix_list: + - name: "ipv4-interfaces" + - name: "ospf-all-routers" + port_protocol: + eq: ssh + protocol: tcp + state: merged + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_acls: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.include_tasks: reset_policy_config.yaml + +- ansible.builtin.debug: + msg: "END junos_acls merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/overridden.yaml new file mode 100644 index 000000000..6de41d2e7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/overridden.yaml @@ -0,0 +1,49 @@ +--- +- ansible.builtin.debug: + msg: "START junos_acls overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + config: + - acls: + - aces: + - name: ace_10 + grant: deny + protocol: tcp + name: acl_1 + - aces: + - name: ace_20 + grant: deny + protocol: udp + name: acl_2 + afi: ipv4 + + - name: Override the entire running configuration with the provided configuration + junipernetworks.junos.junos_acls: &overridden + config: "{{ config }}" + state: overridden + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Override the entire running configuration with the provided configuration (IDEMPOTENT) + junipernetworks.junos.junos_acls: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_acls overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/parsed.yaml new file mode 100644 index 000000000..bd55e13a1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/parsed.yaml @@ -0,0 +1,44 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: + START junos_acls parsed integration tests on connection={{ ansible_connection + }} + +- name: Set facts + ansible.builtin.set_fact: + expected_parsed_output: + - acls: + - aces: + - destination: + address: "11.0.0.0/8" + port_protocol: + eq: "['who', 'radius']" + name: "1" + protocol: "['udp', 'vrrp']" + source: + address: "10.0.0.0/8" + - destination: + port_protocol: + eq: "radius" + name: "2" + name: "from-cisco" + afi: ipv4 + +- name: Parse externally provided acls config to agnostic model + register: result + junipernetworks.junos.junos_acls: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_acls parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/rendered.yaml new file mode 100644 index 000000000..1dae9de30 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/rendered.yaml @@ -0,0 +1,35 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_acls rendered integration tests on connection={{ + ansible_connection }} + +- name: Set facts + ansible.builtin.set_fact: + expected_rendered_output: '<nc:firewall xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:family><nc:inet><nc:filter><nc:name>initial_acl</nc:name><nc:term><nc:name>ten_dot</nc:name><nc:from><nc:source-address>10.0.0.0/8</nc:source-address><nc:source-port>bgp</nc:source-port><nc:protocol>tcp</nc:protocol></nc:from></nc:term></nc:filter></nc:inet></nc:family></nc:firewall>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_acls: + config: + - acls: + - aces: + - name: ten_dot + source: + address: 10.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: initial_acl + afi: ipv4 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- name: Debug task + ansible.builtin.debug: + msg: END junos_acls rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/replaced.yaml new file mode 100644 index 000000000..679dccd23 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/replaced.yaml @@ -0,0 +1,105 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_acls replaced integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + config: + - acls: + - aces: + - name: ten_dot + source: + address: 10.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + - name: eleven_dot + source: + address: 11.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + name: initial_acl + - aces: + - name: twelve_dot + source: + address: 12.0.0.0/8 + port_protocol: + eq: bgp + protocol: tcp + - name: ace_20 + grant: permit + protocol: igmp + source: + address: 192.168.1.100/32 + - name: ace_21 + grant: permit + protocol: tcp + name: second_acl + - aces: + - name: thirteen_dot + source: + address: + - 13.0.0.0/16 + - 13.1.0.0/16 + port_protocol: + eq: bgp + protocol: tcp + name: third_acl + afi: ipv4 + - acls: + - aces: + - name: colon_eleven + source: + address: ::11/128 + port_protocol: + eq: "631" + name: initial_acl6 + afi: ipv6 + + - name: Replace the specified ACL with given config + junipernetworks.junos.junos_acls: &replaced + config: + - afi: ipv4 + acls: + - name: second_acl + aces: + - name: ace_20 + grant: permit + protocol: igmp + source: + address: 192.168.1.100 + - name: ace_21 + grant: permit + protocol: tcp + state: replaced + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Replace the specified ACL with given config (IDEMPOTENT) + junipernetworks.junos.junos_acls: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_acls replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/reset_policy_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/reset_policy_config.yaml new file mode 100644 index 000000000..82c89c158 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_acls/tests/netconf/reset_policy_config.yaml @@ -0,0 +1,16 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_acls reset policy options config on connection={{ ansible_connection }}" + +- name: Reset policy options config + junipernetworks.junos.junos_config: + lines: + - delete firewall family inet filter PROTECT-RE term allow-ospf from source-prefix-list ipv4-interfaces + - delete firewall family inet filter PROTECT-RE term allow-ospf from source-prefix-list ospf-all-routers + - delete policy-options prefix-list ospf-all-routers + - delete policy-options prefix-list ipv4-interfaces + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_acls reset policy options config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/defaults/main.yaml new file mode 100644 index 000000000..9ef5ba516 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/tasks/main.yaml new file mode 100644 index 000000000..ac951c8f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/tasks/netconf.yaml new file mode 100644 index 000000000..824d3b006 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/tasks/netconf.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/tests/netconf/basic.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/tests/netconf/basic.yaml new file mode 100644 index 000000000..f1205566c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_banner/tests/netconf/basic.yaml @@ -0,0 +1,205 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START junos_banner netconf/basic.yaml on connection={{ ansible_connection + }}" + +- name: Setup - remove login banner + junipernetworks.junos.junos_banner: + banner: login + state: absent + +- name: Create login banner + register: result + junipernetworks.junos.junos_banner: + banner: login + text: this is my login banner + state: present + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == true + - "'<message>this is my login banner</message>' in config.xml" + +- name: Create login banner (idempotent) + register: result + junipernetworks.junos.junos_banner: + banner: login + text: this is my login banner + state: present + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + +- name: Deactivate login banner + register: result + junipernetworks.junos.junos_banner: + banner: login + text: this is my login banner + state: present + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == true + - '''<message inactive="inactive">this is my login banner</message>'' in config.xml' + +- name: Activate login banner + register: result + junipernetworks.junos.junos_banner: + banner: login + text: this is my login banner + state: present + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == true + - "'<message>this is my login banner</message>' in config.xml" + +- name: check mode + register: result + check_mode: true + junipernetworks.junos.junos_banner: + banner: login + text: this is not the login banner you're looking for + state: present + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == true + - result.failed == false + +- name: Delete login banner + register: result + junipernetworks.junos.junos_banner: + banner: login + state: absent + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == true + - "'<message>this is my login banner</message>' not in config.xml" + +- name: Setup - remove motd banner + junipernetworks.junos.junos_banner: + banner: motd + state: absent + +- name: Create motd banner + register: result + junipernetworks.junos.junos_banner: + banner: motd + text: this is my motd banner + state: present + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == true + - "'<announcement>this is my motd banner</announcement>' in config.xml" + +- name: Create motd banner (idempotent) + register: result + junipernetworks.junos.junos_banner: + banner: motd + text: this is my motd banner + state: present + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + +- name: Deactivate motd banner + register: result + junipernetworks.junos.junos_banner: + banner: motd + text: this is my motd banner + state: present + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == true + - "'<announcement inactive=\"inactive\">this is my motd banner</announcement>'\ + \ in config.xml" + +- name: Activate motd banner + register: result + junipernetworks.junos.junos_banner: + banner: motd + text: this is my motd banner + state: present + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == true + - "'<announcement>this is my motd banner</announcement>' in config.xml" + +- name: Delete motd banner + register: result + junipernetworks.junos.junos_banner: + banner: motd + state: absent + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == true + - "'<announcement>this is my motd banner</announcement>' not in config.xml" + +- name: Debug task + ansible.builtin.debug: + msg="END junos_banner netconf/basic.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..18a11dd70 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/_reset_config.yaml @@ -0,0 +1,13 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_address_family reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to bgp address family resource + junipernetworks.junos.junos_config: + lines: + - delete protocols bgp family + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_address_family reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/deleted.yaml new file mode 100644 index 000000000..248421891 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/deleted.yaml @@ -0,0 +1,136 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_address_family deleted integration tests on connection={{ ansible_connection }}" + +- block: + - name: Initial configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + expected_deleted_output: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 98 + idle_timeout_value: 2001 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_bgp_address_family: &merged + config: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 98 + idle_timeout_value: 2001 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + - afi: "inet" + af_type: + - type: "flow" + legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + + - type: "unicast" + extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + + - type: "labeled-unicast" + entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_prefix_label: true + per_group_label: true + prefix_limit: + maximum: 20 + limit_threshold: 99 + forever: true + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + + - type: "any" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 99 + idle_timeout_value: 2000 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + state: merged + + - name: Delete existing configuration with running configuration + junipernetworks.junos.junos_bgp_address_family: &deleted + config: + address_family: + - afi: "inet" + state: deleted + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_deleted_output == result.after }}" + + - name: Delete the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_bgp_address_family: *deleted + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Set facts + ansible.builtin.set_fact: + expected_deleted_res_output: {} + + - name: Merge the existing config with provided configuration + junos_bgp_address_family: *merged + register: result + + - name: Delete complete existing bgp address family configuration + junipernetworks.junos.junos_bgp_address_family: &deleted_res + config: + state: deleted + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_deleted_res_output == result.after }}" + + tags: deleted + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_address_family deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..64f38991f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/empty_config.yaml @@ -0,0 +1,70 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: + START junos_bgp_address_family empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_address_family: + config: + state: merged + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_bgp_address_family: + config: + state: replaced + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Override with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_address_family: + config: + state: overridden + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_bgp_address_family: + running_config: + state: parsed + +- name: Debug task + ansible.builtin.debug: + msg: result + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_address_family: + config: + state: rendered + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..bb0b56fce --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <preference>2</preference> + <hold-time>5</hold-time> + <advertise-inactive/> + <out-delay>10</out-delay> + <family> + <inet> + <unicast> + <local-ipv4-address>9.9.9.9</local-ipv4-address> + <extended-nexthop/> + <extended-nexthop-color/> + </unicast> + <flow> + <loops> + <loops>4</loops> + </loops> + <no-install/> + <output-queue-priority> + <expedited/> + </output-queue-priority> + <legacy-redirect-ip-action> + <receive/> + <send/> + </legacy-redirect-ip-action> + <secondary-independent-resolution/> + </flow> + <any> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>99</limit-threshold> + <idle-timeout> + <timeout>2000</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <delay-route-advertisements> + <minimum-delay> + <routing-uptime>23000</routing-uptime> + <inbound-convergence>32000</inbound-convergence> + </minimum-delay> + <maximum-delay> + <route-age>20</route-age> + <routing-uptime>32000</routing-uptime> + </maximum-delay> + </delay-route-advertisements> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + <graceful-restart> + <forwarding-state-bit>from-fib</forwarding-state-bit> + </graceful-restart> + </any> + <labeled-unicast> + <prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>99</limit-threshold> + <idle-timeout> + <forever/> + </idle-timeout> + </teardown> + </prefix-limit> + <route-refresh-priority> + <priority>3</priority> + </route-refresh-priority> + <per-prefix-label/> + <per-group-label/> + <rib> + <inet.3/> + </rib> + <explicit-null> + <connected-only/> + </explicit-null> + <resolve-vpn/> + <entropy-label> + <no-next-hop-validation/> + </entropy-label> + </labeled-unicast> + </inet> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/gathered.yaml new file mode 100644 index 000000000..023c18015 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/gathered.yaml @@ -0,0 +1,149 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_bgp_address_family gathered integration tests on connection={{ ansible_connection }} + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + expected_gathered_output: + address_family: + - af_type: + - accepted_prefix_limit: + idle_timeout_value: 2001 + limit_threshold: 98 + maximum: 20 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + type: "signaling" + afi: "evpn" + + - af_type: + - accepted_prefix_limit: + idle_timeout_value: 2000 + limit_threshold: 99 + maximum: 20 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + type: "any" + + - legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + type: "flow" + + - entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_group_label: true + per_prefix_label: true + prefix_limit: + forever: true + limit_threshold: 99 + maximum: 20 + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + type: "labeled-unicast" + + - extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + type: "unicast" + afi: "inet" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_bgp_address_family: &merged + config: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 98 + idle_timeout_value: 2001 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + - afi: "inet" + af_type: + - type: "flow" + legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + + - type: "unicast" + extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + + - type: "labeled-unicast" + entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_prefix_label: true + per_group_label: true + prefix_limit: + maximum: 20 + limit_threshold: 99 + forever: true + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + + - type: "any" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 99 + idle_timeout_value: 2000 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + state: merged + + - name: Gather bgp address family facts using gathered state + register: result + junipernetworks.junos.junos_bgp_address_family: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ expected_gathered_output == result['gathered'] }}" + + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_bgp_address_family gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/merged.yaml new file mode 100644 index 000000000..f47dd971c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/merged.yaml @@ -0,0 +1,155 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_address_family merged integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + expected_merged_output: + address_family: + - af_type: + - accepted_prefix_limit: + idle_timeout_value: 2001 + limit_threshold: 98 + maximum: 20 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + type: "signaling" + afi: "evpn" + + - af_type: + - accepted_prefix_limit: + idle_timeout_value: 2000 + limit_threshold: 99 + maximum: 20 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + type: "any" + + - legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + type: "flow" + + - entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_group_label: true + per_prefix_label: true + prefix_limit: + forever: true + limit_threshold: 99 + maximum: 20 + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + type: "labeled-unicast" + + - extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + type: "unicast" + afi: "inet" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_bgp_address_family: &merged + config: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 98 + idle_timeout_value: 2001 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + - afi: "inet" + af_type: + - type: "flow" + legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + + - type: "unicast" + extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + + - type: "labeled-unicast" + entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_prefix_label: true + per_group_label: true + prefix_limit: + maximum: 20 + limit_threshold: 99 + forever: true + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + + - type: "any" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 99 + idle_timeout_value: 2000 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + state: merged + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_merged_output == result.after }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_bgp_address_family: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: merged + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_address_family merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/overridden.yaml new file mode 100644 index 000000000..286793b8c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/overridden.yaml @@ -0,0 +1,131 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_address_family overridden integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + expected_overridden_output: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 21 + limit_threshold: 99 + idle_timeout_value: 2002 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + damping: true + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_bgp_address_family: &merged + config: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 98 + idle_timeout_value: 2001 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + - afi: "inet" + af_type: + - type: "flow" + legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + + - type: "unicast" + extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + + - type: "labeled-unicast" + entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_prefix_label: true + per_group_label: true + prefix_limit: + maximum: 20 + limit_threshold: 99 + forever: true + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + + - type: "any" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 99 + idle_timeout_value: 2000 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + state: merged + + - name: Override existing configuration with running configuration + junipernetworks.junos.junos_bgp_address_family: &overridden + config: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 21 + limit_threshold: 99 + idle_timeout_value: 2002 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + damping: true + state: overridden + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_overridden_output == result.after }}" + + - name: Override the existing running configuration with the provided configuration (IDEMPOTENT) + junipernetworks.junos.junos_bgp_address_family: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_address_family overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/parsed.yaml new file mode 100644 index 000000000..5203c8288 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/parsed.yaml @@ -0,0 +1,84 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: + START junos_bgp_address_family parsed integration tests on connection={{ ansible_connection + }} + +- name: Set facts + ansible.builtin.set_fact: + expected_parsed_output: + address_family: + - af_type: + - accepted_prefix_limit: + idle_timeout_value: 2001 + limit_threshold: 98 + maximum: 20 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + type: "signaling" + afi: "evpn" + + - af_type: + - accepted_prefix_limit: + idle_timeout_value: 2000 + limit_threshold: 99 + maximum: 20 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + type: "any" + + - legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + type: "flow" + + - entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_group_label: true + per_prefix_label: true + prefix_limit: + forever: true + limit_threshold: 99 + maximum: 20 + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + type: "labeled-unicast" + + - extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + type: "unicast" + afi: "inet" + +- name: Parse externally provided bgp_address_family config to agnostic model + register: result + junipernetworks.junos.junos_bgp_address_family: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output == result['parsed'] }}" + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_bgp_address_family parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/rendered.yaml new file mode 100644 index 000000000..e919a2c8d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/rendered.yaml @@ -0,0 +1,83 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: + START junos_bgp_address_family rendered integration tests on connection={{ + ansible_connection }} + +- name: Set facts + ansible.builtin.set_fact: + expected_rendered_output: '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:bgp><nc:family><nc:evpn><nc:signaling><nc:accepted-prefix-limit><nc:maximum>20</nc:maximum><nc:teardown><nc:limit-threshold>98</nc:limit-threshold><nc:idle-timeout><nc:timeout>2001</nc:timeout></nc:idle-timeout></nc:teardown></nc:accepted-prefix-limit><nc:damping/><nc:defer-initial-multipath-build><nc:maximum-delay>2</nc:maximum-delay></nc:defer-initial-multipath-build></nc:signaling></nc:evpn><nc:inet><nc:flow><nc:legacy-redirect-ip-action><nc:send/><nc:receive/></nc:legacy-redirect-ip-action><nc:loops>4</nc:loops><nc:no-install/><nc:output-queue-priority><nc:expedited/></nc:output-queue-priority><nc:secondary-independent-resolution/></nc:flow><nc:unicast><nc:extended-nexthop/><nc:extended-nexthop-color/><nc:local-ipv4-address>9.9.9.9</nc:local-ipv4-address></nc:unicast><nc:labeled-unicast><nc:entropy-label><nc:no-next-hop-validation/></nc:entropy-label><nc:explicit-null><nc:connected-only/></nc:explicit-null><nc:per-prefix-label/><nc:per-group-label/><nc:prefix-limit><nc:maximum>20</nc:maximum><nc:teardown>99<nc:idle-timeout><nc:forever/></nc:idle-timeout></nc:teardown></nc:prefix-limit><nc:resolve-vpn/><nc:rib><nc:inet.3/></nc:rib><nc:route-refresh-priority><nc:priority>3</nc:priority></nc:route-refresh-priority></nc:labeled-unicast><nc:any><nc:accepted-prefix-limit><nc:maximum>20</nc:maximum><nc:teardown><nc:limit-threshold>99</nc:limit-threshold><nc:idle-timeout><nc:timeout>2000</nc:timeout></nc:idle-timeout></nc:teardown></nc:accepted-prefix-limit><nc:damping/><nc:defer-initial-multipath-build><nc:maximum-delay>2</nc:maximum-delay></nc:defer-initial-multipath-build><nc:delay-route-advertisements><nc:maximum-delay><nc:route-age>20</nc:route-age><nc:routing-uptime>32000</nc:routing-uptime></nc:maximum-delay><nc:minimum-delay><nc:inbound-convergence>32000</nc:inbound-convergence><nc:routing-uptime>23000</nc:routing-uptime></nc:minimum-delay></nc:delay-route-advertisements><nc:graceful-restart><nc:forwarding-state-bit>from-fib</nc:forwarding-state-bit></nc:graceful-restart></nc:any></nc:inet></nc:family></nc:bgp></nc:protocols>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_bgp_address_family: + config: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 98 + idle_timeout_value: 2001 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + - afi: "inet" + af_type: + - type: "flow" + legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + + - type: "unicast" + extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + + - type: "labeled-unicast" + entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_prefix_label: true + per_group_label: true + prefix_limit: + maximum: 20 + limit_threshold: 99 + forever: true + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + + - type: "any" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 99 + idle_timeout_value: 2000 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_bgp_address_family rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/replaced.yaml new file mode 100644 index 000000000..d827874e9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_address_family/tests/netconf/replaced.yaml @@ -0,0 +1,177 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_address_family replaced integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + expected_replaced_output: + address_family: + - af_type: + - accepted_prefix_limit: + idle_timeout_value: 2002 + limit_threshold: 99 + maximum: 21 + damping: true + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + type: "signaling" + afi: "evpn" + + - af_type: + - accepted_prefix_limit: + idle_timeout_value: 2000 + limit_threshold: 99 + maximum: 20 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + type: "any" + + - legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + type: "flow" + + - entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_group_label: true + per_prefix_label: true + prefix_limit: + forever: true + limit_threshold: 99 + maximum: 20 + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + type: "labeled-unicast" + + - extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + type: "unicast" + afi: "inet" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_bgp_address_family: &merged + config: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 98 + idle_timeout_value: 2001 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + - afi: "inet" + af_type: + - type: "flow" + legacy_redirect_ip_action: + send: true + receive: true + loops: 4 + no_install: true + output_queue_priority_expedited: true + secondary_independent_resolution: true + + - type: "unicast" + extended_nexthop: true + extended_nexthop_color: true + local_ipv4_address: "9.9.9.9" + + - type: "labeled-unicast" + entropy_label: + no_next_hop_validation: true + explicit_null: + connected_only: true + per_prefix_label: true + per_group_label: true + prefix_limit: + maximum: 20 + limit_threshold: 99 + forever: true + resolve_vpn: true + rib: "inet.3" + route_refresh_priority_priority: 3 + + - type: "any" + accepted_prefix_limit: + maximum: 20 + limit_threshold: 99 + idle_timeout_value: 2000 + damping: true + defer_initial_multipath_build: + maximum_delay: 2 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + graceful_restart_forwarding_state_bit: "from-fib" + state: merged + + - name: Replace existing configuration with running configuration + junipernetworks.junos.junos_bgp_address_family: &replaced + config: + address_family: + - afi: "evpn" + af_type: + - type: "signaling" + accepted_prefix_limit: + maximum: 21 + limit_threshold: 99 + idle_timeout_value: 2002 + delay_route_advertisements: + max_delay_route_age: 20 + max_delay_routing_uptime: 32000 + min_delay_inbound_convergence: 32000 + min_delay_routing_uptime: 23000 + damping: true + state: replaced + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_replaced_output == result.after }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_bgp_address_family: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_address_family replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..d5ab5e107 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/_initial_config.yaml @@ -0,0 +1,35 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_global initial config on connection={{ ansible_connection }}" + +- name: Configure basic config relevant to BGP GLOBAL + junipernetworks.junos.junos_config: + lines: + - set routing-options autonomous-system 65534 + - set routing-options autonomous-system loops 3 + - set routing-options autonomous-system asdot-notation + - set protocols bgp accept-remote-nexthop + - set protocols bgp add-path-display-ipv4-address + - set protocols bgp advertise-from-main-vpn-tables + - set protocols bgp advertise-inactive + - set protocols bgp authentication-algorithm md5 + - set protocols bgp bgp-error-tolerance malformed-route-limit 20000000 + - set protocols bgp bmp monitor enable + - set protocols bgp damping + - set protocols bgp description "This is configured with Junos_bgp resource module" + - set protocols bgp egress-te-sid-stats + - set protocols bgp hold-time 5 + - set protocols bgp holddown-all-stale-labels + - set protocols bgp include-mp-next-hop + - set protocols bgp log-updown + - set protocols bgp no-advertise-peer-as + - set protocols bgp no-aggregator-id + - set protocols bgp no-client-reflect + - set protocols bgp out-delay 10 + - set protocols bgp precision-timers + - set protocols bgp preference 2 + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_global initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..efa729d73 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/_reset_config.yaml @@ -0,0 +1,37 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_global reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to bgp global resource + junipernetworks.junos.junos_config: + lines: + - delete routing-options autonomous-system + - delete protocols bgp accept-remote-nexthop + - delete protocols bgp add-path-display-ipv4-address + - delete protocols bgp advertise-from-main-vpn-tables + - delete protocols bgp advertise-inactive + - delete protocols bgp authentication-algorithm + - delete protocols bgp bgp-error-tolerance + - delete protocols bgp bmp + - delete protocols bgp damping + - delete protocols bgp description + - delete protocols bgp egress-te-sid-stats + - delete protocols bgp hold-time + - delete protocols bgp holddown-all-stale-labels + - delete protocols bgp include-mp-next-hop + - delete protocols bgp log-updown + - delete protocols bgp no-advertise-peer-as + - delete protocols bgp no-aggregator-id + - delete protocols bgp no-client-reflect + - delete protocols bgp out-delay + - delete protocols bgp precision-timers + - delete protocols bgp preference + - delete protocols bgp egress-te + - delete protocols bgp egress-te-backup-paths + - delete protocols bgp group external + - delete protocols bgp group internal + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_global reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/deleted.yaml new file mode 100644 index 000000000..c892c7fd3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/deleted.yaml @@ -0,0 +1,34 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_global deleted integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Initial config + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + config: {} + + - name: Delete all ospf config from the device + junipernetworks.junos.junos_bgp_global: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_global deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..50ccb3ff5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/empty_config.yaml @@ -0,0 +1,54 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_bgp_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_global: + config: + state: merged + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_bgp_global: + config: + state: replaced + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_bgp_global: + running_config: + state: parsed + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_global: + config: + state: rendered + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..f91cc45a4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <precision-timers /> + <advertise-from-main-vpn-tables /> + <holddown-all-stale-labels /> + <description>This is configured with Junos_bgp resource module</description> + <accept-remote-nexthop /> + <preference>2</preference> + <hold-time>5</hold-time> + <advertise-inactive /> + <no-advertise-peer-as /> + <no-aggregator-id /> + <out-delay>10</out-delay> + <log-updown /> + <damping /> + <authentication-algorithm>md5</authentication-algorithm> + <remove-private /> + <no-client-reflect /> + <include-mp-next-hop /> + <bmp> + <monitor>enable</monitor> + </bmp> + <advertise-bgp-static> + <policy>static-to-bgp</policy> + </advertise-bgp-static> + <add-path-display-ipv4-address /> + <egress-te-sid-stats /> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/gathered.yaml new file mode 100644 index 000000000..1d1cde1af --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/gathered.yaml @@ -0,0 +1,30 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_bgp_global gathered integration tests on connection={{ ansible_connection }} + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Initial config + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_bgp_global: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['gathered'] }}" + + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_bgp_global gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/merged.yaml new file mode 100644 index 000000000..a89774613 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/merged.yaml @@ -0,0 +1,129 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_global merged integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_bgp_global: &merged + config: + as_number: "65534" + loops: 3 + asdot_notation: true + accept_remote_nexthop: true + add_path_display_ipv4_address: true + advertise_from_main_vpn_tables: true + advertise_inactive: true + authentication_algorithm: "md5" + bgp_error_tolerance: + malformed_route_limit: 20000000 + bmp: + monitor: true + damping: true + description: "This is configured with Junos_bgp resource module" + egress_te_sid_stats: true + hold_time: 5 + holddown_all_stale_labels: true + include_mp_next_hop: true + log_updown: true + no_advertise_peer_as: true + no_aggregator_id: true + no_client_reflect: true + out_delay: 10 + precision_timers: true + preference: "2" + state: merged + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_bgp_global: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Update the running configuration with providede configuration + junipernetworks.junos.junos_bgp_global: + config: + as_number: "65534" + loops: 2 + asdot_notation: true + description: "This is updated with Junos_bgp resource module" + egress_te_backup_paths: + templates: + - path_name: "customer1" + peers: + - "11.11.11.11" + - "11.11.11.12" + - "11.11.11.13" + remote_nexthop: "2.2.2.2" + groups: + - name: "internal" + type: "internal" + vpn_apply_export: true + out_delay: 30 + accept_remote_nexthop: true + add_path_display_ipv4_address: true + peer_as: "65534" + allow: + - "all" + - "1.1.1.0/24" + neighbors: + - neighbor_address: "11.11.11.11" + peer_as: "65534" + out_delay: 11 + - neighbor_address: "11.11.11.12" + peer_as: "65534" + out_delay: 12 + + - name: "external" + out_delay: 20 + peer_as: "65534" + accept_remote_nexthop: true + add_path_display_ipv4_address: true + neighbors: + - neighbor_address: "12.12.12.12" + peer_as: "65534" + out_delay: 21 + accept_remote_nexthop: true + add_path_display_ipv4_address: true + - neighbor_address: "11.11.11.13" + peer_as: "65534" + out_delay: 31 + accept_remote_nexthop: true + add_path_display_ipv4_address: true + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result['after'] }}" + + tags: merged + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_global merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/parsed.yaml new file mode 100644 index 000000000..8b226564e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/parsed.yaml @@ -0,0 +1,52 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: + START junos_bgp_global parsed integration tests on connection={{ ansible_connection + }} + +- name: Set facts + ansible.builtin.set_fact: + expected_parsed_output: + accept_remote_nexthop: true + add_path_display_ipv4_address: true + advertise_bgp_static: + policy: "static-to-bgp" + advertise_from_main_vpn_tables: true + advertise_inactive: true + as_number: "65432" + authentication_algorithm: "md5" + bmp: + monitor: true + damping: true + description: "This is configured with Junos_bgp resource module" + egress_te_sid_stats: true + hold_time: 5 + holddown_all_stale_labels: true + include_mp_next_hop: true + log_updown: true + no_advertise_peer_as: true + no_aggregator_id: true + no_client_reflect: true + out_delay: 10 + precision_timers: true + preference: "2" + remove_private: + set: true + +- name: Parse externally provided bgp_global config to agnostic model + register: result + junipernetworks.junos.junos_bgp_global: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output == result['parsed'] }}" + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_bgp_global parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/purged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/purged.yaml new file mode 100644 index 000000000..6ad1d45b3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/purged.yaml @@ -0,0 +1,34 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_global purged integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Initial config + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + config: {} + + - name: Purge all ospf config from the device + junipernetworks.junos.junos_bgp_global: + state: purged + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_global purged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/rendered.yaml new file mode 100644 index 000000000..6ca1f765d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/rendered.yaml @@ -0,0 +1,41 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_bgp_global rendered integration tests on connection={{ + ansible_connection }} + +- name: Set facts + ansible.builtin.set_fact: + expected_rendered_output: '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:bgp><nc:damping/><nc:egress-te-sid-stats/><nc:authentication-algorithm>md5</nc:authentication-algorithm><nc:description>This is configured with Junos_bgp resource module</nc:description><nc:hold-time>5</nc:hold-time><nc:bfd-liveness-detection><nc:transmit-interval><nc:minimum-interval>2</nc:minimum-interval></nc:transmit-interval><nc:minimum-receive-interval>4</nc:minimum-receive-interval><nc:multiplier>10</nc:multiplier><nc:no-adaptation/><nc:version>automatic</nc:version></nc:bfd-liveness-detection><nc:bgp-error-tolerance><nc:malformed-route-limit>20000000</nc:malformed-route-limit></nc:bgp-error-tolerance><nc:bmp><nc:monitor>enable</nc:monitor></nc:bmp></nc:bgp></nc:protocols>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_bgp_global: + config: + authentication_algorithm: "md5" + bfd_liveness_detection: + minimum_receive_interval: 4 + multiplier: 10 + no_adaptation: true + transmit_interval: + minimum_interval: 2 + version: "automatic" + bgp_error_tolerance: + malformed_route_limit: 20000000 + bmp: + monitor: true + damping: true + description: "This is configured with Junos_bgp resource module" + egress_te_sid_stats: true + hold_time: 5 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- name: Debug task + ansible.builtin.debug: + msg: END junos_bgp_global rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/replaced.yaml new file mode 100644 index 000000000..a34d186fe --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/replaced.yaml @@ -0,0 +1,51 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_bgp_global replaced integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Initial config + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Replace configuration + junipernetworks.junos.junos_bgp_global: &replaced + config: + bgp_error_tolerance: + malformed_route_limit: 20000000 + bmp: + monitor: true + damping: true + description: "This is configured with Junos_bgp resource module" + state: replaced + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_bgp_global: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_bgp_global replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/rtt.yml new file mode 100644 index 000000000..e8bf494b0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/tests/netconf/rtt.yml @@ -0,0 +1,92 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_bgp_global round trip integration tests on connection={{ + ansible_connection }} + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_bgp_global: + config: + accept_remote_nexthop: true + add_path_display_ipv4_address: true + advertise_from_main_vpn_tables: true + advertise_inactive: true + as_number: "65534" + asdot_notation: true + authentication_algorithm: "md5" + bgp_error_tolerance: + malformed_route_limit: 20000000 + bmp: + monitor: true + damping: true + egress_te_sid_stats: true + hold_time: 5 + holddown_all_stale_labels: true + include_mp_next_hop: true + log_updown: true + loops: 3 + no_advertise_peer_as: true + no_aggregator_id: true + no_client_reflect: true + out_delay: 10 + precision_timers: true + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - bgp_global + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_bgp_global: + config: + accept_remote_nexthop: true + add_path_display_ipv4_address: true + advertise_from_main_vpn_tables: true + advertise_inactive: true + as_number: "65535" + asdot_notation: true + authentication_algorithm: "md5" + bgp_error_tolerance: + malformed_route_limit: 20000000 + preference: "2" + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_bgp_global: + config: "{{ ansible_facts['network_resources']['bgp_global'] }}" + state: replaced + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] == revert['before'] }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] == revert['after'] }}" + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_bgp_global round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/vars/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/vars/main.yaml new file mode 100644 index 000000000..5927e7ff0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_bgp_global/vars/main.yaml @@ -0,0 +1,110 @@ +--- +merged: + before: {} + + after: + accept_remote_nexthop: true + add_path_display_ipv4_address: true + advertise_from_main_vpn_tables: true + advertise_inactive: true + as_number: "65534" + asdot_notation: true + authentication_algorithm: "md5" + bgp_error_tolerance: + malformed_route_limit: 20000000 + bmp: + monitor: true + damping: true + description: "This is configured with Junos_bgp resource module" + egress_te_sid_stats: true + hold_time: 5 + holddown_all_stale_labels: true + include_mp_next_hop: true + log_updown: true + loops: 3 + no_advertise_peer_as: true + no_aggregator_id: true + no_client_reflect: true + out_delay: 10 + precision_timers: true + preference: "2" + + updated: + accept_remote_nexthop: true + add_path_display_ipv4_address: true + advertise_from_main_vpn_tables: true + advertise_inactive: true + as_number: "65534" + asdot_notation: true + authentication_algorithm: "md5" + bgp_error_tolerance: + malformed_route_limit: 20000000 + bmp: + monitor: true + damping: true + description: "This is updated with Junos_bgp resource module" + egress_te_backup_paths: + templates: + - path_name: "customer1" + peers: + - "11.11.11.11" + - "11.11.11.12" + - "11.11.11.13" + remote_nexthop: "2.2.2.2" + egress_te_sid_stats: true + groups: + - accept_remote_nexthop: true + add_path_display_ipv4_address: true + allow: + - "0.0.0.0/0" + - "1.1.1.0/24" + name: "internal" + neighbors: + - neighbor_address: "11.11.11.11" + out_delay: 11 + peer_as: "65534" + - neighbor_address: "11.11.11.12" + out_delay: 12 + peer_as: "65534" + out_delay: 30 + peer_as: "65534" + type: "internal" + vpn_apply_export: true + + - accept_remote_nexthop: true + add_path_display_ipv4_address: true + name: "external" + neighbors: + - accept_remote_nexthop: true + add_path_display_ipv4_address: true + neighbor_address: "12.12.12.12" + out_delay: 21 + peer_as: "65534" + + - accept_remote_nexthop: true + add_path_display_ipv4_address: true + neighbor_address: "11.11.11.13" + out_delay: 31 + peer_as: "65534" + out_delay: 20 + peer_as: "65534" + hold_time: 5 + holddown_all_stale_labels: true + include_mp_next_hop: true + log_updown: true + loops: 2 + no_advertise_peer_as: true + no_aggregator_id: true + no_client_reflect: true + out_delay: 10 + precision_timers: true + preference: "2" + +replaced: + after: + bgp_error_tolerance: + malformed_route_limit: 20000000 + bmp: + monitor: true + damping: true + description: "This is configured with Junos_bgp resource module" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/defaults/main.yaml new file mode 100644 index 000000000..9ef5ba516 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/cli.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/cli.yaml new file mode 100644 index 000000000..7a0bc5414 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/cli.yaml @@ -0,0 +1,19 @@ +--- +- name: Collect all cli test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + delegate_to: localhost + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.network_cli) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + vars: + ansible_connection: ansible.netcommon.network_cli + loop_control: + loop_var: test_case_to_run diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/main.yaml new file mode 100644 index 000000000..3243ad57e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/main.yaml @@ -0,0 +1,14 @@ +--- +- name: Invoke netconf xml tasks + ansible.builtin.include_tasks: netconf_xml.yaml + +- name: Invoke netconf text + ansible.builtin.include_tasks: netconf_text.yaml + +- name: Invoke netconf json tasks + ansible.builtin.include_tasks: netconf_json.yaml + +- name: Invoke netconf cli tasks + ansible.builtin.include_tasks: cli.yaml + tags: + - network_cli diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/netconf_json.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/netconf_json.yaml new file mode 100644 index 000000000..88125160e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/netconf_json.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect netconf_json test cases with json encoding + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf_json" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/netconf_text.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/netconf_text.yaml new file mode 100644 index 000000000..6680dd8a3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/netconf_text.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect netconf_text test cases with text encoding + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf_text" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/netconf_xml.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/netconf_xml.yaml new file mode 100644 index 000000000..e2a9be498 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tasks/netconf_xml.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect netconf_xml test cases with xml encoding + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf_xml" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/cli/cli_commmand.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/cli/cli_commmand.yaml new file mode 100644 index 000000000..649e5a52e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/cli/cli_commmand.yaml @@ -0,0 +1,69 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START cli/cli_command.yaml on connection={{ ansible_connection }} + +- block: + - name: Run get output for single command + register: result + ansible.netcommon.cli_command: + command: show version + + - name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + + - name: Run test with prompt and answer + loop: + - configure + - set system syslog file test any any + - rollback + - exit + register: result + ansible.netcommon.cli_command: + command: "{{ item }}" + prompt: + - Exit with uncommitted changes + answer: true + + - name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + + - loop: + - configure + - rollback + - set system login user ansible_test class operator authentication plain-text-password + - commit + register: result + ignore_errors: true + ansible.netcommon.cli_command: + command: "{{item}}" + prompt: + - New password + - Retype new password + answer: + - Test1234 + - Test1234 + check_all: true + + - name: Assertion + ansible.builtin.assert: + that: + - "'failed' not in result" + + - register: result + ignore_errors: true + junipernetworks.junos.junos_netconf: + + - name: Assertion + ansible.builtin.assert: + that: + - result.failed == false + when: ansible_connection == 'ansible.netcommon.network_cli' + +- name: Debug task + ansible.builtin.debug: msg="END cli/cli_command.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/bad_operator.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/bad_operator.yaml new file mode 100644 index 000000000..6b51014f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/bad_operator.yaml @@ -0,0 +1,27 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_json/bad_operator.yaml on connection={{ ansible_connection + }}" + +- name: Run test bad operator with json encoding + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + wait_for: + - result[0]['software-information'][0]['host-name'][0]['data'] foo lo0 + format: json + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - result.msg is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_json/bad_operator.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/contains.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/contains.yaml new file mode 100644 index 000000000..32129d3f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/contains.yaml @@ -0,0 +1,28 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_json/contains.yaml on connection={{ ansible_connection + }}" + +- name: Run test contains operator with json encoding + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['name'][0]['data'] + contains lo0 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_json/contains.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/equal.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/equal.yaml new file mode 100644 index 000000000..9d397f3f7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/equal.yaml @@ -0,0 +1,44 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_json/equal.yaml on connection={{ ansible_connection + }}" + +- name: Perform test == operator with xml encoding + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['name'][0]['data'] + == lo0 + format: json + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Run test eq operator with json encoding + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['name'][0]['data'] + eq lo0 + format: json + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: msg="END netconf_json/equal.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/greaterthan.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/greaterthan.yaml new file mode 100644 index 000000000..474a54bb1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/greaterthan.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_json/greaterthan.yaml on connection={{ ansible_connection + }}" + +- name: Test gt operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['local-index'][0]['data'] + gt 5 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Run test > operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['local-index'][0]['data'] + > 5 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_json/greaterthan.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/greaterthanorequal.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/greaterthanorequal.yaml new file mode 100644 index 000000000..c5ba4a525 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/greaterthanorequal.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_json/greaterthanorequal.yaml on connection={{ ansible_connection + }}" + +- name: Run test ge operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['local-index'][0]['data'] + ge 6 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Run test >= operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['local-index'][0]['data'] + >= 6 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_json/greaterthanorequal.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/lessthan.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/lessthan.yaml new file mode 100644 index 000000000..3fba44bc3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/lessthan.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_json/lessthan.yaml on connection={{ ansible_connection + }}" + +- name: Run test lt operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['local-index'][0]['data'] + lt 7 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Run test < operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['local-index'][0]['data'] + lt 7 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_json/lessthan.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/lessthanorequal.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/lessthanorequal.yaml new file mode 100644 index 000000000..6d5989809 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/lessthanorequal.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_json/lessthanorequal.yaml on connection={{ ansible_connection + }}" + +- name: Run test le operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['local-index'][0][data] + le 6 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Run test <= operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['local-index'][0][data] + <= 6 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_json/lessthanorequal.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/notequal.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/notequal.yaml new file mode 100644 index 000000000..3213b8b64 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/notequal.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_json/notequal.yaml on connection={{ ansible_connection + }}" + +- name: Run test neq operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['name'][0]['data'] + neq em0 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Run test != operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: json + wait_for: + - result[1]['interface-information'][0]['physical-interface'][0]['name'][0]['data'] + neq em0 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_json/notequal.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/output.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/output.yaml new file mode 100644 index 000000000..9e1c16a2b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_json/output.yaml @@ -0,0 +1,67 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_json/output.yaml on connection={{ ansible_connection + }}" + +- name: Run get output for single command + register: result + junipernetworks.junos.junos_command: + commands: + - show version + format: json + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Get output for multiple commands + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show route + format: json + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Get output for single command with cli transport + register: result + connection: ansible.netcommon.network_cli + junipernetworks.junos.junos_command: + commands: + - show version | display json + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Get output for multiple commands with cli transport + register: result + connection: ansible.netcommon.network_cli + junipernetworks.junos.junos_command: + commands: + - show version + - show route + format: json + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: msg="END netconf_json/output.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/bad_operator.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/bad_operator.yaml new file mode 100644 index 000000000..9fa6242da --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/bad_operator.yaml @@ -0,0 +1,28 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_text/bad_operator.yaml on connection={{ ansible_connection + }}" + +- name: Test bad operator with text encoding + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + wait_for: + - result[1].interface-information[0].physical-interface[0].name[0].data foo + lo0 + encoding: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - result.msg is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_text/bad_operator.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/contains.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/contains.yaml new file mode 100644 index 000000000..13cb325c5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/contains.yaml @@ -0,0 +1,27 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_text/contains.yaml on connection={{ ansible_connection + }}" + +- name: Test contains operator with text encoding + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + display: text + wait_for: + - result[1] contains lo0 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_text/contains.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/invalid.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/invalid.yaml new file mode 100644 index 000000000..ae847181a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/invalid.yaml @@ -0,0 +1,41 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_text/invalid.yaml on connection={{ ansible_connection + }}" + +- name: Run invalid command + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show foo + display: text + +- name: Debug task + ansible.builtin.debug: var=result + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - result.msg is defined + +- name: Run commands that ansible.builtin.include invalid command + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - show version + - show foo + display: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - result.msg is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_text/invalid.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/no_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/no_config.yaml new file mode 100644 index 000000000..b90ee1067 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/no_config.yaml @@ -0,0 +1,26 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_text/no_config.yaml on connection={{ ansible_connection + }}" + +- name: Test handling of show command's empty response received from network device + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - show configuration system ntp + display: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == false + - result.changed == false + - result.stdout|symmetric_difference([""]) == [] + - result.stdout_lines|symmetric_difference([[""]]) == [] + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_text/no_config.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/output.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/output.yaml new file mode 100644 index 000000000..74bc67f1a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/output.yaml @@ -0,0 +1,78 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_text/output.yaml on connection={{ ansible_connection + }}" + +- name: Get output for single command + register: result + junipernetworks.junos.junos_command: + commands: show version + display: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Get output for multiple commands + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show route + display: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: get output for partial config commands + register: result + junipernetworks.junos.junos_command: + commands: + - show configuration system syslog + display: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Get output for single command with cli transport + register: result + junipernetworks.junos.junos_command: + commands: show version + display: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Get output for multiple commands with cli transport + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show route + display: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: msg="END netconf_text/output.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/timeout.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/timeout.yaml new file mode 100644 index 000000000..f1a6d51dd --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_text/timeout.yaml @@ -0,0 +1,26 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_text/timeout.yaml on connection={{ ansible_connection + }}" + +- name: Test bad condition + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - show version + wait_for: + - result[0] contains bad_value_string + display: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - result.msg is defined + +- name: Assertion + ansible.builtin.debug: + msg="END netconf_text/timeout.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/bad_operator.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/bad_operator.yaml new file mode 100644 index 000000000..8e3f1c2db --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/bad_operator.yaml @@ -0,0 +1,28 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/bad_operator.yaml on connection={{ ansible_connection + }}" + +- name: Test bad operator with xml encoding + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + wait_for: + - result[1].rpc-reply.interface-information[0].physical-interface[0].name[0].data + foo lo0 + format: xml + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - result.msg is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_xml/bad_operator.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/contains.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/contains.yaml new file mode 100644 index 000000000..1cb019682 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/contains.yaml @@ -0,0 +1,28 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/contains.yaml on connection={{ ansible_connection + }}" + +- name: Test contains operator with xml encoding + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.name contains + lo0 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_xml/contains.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/equal.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/equal.yaml new file mode 100644 index 000000000..74507da7c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/equal.yaml @@ -0,0 +1,40 @@ +--- +- name: Debug task + ansible.builtin.debug: msg="START netconf_xml/equal.yaml on connection={{ ansible_connection }}" + +- name: Run test == operator with xml encoding + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.name == lo0 + format: xml + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Test eq operator with json encoding + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.name eq lo0 + format: xml + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: msg="END netconf_xml/equal.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/greaterthan.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/greaterthan.yaml new file mode 100644 index 000000000..d6ca1d0fd --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/greaterthan.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/greaterthan.yaml on connection={{ ansible_connection + }}" + +- name: Run test gt operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.local-index + gt 5 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Run test > operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.local-index + > 5 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_xml/greaterthan.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/greaterthanorequal.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/greaterthanorequal.yaml new file mode 100644 index 000000000..6f1aebb29 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/greaterthanorequal.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/greaterthanorequal.yaml on connection={{ ansible_connection + }}" + +- name: Test ge operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.local-index + ge 6 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Test >= operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.local-index + >= 6 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_xml/greaterthanorequal.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/invalid.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/invalid.yaml new file mode 100644 index 000000000..95351ecef --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/invalid.yaml @@ -0,0 +1,38 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/invalid.yaml on connection={{ ansible_connection + }}" + +- name: Run invalid command + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - show foo + +- name: Debug task + ansible.builtin.debug: var=result + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - result.msg is defined + +- name: Run commands that ansible.builtin.include invalid command + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - show version + - show foo + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - result.msg is defined + +- name: Debug task + ansible.builtin.debug: msg="END netconf_xml/invalid.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/lessthan.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/lessthan.yaml new file mode 100644 index 000000000..da596f53d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/lessthan.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/lessthan.yaml on connection={{ ansible_connection + }}" + +- name: Test lt operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.local-index + lt 7 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Test < operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.local-index + lt 7 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_xml/lessthan.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/lessthanorequal.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/lessthanorequal.yaml new file mode 100644 index 000000000..bb8c0b852 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/lessthanorequal.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/lessthanorequal.yaml on connection={{ ansible_connection + }}" + +- name: Test le operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.local-index + le 6 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Test <= operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.local-index + <= 6 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_xml/lessthanorequal.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/notequal.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/notequal.yaml new file mode 100644 index 000000000..2e901f215 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/notequal.yaml @@ -0,0 +1,44 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/notequal.yaml on connection={{ ansible_connection + }}" + +- name: Test neq operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.name neq em0 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Test != operator + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show interfaces lo0 + format: xml + wait_for: + - result[1].rpc-reply.interface-information.physical-interface.name neq em0 + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: + msg="END netconf_xml/notequal.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/output.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/output.yaml new file mode 100644 index 000000000..ad3e3f684 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/output.yaml @@ -0,0 +1,66 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/output.yaml on connection={{ ansible_connection + }}" + +- name: Get output for single command + register: result + junipernetworks.junos.junos_command: + commands: + - show version + format: xml + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Get output for multiple commands + register: result + junipernetworks.junos.junos_command: + commands: + - show version + - show route + format: xml + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Get output for single command with cli transport + register: result + connection: ansible.netcommon.network_cli + junipernetworks.junos.junos_command: + commands: show version | display xml + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Get output for multiple commands with cli transport + register: result + connection: ansible.netcommon.network_cli + junipernetworks.junos.junos_command: + commands: + - show version + - show route + display: xml + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - result.stdout is defined + - result.stdout_lines is defined + +- name: Debug task + ansible.builtin.debug: msg="END netconf_xml/output.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/timeout.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/timeout.yaml new file mode 100644 index 000000000..fedb6d5dd --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_command/tests/netconf_xml/timeout.yaml @@ -0,0 +1,23 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg="START netconf_xml/timeout.yaml on connection={{ ansible_connection + }}" + +- name: Test bad condition + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - show version + wait_for: + - result[0] contains bad_value_string + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - result.msg is defined + +- name: Debug task + ansible.builtin.debug: msg="END netconf_xml/timeout.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/defaults/main.yaml new file mode 100644 index 000000000..5f709c5aa --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/cli_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/cli_config.yaml new file mode 100644 index 000000000..7e2151847 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/cli_config.yaml @@ -0,0 +1,19 @@ +--- +- name: Collect all cli test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/cli_config" + patterns: "{{ testcase }}.yaml" + register: test_cases + delegate_to: localhost + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.network_cli) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/main.yaml new file mode 100644 index 000000000..7daaf8c3b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/main.yaml @@ -0,0 +1,12 @@ +--- +- name: Invoke netconf netconf tasks + ansible.builtin.include_tasks: netconf.yaml + +- name: Invoke cli tasks + ansible.builtin.include_tasks: cli_config.yaml + tags: + - network_cli + +- name: Invoke tasks + ansible.builtin.include_tasks: redirection.yaml + when: ansible_version.full is version('2.10.0', '>=') diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/netconf.yaml new file mode 100644 index 000000000..824d3b006 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/netconf.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/redirection.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/redirection.yaml new file mode 100644 index 000000000..7671a0477 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tasks/redirection.yaml @@ -0,0 +1,18 @@ +--- +- name: Collect redirection test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/redirection/" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.j2 b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.j2 new file mode 100644 index 000000000..44ddf67bf --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.j2 @@ -0,0 +1,9 @@ +interfaces { + lo0 { + unit 0 { + family inet { + address 192.0.2.1/32; + } + } + } +} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.set b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.set new file mode 100644 index 000000000..df436bba9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.set @@ -0,0 +1 @@ +set interfaces lo0 unit 0 family inet address 192.0.2.1/32 diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.xml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.xml new file mode 100644 index 000000000..a120d4bc4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.xml @@ -0,0 +1,15 @@ +<interfaces> + <interface> + <name>lo0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>192.0.2.1/32</name> + </address> + </inet> + </family> + </unit> + </interface> +</interfaces> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/cli_config/cli_backup.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/cli_config/cli_backup.yaml new file mode 100644 index 000000000..37c7157bc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/cli_config/cli_backup.yaml @@ -0,0 +1,110 @@ +--- +- ansible.builtin.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 + ansible.builtin.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 + register: result + ansible.netcommon.cli_config: + backup: true + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: collect any backup files + ansible.builtin.find: + paths: "{{ role_path }}/backup" + pattern: "{{ inventory_hostname_short }}_config*" + register: backup_files + connection: local + +- ansible.builtin.assert: + that: + - backup_files.files is defined + +- name: take configuration backup in custom filename and directory path + register: result + ansible.netcommon.cli_config: + backup: true + backup_options: + filename: backup.cfg + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: check if the backup file-1 exist + ansible.builtin.find: + paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup.cfg" + register: backup_file + connection: local + +- ansible.builtin.assert: + that: + - backup_file.files is defined + +- name: take configuration backup in custom filename + register: result + ansible.netcommon.cli_config: + backup: true + backup_options: + filename: backup.cfg + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: check if the backup file-2 exist + ansible.builtin.find: + paths: "{{ role_path }}/backup/backup.cfg" + register: backup_file + connection: local + +- ansible.builtin.assert: + that: + - backup_file.files is defined + +- name: take configuration backup in custom path and default filename + register: result + ansible.netcommon.cli_config: + backup: true + backup_options: + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: check if the backup file-3 exist + ansible.builtin.find: + paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + pattern: "{{ inventory_hostname_short }}_config*" + register: backup_file + connection: local + +- ansible.builtin.assert: + that: + - backup_file.files is defined + +- ansible.builtin.debug: msg="END cli_config/backup.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/cli_config/cli_basic.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/cli_config/cli_basic.yaml new file mode 100644 index 000000000..fd0659a30 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/cli_config/cli_basic.yaml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg="START cli_config/cli_basic.yaml on connection={{ ansible_connection + }}" + +- name: setup + ansible.netcommon.cli_config: &id002 + config: delete interfaces ge-0/0/1 + +- name: setup + ansible.netcommon.cli_config: &id003 + config: delete interfaces ge-0/0/2 + +- name: configure device with config + register: result + ansible.netcommon.cli_config: &id001 + config: set interfaces ge-0/0/1 description 'test-interface' + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: Idempotence + register: result + ansible.netcommon.cli_config: *id001 + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: configure device with config + register: result + ansible.netcommon.cli_config: + config: set interfaces ge-0/0/2 description 'test-interface' + +- name: test rollabck + register: result + ansible.netcommon.cli_config: + rollback: 1 + +- ansible.builtin.assert: + that: + - result.changed == true + - "'ge-0/0/2' in result.diff.prepared" + +- name: remove root-authethication (test error scenario) + ignore_errors: true + register: result + ansible.netcommon.cli_config: + config: delete system root-authentication + +- ansible.builtin.assert: + that: + - result.failed == true + - "'Missing mandatory statement' in result.msg" + +- name: teardown + ansible.netcommon.cli_config: *id002 + +- name: teardown + ansible.netcommon.cli_config: *id003 + +- ansible.builtin.debug: + msg="END cli_config/cli_basic.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/cli_config/cli_replace.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/cli_config/cli_replace.yaml new file mode 100644 index 000000000..b997b318b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/cli_config/cli_replace.yaml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg="START cli_config/cli_replace.yaml on connection={{ ansible_connection + }}" + +- name: set interface config + loop: + - delete interfaces ge-0/0/11 + - set interfaces ge-0/0/11 description "test cli_config" + ansible.netcommon.cli_config: + config: "{{ item }}" + +- name: get running configuration + register: result + ansible.netcommon.cli_command: + command: show configuration + +- name: copy configuration to file + copy: + content: "{{ result['stdout'] }}" + dest: /tmp/junos01.cfg + +- name: modify interface ge-0/0/11 configuration + replace: + path: /tmp/junos01.cfg + regexp: test cli_config + replace: test cli_config replaced + +- name: copy config file to remote host + ansible.netcommon.net_put: + src: /tmp/junos01.cfg + protocol: sftp + dest: /var/home/{{ ansible_user }}/junos01.cfg + +- name: replace syslog test file configuration + ansible.netcommon.cli_config: + replace: /var/home/{{ ansible_user }}/junos01.cfg + +- name: get interface configuration + register: result + ansible.netcommon.cli_command: + command: show configuration interfaces ge-0/0/11 + +- name: ansible.builtin.assert that interface config change is reflected on device + ansible.builtin.assert: + that: + - "'test cli_config replaced' in result.stdout" + +- name: replace interface configuration (idempotent) + register: result + ansible.netcommon.cli_config: + replace: /var/home/{{ ansible_user }}/junos01.cfg + +- name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + +- name: delete interface config + ansible.netcommon.cli_config: + config: delete interfaces ge-0/0/11 + +- ansible.builtin.debug: + msg="END cli_config/cli_replace.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/backup.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/backup.yaml new file mode 100644 index 000000000..b6746c40a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/backup.yaml @@ -0,0 +1,32 @@ +--- +- ansible.builtin.debug: msg="START netconf/backup.yaml on connection={{ ansible_connection }}" + +- name: setup + junipernetworks.junos.junos_config: + lines: + - set system host-name {{ inventory_hostname_short }} + - delete interfaces lo0 + +- name: configure device with config + register: result + junipernetworks.junos.junos_config: + src: basic/config.j2 + backup: true + +- ansible.builtin.assert: + that: + - result.changed == true + - result.updates is not defined + +- name: take configuration backup in custom filename + register: result + junipernetworks.junos.junos_config: + backup: true + backup_options: + filename: backup.cfg + +- ansible.builtin.assert: + that: + - result.changed == true + +- ansible.builtin.debug: msg="END netconf/backup.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/bad_action.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/bad_action.yaml new file mode 100644 index 000000000..ad97a18fd --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/bad_action.yaml @@ -0,0 +1,17 @@ +--- +- ansible.builtin.debug: + msg="START netconf/bad_action.yaml on connection={{ ansible_connection + }}" + +- name: configure single bad_action command + register: result + ignore_errors: true + junipernetworks.junos.junos_config: + lines: + - invalid system foo + +- ansible.builtin.assert: + that: + - result.failed == true + +- ansible.builtin.debug: msg="END netconf/bad_action.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/invalid.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/invalid.yaml new file mode 100644 index 000000000..6cb7453d6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/invalid.yaml @@ -0,0 +1,27 @@ +--- +- ansible.builtin.debug: msg="START netconf/invalid.yaml on connection={{ ansible_connection }}" + +- name: configure single invalid command + register: result + ignore_errors: true + junipernetworks.junos.junos_config: + lines: + - set system foo + +- ansible.builtin.assert: + that: + - result.failed == true + +- name: configure multiple invalid command + register: result + ignore_errors: true + junipernetworks.junos.junos_config: + lines: + - set system host-name {{ inventory_hostname_short }} + - set system foo + +- ansible.builtin.assert: + that: + - result.failed == true + +- ansible.builtin.debug: msg="END netconf/invalid.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/multiple.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/multiple.yaml new file mode 100644 index 000000000..b53841930 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/multiple.yaml @@ -0,0 +1,43 @@ +--- +- ansible.builtin.debug: msg="START netconf/multiple.yaml on connection={{ ansible_connection }}" + +- name: setup + register: test + junipernetworks.junos.junos_config: + lines: + - set system host-name {{ inventory_hostname_short }} + - delete interfaces lo0 + +- name: configure multiple commands + register: result + junipernetworks.junos.junos_config: + lines: + - set system host-name {{ inventory_hostname_short }} + - set interfaces lo0 unit 0 family inet address 192.0.2.1/32 + +- ansible.builtin.assert: + that: + - result.changed == true + - "'host-name;' not in result.diff.prepared" + - "'address 192.0.2.1/32' in result.diff.prepared" + +- name: check multiple commands idempotent + register: result + junipernetworks.junos.junos_config: + lines: + - set system host-name {{ inventory_hostname_short }} + - set interfaces lo0 unit 0 family inet address 192.0.2.1/32 + +- ansible.builtin.assert: + that: + - result.changed == false + - result.diff is not defined + +- name: teardown + register: test + junipernetworks.junos.junos_config: + lines: + - set system host-name {{ inventory_hostname_short }} + - delete interfaces lo0 + +- ansible.builtin.debug: msg="END netconf/multiple.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/single.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/single.yaml new file mode 100644 index 000000000..07f09dce8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/single.yaml @@ -0,0 +1,72 @@ +--- +- ansible.builtin.debug: msg="START netconf/single.yaml on connection={{ ansible_connection }}" + +- name: setup + junipernetworks.junos.junos_config: + lines: + - set system host-name {{ inventory_hostname_short }} + +- name: configure single command + register: result + junipernetworks.junos.junos_config: + lines: + - set system host-name localhost + +- ansible.builtin.assert: + that: + - result.changed == true + - "'+ host-name localhost;' in result.diff.prepared" + +- name: check single command idempotent + register: result + junipernetworks.junos.junos_config: + lines: + - set system host-name localhost + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: confirm previous commit + register: result + junipernetworks.junos.junos_config: + confirm_commit: true + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: teardown for rollback test + junipernetworks.junos.junos_config: + lines: + - delete system syslog file test1 + +- name: Configure syslog file + register: result + junipernetworks.junos.junos_config: + lines: + - set system syslog file test1 any any + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("\+ *file test1") + - result.diff.prepared is search("\+ *any any") + +- name: Rollback junos config + register: result + junipernetworks.junos.junos_config: + rollback: 1 + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("\+ *file test1") + - result.diff.prepared is search("\+ *any any") + +- name: teardown + junipernetworks.junos.junos_config: + lines: + - set system host-name {{ inventory_hostname_short }} + +- ansible.builtin.debug: msg="END netconf/single.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/src_basic.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/src_basic.yaml new file mode 100644 index 000000000..504a76938 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/src_basic.yaml @@ -0,0 +1,96 @@ +--- +- ansible.builtin.debug: msg="START netconf/src_basic.yaml on connection={{ ansible_connection }}" + +- name: setup + junipernetworks.junos.junos_config: + lines: + - set system host-name {{ inventory_hostname_short }} + - delete interfaces lo0 + +- name: configure device with text config + register: result + junipernetworks.junos.junos_config: + src: basic/config.j2 + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: check device with config + register: result + junipernetworks.junos.junos_config: + src: basic/config.j2 + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: teardown + register: result + junipernetworks.junos.junos_config: + lines: + - delete interfaces lo0 + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: configure device with set config + register: result + junipernetworks.junos.junos_config: + src: basic/config.set + +- ansible.builtin.assert: + that: + - result.changed == true + - "'address 192.0.2.1/32' in result.diff.prepared" + +- name: check device with config + register: result + junipernetworks.junos.junos_config: + src: basic/config.set + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: teardown + register: result + junipernetworks.junos.junos_config: + lines: + - delete interfaces lo0 + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: configure device with xml config + register: result + junipernetworks.junos.junos_config: + src: basic/config.xml + +- ansible.builtin.assert: + that: + - result.changed == true + - "'address 192.0.2.1/32' in result.diff.prepared" + +- name: check device with config + register: result + junipernetworks.junos.junos_config: + src: basic/config.xml + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: teardown + register: result + junipernetworks.junos.junos_config: + lines: + - delete interfaces lo0 + +- ansible.builtin.assert: + that: + - result.changed == true + +- ansible.builtin.debug: msg="END netconf/src_basic.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/src_invalid.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/src_invalid.yaml new file mode 100644 index 000000000..1934b1c5f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/netconf/src_invalid.yaml @@ -0,0 +1,18 @@ +--- +- ansible.builtin.debug: + msg="START netconf/src_invalid.yaml on connection={{ ansible_connection + }}" + +- name: configure with invalid src + register: result + ignore_errors: true + junipernetworks.junos.junos_config: + src: basic/foobar.j2 + +- ansible.builtin.assert: + that: + - result.changed == false + - result.failed == true + - result.msg == 'path specified in src not found' + +- ansible.builtin.debug: msg="END netconf/src_invalid.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/redirection/shortname.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/redirection/shortname.yaml new file mode 100644 index 000000000..d21594c28 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/tests/redirection/shortname.yaml @@ -0,0 +1,47 @@ +--- +- ansible.builtin.debug: msg="START redirection/netconf/shortname.yaml on connection={{ ansible_connection }}" + +- name: setup + junipernetworks.junos.config: + lines: + - delete interfaces lo0 + +- name: Use src with module alias + register: result + junipernetworks.junos.config: + src: basic/config.j2 + +- ansible.builtin.assert: + that: + # make sure that the template content was read and not the path + - result.changed == true + +- name: teardown + register: result + junipernetworks.junos.config: + lines: + - delete interfaces lo0 + +- name: use module alias to take configuration backup + register: result + junipernetworks.junos.config: + backup: true + backup_options: + filename: backup_with_alias.cfg + dir_path: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}" + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: check if the backup file-4 exist + ansible.builtin.find: + paths: "{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup_with_alias.cfg" + register: backup_file + connection: local + +- ansible.builtin.assert: + that: + - backup_file.files is defined + +- ansible.builtin.debug: msg="END redirection/netconf/shortname.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/defaults/main.yaml new file mode 100644 index 000000000..9ef5ba516 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/tasks/main.yaml new file mode 100644 index 000000000..ac951c8f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/tasks/netconf.yaml new file mode 100644 index 000000000..824d3b006 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/tasks/netconf.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/tests/netconf/facts.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/tests/netconf/facts.yaml new file mode 100644 index 000000000..b795d98ed --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_facts/tests/netconf/facts.yaml @@ -0,0 +1,126 @@ +--- +- name: Debug task + ansible.builtin.debug: msg="START netconf/facts.yaml on connection={{ ansible_connection }}" + +- name: Collect default facts from device + register: result + junipernetworks.junos.junos_facts: + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - "'ansible_net_hostname' in result['ansible_facts']" + - "'ansible_net_system' in result['ansible_facts']" + - "'ansible_net_model' in result['ansible_facts']" + +- name: Collect config facts from device + register: result + junipernetworks.junos.junos_facts: + gather_subset: config + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - "'ansible_net_config' in result['ansible_facts']" + - "'ansible_net_interfaces' not in result['ansible_facts']" + - "'ansible_net_memfree_mb' not in result['ansible_facts']" + +- name: Collect all facts from device except hardware + register: result + junipernetworks.junos.junos_facts: + gather_subset: "!hardware" + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - "'ansible_net_config' in result['ansible_facts']" + - "'ansible_net_interfaces' in result['ansible_facts']" + - "'ansible_net_memfree_mb' not in result['ansible_facts']" + +- name: Invalid facts subset value + ignore_errors: true + register: result + junipernetworks.junos.junos_facts: + gather_subset: test + +- name: Assertion + ansible.builtin.assert: + that: + - result.failed == true + - "'Subset must be one of' in result.msg" + +- name: Collect config facts from device in set format + register: result + junipernetworks.junos.junos_facts: + gather_subset: config + config_format: set + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - "'set system services netconf ssh' in result['ansible_facts']['ansible_net_config']" + +- name: Collect config facts from device in xml format + register: result + junipernetworks.junos.junos_facts: + gather_subset: config + config_format: xml + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - "'<netconf>' in result['ansible_facts']['ansible_net_config']" + +- name: Collect config facts from device in json format + register: result + junipernetworks.junos.junos_facts: + gather_subset: config + config_format: json + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - "'{{ result['ansible_facts']['ansible_net_config']['configuration'][0]['system'][0]['service'][0]['netconf']\ + \ }}' is defined" + when: ansible_net_version == "15.1X49-D15.4" + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - "'ssh' in result['ansible_facts']['ansible_net_config']['configuration']['system']['services']['netconf']" + when: ansible_net_version == "17.3R1.10" + +- name: Collect config facts from device in text format + register: result + junipernetworks.junos.junos_facts: + gather_subset: config + config_format: text + +- name: Assertion + ansible.builtin.assert: + that: + - result.changed == false + - "'netconf {' in result['ansible_facts']['ansible_net_config']" + +- name: Collect list of available network resources for junos + register: result + junipernetworks.junos.junos_facts: + available_network_resources: true + gather_network_resources: all + +- name: Assert that correct available_network_resources returned + ansible.builtin.assert: + that: + - result.changed == false + - "{{ result['ansible_facts']['available_network_resources'] | symmetric_difference(result['ansible_facts']['ansible_net_gather_network_resources']) |length\ + \ == 0 }}" + +- name: Debug task + ansible.builtin.debug: msg="END netconf/facts.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..cf6e70db9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/_initial_config.yaml @@ -0,0 +1,13 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_hostname initial config on connection={{ ansible_connection }}" + +- name: Configure basic config relevant to ntp global + junipernetworks.junos.junos_config: + lines: + - set system host-name "vsrx12" + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_hostname initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..a8d6419d5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/_reset_config.yaml @@ -0,0 +1,13 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_hostname reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to ntp global resource + junipernetworks.junos.junos_config: + lines: + - delete system host-name + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_hostname reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/deleted.yaml new file mode 100644 index 000000000..00a4b9683 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/deleted.yaml @@ -0,0 +1,33 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_hostname deleted integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Initial configuration + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Set facts + ansible.builtin.set_fact: + config: {} + - name: Delete hostname config + junipernetworks.junos.junos_hostname: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_hostname deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..ca0ed7182 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/empty_config.yaml @@ -0,0 +1,66 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_hostname empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_hostname: + config: + state: merged + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_hostname: + config: + state: replaced + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_hostname: + config: + state: overridden + +- name: Assertion + ansible.builtin.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 + junipernetworks.junos.junos_hostname: + running_config: + state: parsed + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_hostname: + config: + state: rendered + +- name: Assertion + ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..6619c8d64 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,156 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <login> + <user> + <name>vagrant</name> + <uid>2000</uid> + <class>super-user</class> + <authentication> + <encrypted-password>$6$QiBkxU5N$QY11GzNuFs1sfY0OAacyJ/0WFmP9ciovUAmM425yYAo9OjccxvjWlEZNo8SeqCQxYeM86cfd9V.N1RiiHW2zN0</encrypted-password> + <ssh-rsa> + <name>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key</name> + </ssh-rsa> + </authentication> + </user> + </login> + <root-authentication> + <encrypted-password>$1$nq.N1UsY$JxA/ESAj3KuXseXE597gg0</encrypted-password> + <ssh-rsa> + <name>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key</name> + </ssh-rsa> + </root-authentication> + <services> + <ssh> + </ssh> + <netconf> + <ssh> + <port>830</port> + </ssh> + <rfc-compliant/> + </netconf> + </services> + <host-name>vsrx</host-name> + <syslog> + <user> + <name>*</name> + <contents> + <name>any</name> + <emergency/> + </contents> + </user> + <file> + <name>messages</name> + <contents> + <name>any</name> + <any/> + </contents> + <contents> + <name>authorization</name> + <info/> + </contents> + </file> + <file> + <name>interactive-commands</name> + <contents> + <name>interactive-commands</name> + <any/> + </contents> + </file> + </syslog> + <license> + <autoupdate> + <url> + <name>https://ae1.juniper.net/junos/key_retrieval</name> + </url> + </autoupdate> + </license> + <ntp> + <boot-server>78.46.194.186</boot-server> + <interval-range> + <value>2</value> + </interval-range> + <peer> + <name>78.44.194.186</name> + </peer> + <peer> + <name>172.44.194.186</name> + <key>10000</key> + <version>3</version> + <prefer/> + </peer> + <server> + <name>48.46.194.186</name> + <key>34</key> + <version>2</version> + <prefer/> + <routing-instance>rt1</routing-instance> + </server> + <server> + <name>48.45.194.186</name> + <key>34</key> + <version>2</version> + <prefer/> + </server> + <broadcast> + <name>172.16.255.255</name> + <routing-instance-name>rt1</routing-instance-name> + <key>50</key> + <version>3</version> + <ttl>200</ttl> + </broadcast> + <broadcast> + <name>192.16.255.255</name> + <routing-instance-name>rt2</routing-instance-name> + <key>50</key> + <version>3</version> + <ttl>200</ttl> + </broadcast> + <broadcast-client/> + <multicast-client> + <address>224.0.0.1</address> + </multicast-client> + <trusted-key>3000</trusted-key> + <trusted-key>2000</trusted-key> + <threshold> + <value>300</value> + <action>accept</action> + </threshold> + <source-address> + <name>172.45.194.186</name> + <routing-instance>rt1</routing-instance> + </source-address> + <source-address> + <name>171.45.194.186</name> + <routing-instance>rt2</routing-instance> + </source-address> + </ntp> + </system> + <interfaces xmlns="http://yang.juniper.net/junos-es/conf/interfaces"> + <interface> + <name>fxp0</name> + <unit> + <name>0</name> + <family> + <inet> + <dhcp> + </dhcp> + </inet> + </family> + </unit> + </interface> + </interfaces> + <routing-instances xmlns="http://yang.juniper.net/junos-es/conf/routing-instances"> + <instance> + <name>rt1</name> + <description>rt1</description> + </instance> + <instance> + <name>rt2</name> + <description>rt2</description> + </instance> + </routing-instances> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/gathered.yaml new file mode 100644 index 000000000..8c1a988af --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/gathered.yaml @@ -0,0 +1,29 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_hostname gathered integration tests on connection={{ ansible_connection }} + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + - name: Initial configuration + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_hostname: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ merged['gathered'] == result['gathered'] }}" + + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_hostname gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/merged.yaml new file mode 100644 index 000000000..a49fb9e45 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/merged.yaml @@ -0,0 +1,59 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_hostname merged integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_hostname: &merged + config: + hostname: "vsrx" + + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_hostname: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Update the running configuration with providede configuration + junipernetworks.junos.junos_hostname: + config: + hostname: "vsrx14" + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result['after'] }}" + + tags: merged + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Reset configuration + ansible.builtin.debug: + msg: "END junos_hostname merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/overridden.yaml new file mode 100644 index 000000000..365df590b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/overridden.yaml @@ -0,0 +1,46 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_hostname overridden integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Initial configuration + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_hostname: &overridden + config: + hostname: "vsrx14" + state: overridden + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['gathered'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_hostname: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_hostname overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/parsed.yaml new file mode 100644 index 000000000..1591fec93 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/parsed.yaml @@ -0,0 +1,23 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: + START junos_hostname parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided hostname config to agnostic model + register: result + junipernetworks.junos.junos_hostname: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ merged['after'] == result['parsed'] }}" + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_hostname parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/rendered.yaml new file mode 100644 index 000000000..83d106858 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/rendered.yaml @@ -0,0 +1,26 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_hostname rendered integration tests on connection={{ + ansible_connection }} + +- name: Set facts + ansible.builtin.set_fact: + expected_rendered_output: '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:host-name>vsrx14</nc:host-name></nc:system>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_hostname: + config: + hostname: "vsrx14" + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- name: Debug task + ansible.builtin.debug: + msg: END junos_hostname rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/replaced.yaml new file mode 100644 index 000000000..d7b35b962 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/replaced.yaml @@ -0,0 +1,45 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_hostname replaced integration tests on connection={{ ansible_connection }}" + +- block: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + + - name: Initial configuration + ansible.builtin.include_tasks: _initial_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_hostname: &replaced + config: + hostname: "vsrx14" + state: replaced + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['gathered'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_hostname: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_hostname replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/rtt.yml new file mode 100644 index 000000000..c08892aac --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/tests/netconf/rtt.yml @@ -0,0 +1,60 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_hostname round trip integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_hostname: + config: + hostname: vsrx + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - hostname + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_hostname: + config: + hostname: "vsrx14" + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_hostname: + config: "{{ ansible_facts['network_resources']['hostname'] }}" + state: replaced + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] == revert['before'] }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] == revert['after'] }}" + always: + - name: Reset configuration + ansible.builtin.include_tasks: _reset_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_hostname round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/vars/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/vars/main.yaml new file mode 100644 index 000000000..13d4c1954 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_hostname/vars/main.yaml @@ -0,0 +1,12 @@ +--- +merged: + before: {} + + after: + hostname: "vsrx" + + updated: + hostname: "vsrx14" + + gathered: + hostname: "vsrx12" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..b2c608df6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/_initial_config.yaml @@ -0,0 +1,15 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: "START junos_interfaces initial config on connection={{ ansible_connection }}" + +- name: Configure basic config relevant to interfaces + junipernetworks.junos.junos_config: + lines: + - set interfaces fe-0/0/2 vlan-tagging + - set interfaces fe-0/0/2.10 vlan-id 10 + - set interfaces fe-0/0/2.11 vlan-id 11 + +- name: Debug task + ansible.builtin.debug: + msg: "END junos_interfaces initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/_remove_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/_remove_config.yaml new file mode 100644 index 000000000..875fd360b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/_remove_config.yaml @@ -0,0 +1,21 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: + Start junos_nterfaces deleted remove interface config ansible_connection={{ + ansible_connection }} + +- name: Setup - remove interface config + junipernetworks.junos.junos_config: + lines: + - delete interfaces ge-0/0/1 + - delete interfaces ge-0/0/2 + - delete interfaces ge-0/0/3 + - delete interfaces lo0 + - delete interfaces fe-0/0/2 + +- name: Debug task + ansible.builtin.debug: + msg: + End junos_nterfaces deleted remove interface config ansible_connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/deleted.yaml new file mode 100644 index 000000000..524476f20 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/deleted.yaml @@ -0,0 +1,105 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: + START junos_interfaces deleted integration tests on connection={{ ansible_connection + }} + +- name: Reset configuration + ansible.builtin.include_tasks: _remove_config.yaml + +- name: Set facts + ansible.builtin.set_fact: + expected_deleted_output: + - name: fxp0 + enabled: true + - name: ge-0/0/2 + enabled: true + +- block: + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_interfaces: &id002 + config: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 + mtu: 1024 + speed: 100m + enabled: false + duplex: full-duplex + hold_time: + up: 2000 + down: 2200 + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + hold_time: + up: 3000 + down: 3200 + units: + - name: 0 + description: "Logical interface UNIT 0" + state: merged + + - name: Delete the provided interface configuration from running configuration + register: result + junipernetworks.junos.junos_interfaces: &id001 + config: + - name: ge-0/0/1 + + - name: ge-0/0/2 + + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_deleted_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Delete the provided interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_interfaces: *id002 + + - name: Delete the all interface configuration from running configuration + register: result + junipernetworks.junos.junos_interfaces: + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_deleted_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: Delete the all interface configuration from running configuration (IDEMPOTENT) + register: result + junipernetworks.junos.junos_interfaces: + state: deleted + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - name: Reset configuration + ansible.builtin.include_tasks: _remove_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_interfaces deleted integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..26d323fcc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <interfaces> + <interface> + <name>ge-0/0/1</name> + <description>Configured by Ansible</description> + <disable/> + <speed>100m</speed> + <mtu>1024</mtu> + <hold-time> + <up>2000</up> + <down>2200</down> + </hold-time> + <link-mode>full-duplex</link-mode> + <unit> + <name>0</name> + <family> + <ethernet-switching> + <interface-mode>access</interface-mode> + <vlan> + <members>vlan100</members> + </vlan> + </ethernet-switching> + </family> + </unit> + </interface> + <interface> + <name>ge-0/0/2</name> + <description>Configured by Ansible</description> + <native-vlan-id>400</native-vlan-id> + <speed>10m</speed> + <mtu>2048</mtu> + <hold-time> + <up>3000</up> + <down>3200</down> + </hold-time> + <unit> + <name>0</name> + <family> + <ethernet-switching> + <interface-mode>trunk</interface-mode> + <vlan> + <members>vlan200</members> + <members>vlan300</members> + </vlan> + </ethernet-switching> + </family> + </unit> + </interface> + </interfaces> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/gathered.yaml new file mode 100644 index 000000000..05e8b095f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/gathered.yaml @@ -0,0 +1,77 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: START junos_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- name: Reset configuration + ansible.builtin.include_tasks: _remove_config.yaml + +- name: Set facts + ansible.builtin.set_fact: + expected_merged_output: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 + mtu: 1024 + speed: 100m + enabled: false + duplex: full-duplex + hold_time: + up: 2000 + down: 2200 + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + enabled: true + hold_time: + up: 3000 + down: 3200 + + - name: fxp0 + enabled: true + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_interfaces: &id001 + config: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 + mtu: 1024 + speed: 100m + enabled: false + duplex: full-duplex + hold_time: + up: 2000 + down: 2200 + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + hold_time: + up: 3000 + down: 3200 + state: merged + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + "{{ expected_merged_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + - name: Reset configuration + ansible.builtin.include_tasks: _remove_config.yaml + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_interfaces gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/groups.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/groups.yaml new file mode 100644 index 000000000..f69602758 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/groups.yaml @@ -0,0 +1,59 @@ +--- +- name: Debug task + ansible.builtin.debug: + msg: + START junos_interfaces groups integration tests on connection={{ ansible_connection + }} + +- name: Reset configuration + ansible.builtin.include_tasks: _remove_config.yaml + +- name: Set facts + ansible.builtin.set_fact: + expected_group_output: + - name: ge-0/0/11 + description: within test group + enabled: true + + - name: ge-0/0/12 + description: global interface config + enabled: true + + - name: fxp0 + enabled: true + +- name: Teardown delete interface configuration + junipernetworks.junos.junos_config: &id001 + lines: + - delete apply-groups test + - delete groups test interfaces ge-0/0/11 + - delete interfaces ge-0/0/12 + +- block: + - name: Setup interface configuration + junipernetworks.junos.junos_config: + lines: + - set groups test interfaces ge-0/0/11 description "within test group" + - set apply-groups test + - set interfaces ge-0/0/12 description "global interface config" + + - name: Get junos interfaces facts + register: result + junipernetworks.junos.junos_facts: + gather_subset: min + gather_network_resources: interfaces + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_group_output | symmetric_difference(result['ansible_facts']['ansible_network_resources']['interfaces'])|length\ + \ == 0 }}" + always: + - name: Teardown delete interface configuration + junipernetworks.junos.junos_config: *id001 + +- name: Debug task + ansible.builtin.debug: + msg: + END junos_interfaces merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/merged.yaml new file mode 100644 index 000000000..3d4f364eb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/merged.yaml @@ -0,0 +1,94 @@ +--- +- ansible.builtin.debug: + msg: + START junos_interfaces merged integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _initial_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 + mtu: 1024 + speed: 100m + enabled: false + duplex: full-duplex + hold_time: + up: 2000 + down: 2200 + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + enabled: true + hold_time: + up: 3000 + down: 3200 + + - enabled: true + name: fe-0/0/2 + units: + - description: "This is logical interface UNIT 10" + name: 10 + - description: "This is logical interface UNIT 11" + name: 11 + - name: fxp0 + enabled: true + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_interfaces: &id001 + config: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 + mtu: 1024 + speed: 100m + enabled: false + duplex: full-duplex + hold_time: + up: 2000 + down: 2200 + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + hold_time: + up: 3000 + down: 3200 + - name: fe-0/0/2 + units: + - name: 10 + description: "This is logical interface UNIT 10" + - name: 11 + description: "This is logical interface UNIT 11" + state: merged + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_interfaces merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/overridden.yaml new file mode 100644 index 000000000..2cb15c8f2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/overridden.yaml @@ -0,0 +1,72 @@ +--- +- ansible.builtin.debug: + msg: + START junos_interfaces overridden integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_overridden_output: + - name: ge-0/0/1 + description: Overridden by Ansible - Interface 1 + enabled: true + + - name: fxp0 + enabled: true + +- block: + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_interfaces: + config: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 + mtu: 1024 + speed: 100m + enabled: false + duplex: full-duplex + hold_time: + up: 2000 + down: 2200 + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + hold_time: + up: 3000 + down: 3200 + state: merged + + - name: Override the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_interfaces: &id001 + config: + - name: ge-0/0/1 + description: Overridden by Ansible - Interface 1 + state: overridden + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_overridden_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Override the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_interfaces overridden integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/parsed.yaml new file mode 100644 index 000000000..0a1c50b1c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/parsed.yaml @@ -0,0 +1,42 @@ +--- +- ansible.builtin.debug: + msg: + START junos_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - description: Configured by Ansible + duplex: full-duplex + enabled: false + hold_time: + down: 2200 + up: 2000 + mtu: 1024 + name: ge-0/0/1 + speed: 100m + + - description: Configured by Ansible + enabled: true + hold_time: + down: 3200 + up: 3000 + mtu: 2048 + name: ge-0/0/2 + speed: 10m + +- name: Parse externally provided interfaces config to agnostic model + register: result + junipernetworks.junos.junos_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" +- ansible.builtin.debug: + msg: + END junos_interfaces parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/rendered.yaml new file mode 100644 index 000000000..e41c92b08 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/rendered.yaml @@ -0,0 +1,29 @@ +--- +- ansible.builtin.debug: + msg: START junos_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface><nc:name>ge-0/0/2</nc:name><nc:description>Configured by Ansibull</nc:description><nc:speed>20m</nc:speed><nc:mtu>2048</nc:mtu><nc:hold-time><nc:up>3200</nc:up><nc:down>3200</nc:down></nc:hold-time></nc:interface></nc:interfaces>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_interfaces: + config: + - name: ge-0/0/2 + description: Configured by Ansibull + mtu: 2048 + speed: 20m + hold_time: + up: 3200 + down: 3200 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_interfaces rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/replaced.yaml new file mode 100644 index 000000000..bcec623b7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/replaced.yaml @@ -0,0 +1,86 @@ +--- +- ansible.builtin.debug: + msg: + START junos_interfaces replaced integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_replaced_output: + - name: ge-0/0/1 + description: Replaced by Ansible - Interface 1 + mtu: 2048 + speed: 10m + enabled: true + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + enabled: true + hold_time: + up: 3000 + down: 3200 + + - name: fxp0 + enabled: true + +- block: + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_interfaces: + config: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 + mtu: 1024 + speed: 100m + enabled: false + duplex: full-duplex + hold_time: + up: 2000 + down: 2200 + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + hold_time: + up: 3000 + down: 3200 + state: merged + + - name: Replace the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_interfaces: &id001 + config: + - name: ge-0/0/1 + description: Replaced by Ansible - Interface 1 + mtu: 2048 + speed: 10m + enabled: true + state: replaced + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_replaced_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Replace the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_interfaces replaced integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/rtt.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/rtt.yaml new file mode 100644 index 000000000..cb8bb6c2a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_interfaces/tests/netconf/rtt.yaml @@ -0,0 +1,105 @@ +--- +- ansible.builtin.debug: + msg: + START junos_interfaces round trip integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_revert_output: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 + mtu: 1024 + speed: 100m + enabled: false + duplex: full-duplex + hold_time: + up: 2000 + down: 2200 + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + enabled: true + hold_time: + up: 3000 + down: 3200 + + - name: fxp0 + enabled: true + +- block: + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_interfaces: + config: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 + mtu: 1024 + speed: 100m + enabled: false + duplex: full-duplex + hold_time: + up: 2000 + down: 2200 + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 + mtu: 2048 + speed: 10m + enabled: true + hold_time: + up: 3000 + down: 3200 + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_interfaces: + config: + - name: ge-0/0/1 + description: Configured by Ansible - Interface 1 modified + mtu: 3048 + speed: 10m + enabled: true + duplex: half-duplex + hold_time: + up: 3000 + down: 2200 + + - name: ge-0/0/2 + description: Configured by Ansible - Interface 2 modified + mtu: 4048 + speed: 100m + enabled: false + hold_time: + up: 4000 + down: 5200 + state: merged + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_interfaces: + config: "{{ ansible_facts['network_resources']['interfaces'] }}" + state: replaced + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + "{{ expected_revert_output | symmetric_difference(revert['after'])\ + \ |length == 0 }}" + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tasks/netconf.yaml new file mode 100644 index 000000000..b88eee1c9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/_base_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/_base_config.yaml new file mode 100644 index 000000000..24bc9e1d1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/_base_config.yaml @@ -0,0 +1,18 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_l2_interfaces base config ansible_connection={{ ansible_connection + }} + +- name: Configure vlan + junipernetworks.junos.junos_config: + lines: + - set vlans vlan100 vlan-id 100 + - set vlans vlan200 vlan-id 200 + - set vlans vlan300 vlan-id 300 + - set vlans vlan400 vlan-id 400 + +- ansible.builtin.debug: + msg: + End junos_l2_interfaces base config ansible_connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/_remove_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/_remove_config.yaml new file mode 100644 index 000000000..2b814d639 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/_remove_config.yaml @@ -0,0 +1,22 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_l2_interfaces deleted remove l2 interface config ansible_connection={{ + ansible_connection }} + +- name: Setup - remove interface config + junipernetworks.junos.junos_config: + lines: + - delete interfaces ge-0/0/1 + - delete interfaces ge-0/0/2 + - delete interfaces ge-0/0/3 + - delete interfaces lo0 + - delete vlans vlan100 + - delete vlans vlan200 + - delete vlans vlan300 + - delete vlans vlan400 + +- ansible.builtin.debug: + msg: + End junos_l2_interfaces deleted remove l2 interface config ansible_connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/deleted.yaml new file mode 100644 index 000000000..d26fa62d4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/deleted.yaml @@ -0,0 +1,90 @@ +--- +- ansible.builtin.debug: + msg: + START junos_l2_interfaces deleted integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_deleted_output: + - name: ge-0/0/1 + unit: 0 + enhanced_layer: true + access: + vlan: vlan100 + +- block: + - name: Configure initial state for l2 interface + register: result + junipernetworks.junos.junos_l2_interfaces: &id002 + config: + - name: ge-0/0/1 + access: + vlan: vlan100 + + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan200 + - vlan300 + native_vlan: "400" + state: merged + + - name: Delete the provided l2 interface configuration from running configuration + register: result + junipernetworks.junos.junos_l2_interfaces: &id001 + config: + - name: ge-0/0/2 + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_deleted_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Delete the provided l2 interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_l2_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_l2_interfaces: *id002 + + - name: Delete the all l2 interface configuration from running configuration + register: result + junipernetworks.junos.junos_l2_interfaces: + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ result['after'] == [] }}" + + - name: Delete the all l2 interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_l2_interfaces: + state: deleted + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_l2_interfaces deleted integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..26d323fcc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <interfaces> + <interface> + <name>ge-0/0/1</name> + <description>Configured by Ansible</description> + <disable/> + <speed>100m</speed> + <mtu>1024</mtu> + <hold-time> + <up>2000</up> + <down>2200</down> + </hold-time> + <link-mode>full-duplex</link-mode> + <unit> + <name>0</name> + <family> + <ethernet-switching> + <interface-mode>access</interface-mode> + <vlan> + <members>vlan100</members> + </vlan> + </ethernet-switching> + </family> + </unit> + </interface> + <interface> + <name>ge-0/0/2</name> + <description>Configured by Ansible</description> + <native-vlan-id>400</native-vlan-id> + <speed>10m</speed> + <mtu>2048</mtu> + <hold-time> + <up>3000</up> + <down>3200</down> + </hold-time> + <unit> + <name>0</name> + <family> + <ethernet-switching> + <interface-mode>trunk</interface-mode> + <vlan> + <members>vlan200</members> + <members>vlan300</members> + </vlan> + </ethernet-switching> + </family> + </unit> + </interface> + </interfaces> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/gathered.yaml new file mode 100644 index 000000000..1d66a9759 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/gathered.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: START junos_l2_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - name: ge-0/0/1 + access: + vlan: vlan100 + enhanced_layer: true + unit: 0 + + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan200 + - vlan300 + native_vlan: "400" + enhanced_layer: true + unit: 0 + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_l2_interfaces: + config: + - name: ge-0/0/1 + access: + vlan: vlan100 + + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan200 + - vlan300 + native_vlan: "400" + state: merged + + - name: Gather l2_interfaces facts using gathered state + register: result + junipernetworks.junos.junos_l2_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + "{{ expected_merged_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_l2_interfaces gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/merged.yaml new file mode 100644 index 000000000..426f565ef --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/merged.yaml @@ -0,0 +1,67 @@ +--- +- ansible.builtin.debug: + msg: + START junos_l2_interfaces merged integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - name: ge-0/0/1 + access: + vlan: vlan100 + enhanced_layer: true + unit: 0 + + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan200 + - vlan300 + native_vlan: "400" + enhanced_layer: true + unit: 0 + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_l2_interfaces: &id001 + config: + - name: ge-0/0/1 + access: + vlan: vlan100 + + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan200 + - vlan300 + native_vlan: "400" + state: merged + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: + Merge the provided l2 interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_l2_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_l2_interfaces merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/overridden.yaml new file mode 100644 index 000000000..b418b355f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/overridden.yaml @@ -0,0 +1,71 @@ +--- +- ansible.builtin.debug: + msg: + START junos_l2_interfaces override integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_overridden_output: + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan100 + native_vlan: "200" + enhanced_layer: true + unit: 0 + +- block: + - name: Setup initial l2 configuration + register: result + junipernetworks.junos.junos_l2_interfaces: + config: + - name: ge-0/0/1 + access: + vlan: vlan100 + + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan200 + - vlan300 + native_vlan: "400" + state: overridden + + - name: Override the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_l2_interfaces: &id001 + config: + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan100 + native_vlan: "200" + state: overridden + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_overridden_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Override the provided l2 interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_l2_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_l2_interfaces override integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/parsed.yaml new file mode 100644 index 000000000..805d43ddf --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/parsed.yaml @@ -0,0 +1,38 @@ +--- +- ansible.builtin.debug: + msg: + START junos_l2_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - name: ge-0/0/1 + access: + vlan: vlan100 + enhanced_layer: true + unit: 0 + + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan200 + - vlan300 + native_vlan: "400" + enhanced_layer: true + unit: 0 + +- name: Parse externally provided interfaces config to agnostic model + register: result + junipernetworks.junos.junos_l2_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" +- ansible.builtin.debug: + msg: + END junos_l2_interfaces parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/rendered.yaml new file mode 100644 index 000000000..ca1d574f7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/rendered.yaml @@ -0,0 +1,63 @@ +--- +- ansible.builtin.debug: + msg: START junos_l2_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:interfaces + xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> + <nc:interface> + <nc:name>ge-0/0/1</nc:name> + <nc:unit> + <nc:name>0</nc:name> + <nc:family> + <nc:ethernet-switching> + <nc:interface-mode>access</nc:interface-mode> + <nc:vlan> + <nc:members>vlan100</nc:members> + </nc:vlan> + </nc:ethernet-switching> + </nc:family> + </nc:unit> + </nc:interface> + <nc:interface> + <nc:name>ge-0/0/2</nc:name> + <nc:unit> + <nc:name>0</nc:name> + <nc:family> + <nc:ethernet-switching> + <nc:interface-mode>trunk</nc:interface-mode> + <nc:vlan> + <nc:members>vlan200</nc:members> + <nc:members>vlan300</nc:members> + </nc:vlan> + </nc:ethernet-switching> + </nc:family> + </nc:unit> + <nc:native-vlan-id>400</nc:native-vlan-id> + </nc:interface> + </nc:interfaces>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_l2_interfaces: + config: + - name: ge-0/0/1 + access: + vlan: vlan100 + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan200 + - vlan300 + native_vlan: "400" + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_l2_interfaces rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/replaced.yaml new file mode 100644 index 000000000..af2684505 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/replaced.yaml @@ -0,0 +1,67 @@ +--- +- ansible.builtin.debug: + msg: + START junos_l2_interfaces replaced integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_replaced_output: + - name: ge-0/0/1 + trunk: + allowed_vlans: + - vlan100 + - vlan300 + native_vlan: "400" + enhanced_layer: true + unit: 0 + + - name: ge-0/0/2 + access: + vlan: vlan200 + enhanced_layer: true + unit: 0 + +- block: + - name: Replace the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_l2_interfaces: &id001 + config: + - name: ge-0/0/1 + trunk: + allowed_vlans: + - vlan100 + - vlan300 + native_vlan: "400" + + - name: ge-0/0/2 + access: + vlan: vlan200 + state: replaced + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_replaced_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Replace the provided interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_l2_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_l2_interfaces replaced integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/rtt.yml new file mode 100644 index 000000000..4b5501a05 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l2_interfaces/tests/netconf/rtt.yml @@ -0,0 +1,76 @@ +--- +- ansible.builtin.debug: + msg: START junos_l2_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_revert_output: + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan100 + native_vlan: "200" + enhanced_layer: true + unit: 0 + +- block: + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_l2_interfaces: + config: + - name: ge-0/0/2 + trunk: + allowed_vlans: + - vlan100 + native_vlan: "200" + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - l2_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_l2_interfaces: + config: + - name: ge-0/0/1 + trunk: + allowed_vlans: + - vlan100 + - vlan300 + native_vlan: "400" + + - name: ge-0/0/2 + access: + vlan: vlan200 + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_l2_interfaces: + config: "{{ ansible_facts['network_resources']['l2_interfaces'] }}" + state: overridden + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + "{{ expected_revert_output | symmetric_difference(revert['after'])\ + \ |length == 0 }}" + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_l2_interfaces round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tasks/main.yaml new file mode 100644 index 000000000..a6fc560ad --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tasks/netconf.yaml new file mode 100644 index 000000000..7be9e860a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tasks/netconf.yaml @@ -0,0 +1,19 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..bca8ef294 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <interfaces> + <interface> + <name>ge-1/0/0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>192.168.100.1/24</name> + </address> + <address> + <name>10.200.16.20/24</name> + </address> + </inet> + <inet6></inet6> + </family> + </unit> + </interface> + <interface> + <name>ge-2/0/0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>192.168.100.2/24</name> + </address> + <address> + <name>10.200.16.21/24</name> + </address> + </inet> + <inet6></inet6> + </family> + </unit> + <unit> + <name>1</name> + <family> + <inet> + <address> + <name>192.178.100.2/24</name> + </address> + <address> + <name>10.210.16.21/24</name> + </address> + </inet> + <inet6></inet6> + </family> + </unit> + </interface> + </interfaces> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/junos_l3_interfaces.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/junos_l3_interfaces.yml new file mode 100644 index 000000000..468974c71 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/junos_l3_interfaces.yml @@ -0,0 +1,131 @@ +--- +- name: bootstrap interfaces + register: result + junipernetworks.junos.junos_l3_interfaces: + config: + - name: ge-1/0/0 + ipv4: + - address: 192.168.100.1/24 + + - address: 10.200.16.20/24 + + - name: ge-2/0/0 + ipv4: + - address: 192.168.100.2/24 + + - address: 10.200.16.21/24 + + - name: ge-3/0/0 + ipv4: + - address: 192.168.100.3/24 + + - address: 10.200.16.22/24 + state: replaced + +- ansible.builtin.assert: + that: + - result is changed + - "'<nc:address><nc:name>192.168.100.1/24</nc:name></nc:address>' in result.commands[0]" + - "'<nc:address><nc:name>10.200.16.20/24</nc:name></nc:address>' in result.commands[0]" + - result.after[0].name == 'ge-1/0/0' + - result.after[0].ipv4[0]['address'] == '192.168.100.1/24' + - result.after[0].ipv4[1]['address'] == '10.200.16.20/24' + +- name: bootstrap interfaces (idempotent) + register: result + junipernetworks.junos.junos_l3_interfaces: + config: + - name: ge-1/0/0 + ipv4: + - address: 192.168.100.1/24 + + - address: 10.200.16.20/24 + + - name: ge-2/0/0 + ipv4: + - address: 192.168.100.2/24 + + - address: 10.200.16.21/24 + + - name: ge-3/0/0 + ipv4: + - address: 192.168.100.3/24 + + - address: 10.200.16.22/24 + state: replaced + +- ansible.builtin.assert: + that: + - result is not changed + +- name: Gather l3_interfaces facts using gathered state + register: result + junipernetworks.junos.junos_l3_interfaces: + state: gathered + +- name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + - result.gathered[0].name == 'ge-1/0/0' + - result.gathered[0].ipv4[0]['address'] == '192.168.100.1/24' + - result.gathered[0].ipv4[1]['address'] == '10.200.16.20/24' + - result.gathered[1].name == 'ge-2/0/0' + - result.gathered[1].ipv4[0]['address'] == '192.168.100.2/24' + - result.gathered[1].ipv4[1]['address'] == '10.200.16.21/24' + - result.gathered[2].name == 'ge-3/0/0' + - result.gathered[2].ipv4[0]['address'] == '192.168.100.3/24' + - result.gathered[2].ipv4[1]['address'] == '10.200.16.22/24' + +- name: Add another interface ip + register: result + junipernetworks.junos.junos_l3_interfaces: + config: + - name: ge-1/0/0 + ipv4: + - address: 100.64.0.1/10 + + - address: 100.64.0.2/10 + state: merged + +- ansible.builtin.assert: + that: + - result is changed + - "'<nc:address><nc:name>100.64.0.1/10</nc:name></nc:address>' in result.commands[0]" + - "'<nc:address><nc:name>100.64.0.2/10</nc:name></nc:address>' in result.commands[0]" + - result.after[0].name == 'ge-1/0/0' + - result.after[0].ipv4[0]['address'] == '192.168.100.1/24' + - result.after[0].ipv4[1]['address'] == '10.200.16.20/24' + - result.after[0].ipv4[2]['address'] == '100.64.0.1/10' + - result.after[0].ipv4[3]['address'] == '100.64.0.2/10' + +- name: Delete ge-2/0/0 interface config + register: result + junipernetworks.junos.junos_l3_interfaces: + config: + - name: ge-2/0/0 + state: deleted + +- ansible.builtin.assert: + that: + - result is changed + - "'<nc:name>ge-2/0/0</nc:name><nc:unit><nc:name>0</nc:name><nc:family><nc:inet><nc:address\ + \ delete=\"delete\"/>' in result.commands[0]" + +- name: Override all config + register: result + junipernetworks.junos.junos_l3_interfaces: + config: + - name: ge-1/0/0 + ipv4: + - address: dhcp + + - name: fxp0 + ipv4: + - address: dhcp + state: overridden + +- ansible.builtin.assert: + that: + - result is changed + - "'<nc:name>fxp0</nc:name><nc:unit><nc:name>0</nc:name><nc:family><nc:inet><nc:dhcp/></nc:inet>'\ + \ in result.commands[0]" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/parsed.yaml new file mode 100644 index 000000000..37c27ba2f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/parsed.yaml @@ -0,0 +1,44 @@ +--- +- ansible.builtin.debug: + msg: + START junos_l3_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - name: ge-1/0/0 + ipv4: + - address: 192.168.100.1/24 + + - address: 10.200.16.20/24 + unit: 0 + + - name: ge-2/0/0 + ipv4: + - address: 192.168.100.2/24 + + - address: 10.200.16.21/24 + unit: 0 + + - name: ge-2/0/0 + ipv4: + - address: 192.178.100.2/24 + + - address: 10.210.16.21/24 + unit: 1 + +- name: Parse externally provided interfaces config to agnostic model + register: result + junipernetworks.junos.junos_l3_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" +- ansible.builtin.debug: + msg: + END junos_l3_interfaces parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/rendered.yaml new file mode 100644 index 000000000..f0756bb8f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_l3_interfaces/tests/netconf/rendered.yaml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg: START junos_l3_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:interfaces + xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> + <nc:interface> + <nc:name>ge-0/0/1</nc:name> + <nc:unit> + <nc:name>0</nc:name> + <nc:family> + <nc:ethernet-switching> + <nc:interface-mode>access</nc:interface-mode> + <nc:vlan> + <nc:members>vlan100</nc:members> + </nc:vlan> + </nc:ethernet-switching> + </nc:family> + </nc:unit> + </nc:interface> + <nc:interface> + <nc:name>ge-0/0/2</nc:name> + <nc:unit> + <nc:name>0</nc:name> + <nc:family> + <nc:ethernet-switching> + <nc:interface-mode>trunk</nc:interface-mode> + <nc:vlan> + <nc:members>vlan200</nc:members> + <nc:members>vlan300</nc:members> + </nc:vlan> + </nc:ethernet-switching> + </nc:family> + </nc:unit> + <nc:native-vlan-id>400</nc:native-vlan-id> + </nc:interface> + </nc:interfaces>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_l3_interfaces: + config: + - name: ge-1/0/0 + ipv4: + - address: 192.168.100.1/24 + - address: 10.200.16.20/24 + unit: 0 + + - name: ge-2/0/0 + ipv4: + - address: 192.168.100.2/24 + - address: 10.200.16.21/24 + unit: 0 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_l3_interfaces rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tasks/main.yaml new file mode 100644 index 000000000..8248d55c6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf task + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/_remove_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/_remove_config.yaml new file mode 100644 index 000000000..e15b129d6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/_remove_config.yaml @@ -0,0 +1,15 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_lacp deleted remove lacp config ansible_connection={{ ansible_connection + }} + +- name: Setup - remove lacp config + junipernetworks.junos.junos_config: + lines: + - delete chassis aggregated-devices ethernet lacp + +- ansible.builtin.debug: + msg: + End junos_lacp deleted remove lacp config ansible_connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/deleted.yaml new file mode 100644 index 000000000..31b72d419 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/deleted.yaml @@ -0,0 +1,47 @@ +--- +- ansible.builtin.debug: + msg: START junos_lacp deleted lacp tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_deleted_output: [] + +- block: + - name: Merge global LACP attributes + register: result + junipernetworks.junos.junos_lacp: + config: + system_priority: 63 + link_protection: revertive + state: merged + + - name: Delete global lacp attributes + register: result + junipernetworks.junos.junos_lacp: &id001 + config: + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ result['after'] == {} }}" + + - name: + Delete the provided interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lacp: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp deleted lacp integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..88c8729fc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <chassis> + <aggregated-devices> + <ethernet> + <lacp> + <system-priority>63</system-priority> + <link-protection> + </link-protection> + </lacp> + </ethernet> + </aggregated-devices> + </chassis> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/gathered.yaml new file mode 100644 index 000000000..bc3effbc1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/gathered.yaml @@ -0,0 +1,37 @@ +--- +- ansible.builtin.debug: + msg: START junos_lacp gathered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + system_priority: 63 + link_protection: revertive + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lacp: &id001 + config: + system_priority: 63 + link_protection: revertive + state: merged + + - name: Gather lacp facts using gathered state + register: result + junipernetworks.junos.junos_lacp: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ expected_merged_output == result['gathered'] }}" + + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/merged.yaml new file mode 100644 index 000000000..9776ac8fd --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/merged.yaml @@ -0,0 +1,45 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lacp merged integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - system_priority: 63 + link_protection: revertive + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lacp: &id001 + config: + system_priority: 63 + link_protection: revertive + state: merged + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_merged_output | symmetric_difference([result['after']])\ + \ |length == 0 }}" + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lacp: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/parsed.yaml new file mode 100644 index 000000000..7f297c085 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/parsed.yaml @@ -0,0 +1,25 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lacp parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + link_protection: revertive + system_priority: 63 + +- name: Parse externally provided lacp config to agnostic model + register: result + junipernetworks.junos.junos_lacp: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_lacp parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/rendered.yaml new file mode 100644 index 000000000..6935d4904 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/rendered.yaml @@ -0,0 +1,24 @@ +--- +- ansible.builtin.debug: + msg: START junos_lacp rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:chassis xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:aggregated-devices><nc:ethernet><nc:lacp><nc:system-priority>63</nc:system-priority><nc:link-protection><nc:non-revertive delete="delete"/></nc:link-protection></nc:lacp></nc:ethernet></nc:aggregated-devices></nc:chassis>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_lacp: + config: + system_priority: 63 + link_protection: revertive + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_lacp rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/replaced.yaml new file mode 100644 index 000000000..d898a551e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/replaced.yaml @@ -0,0 +1,50 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lacp replaced integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_replaced_output: + - system_priority: 73 + +- block: + - name: Set initial config + junipernetworks.junos.junos_lacp: + config: + system_priority: 73 + link_protection: revertive + state: replaced + + - name: Replace the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lacp: &id001 + config: + system_priority: 73 + state: replaced + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_replaced_output | symmetric_difference([result['after']])\ + \ |length == 0 }}" + + - name: + Replace the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lacp: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp replaced integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/rtt.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/rtt.yaml new file mode 100644 index 000000000..eca820939 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp/tests/netconf/rtt.yaml @@ -0,0 +1,58 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lacp RTT integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_revert_output: + - system_priority: 63 + link_protection: non-revertive + +- block: + - name: Apply the provided configuration (base config) + junipernetworks.junos.junos_lacp: + config: + system_priority: 63 + link_protection: non-revertive + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - lacp + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_lacp: + config: + system_priority: 73 + link_protection: revertive + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_lacp: + config: "{{ ansible_facts['network_resources']['lacp'] }}" + state: replaced + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + "{{ expected_revert_output | symmetric_difference([revert['after']])\ + \ |length == 0 }}" + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp RTT integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/meta/main.yaml new file mode 100644 index 000000000..7f867d73b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tasks/main.yaml new file mode 100644 index 000000000..61aebceb0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf play + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/_base_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/_base_config.yaml new file mode 100644 index 000000000..56113e5d5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/_base_config.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_lacp_interfaces base config ansible_connection={{ ansible_connection + }} + +- name: Configure base lag interface + junipernetworks.junos.junos_config: + lines: + - set interfaces ae1 description "Configured by Ansible" + - set interfaces ae2 description "Configured by Ansible" + - set interfaces ge-0/0/1 ether-options 802.3ad ae1 + - set interfaces ge-0/0/2 ether-options 802.3ad ae1 + - set interfaces ge-0/0/3 ether-options 802.3ad ae2 + - set interfaces ge-0/0/4 ether-options 802.3ad ae2 + +- ansible.builtin.debug: + msg: + End junos_lacp_interfaces base config ansible_connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/_remove_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/_remove_config.yaml new file mode 100644 index 000000000..c180dc0a9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/_remove_config.yaml @@ -0,0 +1,21 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_nterfaces deleted remove interface config ansible_connection={{ + ansible_connection }} + +- name: Setup - remove interface config + junipernetworks.junos.junos_config: + lines: + - delete interfaces ae1 + - delete interfaces ae2 + - delete interfaces ge-0/0/1 + - delete interfaces ge-0/0/2 + - delete interfaces ge-0/0/3 + - delete interfaces ge-0/0/4 + - delete interfaces lo0 + +- ansible.builtin.debug: + msg: + End junos_nterfaces deleted remove interface config ansible_connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/deleted.yaml new file mode 100644 index 000000000..2eec2f58d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/deleted.yaml @@ -0,0 +1,110 @@ +--- +- ansible.builtin.debug: + msg: START junos_lacp_interfaces deleted integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_deleted_output: + - name: ae2 + period: slow + sync_reset: disable + system: + priority: 200 + mac: + address: 00:00:00:00:00:04 + + - name: ge-0/0/3 + port_priority: 300 + +- block: + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_lacp_interfaces: &id002 + config: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:02 + + - name: ge-0/0/1 + port_priority: 100 + force_up: true + + - name: ae2 + period: slow + sync_reset: disable + system: + priority: 200 + mac: + address: 00:00:00:00:00:04 + + - name: ge-0/0/3 + port_priority: 300 + force_up: false + state: merged + + - name: Delete the provided interface configuration from running configuration + register: result + junipernetworks.junos.junos_lacp_interfaces: &id001 + config: + - name: ae1 + + - name: ge-0/0/1 + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_deleted_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Delete the provided lacp interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lacp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_lacp_interfaces: *id002 + + - name: Delete the all lacp interface configuration from running configuration + register: result + junipernetworks.junos.junos_lacp_interfaces: + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ result['after'] == [] }}" + + - name: + Delete the all lacp interfaces configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lacp_interfaces: + state: deleted + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp_interfaces deleted integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..d7bd3d84c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <interfaces> + <interface> + <name>ge-0/0/1</name> + <ether-options> + <ieee-802.3ad> + <lacp> + <force-up/> + <port-priority>100</port-priority> + </lacp> + <bundle>ae1</bundle> + </ieee-802.3ad> + </ether-options> + </interface> + <interface> + <name>ge-0/0/2</name> + <ether-options> + <ieee-802.3ad> + <bundle>ae1</bundle> + </ieee-802.3ad> + </ether-options> + </interface> + <interface> + <name>ge-0/0/3</name> + <ether-options> + <ieee-802.3ad> + <bundle>ae2</bundle> + </ieee-802.3ad> + </ether-options> + </interface> + <interface> + <name>ge-0/0/4</name> + <ether-options> + <ieee-802.3ad> + <bundle>ae2</bundle> + </ieee-802.3ad> + </ether-options> + </interface> + <interface> + <name>ge-1/0/0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>192.168.100.1/24</name> + </address> + <address> + <name>10.200.16.20/24</name> + </address> + </inet> + <inet6></inet6> + </family> + </unit> + </interface> + <interface> + <name>ge-2/0/0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>192.168.100.2/24</name> + </address> + <address> + <name>10.200.16.21/24</name> + </address> + </inet> + <inet6></inet6> + </family> + </unit> + </interface> + <interface> + <name>ge-3/0/0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>192.168.100.3/24</name> + </address> + <address> + <name>10.200.16.22/24</name> + </address> + </inet> + <inet6></inet6> + </family> + </unit> + </interface> + <interface> + <name>ae1</name> + <description>Configured by Ansible</description> + <aggregated-ether-options> + <lacp> + <periodic>fast</periodic> + <sync-reset>enable</sync-reset> + <system-priority>100</system-priority> + <system-id>00:00:00:00:00:02</system-id> + </lacp> + </aggregated-ether-options> + </interface> + <interface> + <name>ae2</name> + <description>Configured by Ansible</description> + </interface> + <interface> + <name>em1</name> + <description>TEST</description> + </interface> + <interface> + <name>fxp0</name> + <description>ANSIBLE</description> + <speed>1g</speed> + <link-mode>automatic</link-mode> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>10.8.38.38/24</name> + </address> + </inet> + </family> + </unit> + </interface> + </interfaces> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/gathered.yaml new file mode 100644 index 000000000..87e3ac1b1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/gathered.yaml @@ -0,0 +1,59 @@ +--- +- ansible.builtin.debug: + msg: START junos_lacp_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:02 + + - name: ge-0/0/1 + port_priority: 100 + force_up: true + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lacp_interfaces: &id001 + config: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:02 + + - name: ge-0/0/1 + port_priority: 100 + force_up: true + state: merged + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_lacp_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + "{{ expected_merged_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp_interfaces gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/merged.yaml new file mode 100644 index 000000000..5b057b7a2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/merged.yaml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lacp_interfaces merged integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:02 + + - name: ge-0/0/1 + port_priority: 100 + force_up: true + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lacp_interfaces: &id001 + config: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:02 + + - name: ge-0/0/1 + port_priority: 100 + force_up: true + state: merged + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lacp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp_interfaces merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/overridden.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/overridden.yml new file mode 100644 index 000000000..4f3e33f77 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/overridden.yml @@ -0,0 +1,85 @@ +--- +- ansible.builtin.debug: + msg: START junos_lacp_interfaces overide integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_overridden_output: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:01 + +- block: + - name: Configure initial state for lacp interface + register: result + junipernetworks.junos.junos_lacp_interfaces: + config: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:02 + + - name: ge-0/0/1 + port_priority: 100 + force_up: true + + - name: ae2 + period: slow + sync_reset: disable + system: + priority: 200 + mac: + address: 00:00:00:00:00:04 + + - name: ge-0/0/3 + port_priority: 300 + force_up: false + state: merged + + - name: Override the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lacp_interfaces: &id001 + config: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:01 + state: overridden + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_overridden_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Override the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lacp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp_interfaces override integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/parsed.yaml new file mode 100644 index 000000000..52bf84add --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/parsed.yaml @@ -0,0 +1,35 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lacp_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:02 + + - name: ge-0/0/1 + port_priority: 100 + force_up: true + +- name: Parse externally provided interfaces config to agnostic model + register: result + junipernetworks.junos.junos_lacp_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" +- ansible.builtin.debug: + msg: + END junos_lacp_interfaces parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/rendered.yaml new file mode 100644 index 000000000..99299abd0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/rendered.yaml @@ -0,0 +1,33 @@ +--- +- ansible.builtin.debug: + msg: START junos_lacp_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface><nc:name>ae1</nc:name><nc:aggregated-ether-options><nc:lacp><nc:periodic>fast</nc:periodic><nc:sync-reset>enable</nc:sync-reset><nc:system-id>00:00:00:00:00:02</nc:system-id><nc:system-priority>100</nc:system-priority></nc:lacp></nc:aggregated-ether-options></nc:interface><nc:interface><nc:name>ge-0/0/1</nc:name><nc:ether-options><nc:ieee-802.3ad><nc:lacp><nc:port-priority>100</nc:port-priority><nc:force-up/></nc:lacp></nc:ieee-802.3ad></nc:ether-options></nc:interface></nc:interfaces>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_lacp_interfaces: + config: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:02 + + - name: ge-0/0/1 + port_priority: 100 + force_up: true + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_lacp_interfaces rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/replaced.yaml new file mode 100644 index 000000000..34fc141cb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/replaced.yaml @@ -0,0 +1,117 @@ +--- +- ansible.builtin.debug: + msg: START junos_lacp_interfaces replaced integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_replaced_output: + - name: ae1 + period: slow + sync_reset: disable + system: + priority: 10 + mac: + address: 00:00:00:00:00:03 + + - name: ae2 + period: fast + system: + priority: 300 + + - name: ge-0/0/1 + force_up: true + port_priority: 100 + + - name: ge-0/0/2 + port_priority: 250 + + - name: ge-0/0/3 + port_priority: 300 + + - name: ge-0/0/4 + port_priority: 400 + force_up: true + +- block: + - name: Configure initial state for lacp interface + register: result + junipernetworks.junos.junos_lacp_interfaces: + config: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:02 + + - name: ge-0/0/1 + port_priority: 100 + force_up: true + + - name: ae2 + period: slow + sync_reset: disable + system: + priority: 200 + mac: + address: 00:00:00:00:00:04 + + - name: ge-0/0/3 + port_priority: 300 + force_up: false + state: merged + + - name: Replace the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lacp_interfaces: &id001 + config: + - name: ae1 + period: slow + sync_reset: disable + system: + priority: 10 + mac: + address: 00:00:00:00:00:03 + + - name: ge-0/0/2 + port_priority: 250 + force_up: false + + - name: ae2 + period: fast + system: + priority: 300 + + - name: ge-0/0/4 + port_priority: 400 + force_up: true + state: replaced + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_replaced_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Replace the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lacp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lacp_interfaces replaced integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/rtt.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/rtt.yaml new file mode 100644 index 000000000..11c497b29 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lacp_interfaces/tests/netconf/rtt.yaml @@ -0,0 +1,81 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lacp_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_revert_output: &base_config + - name: ae1 + period: slow + sync_reset: disable + system: + priority: 10 + mac: + address: 00:00:00:00:00:03 + + - name: ae2 + period: fast + system: + priority: 300 + + - name: ge-0/0/2 + port_priority: 250 + force_up: true + + - name: ge-0/0/4 + port_priority: 400 + force_up: true + +- block: + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_lacp_interfaces: + config: *base_config + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - lacp_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_lacp_interfaces: + config: + - name: ae1 + period: fast + sync_reset: enable + system: + priority: 100 + mac: + address: 00:00:00:00:00:01 + state: merged + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_lacp_interfaces: + config: "{{ ansible_facts['network_resources']['lacp_interfaces'] }}" + state: overridden + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + "{{ expected_revert_output | symmetric_difference(revert['after'])\ + \ |length == 0 }}" + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: END junos_lacp_interfaces round trip integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tasks/main.yaml new file mode 100644 index 000000000..a6fc560ad --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/_base_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/_base_config.yaml new file mode 100644 index 000000000..8239e190e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/_base_config.yaml @@ -0,0 +1,16 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_lag_interfaces base config ansible_connection={{ ansible_connection + }} + +- name: Configure base lag interface + junipernetworks.junos.junos_config: + lines: + - set interfaces ae1 description "Configured by Ansible" + - set interfaces ae2 description "Configured by Ansible" + +- ansible.builtin.debug: + msg: + End junos_lag_interfaces base config ansible_connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/_remove_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/_remove_config.yaml new file mode 100644 index 000000000..acdbafbac --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/_remove_config.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_lag_interfaces teardown ansible_connection={{ ansible_connection + }} + +- name: Remove interface config + junipernetworks.junos.junos_config: + lines: + - delete interfaces ge-0/0/1 + - delete interfaces ge-0/0/2 + - delete interfaces ge-0/0/3 + - delete interfaces ge-0/0/4 + - delete interfaces ae1 + - delete interfaces ae2 + +- ansible.builtin.debug: + msg: + End junos_lag_interfaces teardown ansible_connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/deleted.yaml new file mode 100644 index 000000000..02a7be520 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/deleted.yaml @@ -0,0 +1,99 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lag_interfaces deleted integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_deleted_1_output: + - name: ae1 + members: + - member: ge-0/0/1 + + - member: ge-0/0/2 + mode: active + expected_deleted_2_output: [] + +- block: + - name: Base LAG configuration + junipernetworks.junos.junos_lag_interfaces: &id002 + config: + - name: ae1 + members: + - member: ge-0/0/1 + + - member: ge-0/0/2 + mode: active + + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + + - member: ge-0/0/4 + link_type: backup + mode: passive + state: merged + + - name: Delete the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lag_interfaces: &id001 + config: + - name: ae2 + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_deleted_1_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Delete the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lag_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + + - name: Configure initial state for lag interface + register: result + junipernetworks.junos.junos_lag_interfaces: *id002 + + - name: Delete the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lag_interfaces: + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_deleted_2_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Delete the provided configuration with the exisiting running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lag_interfaces: + state: deleted + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lag_interfaces deleted integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..99a37d1c7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,135 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> +<interfaces> + <interface> + <name>ge-0/0/1</name> + <ether-options> + <ieee-802.3ad> + <bundle>ae1</bundle> + </ieee-802.3ad> + </ether-options> + </interface> + <interface> + <name>ge-0/0/2</name> + <ether-options> + <ieee-802.3ad> + <bundle>ae1</bundle> + </ieee-802.3ad> + </ether-options> + </interface> + <interface> + <name>ge-0/0/3</name> + <ether-options> + <ieee-802.3ad> + <bundle>ae2</bundle> + <primary/> + </ieee-802.3ad> + </ether-options> + </interface> + <interface> + <name>ge-0/0/4</name> + <ether-options> + <ieee-802.3ad> + <bundle>ae2</bundle> + <backup/> + </ieee-802.3ad> + </ether-options> + </interface> + <interface> + <name>ge-1/0/0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>192.168.100.1/24</name> + </address> + <address> + <name>10.200.16.20/24</name> + </address> + </inet> + <inet6> + </inet6> + </family> + </unit> + </interface> + <interface> + <name>ge-2/0/0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>192.168.100.2/24</name> + </address> + <address> + <name>10.200.16.21/24</name> + </address> + </inet> + <inet6> + </inet6> + </family> + </unit> + </interface> + <interface> + <name>ge-3/0/0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>192.168.100.3/24</name> + </address> + <address> + <name>10.200.16.22/24</name> + </address> + </inet> + <inet6> + </inet6> + </family> + </unit> + </interface> + <interface> + <name>ae1</name> + <description>Configured by Ansible</description> + <aggregated-ether-options> + <lacp> + <active/> + </lacp> + </aggregated-ether-options> + </interface> + <interface> + <name>ae2</name> + <description>Configured by Ansible</description> + <aggregated-ether-options> + <link-protection> + </link-protection> + <lacp> + <passive/> + </lacp> + </aggregated-ether-options> + </interface> + <interface> + <name>em1</name> + <description>TEST</description> + </interface> + <interface> + <name>fxp0</name> + <description>ANSIBLE</description> + <speed>1g</speed> + <link-mode>automatic</link-mode> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>10.8.38.38/24</name> + </address> + </inet> + </family> + </unit> + </interface> + </interfaces> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/gathered.yaml new file mode 100644 index 000000000..e61242861 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/gathered.yaml @@ -0,0 +1,66 @@ +--- +- ansible.builtin.debug: + msg: START junos_lag_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - name: ae1 + members: + - member: ge-0/0/1 + - member: ge-0/0/2 + mode: active + + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + + - member: ge-0/0/4 + link_type: backup + mode: passive + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lag_interfaces: &id001 + config: + - name: ae1 + members: + - member: ge-0/0/1 + - member: ge-0/0/2 + mode: active + + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + - member: ge-0/0/4 + link_type: backup + mode: passive + state: merged + + - name: Gather lag interfaces facts using gathered state + register: result + junipernetworks.junos.junos_lag_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + "{{ expected_merged_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lag_interfaces gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/merged.yaml new file mode 100644 index 000000000..abbd1c74b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/merged.yaml @@ -0,0 +1,75 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lag_interfaces merged integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - name: ae1 + members: + - member: ge-0/0/1 + + - member: ge-0/0/2 + mode: active + + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + + - member: ge-0/0/4 + link_type: backup + mode: passive + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lag_interfaces: &id001 + config: + - name: ae1 + members: + - member: ge-0/0/1 + + - member: ge-0/0/2 + mode: active + + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + + - member: ge-0/0/4 + link_type: backup + mode: passive + state: merged + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lag_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lag_interfaces merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/overridden.yaml new file mode 100644 index 000000000..0607e5818 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/overridden.yaml @@ -0,0 +1,71 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lag_interfaces overridden integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_overridden_output: + - name: ae1 + members: + - member: ge-0/0/2 + mode: active + +- block: + - name: Base LAG configuration + junipernetworks.junos.junos_lag_interfaces: + config: + - name: ae1 + members: + - member: ge-0/0/1 + + - member: ge-0/0/2 + mode: active + + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + + - member: ge-0/0/4 + link_type: backup + mode: passive + state: merged + + - name: Override the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lag_interfaces: &id001 + config: + - name: ae1 + members: + - member: ge-0/0/2 + mode: active + state: overridden + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_overridden_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Override the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lag_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: END junos_lag_interfaces overridden integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/parsed.yaml new file mode 100644 index 000000000..309be925c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/parsed.yaml @@ -0,0 +1,38 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lag_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - name: ae1 + members: + - member: ge-0/0/1 + - member: ge-0/0/2 + mode: active + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + + - member: ge-0/0/4 + link_type: backup + mode: passive + +- name: Parse externally provided interfaces config to agnostic model + register: result + junipernetworks.junos.junos_lag_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" +- ansible.builtin.debug: + msg: + END junos_lag_interfaces parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/rendered.yaml new file mode 100644 index 000000000..a5abcfac1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/rendered.yaml @@ -0,0 +1,36 @@ +--- +- ansible.builtin.debug: + msg: START junos_lag_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface><nc:name>ae1</nc:name><nc:aggregated-ether-options><nc:lacp><nc:active/></nc:lacp></nc:aggregated-ether-options></nc:interface><nc:interface><nc:name>ge-0/0/1</nc:name><nc:ether-options><nc:ieee-802.3ad><nc:bundle>ae1</nc:bundle></nc:ieee-802.3ad></nc:ether-options></nc:interface><nc:interface><nc:name>ge-0/0/2</nc:name><nc:ether-options><nc:ieee-802.3ad><nc:bundle>ae1</nc:bundle></nc:ieee-802.3ad></nc:ether-options></nc:interface><nc:interface><nc:name>ae2</nc:name><nc:aggregated-ether-options><nc:lacp><nc:passive/></nc:lacp><nc:link-protection/></nc:aggregated-ether-options></nc:interface><nc:interface><nc:name>ge-0/0/3</nc:name><nc:ether-options><nc:ieee-802.3ad><nc:bundle>ae2</nc:bundle><nc:primary/></nc:ieee-802.3ad></nc:ether-options></nc:interface><nc:interface><nc:name>ge-0/0/4</nc:name><nc:ether-options><nc:ieee-802.3ad><nc:bundle>ae2</nc:bundle><nc:backup/></nc:ieee-802.3ad></nc:ether-options></nc:interface></nc:interfaces>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_lag_interfaces: + config: + - name: ae1 + members: + - member: ge-0/0/1 + - member: ge-0/0/2 + mode: active + + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + - member: ge-0/0/4 + link_type: backup + mode: passive + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_lag_interfaces rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/replaced.yaml new file mode 100644 index 000000000..67d352205 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lag_interfaces/tests/netconf/replaced.yaml @@ -0,0 +1,81 @@ +--- +- ansible.builtin.debug: + msg: START junos_lag_interfaces replaced integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_replaced_output: + - name: ae1 + members: + - member: ge-0/0/1 + mode: passive + + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + + - member: ge-0/0/4 + link_type: backup + mode: passive + +- block: + - name: Base LAG configuration + junipernetworks.junos.junos_lag_interfaces: + config: + - name: ae1 + members: + - member: ge-0/0/1 + + - member: ge-0/0/2 + mode: active + + - name: ae2 + link_protection: true + members: + - member: ge-0/0/3 + link_type: primary + + - member: ge-0/0/4 + link_type: backup + mode: passive + state: merged + + - name: Replace the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lag_interfaces: &id001 + config: + - name: ae1 + members: + - member: ge-0/0/1 + mode: passive + state: replaced + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_replaced_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Replace the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lag_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_lag_interfaces replaced integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tasks/main.yaml new file mode 100644 index 000000000..a6fc560ad --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/_remove_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/_remove_config.yaml new file mode 100644 index 000000000..9d317f61d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/_remove_config.yaml @@ -0,0 +1,15 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_lldp_global deleted remove interface config ansible_connection={{ + ansible_connection }} + +- name: Setup - remove lldp global config + junipernetworks.junos.junos_config: + lines: + - delete protocols lldp + +- ansible.builtin.debug: + msg: + End junos_lldp_global deleted remove interface config ansible_connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/deleted.yaml new file mode 100644 index 000000000..88d00b316 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/deleted.yaml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lldp_global deleted integration tests on connection={{ ansible_connection + }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.set_fact: + expected_deleted_output: [] + + - name: Configure initial state for lldp global + register: result + junipernetworks.junos.junos_lldp_global: + config: + interval: 10000 + address: 10.1.1.1 + transmit_delay: 400 + hold_multiplier: 10 + state: merged + + - name: Delete the provided configuration from running configuration + register: result + junipernetworks.junos.junos_lldp_global: &id001 + config: + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ result['after'] == {} }}" + + - name: Delete the provided configuration from running configuration (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lldp_global: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: + END junos_lldp_global deleted integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..28735efbf --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <protocols> + <ospf> + <area> + <name>0.0.0.0</name> + <interface> + <name>ge-0/0/0.0</name> + </interface> + </area> + </ospf> + <lldp> + <management-address>10.1.1.1</management-address> + <advertisement-interval>10000</advertisement-interval> + <transmit-delay>400</transmit-delay> + <hold-multiplier>10</hold-multiplier> + <interface> + <name>ge-0/0/1</name> + </interface> + <interface> + <name>ge-0/0/2</name> + <disable/> + </interface> + </lldp> + </protocols> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/gathered.yaml new file mode 100644 index 000000000..1d18ea0f9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/gathered.yaml @@ -0,0 +1,56 @@ +--- +- ansible.builtin.debug: + msg: START junos_lldp_global gathered integration tests on connection={{ + ansible_connection }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- ansible.builtin.set_fact: + expected_merged_output: + - interval: 10000 + address: 10.1.1.1 + transmit_delay: 400 + hold_multiplier: 1 + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lldp_global: &id001 + config: + interval: 10000 + address: 10.1.1.1 + transmit_delay: 400 + hold_multiplier: 10 + state: merged + + - name: Gather lldp_global facts using gathered state + register: result + junipernetworks.junos.junos_lldp_global: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ expected_merged_output == result['gathered'] }}" + + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: + END junos_lldp_global gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/merged.yaml new file mode 100644 index 000000000..ba65dca5f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/merged.yaml @@ -0,0 +1,66 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lldp_global merged integration tests on connection={{ ansible_connection + }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.set_fact: + expected_merged_output: + - interval: 10000 + address: 10.1.1.1 + transmit_delay: 400 + hold_multiplier: 10 + + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lldp_global: &id001 + config: + interval: 10000 + address: 10.1.1.1 + transmit_delay: 400 + hold_multiplier: 10 + state: merged + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_merged_output | symmetric_difference([result['after']])\ + \ |length == 0 }}" + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lldp_global: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: + END junos_lldp_global merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/parsed.yaml new file mode 100644 index 000000000..7a8b2eeca --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/parsed.yaml @@ -0,0 +1,27 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lldp_global parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + address: 10.1.1.1 + hold_multiplier: 10 + interval: 10000 + transmit_delay: 400 + +- name: Parse externally provided lldp_global config to agnostic model + register: result + junipernetworks.junos.junos_lldp_global: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_lldp_global parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/rendered.yaml new file mode 100644 index 000000000..c79ad52ad --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/rendered.yaml @@ -0,0 +1,26 @@ +--- +- ansible.builtin.debug: + msg: START junos_lldp_global rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:lldp><nc:management-address>10.1.1.1</nc:management-address><nc:advertisement-interval>10000</nc:advertisement-interval><nc:transmit-delay>400</nc:transmit-delay><nc:hold-multiplier>10</nc:hold-multiplier><nc:disable delete="delete"/></nc:lldp></nc:protocols>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_lldp_global: + config: + interval: 10000 + address: 10.1.1.1 + transmit_delay: 400 + hold_multiplier: 10 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_lldp_global rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/replaced.yaml new file mode 100644 index 000000000..6f0f50ea6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/replaced.yaml @@ -0,0 +1,78 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lldp_global replaced integration tests on connection={{ ansible_connection + }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.set_fact: + expected_replaced_output: + - interval: 20000 + address: 10.1.1.2 + transmit_delay: 500 + hold_multiplier: 5 + enabled: false + + - name: Configure initial state for lldp global + register: result + junipernetworks.junos.junos_lldp_global: + config: + interval: 10000 + address: 10.1.1.1 + transmit_delay: 400 + hold_multiplier: 10 + state: merged + + - name: Replace the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lldp_global: &id001 + config: + interval: 20000 + address: 10.1.1.2 + transmit_delay: 500 + hold_multiplier: 5 + enabled: false + state: replaced + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_replaced_output | symmetric_difference([result['after']])\ + \ |length == 0 }}" + + - name: + Replace the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lldp_global: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: + END junos_lldp_global replaced integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/rtt.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/rtt.yaml new file mode 100644 index 000000000..e7537bf5e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_global/tests/netconf/rtt.yaml @@ -0,0 +1,83 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lldp_global round trip integration tests on connection={{ ansible_connection + }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.set_fact: + expected_revert_output: + - interval: 10000 + address: 10.1.1.1 + transmit_delay: 400 + hold_multiplier: 10 + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_lldp_global: + config: + interval: 10000 + address: 10.1.1.1 + transmit_delay: 400 + hold_multiplier: 10 + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - lldp_global + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_lldp_global: + config: + interval: 20000 + address: 10.1.1.2 + transmit_delay: 500 + hold_multiplier: 5 + enabled: false + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_lldp_global: + config: "{{ ansible_facts['network_resources']['lldp_global'] }}" + state: replaced + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + "{{ expected_revert_output | symmetric_difference([revert['after']])\ + \ |length == 0 }}" + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: + END junos_lldp_global round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tasks/main.yaml new file mode 100644 index 000000000..a6fc560ad --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/_remove_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/_remove_config.yaml new file mode 100644 index 000000000..5c1c477ac --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/_remove_config.yaml @@ -0,0 +1,15 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_lldp_interfaces deleted remove interface config ansible_connection={{ + ansible_connection }} + +- name: Setup - remove lldp interfaces config + junipernetworks.junos.junos_config: + lines: + - delete protocols lldp + +- ansible.builtin.debug: + msg: + End junos_lldp_interfaces deleted remove interface config ansible_connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/deleted.yaml new file mode 100644 index 000000000..31849facf --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/deleted.yaml @@ -0,0 +1,95 @@ +--- +- ansible.builtin.debug: + msg: START junos_lldp_interfaces deleted integration tests on connection={{ + ansible_connection }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.set_fact: + expected_deleted_output: + - name: ge-0/0/1 + + - name: Configure initial state for lldp interfaces + register: result + junipernetworks.junos.junos_lldp_interfaces: &id002 + config: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + state: merged + + - name: Delete the provided lldp interface configuration from running configuration + register: result + junipernetworks.junos.junos_lldp_interfaces: &id001 + config: + - name: ge-0/0/2 + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_deleted_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Delete the provided lldp interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lldp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_lldp_interfaces: *id002 + + - name: Delete the all lldp interface configuration from running configuration + register: result + junipernetworks.junos.junos_lldp_interfaces: + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ result['after'] == []}}" + + - name: + Delete the all lldp interface configuration from running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lldp_interfaces: + state: deleted + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: + END junos_lldp_interfaces deleted integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..7875abecb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <protocols> + <ospf> + <area> + <name>0.0.0.0</name> + <interface> + <name>ge-0/0/0.0</name> + </interface> + </area> + </ospf> + <lldp> + <interface> + <name>ge-0/0/1</name> + </interface> + <interface> + <name>ge-0/0/2</name> + <disable/> + </interface> + </lldp> + </protocols> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/gathered.yaml new file mode 100644 index 000000000..05765490e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/gathered.yaml @@ -0,0 +1,58 @@ +--- +- ansible.builtin.debug: + msg: START junos_lldp_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- ansible.builtin.set_fact: + expected_merged_output: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lldp_interfaces: &id001 + config: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + state: merged + + - name: Gather lag interfaces facts using gathered state + register: result + junipernetworks.junos.junos_lldp_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + "{{ expected_merged_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: + END junos_lldp_interfaces gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/merged.yaml new file mode 100644 index 000000000..9454ac5f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/merged.yaml @@ -0,0 +1,66 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lldp_interfaces merged integration tests on connection={{ ansible_connection + }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.set_fact: + expected_merged_output: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lldp_interfaces: &id001 + config: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + state: merged + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lldp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: + END junos_lldp_interfaces merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/overridden.yaml new file mode 100644 index 000000000..ad3f8e540 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/overridden.yaml @@ -0,0 +1,69 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lldp_interfaces overridden integration tests on connection={{ + ansible_connection }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.set_fact: + expected_overridden_output: + - name: ge-0/0/2 + + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_lldp_interfaces: + config: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + state: merged + + - name: Override the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lldp_interfaces: &id001 + config: + - name: ge-0/0/2 + state: overridden + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_overridden_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Override the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lldp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: END junos_lldp_interfaces overridden integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/parsed.yaml new file mode 100644 index 000000000..8ef4a0879 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/parsed.yaml @@ -0,0 +1,28 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lldp_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + +- name: Parse externally provided lldp interfaces config to agnostic model + register: result + junipernetworks.junos.junos_lldp_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" +- ansible.builtin.debug: + msg: + END junos_lldp_interfaces parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/rendered.yaml new file mode 100644 index 000000000..b37382624 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/rendered.yaml @@ -0,0 +1,26 @@ +--- +- ansible.builtin.debug: + msg: START junos_lldp_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:lldp><nc:interface><nc:name>ge-0/0/1</nc:name><nc:disable delete="delete"/></nc:interface><nc:interface><nc:name>ge-0/0/2</nc:name><nc:disable/></nc:interface></nc:lldp></nc:protocols>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_lldp_interfaces: + config: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_lldp_interfaces rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/replaced.yaml new file mode 100644 index 000000000..aa791070f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/replaced.yaml @@ -0,0 +1,73 @@ +--- +- ansible.builtin.debug: + msg: START junos_lldp_interfaces replaced integration tests on connection={{ + ansible_connection }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.set_fact: + expected_replaced_output: + - name: ge-0/0/1 + enabled: false + + - name: ge-0/0/2 + enabled: false + + - name: Configure initial state for interface + register: result + junipernetworks.junos.junos_lldp_interfaces: + config: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + + - name: Replace the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_lldp_interfaces: &id001 + config: + - name: ge-0/0/1 + enabled: false + state: replaced + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_replaced_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Replace the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_lldp_interfaces: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: + END junos_lldp_interfaces replaced integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/rtt.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/rtt.yaml new file mode 100644 index 000000000..db6c7c20a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_lldp_interfaces/tests/netconf/rtt.yaml @@ -0,0 +1,78 @@ +--- +- ansible.builtin.debug: + msg: + START junos_lldp_interfaces round trip integration tests on connection={{ + ansible_connection }} + +- name: get supported protocols + register: result + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show lldp + +- name: lldp supported + ansible.builtin.set_fact: + lldp_supported: true + when: not result.failed + +- name: lldp not supported + ansible.builtin.set_fact: + lldp_supported: false + when: result.failed + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.set_fact: + expected_revert_output: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_lldp_interfaces: + config: + - name: ge-0/0/1 + + - name: ge-0/0/2 + enabled: false + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - lldp_interfaces + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_lldp_interfaces: + config: + - name: ge-0/0/2 + state: overridden + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_lldp_interfaces: + config: "{{ ansible_facts['network_resources']['lldp_interfaces'] }}" + state: replaced + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + "{{ expected_revert_output | symmetric_difference(revert['after'])\ + \ |length == 0 }}" + always: + - ansible.builtin.include_tasks: _remove_config.yaml + when: lldp_supported + +- ansible.builtin.debug: + msg: END junos_lldp_interfaces round trip integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/aliases b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/aliases diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/defaults/main.yaml new file mode 100644 index 000000000..5f709c5aa --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/tasks/main.yaml new file mode 100644 index 000000000..eace31d3f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/tasks/netconf.yaml new file mode 100644 index 000000000..6071adcfe --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/tasks/netconf.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + register: test_cases + connection: local + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/tests/netconf/basic.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/tests/netconf/basic.yaml new file mode 100644 index 000000000..030ce9e69 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging/tests/netconf/basic.yaml @@ -0,0 +1,407 @@ +--- +- ansible.builtin.debug: + msg="START junos_logging netconf/basic.yaml on connection={{ ansible_connection + }}" + +- name: setup - remove file logging + junipernetworks.junos.junos_logging: + dest: file + name: test + facility: pfe + level: error + state: absent + +- name: Create file logging + register: result + junipernetworks.junos.junos_logging: + dest: file + name: test_file + facility: pfe + level: error + state: present + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>test_file</name>' in config.xml" + - "'<name>pfe</name>' in config.xml" + - "'<error/>' in config.xml" + +- name: Create file logging (idempotent) + register: result + junipernetworks.junos.junos_logging: + dest: file + name: test_file + facility: pfe + level: error + state: present + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Deactivate logging configuration + register: result + junipernetworks.junos.junos_logging: + dest: file + name: test_file + facility: pfe + level: error + state: present + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - '''<file inactive="inactive">'' in config.xml' + - '''<contents inactive="inactive">'' in config.xml' + +- name: Activate logging configuration + register: result + junipernetworks.junos.junos_logging: + dest: file + name: test_file + facility: pfe + level: error + state: present + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>test_file</name>' in config.xml" + - "'<name>pfe</name>' in config.xml" + - "'<error/>' in config.xml" + +- name: Delete logging configuration + register: result + junipernetworks.junos.junos_logging: + dest: file + name: test_file + facility: pfe + level: error + state: absent + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>test_file</name>' not in config.xml" + +- name: Configure console logging + register: result + junipernetworks.junos.junos_logging: + dest: console + facility: kernel + level: emergency + state: present + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<console>' in config.xml" + - "'<name>kernel</name>' in config.xml" + - "'<emergency/>' in config.xml" + +- name: Configure console logging (idempotent) + register: result + junipernetworks.junos.junos_logging: + dest: console + facility: kernel + level: emergency + state: present + active: true + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Disable console logging + register: result + junipernetworks.junos.junos_logging: + dest: console + facility: kernel + level: emergency + state: present + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - '''<console inactive="inactive">'' in config.xml' + +- name: Delete console logging + register: result + junipernetworks.junos.junos_logging: + dest: console + facility: kernel + level: emergency + state: absent + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<console>' not in config.xml" + +- name: Configure logging parameters + register: result + junipernetworks.junos.junos_logging: + size: 65536 + files: 40 + rotate_frequency: 20 + state: present + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<size>64k</size>' in config.xml" + - "'<files>40</files>' in config.xml" + - "'<log-rotate-frequency>20</log-rotate-frequency>' in config.xml" + +- name: Configure logging parameters (idempotent) + register: result + junipernetworks.junos.junos_logging: + size: 65536 + files: 40 + rotate_frequency: 20 + state: present + active: true + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Disable logging parameters + register: result + junipernetworks.junos.junos_logging: + size: 65536 + files: 40 + rotate_frequency: 20 + state: present + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - '''<size inactive="inactive">64k</size>'' in config.xml' + - '''<files inactive="inactive">40</files>'' in config.xml' + - "'<log-rotate-frequency inactive=\"inactive\">20</log-rotate-frequency>'\ + \ in config.xml" + +- name: Activate logging parameters + register: result + junipernetworks.junos.junos_logging: + size: 65536 + files: 40 + rotate_frequency: 20 + state: present + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<size>64k</size>' in config.xml" + - "'<files>40</files>' in config.xml" + - "'<log-rotate-frequency>20</log-rotate-frequency>' in config.xml" + +- name: Delete logging parameters + register: result + junipernetworks.junos.junos_logging: + size: 65536 + files: 40 + rotate_frequency: 20 + state: absent + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<size>64k</size>' not in config.xml" + - "'<files>40</files>' not in config.xml" + - "'<log-rotate-frequency>20</log-rotate-frequency>' not in config.xml" + +- name: Seup file logging using aggregate + register: result + junipernetworks.junos.junos_logging: + aggregate: + - dest: file + name: test-1 + facility: pfe + level: critical + state: absent + + - dest: file + name: test-2 + facility: kernel + level: emergency + state: absent + +- name: Configure file logging using aggregate + register: result + junipernetworks.junos.junos_logging: + aggregate: + - dest: file + name: test-1 + facility: pfe + level: critical + active: true + + - dest: file + name: test-2 + facility: kernel + level: emergency + active: true + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("\+ *file test-1") + - result.diff.prepared is search("\+ *pfe critical") + - result.diff.prepared is search("\+ *file test-2") + - result.diff.prepared is search("\+ *kernel emergency") + +- name: Deactivate file logging configuration using aggregate + register: result + junipernetworks.junos.junos_logging: + aggregate: + - dest: file + name: test-1 + facility: pfe + level: critical + + - dest: file + name: test-2 + facility: kernel + level: emergency + active: false + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("! *inactive[:] file test-1") + - result.diff.prepared is search("! *inactive[:] pfe") + - result.diff.prepared is search("! *inactive[:] file test-2") + - result.diff.prepared is search("! *inactive[:] kernel") + +- name: activate file logging configuration using aggregate + register: result + junipernetworks.junos.junos_logging: + aggregate: + - dest: file + name: test-1 + facility: pfe + level: critical + + - dest: file + name: test-2 + facility: kernel + level: emergency + active: true + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("! *active[:] file test-1") + - result.diff.prepared is search("! *active[:] pfe") + - result.diff.prepared is search("! *active[:] file test-2") + - result.diff.prepared is search("! *active[:] kernel") + +- name: Delete file logging using aggregate + register: result + junipernetworks.junos.junos_logging: + aggregate: + - dest: file + name: test-1 + facility: pfe + level: critical + + - dest: file + name: test-2 + facility: kernel + level: emergency + state: absent + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("\- *file test-1") + - result.diff.prepared is search("\- *pfe critical") + - result.diff.prepared is search("\- *file test-2") + - result.diff.prepared is search("\- *kernel emergency") + +- name: Delete file logging using aggregate (idempotent) + register: result + junipernetworks.junos.junos_logging: + aggregate: + - dest: file + name: test-1 + facility: pfe + level: critical + + - dest: file + name: test-2 + facility: kernel + level: emergency + state: absent + +- ansible.builtin.assert: + that: + - result.changed == false + +- ansible.builtin.debug: + msg="END junos_logging netconf/basic.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tasks/main.yaml new file mode 100644 index 000000000..a6fc560ad --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..289c92300 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/_initial_config.yaml @@ -0,0 +1,11 @@ +--- +- ansible.builtin.debug: + msg: "START junos_logging_global initial config on connection={{ ansible_connection }}" + +- name: Configure basic config relevant to logging global + junipernetworks.junos.junos_config: + lines: + - set routing-instances inst11 description "inst11" + +- ansible.builtin.debug: + msg: "END junos_logging_global initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..72d9d08cc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/_reset_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_logging_global reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to logging global resource + junipernetworks.junos.junos_config: + lines: + - delete system syslog + - delete routing-instances + +- ansible.builtin.debug: + msg: "END junos_logging_global reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/backups/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/backups/empty_config.yaml new file mode 100644 index 000000000..c2d74d60a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/backups/empty_config.yaml @@ -0,0 +1,49 @@ +--- +- ansible.builtin.debug: + msg: START junos_bgp_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_global: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_bgp_global: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_bgp_global: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_global: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/deleted.yaml new file mode 100644 index 000000000..88e25a4db --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/deleted.yaml @@ -0,0 +1,99 @@ +--- +- ansible.builtin.debug: + msg: "START junos_logging_global deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.set_fact: + config: {} + - name: Pre gathered operation configuration + junipernetworks.junos.junos_logging_global: + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 10 + file_size: 65578 + no_world_readable: true + console: + any: + level: "info" + authorization: + level: "any" + change_log: + level: "critical" + ftp: + level: "none" + files: + - name: "file101" + allow_duplicates: true + - name: "file102" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + set: true + no_binary_data: true + files: 10 + file_size: 65578 + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info + state: merged + - name: Delete all ospf config from the device + junipernetworks.junos.junos_logging_global: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_logging_global deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..2afd92339 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/empty_config.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: + START junos_logging_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_logging_global: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_logging_global: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_logging_global: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_logging_global: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_logging_global: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..5c1e3dc41 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,152 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <login> + <user> + <name>vagrant</name> + <uid>2000</uid> + <class>super-user</class> + <authentication> + <encrypted-password>$6$QiBkxU5N$QY11GzNuFs1sfY0OAacyJ/0WFmP9ciovUAmM425yYAo9OjccxvjWlEZNo8SeqCQxYeM86cfd9V.N1RiiHW2zN0</encrypted-password> + <ssh-rsa> + <name>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key</name> + </ssh-rsa> + </authentication> + </user> + </login> + <root-authentication> + <encrypted-password>$1$nq.N1UsY$JxA/ESAj3KuXseXE597gg0</encrypted-password> + <ssh-rsa> + <name>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key</name> + </ssh-rsa> + </root-authentication> + <services> + <ssh> + </ssh> + <netconf> + <ssh> + <port>830</port> + </ssh> + <rfc-compliant/> + </netconf> + </services> + <host-name>vsrx</host-name> + <syslog> + <archive> + <size>5m</size> + <files>10</files> + <no-world-readable/> + <no-binary-data/> + </archive> + <user> + <name>user1</name> + <allow-duplicates/> + </user> + <user> + <name>user2</name> + <contents> + <name>any</name> + <any/> + </contents> + <contents> + <name>user</name> + <info/> + </contents> + <allow-duplicates/> + </user> + <host> + <name>host111</name> + <contents> + <name>any</name> + <any/> + </contents> + <match>^set*</match> + <allow-duplicates/> + <port>1231</port> + <facility-override>ftp</facility-override> + <log-prefix>field</log-prefix> + <source-address>11.1.1.11</source-address> + <routing-instance>inst11</routing-instance> + <exclude-hostname/> + <match-strings>^delete</match-strings> + <match-strings>^prompt</match-strings> + <structured-data> + <brief/> + </structured-data> + </host> + <allow-duplicates/> + <file> + <name>file101</name> + <allow-duplicates/> + </file> + <file> + <name>file102</name> + <contents> + <name>any</name> + <any/> + </contents> + <allow-duplicates/> + <structured-data> + </structured-data> + </file> + <file> + <name>file103</name> + <match>^set*</match> + <archive> + <size>65578</size> + <files>10</files> + <no-world-readable/> + <no-binary-data/> + </archive> + <explicit-priority/> + <match-strings>^delete</match-strings> + <match-strings>^prompt</match-strings> + </file> + <console> + <name>any</name> + <info/> + </console> + <console> + <name>authorization</name> + <any/> + </console> + <console> + <name>ftp</name> + <none/> + </console> + <console> + <name>change-log</name> + <critical/> + </console> + <time-format> + <year/> + <millisecond/> + </time-format> + <source-address>33.33.33.33</source-address> + <routing-instance>inst11</routing-instance> + <log-rotate-frequency>45</log-rotate-frequency> + </syslog> + <license> + <autoupdate> + <url> + <name>https://ae1.juniper.net/junos/key_retrieval</name> + </url> + </autoupdate> + </license> + </system> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/gathered.yaml new file mode 100644 index 000000000..df3ebfd42 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/gathered.yaml @@ -0,0 +1,99 @@ +--- +- ansible.builtin.debug: + msg: START junos_logging_global gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Pre gathered operation configuration + junipernetworks.junos.junos_logging_global: + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 10 + file_size: "5m" + no_world_readable: true + console: + any: + level: "info" + authorization: + level: "any" + change_log: + level: "critical" + ftp: + level: "none" + files: + - name: "file101" + allow_duplicates: true + - name: "file102" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + set: true + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info + state: merged + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_logging_global: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['gathered'] }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_logging_global gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/merged.yaml new file mode 100644 index 000000000..9bcfcd7c8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/merged.yaml @@ -0,0 +1,136 @@ +--- +- ansible.builtin.debug: + msg: "START junos_logging_global merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_logging_global: &merged + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 10 + file_size: "5m" + no_world_readable: true + console: + any: + level: "info" + authorization: + level: "any" + change_log: + level: "critical" + ftp: + level: "none" + files: + - name: "file101" + allow_duplicates: true + - name: "file102" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + set: true + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + + routing_instance: "inst11" + + log_rotate_frequency: 45 + + source_address: "33.33.33.33" + + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_logging_global: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Update the running configuration with providede configuration + junipernetworks.junos.junos_logging_global: + config: + files: + - name: "file101" + allow_duplicates: true + - name: "file104" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result['after'] }}" + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_logging_global merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/overridden.yaml new file mode 100644 index 000000000..fbdc80f3b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/overridden.yaml @@ -0,0 +1,175 @@ +--- +- ansible.builtin.debug: + msg: "START junos_logging_global overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Pre overridden operation configuration + junipernetworks.junos.junos_logging_global: + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 10 + file_size: "5m" + no_world_readable: true + console: + any: + level: "info" + authorization: + level: "any" + change_log: + level: "critical" + ftp: + level: "none" + files: + - name: "file101" + allow_duplicates: true + - name: "file102" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + set: true + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info + state: merged + + - name: Override configuration + junipernetworks.junos.junos_logging_global: &overridden + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 10 + file_size: "5m" + no_world_readable: true + files: + - name: "file101" + allow_duplicates: true + - name: "file104" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + set: true + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info + state: overridden + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_logging_global: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_logging_global overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/parsed.yaml new file mode 100644 index 000000000..e3cd47f98 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/parsed.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: + START junos_logging_global parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided logging_global config to agnostic model + register: result + junipernetworks.junos.junos_logging_global: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ merged['after'] == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_logging_global parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/rendered.yaml new file mode 100644 index 000000000..b9555f5d4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/rendered.yaml @@ -0,0 +1,29 @@ +--- +- ansible.builtin.debug: + msg: START junos_logging_global rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:syslog><nc:allow-duplicates/><nc:archive><nc:files>10</nc:files><nc:no-binary-data/><nc:size>65578</nc:size><nc:no-world-readable/></nc:archive></nc:syslog></nc:system>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_logging_global: + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_logging_global rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/replaced.yaml new file mode 100644 index 000000000..fbfb074e3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/replaced.yaml @@ -0,0 +1,175 @@ +--- +- ansible.builtin.debug: + msg: "START junos_logging_global replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Pre replaced operation configuration + junipernetworks.junos.junos_logging_global: + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 10 + file_size: "5m" + no_world_readable: true + console: + any: + level: "info" + authorization: + level: "any" + change_log: + level: "critical" + ftp: + level: "none" + files: + - name: "file101" + allow_duplicates: true + - name: "file102" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + set: true + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info + state: merged + + - name: Replace configuration + junipernetworks.junos.junos_logging_global: &replaced + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 10 + file_size: "5m" + no_world_readable: true + files: + - name: "file101" + allow_duplicates: true + - name: "file104" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + set: true + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info + state: replaced + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_logging_global: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_logging_global replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/rtt.yml new file mode 100644 index 000000000..984a52afb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/tests/netconf/rtt.yml @@ -0,0 +1,141 @@ +--- +- ansible.builtin.debug: + msg: + START junos_logging_global round trip integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_logging_global: + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 10 + file_size: "5m" + no_world_readable: true + console: + any: + level: "info" + authorization: + level: "any" + change_log: + level: "critical" + ftp: + level: "none" + files: + - name: "file101" + allow_duplicates: true + - name: "file102" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + set: true + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - logging_global + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_logging_global: + config: + allow_duplicates: true + archive: + set: true + no_binary_data: true + files: 12 + file_size: "5m" + no_world_readable: true + console: + any: + level: "info" + authorization: + level: "info" + change_log: + level: "info" + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_logging_global: + config: "{{ ansible_facts['network_resources']['logging_global'] }}" + state: replaced + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] == revert['before'] }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] == revert['after'] }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_logging_global round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/vars/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/vars/main.yaml new file mode 100644 index 000000000..ba51d3683 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_logging_global/vars/main.yaml @@ -0,0 +1,206 @@ +--- +merged: + before: {} + + after: + allow_duplicates: true + archive: + file_size: "5m" + files: 10 + no_binary_data: true + no_world_readable: true + console: + any: + level: "info" + authorization: + level: "any" + change_log: + level: "critical" + ftp: + level: "none" + files: + - name: "file101" + allow_duplicates: true + - name: "file102" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info + updated: + allow_duplicates: true + archive: + no_binary_data: true + files: 10 + file_size: "5m" + no_world_readable: true + console: + any: + level: "info" + authorization: + level: "any" + change_log: + level: "critical" + ftp: + level: "none" + files: + - name: "file101" + allow_duplicates: true + - name: "file102" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + - name: "file104" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info +replaced: + after: + allow_duplicates: true + archive: + file_size: "5m" + files: 10 + no_binary_data: true + no_world_readable: true + files: + - name: "file101" + allow_duplicates: true + - name: "file104" + allow_duplicates: true + any: + level: "any" + structured_data: + set: true + - name: "file103" + archive: + no_binary_data: true + files: 10 + file_size: "65578" + no_world_readable: true + explicit_priority: true + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + hosts: + - name: host111 + exclude_hostname: true + allow_duplicates: true + any: + level: "any" + structured_data: + brief: true + facility_override: "ftp" + log_prefix: "field" + match: "^set*" + match_strings: + - "^delete" + - "^prompt" + port: 1231 + routing_instance: "inst11" + source_address: "11.1.1.11" + routing_instance: "inst11" + log_rotate_frequency: 45 + source_address: "33.33.33.33" + time_format: + millisecond: true + year: true + users: + - name: "user1" + allow_duplicates: true + - name: "user2" + allow_duplicates: true + any: + level: "any" + user: + level: info diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/defaults/main.yaml new file mode 100644 index 000000000..9ef5ba516 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tasks/cli.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tasks/cli.yaml new file mode 100644 index 000000000..0637e8c16 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tasks/cli.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect all cli test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + connection: local + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.network_cli) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.network_cli + tags: + - network_cli diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tasks/main.yaml new file mode 100644 index 000000000..aed90a6c6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: cli.yaml diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tests/cli/changeport.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tests/cli/changeport.yaml new file mode 100644 index 000000000..ae84d4b98 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tests/cli/changeport.yaml @@ -0,0 +1,123 @@ +--- +- ansible.builtin.debug: + msg="START netconf/changeport.yaml on connection={{ ansible_connection + }}" + +- name: Setup + junipernetworks.junos.junos_netconf: + state: present + +- name: Change port + register: result + junipernetworks.junos.junos_netconf: + state: present + netconf_port: 8022 + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: idempotent tests + register: result + junipernetworks.junos.junos_netconf: + state: present + netconf_port: 8022 + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: wait for netconf port tcp/8022 to be open + wait_for: + host: "{{ hostvars[item].ansible_host }}" + port: 8022 + with_inventory_hostnames: junos + +- name: Reset ansible connections + meta: reset_connection + +- name: Ensure we can communicate over 8022 + ansible.builtin.include_tasks: "{{ role_path }}/tests/utils/junos_command.yaml" + vars: + ansible_connection: ansible.netcommon.netconf + ansible_port: 8022 + is_ignore_errors: false + +- name: wait for netconf port tcp/830 to be closed + wait_for: + host: "{{ hostvars[item].ansible_host }}" + port: 830 + state: stopped + with_inventory_hostnames: junos + +- name: Ensure we can NOT communicate over default port + ansible.builtin.include_tasks: "{{ role_path }}/tests/utils/junos_command.yaml" + vars: + ansible_connection: ansible.netcommon.netconf + ansible_port: 830 + is_ignore_errors: true + +- ansible.builtin.assert: + that: + - result.failed == true + +- name: Set back netconf to default port + junipernetworks.junos.junos_netconf: + state: present + +- name: wait for netconf port tcp/830 to be open + wait_for: + host: "{{ hostvars[item].ansible_host }}" + port: 830 + with_inventory_hostnames: junos + +- name: Reset ansible connections + meta: reset_connection + +- name: Ensure we can communicate over netconf + ansible.builtin.include_tasks: "{{ role_path }}/tests/utils/junos_command.yaml" + vars: + ansible_connection: ansible.netcommon.netconf + ansible_port: 830 + is_ignore_errors: false + +- name: Change port (check mode) + register: result + check_mode: true + junipernetworks.junos.junos_netconf: + state: present + netconf_port: 12345 + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: wait for netconf port tcp/12345 to be closed + wait_for: + host: "{{ hostvars[item].ansible_host }}" + port: 12345 + state: stopped + with_inventory_hostnames: junos + +- name: Reset ansible connections + meta: reset_connection + +- name: Ensure we can NOT communicate over non-default port + ansible.builtin.include_tasks: "{{ role_path }}/tests/utils/junos_command.yaml" + vars: + ansible_connection: ansible.netcommon.netconf + ansible_port: 12345 + is_ignore_errors: true + +- ansible.builtin.assert: + that: + - result.failed == true + +- name: Ensure we can communicate over default port + ansible.builtin.include_tasks: "{{ role_path }}/tests/utils/junos_command.yaml" + vars: + ansible_connection: ansible.netcommon.netconf + ansible_port: 830 + is_ignore_errors: false + +- ansible.builtin.debug: msg="END netconf/changeport.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tests/cli/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tests/cli/netconf.yaml new file mode 100644 index 000000000..97cf4f3ec --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tests/cli/netconf.yaml @@ -0,0 +1,133 @@ +--- +- ansible.builtin.debug: msg="START netconf/netconf.yaml on connection={{ ansible_connection }}" + +- name: Ensure netconf is enabled + junipernetworks.junos.junos_netconf: + state: present + +- name: idempotent tests + register: result + junipernetworks.junos.junos_netconf: + state: present + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: wait for netconf port tcp/830 to be open + wait_for: + host: "{{ hostvars[item].ansible_host }}" + port: 830 + with_inventory_hostnames: junos + +- name: Reset ansible connections + meta: reset_connection + +- name: Ensure we can communicate over netconf + ansible.builtin.include_tasks: "{{ role_path }}/tests/utils/junos_command.yaml" + vars: + ansible_connection: ansible.netcommon.netconf + ansible_port: 830 + is_ignore_errors: false + +- name: Disable netconf (check mode) + register: result + check_mode: true + junipernetworks.junos.junos_netconf: + state: absent + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: wait for netconf port tcp/830 to be open + wait_for: + host: "{{ hostvars[item].ansible_host }}" + port: 830 + with_inventory_hostnames: junos + +- name: Reset ansible connections + meta: reset_connection + +- name: Ensure we can communicate over netconf + ansible.builtin.include_tasks: "{{ role_path }}/tests/utils/junos_command.yaml" + vars: + ansible_connection: ansible.netcommon.netconf + ansible_port: 830 + is_ignore_errors: false + +- name: Disable netconf + register: result + junipernetworks.junos.junos_netconf: + state: absent + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: idempotent tests + register: result + junipernetworks.junos.junos_netconf: + state: absent + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: wait for netconf port tcp/830 to be closed + wait_for: + host: "{{ hostvars[item].ansible_host }}" + port: 830 + state: stopped + with_inventory_hostnames: junos + +- name: Reset ansible connections + meta: reset_connection + +- name: Ensure we can NOT talk via netconf + ansible.builtin.include_tasks: "{{ role_path }}/tests/utils/junos_command.yaml" + vars: + ansible_connection: ansible.netcommon.netconf + ansible_port: 830 + is_ignore_errors: true + +- ansible.builtin.assert: + that: + - result.failed == true + +- name: Enable netconf (check mode) + register: result + check_mode: true + junipernetworks.junos.junos_netconf: + state: present + +- ansible.builtin.assert: + that: + - result.changed == true + +- name: wait for netconf port tcp/830 to be closed + wait_for: + host: "{{ hostvars[item].ansible_host }}" + port: 830 + state: stopped + with_inventory_hostnames: junos + +- name: Reset ansible connections + meta: reset_connection + +- name: Ensure we can NOT talk via netconf + ansible.builtin.include_tasks: "{{ role_path }}/tests/utils/junos_command.yaml" + vars: + ansible_connection: ansible.netcommon.netconf + ansible_port: 830 + is_ignore_errors: true + +- ansible.builtin.assert: + that: + - result.failed == true + +- name: re-enable netconf + junipernetworks.junos.junos_netconf: + state: present + +- ansible.builtin.debug: msg="END netconf/netconfg.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tests/utils/junos_command.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tests/utils/junos_command.yaml new file mode 100644 index 000000000..76fa9c4d6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_netconf/tests/utils/junos_command.yaml @@ -0,0 +1,6 @@ +--- +- name: run junos_command to check netconf connectivity + register: result + ignore_errors: "{{ is_ignore_errors }}" + junipernetworks.junos.junos_command: + rpcs: get-software-information diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tasks/main.yaml new file mode 100644 index 000000000..a6fc560ad --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..dc07e5102 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/_initial_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ntp_global initial config on connection={{ ansible_connection }}" + +- name: Configure basic config relevant to ntp global + junipernetworks.junos.junos_config: + lines: + - set routing-instances rt1 description "rt1" + - set routing-instances rt2 description "rt2" + +- ansible.builtin.debug: + msg: "END junos_ntp_global initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/_populate_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/_populate_config.yaml new file mode 100644 index 000000000..c42d5eb5b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/_populate_config.yaml @@ -0,0 +1,21 @@ +--- +- name: Populate config + junipernetworks.junos.junos_config: + lines: + - "set system ntp boot-server 78.46.194.186" + - "set system ntp broadcast 172.16.255.255 key 50 ttl 200 version 3 routing-instance-name rt1" + - "set system ntp broadcast 192.16.255.255 key 50 ttl 200 version 3 routing-instance-name rt2" + - "set system ntp broadcast-client" + - "set system ntp multicast-client 224.0.0.1" + - "set system ntp interval-range 2" + - "set system ntp peer 78.44.194.186" + - "set system ntp peer 172.44.194.186 key 10000 prefer version 3" + - "set system ntp server 48.46.194.186" + - "set system ntp server 48.46.194.186 key 34 prefer routing-instance rt1 version 2" + - "set system ntp server 48.45.194.186 key 34 prefer version 2" + - "set system ntp source-address 172.45.194.186 routing-instance rt1" + - "set system ntp source-address 171.45.194.186 routing-instance rt2" + - "set system ntp trusted-key 2000" + - "set system ntp trusted-key 3000" + - "set system ntp threshold 300 action accept" + - "set system ntp trusted-key 3000" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..0c08a7ced --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/_reset_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ntp_global reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to ntp global resource + junipernetworks.junos.junos_config: + lines: + - delete system ntp + - delete routing-instances + +- ansible.builtin.debug: + msg: "END junos_ntp_global reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/backups/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/backups/empty_config.yaml new file mode 100644 index 000000000..c2d74d60a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/backups/empty_config.yaml @@ -0,0 +1,49 @@ +--- +- ansible.builtin.debug: + msg: START junos_bgp_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_global: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_bgp_global: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_bgp_global: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_global: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/deleted.yaml new file mode 100644 index 000000000..cd29f7ddb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/deleted.yaml @@ -0,0 +1,26 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ntp_global deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + - ansible.builtin.set_fact: + config: {} + - name: Delete all ospf config from the device + junipernetworks.junos.junos_ntp_global: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ntp_global deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..53b90ed0a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- ansible.builtin.debug: + msg: START junos_ntp_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_ntp_global: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_ntp_global: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_ntp_global: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_ntp_global: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_ntp_global: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..6619c8d64 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,156 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <login> + <user> + <name>vagrant</name> + <uid>2000</uid> + <class>super-user</class> + <authentication> + <encrypted-password>$6$QiBkxU5N$QY11GzNuFs1sfY0OAacyJ/0WFmP9ciovUAmM425yYAo9OjccxvjWlEZNo8SeqCQxYeM86cfd9V.N1RiiHW2zN0</encrypted-password> + <ssh-rsa> + <name>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key</name> + </ssh-rsa> + </authentication> + </user> + </login> + <root-authentication> + <encrypted-password>$1$nq.N1UsY$JxA/ESAj3KuXseXE597gg0</encrypted-password> + <ssh-rsa> + <name>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key</name> + </ssh-rsa> + </root-authentication> + <services> + <ssh> + </ssh> + <netconf> + <ssh> + <port>830</port> + </ssh> + <rfc-compliant/> + </netconf> + </services> + <host-name>vsrx</host-name> + <syslog> + <user> + <name>*</name> + <contents> + <name>any</name> + <emergency/> + </contents> + </user> + <file> + <name>messages</name> + <contents> + <name>any</name> + <any/> + </contents> + <contents> + <name>authorization</name> + <info/> + </contents> + </file> + <file> + <name>interactive-commands</name> + <contents> + <name>interactive-commands</name> + <any/> + </contents> + </file> + </syslog> + <license> + <autoupdate> + <url> + <name>https://ae1.juniper.net/junos/key_retrieval</name> + </url> + </autoupdate> + </license> + <ntp> + <boot-server>78.46.194.186</boot-server> + <interval-range> + <value>2</value> + </interval-range> + <peer> + <name>78.44.194.186</name> + </peer> + <peer> + <name>172.44.194.186</name> + <key>10000</key> + <version>3</version> + <prefer/> + </peer> + <server> + <name>48.46.194.186</name> + <key>34</key> + <version>2</version> + <prefer/> + <routing-instance>rt1</routing-instance> + </server> + <server> + <name>48.45.194.186</name> + <key>34</key> + <version>2</version> + <prefer/> + </server> + <broadcast> + <name>172.16.255.255</name> + <routing-instance-name>rt1</routing-instance-name> + <key>50</key> + <version>3</version> + <ttl>200</ttl> + </broadcast> + <broadcast> + <name>192.16.255.255</name> + <routing-instance-name>rt2</routing-instance-name> + <key>50</key> + <version>3</version> + <ttl>200</ttl> + </broadcast> + <broadcast-client/> + <multicast-client> + <address>224.0.0.1</address> + </multicast-client> + <trusted-key>3000</trusted-key> + <trusted-key>2000</trusted-key> + <threshold> + <value>300</value> + <action>accept</action> + </threshold> + <source-address> + <name>172.45.194.186</name> + <routing-instance>rt1</routing-instance> + </source-address> + <source-address> + <name>171.45.194.186</name> + <routing-instance>rt2</routing-instance> + </source-address> + </ntp> + </system> + <interfaces xmlns="http://yang.juniper.net/junos-es/conf/interfaces"> + <interface> + <name>fxp0</name> + <unit> + <name>0</name> + <family> + <inet> + <dhcp> + </dhcp> + </inet> + </family> + </unit> + </interface> + </interfaces> + <routing-instances xmlns="http://yang.juniper.net/junos-es/conf/routing-instances"> + <instance> + <name>rt1</name> + <description>rt1</description> + </instance> + <instance> + <name>rt2</name> + <description>rt2</description> + </instance> + </routing-instances> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/gathered.yaml new file mode 100644 index 000000000..b14ab74f8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/gathered.yaml @@ -0,0 +1,25 @@ +--- +- ansible.builtin.debug: + msg: START junos_ntp_global gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_ntp_global: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['gathered'] }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_ntp_global gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/merged.yaml new file mode 100644 index 000000000..78e943cd6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/merged.yaml @@ -0,0 +1,101 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ntp_global merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_ntp_global: &merged + config: + boot_server: "78.46.194.186" + broadcasts: + - address: "172.16.255.255" + key: "50" + ttl: 200 + version: 3 + routing_instance_name: "rt1" + - address: "192.16.255.255" + key: "50" + ttl: 200 + version: 3 + routing_instance_name: "rt2" + broadcast_client: true + interval_range: 2 + multicast_client: "224.0.0.1" + peers: + - peer: "78.44.194.186" + - peer: "172.44.194.186" + key_id: 10000 + prefer: true + version: 3 + servers: + - server: "48.46.194.186" + key_id: 34 + prefer: true + version: 2 + routing_instance: "rt1" + - server: "48.45.194.186" + key_id: 34 + prefer: true + version: 2 + source_addresses: + - source_address: "172.45.194.186" + routing_instance: "rt1" + - source_address: "171.45.194.186" + routing_instance: "rt2" + threshold: + value: 300 + action: "accept" + trusted_keys: + - key_id: 3000 + - key_id: 2000 + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_ntp_global: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Update the running configuration with providede configuration + junipernetworks.junos.junos_ntp_global: + config: + interval_range: 3 + peers: + - peer: "172.44.194.188" + key_id: 10000 + prefer: true + version: 3 + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result['after'] }}" + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ntp_global merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/overridden.yaml new file mode 100644 index 000000000..81db02e3d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/overridden.yaml @@ -0,0 +1,47 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ntp_global overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_ntp_global: &overridden + config: + multicast_client: "224.0.0.1" + interval_range: 3 + peers: + - peer: "172.44.194.188" + key_id: 10000 + prefer: true + version: 3 + state: overridden + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_ntp_global: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ntp_global overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/parsed.yaml new file mode 100644 index 000000000..821d2c13f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/parsed.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: + START junos_ntp_global parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided ntp_global config to agnostic model + register: result + junipernetworks.junos.junos_ntp_global: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ merged['after'] == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_ntp_global parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/rendered.yaml new file mode 100644 index 000000000..ba768e131 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/rendered.yaml @@ -0,0 +1,30 @@ +--- +- ansible.builtin.debug: + msg: START junos_ntp_global rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ntp><nc:interval-range>2</nc:interval-range><nc:multicast-client>224.0.0.1</nc:multicast-client><nc:peer><nc:name>78.44.194.186</nc:name></nc:peer><nc:peer><nc:name>172.44.194.186</nc:name><nc:key>10000</nc:key><nc:prefer/><nc:version>3</nc:version></nc:peer></nc:ntp></nc:system>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_ntp_global: + config: + interval_range: 2 + multicast_client: "224.0.0.1" + peers: + - peer: "78.44.194.186" + - peer: "172.44.194.186" + key_id: 10000 + prefer: true + version: 3 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_ntp_global rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/replaced.yaml new file mode 100644 index 000000000..fdca062c1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/replaced.yaml @@ -0,0 +1,47 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ntp_global replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_ntp_global: &replaced + config: + multicast_client: "224.0.0.1" + interval_range: 3 + peers: + - peer: "172.44.194.188" + key_id: 10000 + prefer: true + version: 3 + state: replaced + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_ntp_global: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ntp_global replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/rtt.yml new file mode 100644 index 000000000..8e24da5ff --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/tests/netconf/rtt.yml @@ -0,0 +1,105 @@ +--- +- ansible.builtin.debug: + msg: START junos_ntp_global round trip integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_ntp_global: + config: + boot_server: "78.46.194.186" + broadcasts: + - address: "172.16.255.255" + key: "50" + ttl: 200 + version: 3 + routing_instance_name: "rt1" + - address: "192.16.255.255" + key: "50" + ttl: 200 + version: 3 + routing_instance_name: "rt2" + broadcast_client: true + interval_range: 2 + multicast_client: "224.0.0.1" + peers: + - peer: "78.44.194.186" + - peer: "172.44.194.186" + key_id: 10000 + prefer: true + version: 3 + servers: + - server: "48.46.194.186" + key_id: 34 + prefer: true + version: 2 + routing_instance: "rt1" + - server: "48.45.194.186" + key_id: 34 + prefer: true + version: 2 + source_addresses: + - source_address: "172.45.194.186" + routing_instance: "rt1" + - source_address: "171.45.194.186" + routing_instance: "rt2" + threshold: + value: 300 + action: "accept" + trusted_keys: + - key_id: 3000 + - key_id: 2000 + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - ntp_global + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_ntp_global: + config: + multicast_client: "224.0.0.1" + interval_range: 3 + peers: + - peer: "172.44.194.188" + key_id: 10000 + prefer: true + version: 3 + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_ntp_global: + config: "{{ ansible_facts['network_resources']['ntp_global'] }}" + state: replaced + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] == revert['before'] }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] == revert['after'] }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_ntp_global round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/vars/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/vars/main.yaml new file mode 100644 index 000000000..1122d40ae --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ntp_global/vars/main.yaml @@ -0,0 +1,104 @@ +--- +merged: + before: {} + + after: + boot_server: "78.46.194.186" + broadcast_client: true + broadcasts: + - address: "172.16.255.255" + key: "50" + routing_instance_name: "rt1" + ttl: 200 + version: 3 + - address: "192.16.255.255" + key: "50" + routing_instance_name: "rt2" + ttl: 200 + version: 3 + interval_range: 2 + multicast_client: "224.0.0.1" + peers: + - peer: "78.44.194.186" + - key_id: 10000 + peer: "172.44.194.186" + prefer: true + version: 3 + servers: + - key_id: 34 + prefer: true + routing_instance: "rt1" + server: "48.46.194.186" + version: 2 + - key_id: 34 + prefer: true + server: "48.45.194.186" + version: 2 + source_addresses: + - routing_instance: "rt1" + source_address: "172.45.194.186" + - routing_instance: "rt2" + source_address: "171.45.194.186" + threshold: + action: "accept" + value: 300 + trusted_keys: + - key_id: 2000 + - key_id: 3000 + + updated: + boot_server: "78.46.194.186" + broadcasts: + - address: "172.16.255.255" + key: "50" + ttl: 200 + version: 3 + routing_instance_name: "rt1" + - address: "192.16.255.255" + key: "50" + ttl: 200 + version: 3 + routing_instance_name: "rt2" + broadcast_client: true + interval_range: 3 + multicast_client: "224.0.0.1" + peers: + - peer: "78.44.194.186" + - peer: "172.44.194.186" + key_id: 10000 + prefer: true + version: 3 + - peer: "172.44.194.188" + key_id: 10000 + prefer: true + version: 3 + servers: + - server: "48.46.194.186" + key_id: 34 + prefer: true + version: 2 + routing_instance: "rt1" + - server: "48.45.194.186" + key_id: 34 + prefer: true + version: 2 + source_addresses: + - source_address: "172.45.194.186" + routing_instance: "rt1" + - source_address: "171.45.194.186" + routing_instance: "rt2" + threshold: + value: 300 + action: "accept" + trusted_keys: + - key_id: 2000 + - key_id: 3000 +replaced: + after: + interval_range: 3 + multicast_client: "224.0.0.1" + peers: + - peer: "172.44.194.188" + key_id: 10000 + prefer: true + version: 3 diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tasks/main.yaml new file mode 100644 index 000000000..e9b22ba68 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml + tags: ["netconf"] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..41932e7dd --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/_initial_config.yaml @@ -0,0 +1,18 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv2 initial config on connection={{ ansible_connection }}" + +- name: Set initial configuration for ospf + junos_ospfv2: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + - area_id: 0.0.0.200 + interfaces: + - name: ge-2/2/0.0 + +- ansible.builtin.debug: + msg: "END junos_ospfv2 initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..6c3974c8f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/_reset_config.yaml @@ -0,0 +1,11 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv2 reset config on connection={{ ansible_connection }}" + +- name: Reset configuration for ospf and routing-options + junipernetworks.junos.junos_config: + lines: + - delete protocols ospf + - delete routing-options +- ansible.builtin.debug: + msg: "END junos_ospfv2 reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/deleted.yaml new file mode 100644 index 000000000..3318258e6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/deleted.yaml @@ -0,0 +1,25 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv2 deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Delete all ospf config from the device + junos_ospfv2: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ []|symmetric_difference(result.after) == [] }}" + + tags: deleted + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospfv2 deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..8d455dbaf --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/empty_config.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: START junos_ospfv2 empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_ospfv2: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_ospfv2: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Override with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_ospfv2: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_ospfv2: + running_config: + state: parsed + +- ansible.builtin.debug: + msg: result +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_ospfv2: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..01d8294e2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <ospf> + <area> + <name>0.0.0.200</name> + <interface> + <name>so-0/0/0.1</name> + <metric>3</metric> + <priority>5</priority> + </interface> + </area> + <area> + <name>0.0.0.100</name> + <stub> + <default-metric>200</default-metric> + </stub> + <interface> + <name>so-0/0/0.0</name> + <metric>5</metric> + <priority>3</priority> + </interface> + </area> + </ospf> + </protocols> + <routing-options> + <router-id>10.200.16.7</router-id> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/gathered.yaml new file mode 100644 index 000000000..304246381 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/gathered.yaml @@ -0,0 +1,50 @@ +--- +- ansible.builtin.debug: + msg: START junos_ospfv2 gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_gathered_output: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + - area_id: 0.0.0.200 + interfaces: + - name: ge-2/2/0.0 + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_ospfv2: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + - area_id: 0.0.0.200 + interfaces: + - name: ge-2/2/0.0 + state: merged + + - name: Gather OSPFv2 facts using gathered state + register: result + junipernetworks.junos.junos_ospfv2: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + "{{ expected_gathered_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_ospfv2 gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/merged.yaml new file mode 100644 index 000000000..7207f62b6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/merged.yaml @@ -0,0 +1,57 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv2 merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + config: + - areas: + - area_id: 0.0.0.100 + interfaces: + - metric: 5 + name: so-0/0/0.0 + priority: 3 + stub: + default_metric: 200 + set: true + router_id: 10.200.16.75 + + - name: Merge the provided configuration with the exisiting running configuration + junos_ospfv2: &merged + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + stub: + default_metric: 200 + set: true + interfaces: + - name: so-0/0/0.0 + priority: 3 + metric: 5 + state: merged + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_ospfv2: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospfv2 merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/overridden.yaml new file mode 100644 index 000000000..6cabbe25b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/overridden.yaml @@ -0,0 +1,64 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv2 overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + stub: + default_metric: 200 + set: true + interfaces: + - name: so-0/0/0.0 + priority: 3 + metric: 5 + flood_reduction: true + passive: true + - area_id: 0.0.0.200 + interfaces: + - name: ge-1/1/0.0 + - name: ge-2/2/0.0 + + - name: Override Junos OSPF config + junos_ospfv2: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + stub: + default_metric: 200 + set: true + interfaces: + - name: so-0/0/0.0 + priority: 3 + metric: 5 + flood_reduction: true + passive: true + - area_id: 0.0.0.200 + interfaces: + - name: ge-1/1/0.0 + - name: ge-2/2/0.0 + state: overridden + register: result + + - name: Assert changed + ansible.builtin.assert: &changed + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Assert changed + ansible.builtin.assert: *changed + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospfv2 overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/parsed.yaml new file mode 100644 index 000000000..67e573c33 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/parsed.yaml @@ -0,0 +1,38 @@ +--- +- ansible.builtin.debug: + msg: + START junos_ospfv2 parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - areas: + - area_id: 0.0.0.200 + interfaces: + - metric: 3 + name: so-0/0/0.1 + priority: 5 + - area_id: 0.0.0.100 + interfaces: + - metric: 5 + name: so-0/0/0.0 + priority: 3 + stub: + default_metric: 200 + set: true + router_id: 10.200.16.7 + +- name: Parse OSPFV2 running-config to agnostic model + register: result + junipernetworks.junos.junos_ospfv2: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_ospfv2 parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/rendered.yaml new file mode 100644 index 000000000..8e123b746 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/rendered.yaml @@ -0,0 +1,38 @@ +--- +- ansible.builtin.debug: + msg: START junos_ospfv2 rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf><nc:area><nc:name>0.0.0.200</nc:name><nc:interface><nc:name>so-0/0/0.1</nc:name><nc:priority>5</nc:priority><nc:metric>3</nc:metric></nc:interface></nc:area><nc:area><nc:name>0.0.0.100</nc:name><nc:interface><nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority><nc:metric>5</nc:metric></nc:interface><nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_ospfv2: + config: + - areas: + - area_id: 0.0.0.200 + interfaces: + - metric: 3 + name: so-0/0/0.1 + priority: 5 + - area_id: 0.0.0.100 + interfaces: + - metric: 5 + name: so-0/0/0.0 + priority: 3 + stub: + default_metric: 200 + set: true + router_id: 10.200.16.7 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + - result.changed == False + +- ansible.builtin.debug: + msg: END junos_ospfv2 rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/replaced.yaml new file mode 100644 index 000000000..5c7f1967d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/replaced.yaml @@ -0,0 +1,38 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv2 replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + + - name: Replace configuration + junos_ospfv2: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + state: replaced + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - "{{ config|symmetric_difference(result.after) == [] }}" + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospfv2 replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/rtt.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/rtt.yaml new file mode 100644 index 000000000..7e8080a63 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf/tests/netconf/rtt.yaml @@ -0,0 +1,73 @@ +--- +- ansible.builtin.debug: + msg: START junos_ospfv2 round trip integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_ospfv2: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + stub: + default_metric: 200 + set: true + interfaces: + - name: so-0/0/0.0 + priority: 3 + metric: 5 + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - ospf + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_ospfv2: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_ospfv2: + config: "{{ ansible_facts['network_resources']['ospfv2'] }}" + state: overridden + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] | symmetric_difference( revert['before'])\ + \ |length == 0 }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] | symmetric_difference( revert['after'])\ + \ |length == 0 }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_ospfv2 round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tasks/main.yaml new file mode 100644 index 000000000..e9b22ba68 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml + tags: ["netconf"] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..8ee537f2c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/_initial_config.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospf_interfaces initial config on connection={{ ansible_connection }}" + +- name: Set initial configuration for ospf interfaces + junipernetworks.junos.junos_ospf_interfaces: + config: + - router_id: "10.200.16.75" + name: "ge-0/0/2.0" + address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.2" + priority: 3 + metric: 5 + state: merged + +- ansible.builtin.debug: + msg: "END junos_ospf_interfaces initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..8ed9385eb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/_reset_config.yaml @@ -0,0 +1,11 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv3 reset config on connection={{ ansible_connection }}" + +- name: Reset configuration for ospf3 and routing-options + junipernetworks.junos.junos_config: + lines: + - delete protocols ospf + - delete routing-options +- ansible.builtin.debug: + msg: "END junos_ospfv3 reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/deleted.yaml new file mode 100644 index 000000000..4ac54eb97 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/deleted.yaml @@ -0,0 +1,69 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospf_interfaces deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_config: + - address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.2" + priority: 3 + metric: 5 + name: "ge-0/0/2.0" + router_id: "10.200.16.75" + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_ospf_interfaces: &merged + config: + - router_id: "10.200.16.75" + name: "ge-0/0/3.0" + address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.3" + priority: 3 + metric: 5 + state: merged + - name: Delete single ospf interface configuration + junipernetworks.junos.junos_ospf_interfaces: + config: + - router_id: 10.200.16.75 + name: "ge-0/0/3.0" + state: deleted + register: result + + - ansible.builtin.debug: + var: result.after + + - ansible.builtin.debug: + var: config + + - name: Assert changed + ansible.builtin.assert: &changed + that: + - result.changed == True + - "{{ expected_config|symmetric_difference(result.after) == [] }}" + + - ansible.builtin.set_fact: + expected_config: [] + + - name: Delete all ospf config from the device + junipernetworks.junos.junos_ospf_interfaces: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: *changed + + tags: deleted + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospf_interfaces deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..4b865a5ac --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/empty_config.yaml @@ -0,0 +1,50 @@ +--- +- ansible.builtin.debug: + msg: + START junos_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 + junipernetworks.junos.junos_ospf_interfaces: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_ospf_interfaces: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_ospf_interfaces: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_ospf_interfaces: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/fixtures/parse_ospf_router_id.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/fixtures/parse_ospf_router_id.cfg new file mode 100644 index 000000000..750b3d814 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/fixtures/parse_ospf_router_id.cfg @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <protocols> + <ospf> + <area> + <name>0.0.0.2</name> + <stub> + <default-metric>200</default-metric> + </stub> + <interface> + <name>ge-0/0/2.0</name> + <metric>5</metric> + <priority>3</priority> + </interface> + </area> + </ospf> + </protocols> + <routing-options> + <router-id>10.200.16.75</router-id> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..dc2e6145e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <protocols> + <ospf> + <area> + <name>0.0.0.2</name> + <stub> + <default-metric>200</default-metric> + </stub> + <interface> + <name>ge-0/0/2.0</name> + <metric>5</metric> + <priority>3</priority> + </interface> + </area> + </ospf> + </protocols> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/gathered.yaml new file mode 100644 index 000000000..01e0c4b23 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/gathered.yaml @@ -0,0 +1,39 @@ +--- +- ansible.builtin.debug: + msg: START junos_ospf_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_gathered_output: + - address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.2" + priority: 3 + metric: 5 + name: "ge-0/0/2.0" + router_id: "10.200.16.75" + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_ospf_interfaces: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + "{{ expected_gathered_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_ospf_interfaces gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/merged.yaml new file mode 100644 index 000000000..5d7d1980c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/merged.yaml @@ -0,0 +1,56 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospf_interfaces merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + expected_config: + - address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.2" + priority: 3 + metric: 5 + name: "ge-0/0/2.0" + router_id: "10.200.16.75" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_ospf_interfaces: &merged + config: + - router_id: "10.200.16.75" + name: "ge-0/0/2.0" + address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.2" + priority: 3 + metric: 5 + state: merged + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_config | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_ospf_interfaces: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospf_interfaces merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/merged_update.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/merged_update.yaml new file mode 100644 index 000000000..067698e19 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/merged_update.yaml @@ -0,0 +1,66 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospf_interfaces merged update integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_config: + - address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.2" + priority: 3 + metric: 5 + name: "ge-0/0/2.0" + router_id: "10.200.16.75" + - address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.3" + priority: 3 + metric: 5 + name: "ge-0/0/3.0" + router_id: "10.200.16.75" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_ospf_interfaces: &merged + config: + - router_id: "10.200.16.75" + name: "ge-0/0/3.0" + address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.3" + priority: 3 + metric: 5 + state: merged + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_config | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_ospf_interfaces: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: merged_update + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospf_interfaces merged update integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/overridden.yaml new file mode 100644 index 000000000..ad7df535d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/overridden.yaml @@ -0,0 +1,69 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospf_interfaces overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_config: + - address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.1" + priority: 6 + metric: 7 + name: "ge-0/0/1.0" + router_id: "10.200.16.75" + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_ospf_interfaces: &merged + config: + - router_id: "10.200.16.75" + name: "ge-0/0/3.0" + address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.3" + priority: 3 + metric: 5 + state: merged + - name: Override configuration + junipernetworks.junos.junos_ospf_interfaces: &overridden + config: + - router_id: "10.200.16.75" + name: "ge-0/0/1.0" + address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.1" + priority: 6 + metric: 7 + state: overridden + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_config | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Override the provided configuration with the existing running configuration (IDEMPOTENT) + junos_ospf_interfaces: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospf_interfaces overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/parsed.yaml new file mode 100644 index 000000000..6c0b740f1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/parsed.yaml @@ -0,0 +1,57 @@ +--- +- ansible.builtin.debug: + msg: + START junos_ospf_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.2" + metric: 5 + priority: 3 + name: "ge-0/0/2.0" + +- name: Parse externally provided interfaces config to agnostic model + register: result + junipernetworks.junos.junos_ospf_interfaces: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" + +- ansible.builtin.set_fact: + expected_parsed_output: + - address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.2" + metric: 5 + priority: 3 + name: "ge-0/0/2.0" + router_id: "10.200.16.75" + +- name: Parse externally provided interfaces config to agnostic model + register: result + junipernetworks.junos.junos_ospf_interfaces: + running_config: "{{ lookup('file', './fixtures/parse_ospf_router_id.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" + +- ansible.builtin.debug: + msg: + END junos_ospf_interfaces parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/rendered.yaml new file mode 100644 index 000000000..c837c8ba1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/rendered.yaml @@ -0,0 +1,31 @@ +--- +- ansible.builtin.debug: + msg: START junos_ospf_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf><nc:area><nc:name>0.0.0.2</nc:name><nc:interface><nc:name>ge-0/0/2.0</nc:name><nc:priority>3</nc:priority><nc:metric>5</nc:metric></nc:interface></nc:area></nc:ospf></nc:protocols>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_ospf_interfaces: + config: + - router_id: "10.200.16.75" + name: "ge-0/0/2.0" + address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.2" + priority: 3 + metric: 5 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_ospf_interfaces rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/replaced.yaml new file mode 100644 index 000000000..488f97906 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospf_interfaces/tests/netconf/replaced.yaml @@ -0,0 +1,46 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospf_interfaces replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_config: + - address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.1" + priority: 6 + metric: 7 + name: "ge-0/0/2.0" + router_id: "10.200.16.75" + + - name: Replace configuration + junipernetworks.junos.junos_ospf_interfaces: + config: + - router_id: "10.200.16.75" + name: "ge-0/0/2.0" + address_family: + - afi: "ipv4" + processes: + area: + area_id: "0.0.0.1" + priority: 6 + metric: 7 + state: replaced + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - "{{ expected_config|symmetric_difference(result.after) == [] }}" + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospf_interfaces replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/meta/main.yaml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tasks/main.yaml new file mode 100644 index 000000000..e9b22ba68 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- name: Invoke netconf + ansible.builtin.include_tasks: netconf.yaml + tags: ["netconf"] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..36c3ef921 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/_initial_config.yaml @@ -0,0 +1,18 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv3 initial config on connection={{ ansible_connection }}" + +- name: Set initial configuration for ospf + junipernetworks.junos.junos_ospfv3: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + - area_id: 0.0.0.200 + interfaces: + - name: ge-2/2/0.0 + +- ansible.builtin.debug: + msg: "END junos_ospfv3 initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..c5cab9852 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/_reset_config.yaml @@ -0,0 +1,11 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv3 reset config on connection={{ ansible_connection }}" + +- name: Reset configuration for ospf3 and routing-options + junipernetworks.junos.junos_config: + lines: + - delete protocols ospf3 + - delete routing-options +- ansible.builtin.debug: + msg: "END junos_ospfv3 reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/deleted.yaml new file mode 100644 index 000000000..b2733d48f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/deleted.yaml @@ -0,0 +1,56 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv3 deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.200 + interfaces: + - name: ge-2/2/0.0 + + - name: Delete an area + junipernetworks.junos.junos_ospfv3: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + state: deleted + register: result + + - ansible.builtin.debug: + var: result.after + + - ansible.builtin.debug: + var: config + + - name: Assert changed + ansible.builtin.assert: &changed + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - ansible.builtin.set_fact: + config: [] + + - name: Delete all ospf config from the device + junipernetworks.junos.junos_ospfv3: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: *changed + + tags: deleted + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospfv3 deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..b98618d17 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/empty_config.yaml @@ -0,0 +1,49 @@ +--- +- ansible.builtin.debug: + msg: START junos_ospfv3 empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_ospfv3: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_ospfv3: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_ospfv3: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_ospfv3: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..5f9a871ff --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <protocols> + <ospf3> + <area> + <name>0.0.0.100</name> + <stub> + <default-metric>200</default-metric> + </stub> + <interface> + <name>so-0/0/0.0</name> + <passive></passive> + <metric>5</metric> + <priority>3</priority> + <flood-reduction/> + </interface> + </area> + <area> + <name>0.0.0.200</name> + <interface> + <name>ge-1/1/0.0</name> + </interface> + <interface> + <name>ge-2/2/0.0</name> + </interface> + </area> + </ospf3> + </protocols> + <routing-options> + <router-id>10.200.16.75</router-id> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/gathered.yaml new file mode 100644 index 000000000..e8c32a8fa --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/gathered.yaml @@ -0,0 +1,38 @@ +--- +- ansible.builtin.debug: + msg: START junos_ospfv3 gathered integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_gathered_output: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + - area_id: 0.0.0.200 + interfaces: + - name: ge-2/2/0.0 + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_ospfv3: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + "{{ expected_gathered_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_ospfv3 gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/merged.yaml new file mode 100644 index 000000000..c0ff17516 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/merged.yaml @@ -0,0 +1,57 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv3 merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - metric: 5 + name: so-0/0/0.0 + priority: 3 + stub: + default_metric: 200 + set: true + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_ospfv3: &merged + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + stub: + default_metric: 200 + set: true + interfaces: + - name: so-0/0/0.0 + priority: 3 + metric: 5 + state: merged + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_ospfv3: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospfv3 merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/overridden.yaml new file mode 100644 index 000000000..552c80fa2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/overridden.yaml @@ -0,0 +1,64 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv3 overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + stub: + default_metric: 200 + set: true + interfaces: + - name: so-0/0/0.0 + priority: 3 + metric: 5 + flood_reduction: true + passive: true + - area_id: 0.0.0.200 + interfaces: + - name: ge-1/1/0.0 + - name: ge-2/2/0.0 + + - name: Override Junos OSPF config + junipernetworks.junos.junos_ospfv3: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + stub: + default_metric: 200 + set: true + interfaces: + - name: so-0/0/0.0 + priority: 3 + metric: 5 + flood_reduction: true + passive: true + - area_id: 0.0.0.200 + interfaces: + - name: ge-1/1/0.0 + - name: ge-2/2/0.0 + state: overridden + register: result + + - name: Assert changed + ansible.builtin.assert: &changed + that: + - result.changed == True + - "{{ config|symmetric_difference(result.after) == [] }}" + + - name: Assert changed + ansible.builtin.assert: *changed + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospfv3 overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/parsed.yaml new file mode 100644 index 000000000..613ffd2c5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/parsed.yaml @@ -0,0 +1,40 @@ +--- +- ansible.builtin.debug: + msg: + START junos_ospfv3 parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + stub: + default_metric: 200 + set: true + interfaces: + - name: so-0/0/0.0 + priority: 3 + metric: 5 + flood_reduction: true + passive: true + - area_id: 0.0.0.200 + interfaces: + - name: ge-1/1/0.0 + - name: ge-2/2/0.0 + +- name: Parse externally provided interfaces config to agnostic model + register: result + junipernetworks.junos.junos_ospfv3: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" +- ansible.builtin.debug: + msg: + END junos_ospfv3 parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/rendered.yaml new file mode 100644 index 000000000..9bb6a48c0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/rendered.yaml @@ -0,0 +1,38 @@ +--- +- ansible.builtin.debug: + msg: START junos_ospfv3 rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf3><nc:area><nc:name>0.0.0.100</nc:name><nc:interface><nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority><nc:flood-reduction/><nc:metric>5</nc:metric><nc:passive/></nc:interface><nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area><nc:area><nc:name>0.0.0.200</nc:name><nc:interface><nc:name>ge-1/1/0.0</nc:name></nc:interface><nc:interface><nc:name>ge-2/2/0.0</nc:name></nc:interface></nc:area></nc:ospf3></nc:protocols>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_ospfv3: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + stub: + default_metric: 200 + set: true + interfaces: + - name: so-0/0/0.0 + priority: 3 + metric: 5 + flood_reduction: true + passive: true + - area_id: 0.0.0.200 + interfaces: + - name: ge-1/1/0.0 + - name: ge-2/2/0.0 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_ospfv3 rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/replaced.yaml new file mode 100644 index 000000000..6750990f2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_ospfv3/tests/netconf/replaced.yaml @@ -0,0 +1,41 @@ +--- +- ansible.builtin.debug: + msg: "START junos_ospfv3 replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.200 + interfaces: + - name: ge-2/2/0.0 + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + + - name: Replace configuration + junipernetworks.junos.junos_ospfv3: + config: + - router_id: 10.200.16.75 + areas: + - area_id: 0.0.0.100 + interfaces: + - name: so-0/0/0.0 + state: replaced + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - "{{ config|symmetric_difference(result.after) == [] }}" + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_ospfv3 replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..280b43ff5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/_reset_config.yaml @@ -0,0 +1,10 @@ +--- +- ansible.builtin.debug: + msg: "START junos_prefix_lists reset config on connection={{ ansible_connection }}" + +- name: Reset the prefix lists configuration + junipernetworks.junos.junos_config: + lines: + - delete policy-options +- ansible.builtin.debug: + msg: "END junos_prefix_lists reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/deleted.yaml new file mode 100644 index 000000000..ee5dc577e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/deleted.yaml @@ -0,0 +1,78 @@ +--- +- ansible.builtin.debug: + msg: "START junos_prefix_lists deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + expected_deleted_output: + - dynamic_db: true + name: Test1 + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_prefix_lists: &merged + config: + - name: Internal + address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - name: Test1 + dynamic_db: true + - name: Test2 + address_prefixes: + - 172.16.2.16/28 + - 172.16.2.32/28 + - 172.16.2.48/28 + state: merged + + - name: Delete existing prefix list configuration identified with name + junipernetworks.junos.junos_prefix_lists: &deleted + config: + - name: Test2 + - name: Internal + state: deleted + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_deleted_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete the existing running configuration (IDEMPOTENT) + junos_prefix_lists: *deleted + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - ansible.builtin.set_fact: + expected_deleted_output: [] + + - name: Merge the existing config with provided configuration + junos_prefix_lists: *merged + register: result + + - name: Delete complete existing bgp address family configuration + junipernetworks.junos.junos_prefix_lists: &deleted_res + config: + state: deleted + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_deleted_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + tags: deleted + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_prefix_lists deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..c8df9e36e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/empty_config.yaml @@ -0,0 +1,62 @@ +--- +- ansible.builtin.debug: + msg: + START junos_prefix_lists empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_prefix_lists: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_prefix_lists: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Override with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_prefix_lists: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_prefix_lists: + running_config: + state: parsed + +- ansible.builtin.debug: + msg: result +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_prefix_lists: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..3ed5f856f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <policy-options> + <prefix-list> + <name>64510</name> + </prefix-list> + <prefix-list> + <name>64500</name> + <dynamic-db/> + <prefix-list-item> + <name>172.16.1.16/28</name> + </prefix-list-item> + <prefix-list-item> + <name>172.16.1.32/28</name> + </prefix-list-item> + </prefix-list> + </policy-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/gathered.yaml new file mode 100644 index 000000000..18c9d6f8c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/gathered.yaml @@ -0,0 +1,56 @@ +--- +- ansible.builtin.debug: + msg: START junos_prefix_lists gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + expected_gathered_output: + - address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + name: Internal + - dynamic_db: true + name: Test1 + - address_prefixes: + - 172.16.2.16/28 + - 172.16.2.32/28 + - 172.16.2.48/28 + name: Test2 + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_prefix_lists: &merged + config: + - name: Internal + address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - name: Test1 + dynamic_db: true + - name: Test2 + address_prefixes: + - 172.16.2.16/28 + - 172.16.2.32/28 + - 172.16.2.48/28 + state: merged + register: result + + - name: Gather prefix-lists facts using gathered state + register: result + junipernetworks.junos.junos_prefix_lists: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + - "{{ expected_gathered_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_prefix_lists gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/merged.yaml new file mode 100644 index 000000000..140601233 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/merged.yaml @@ -0,0 +1,93 @@ +--- +- ansible.builtin.debug: + msg: "START junos_prefix_lists merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + expected_merged_output: + - address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + name: Internal + - dynamic_db: true + name: Test1 + - address_prefixes: + - 172.16.2.16/28 + - 172.16.2.32/28 + - 172.16.2.48/28 + name: Test2 + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_prefix_lists: &merged + config: + - name: Internal + address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - name: Test1 + dynamic_db: true + - name: Test2 + address_prefixes: + - 172.16.2.16/28 + - 172.16.2.32/28 + - 172.16.2.48/28 + state: merged + register: result + + - name: Assert the correct configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_prefix_lists: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - ansible.builtin.set_fact: + expected_merged_output: + - address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - 172.16.1.48/28 + name: Internal + - dynamic_db: true + name: Test1 + - address_prefixes: + - 172.16.2.16/28 + - 172.16.2.32/28 + - 172.16.2.48/28 + name: Test2 + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_prefix_lists: + config: + - name: Internal + address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - 172.16.1.48/28 + state: merged + register: result + + - name: Assert the correct configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_prefix_lists merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/overridden.yaml new file mode 100644 index 000000000..5f1b7970d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/overridden.yaml @@ -0,0 +1,70 @@ +--- +- ansible.builtin.debug: + msg: "START junos_prefix_lists overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + expected_overridden_output: + - address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + name: Internal + - address_prefixes: + - 172.16.2.48/28 + - 172.16.3.32/28 + name: Test2 + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_prefix_lists: &merged + config: + - name: Internal + address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - name: Test1 + dynamic_db: true + - name: Test2 + address_prefixes: + - 172.16.2.16/28 + - 172.16.2.32/28 + - 172.16.2.48/28 + state: merged + + - name: Override the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_prefix_lists: &overridden + config: + - name: Internal + address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - name: Test2 + address_prefixes: + - 172.16.3.32/28 + - 172.16.2.48/28 + state: overridden + register: result + + - name: Assert the correct configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_overridden_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Override existing running prefix lists configuration with provided (IDEMPOTENT) + junos_prefix_lists: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_prefix_lists overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/parsed.yaml new file mode 100644 index 000000000..18fec21b7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/parsed.yaml @@ -0,0 +1,30 @@ +--- +- ansible.builtin.debug: + msg: + START junos_prefix_lists parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - name: "64510" + - address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + dynamic_db: true + name: "64500" + +- name: Parse externally provided prefix_lists config to agnostic model + register: result + junipernetworks.junos.junos_prefix_lists: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output | symmetric_difference(result['parsed']) |length\ + \ == 0 }}" +- ansible.builtin.debug: + msg: + END junos_prefix_lists parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/rendered.yaml new file mode 100644 index 000000000..05650bfa7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/rendered.yaml @@ -0,0 +1,34 @@ +--- +- ansible.builtin.debug: + msg: START junos_prefix_lists rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:prefix-list><nc:name>Internal</nc:name><nc:prefix-list-item><nc:name>172.16.1.16/28</nc:name></nc:prefix-list-item><nc:prefix-list-item><nc:name>172.16.1.32/28</nc:name></nc:prefix-list-item></nc:prefix-list><nc:prefix-list><nc:name>Test1</nc:name><nc:dynamic-db/></nc:prefix-list><nc:prefix-list><nc:name>Test2</nc:name><nc:prefix-list-item><nc:name>172.16.2.16/28</nc:name></nc:prefix-list-item><nc:prefix-list-item><nc:name>172.16.2.32/28</nc:name></nc:prefix-list-item><nc:prefix-list-item><nc:name>172.16.2.48/28</nc:name></nc:prefix-list-item></nc:prefix-list></nc:policy-options>' +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_prefix_lists: + config: + - name: Internal + address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - name: Test1 + dynamic_db: true + - name: Test2 + address_prefixes: + - 172.16.2.16/28 + - 172.16.2.32/28 + - 172.16.2.48/28 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - result.changed == False + - "{{ expected_rendered_output | symmetric_difference(result['rendered']) |length\ + \ == 0 }}" + +- ansible.builtin.debug: + msg: END junos_prefix_lists rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/replaced.yaml new file mode 100644 index 000000000..375813c1d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_prefix_lists/tests/netconf/replaced.yaml @@ -0,0 +1,72 @@ +--- +- ansible.builtin.debug: + msg: "START junos_prefix_lists replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.set_fact: + expected_replaced_output: + - address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + name: Internal + - dynamic_db: true + name: Test1 + - address_prefixes: + - 172.16.2.48/28 + - 172.16.3.32/28 + name: Test2 + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_prefix_lists: &merged + config: + - name: Internal + address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - name: Test1 + dynamic_db: true + - name: Test2 + address_prefixes: + - 172.16.2.16/28 + - 172.16.2.32/28 + - 172.16.2.48/28 + state: merged + + - name: Replace the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_prefix_lists: &replaced + config: + - name: Internal + address_prefixes: + - 172.16.1.16/28 + - 172.16.1.32/28 + - name: Test2 + address_prefixes: + - 172.16.3.32/28 + - 172.16.2.48/28 + state: replaced + register: result + + - name: Assert the correct configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_replaced_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Replace existing running prefix lists configuration with provided (IDEMPOTENT) + junos_prefix_lists: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_prefix_lists replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..c2ffc16ea --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/_initial_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_instances reset config on connection={{ ansible_connection }}" + +- name: Configure policy options w.r.t routing-instances + junipernetworks.junos.junos_config: + lines: + - set policy-options policy-statement test-policy term t1 then reject + - set policy-options policy-statement test-policy-1 term t1 then reject + +- ansible.builtin.debug: + msg: "END junos_routing_instances reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..dd2e4faa8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/_reset_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_instances reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to bgp address family resource + junipernetworks.junos.junos_config: + lines: + - delete routing-instances + - delete policy-options + +- ansible.builtin.debug: + msg: "END junos_routing_instances reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/deleted.yaml new file mode 100644 index 000000000..e759b7c97 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/deleted.yaml @@ -0,0 +1,84 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_instances deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_deleted_output: + - name: "forwardinst" + type: "forwarding" + description: "Configured by Ansible Content Team" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_routing_instances: &merged + config: + - name: "test" + type: "vrf" + route_distinguisher: "10.58.255.1:37" + vrf_imports: + - "test-policy" + vrf_exports: + - "test-policy" + - "test-policy-1" + interfaces: + - name: "sp-0/0/0.0" + - name: "gr-0/0/0.0" + connector_id_advertise: true + - name: "forwardinst" + type: "forwarding" + description: "Configured by Ansible Content Team" + state: merged + + - name: Delete existing configuration with running configuration + junipernetworks.junos.junos_routing_instances: &deleted + config: + - name: "test" + state: deleted + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_deleted_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Delete the existing running configuration (IDEMPOTENT) + junos_routing_instances: *deleted + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - ansible.builtin.set_fact: + expected_deleted_rints_output: [] + + - name: Merge the existing config with provided configuration + junos_routing_instances: *merged + register: result + + - name: Delete complete existing bgp address family configuration + junipernetworks.junos.junos_routing_instances: &deleted_res + config: + state: deleted + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_deleted_rints_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + tags: deleted + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_routing_instances deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..2d4c4b63d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/empty_config.yaml @@ -0,0 +1,62 @@ +--- +- ansible.builtin.debug: + msg: + START junos_routing_instances empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_routing_instances: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_routing_instances: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Override with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_routing_instances: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_routing_instances: + running_config: + state: parsed + +- ansible.builtin.debug: + msg: result +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_routing_instances: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..bbbb40400 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <routing-instances> + <instance> + <name>forwardinst</name> + <description>Configured by Ansible Content Team</description> + <instance-type>forwarding</instance-type> + </instance> + <instance> + <name>test</name> + <instance-type>vrf</instance-type> + <interface> + <name>gr-0/0/0.0</name> + </interface> + <interface> + <name>sp-0/0/0.0</name> + </interface> + <route-distinguisher> + <rd-type>10.58.255.1:37</rd-type> + </route-distinguisher> + <vrf-import>test-policy</vrf-import> + <vrf-export>test-policy</vrf-export> + <vrf-export>test-policy-1</vrf-export> + <connector-id-advertise/> + </instance> + </routing-instances> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/gathered.yaml new file mode 100644 index 000000000..a311f835b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/gathered.yaml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg: START junos_routing_instances gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_gathered_output: + - description: "Configured by Ansible Content Team" + name: "forwardinst" + type: "forwarding" + + - connector_id_advertise: true + interfaces: + - name: "gr-0/0/0.0" + - name: "sp-0/0/0.0" + name: "test" + route_distinguisher: "10.58.255.1:37" + type: "vrf" + vrf_exports: + - "test-policy" + - "test-policy-1" + vrf_imports: + - "test-policy" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_routing_instances: &merged + config: + - name: "test" + type: "vrf" + route_distinguisher: "10.58.255.1:37" + vrf_imports: + - "test-policy" + vrf_exports: + - "test-policy" + - "test-policy-1" + interfaces: + - name: "sp-0/0/0.0" + - name: "gr-0/0/0.0" + connector_id_advertise: true + - name: "forwardinst" + type: "forwarding" + description: "Configured by Ansible Content Team" + state: merged + + - name: Gather bgp address family facts using gathered state + register: result + junipernetworks.junos.junos_routing_instances: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + "{{ expected_gathered_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_routing_instances gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/merged.yaml new file mode 100644 index 000000000..35d1168b4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/merged.yaml @@ -0,0 +1,71 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_instances merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_merged_output: + - description: "Configured by Ansible Content Team" + name: "forwardinst" + type: "forwarding" + + - connector_id_advertise: true + interfaces: + - name: "gr-0/0/0.0" + - name: "sp-0/0/0.0" + name: "test" + route_distinguisher: "10.58.255.1:37" + type: "vrf" + vrf_exports: + - "test-policy" + - "test-policy-1" + vrf_imports: + - "test-policy" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_routing_instances: &merged + config: + - name: "test" + type: "vrf" + route_distinguisher: "10.58.255.1:37" + vrf_imports: + - "test-policy" + vrf_exports: + - "test-policy" + - "test-policy-1" + interfaces: + - name: "sp-0/0/0.0" + - name: "gr-0/0/0.0" + connector_id_advertise: true + - name: "forwardinst" + type: "forwarding" + description: "Configured by Ansible Content Team" + state: merged + register: result + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_routing_instances: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_routing_instances merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/overridden.yaml new file mode 100644 index 000000000..ea49cc6ea --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/overridden.yaml @@ -0,0 +1,111 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_instances overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_overridden_output: + - description: "Configured by Ansible Content Team" + name: "forwardinst" + type: "forwarding" + - connector_id_advertise: true + interfaces: + - name: "gr-0/0/0.0" + - name: "sp-0/0/0.0" + name: "test" + route_distinguisher: "10.58.255.1:37" + type: "vrf" + vrf_exports: + - "test-policy" + - "test-policy-1" + vrf_imports: + - "test-policy" + - name: "vtest1" + type: "virtual-router" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_routing_instances: &merged + config: + - name: "test" + type: "vrf" + route_distinguisher: "10.58.255.1:37" + vrf_imports: + - "test-policy" + vrf_exports: + - "test-policy" + - "test-policy-1" + interfaces: + - name: "sp-0/0/0.0" + - name: "gr-0/0/0.0" + connector_id_advertise: true + - name: "forwardinst" + type: "forwarding" + description: "Configured by Ansible Content Team" + state: merged + + - name: Replace existing configuration with running configuration + junipernetworks.junos.junos_routing_instances: &replaced + config: + - name: "test" + type: "vrf" + route_distinguisher: "10.57.255.1:37" + vrf_imports: + - "test-policy" + vrf_exports: + - "test-policy" + interfaces: + - name: "sp-0/0/0.0" + - name: "gr-0/0/0.0" + connector_id_advertise: false + description: "Configured by Ansible Content Team" + state: replaced + + - name: Override existing configuration with running configuration + junipernetworks.junos.junos_routing_instances: &overridden + config: + - name: "test" + type: "vrf" + route_distinguisher: "10.58.255.1:37" + vrf_imports: + - "test-policy" + vrf_exports: + - "test-policy" + - "test-policy-1" + interfaces: + - name: "sp-0/0/0.0" + - name: "gr-0/0/0.0" + connector_id_advertise: true + - name: "forwardinst" + type: "forwarding" + description: "Configured by Ansible Content Team" + - name: "vtest1" + type: "virtual-router" + state: overridden + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_overridden_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Override the existing running configuration with the provided configuration (IDEMPOTENT) + junos_routing_instances: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_routing_instances overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/parsed.yaml new file mode 100644 index 000000000..e88c5730d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/parsed.yaml @@ -0,0 +1,39 @@ +--- +- ansible.builtin.debug: + msg: + START junos_routing_instances parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - description: "Configured by Ansible Content Team" + name: "forwardinst" + type: "forwarding" + + - connector_id_advertise: true + interfaces: + - name: "gr-0/0/0.0" + - name: "sp-0/0/0.0" + name: "test" + route_distinguisher: "10.58.255.1:37" + type: "vrf" + vrf_exports: + - "test-policy" + - "test-policy-1" + vrf_imports: + - "test-policy" + +- name: Parse externally provided routing_instances config to agnostic model + register: result + junipernetworks.junos.junos_routing_instances: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_routing_instances parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/rendered.yaml new file mode 100644 index 000000000..60081f955 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/rendered.yaml @@ -0,0 +1,37 @@ +--- +- ansible.builtin.debug: + msg: + START junos_routing_instances rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:instance><nc:name>test</nc:name><nc:connector-id-advertise/><nc:instance-type>vrf</nc:instance-type><nc:interface><nc:name>sp-0/0/0.0</nc:name></nc:interface><nc:interface><nc:name>gr-0/0/0.0</nc:name></nc:interface><nc:route-distinguisher><nc:rd-type>10.58.255.1:37</nc:rd-type></nc:route-distinguisher><nc:vrf-import>test-policy</nc:vrf-import><nc:vrf-export>test-policy</nc:vrf-export><nc:vrf-export>test-policy-1</nc:vrf-export></nc:instance><nc:instance><nc:name>forwardinst</nc:name><nc:description>Configured by Ansible Content Team</nc:description><nc:instance-type>forwarding</nc:instance-type></nc:instance></nc:routing-instances>' +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_routing_instances: + config: + - name: "test" + type: "vrf" + route_distinguisher: "10.58.255.1:37" + vrf_imports: + - "test-policy" + vrf_exports: + - "test-policy" + - "test-policy-1" + interfaces: + - name: "sp-0/0/0.0" + - name: "gr-0/0/0.0" + connector_id_advertise: true + - name: "forwardinst" + type: "forwarding" + description: "Configured by Ansible Content Team" + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_routing_instances rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/replaced.yaml new file mode 100644 index 000000000..33e88d048 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_instances/tests/netconf/replaced.yaml @@ -0,0 +1,87 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_instances replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_replaced_output: + - description: "Configured by Ansible Content Team" + name: "forwardinst" + type: "forwarding" + + - description: "Configured by Ansible Content Team" + interfaces: + - name: "gr-0/0/0.0" + - name: "sp-0/0/0.0" + name: "test" + route_distinguisher: "10.57.255.1:37" + type: "vrf" + vrf_exports: + - "test-policy" + vrf_imports: + - "test-policy" + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_routing_instances: &merged + config: + - name: "test" + type: "vrf" + route_distinguisher: "10.58.255.1:37" + vrf_imports: + - "test-policy" + vrf_exports: + - "test-policy" + - "test-policy-1" + interfaces: + - name: "sp-0/0/0.0" + - name: "gr-0/0/0.0" + connector_id_advertise: true + - name: "forwardinst" + type: "forwarding" + description: "Configured by Ansible Content Team" + state: merged + + - name: Replace existing configuration with running configuration + junipernetworks.junos.junos_routing_instances: &replaced + config: + - name: "test" + type: "vrf" + route_distinguisher: "10.57.255.1:37" + vrf_imports: + - "test-policy" + vrf_exports: + - "test-policy" + interfaces: + - name: "sp-0/0/0.0" + - name: "gr-0/0/0.0" + connector_id_advertise: false + description: "Configured by Ansible Content Team" + state: replaced + register: result + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ expected_replaced_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_routing_instances: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_routing_instances replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/_populate_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/_populate_config.yaml new file mode 100644 index 000000000..5b2bacc96 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/_populate_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Populate config + junipernetworks.junos.junos_config: + lines: + - "set routing-options autonomous-system asdot-notation" + - "set routing-options autonomous-system loops 4" + - "set routing-options autonomous-system 2" + - "set routing-options router-id 12.12.12.12" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..46c861644 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/_reset_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_options reset config on connection={{ ansible_connection }}" + +- name: Reset routing options configuration + junipernetworks.junos.junos_config: + lines: + - delete routing-options router-id + - delete routing-options autonomous-system + +- ansible.builtin.debug: + msg: "END junos_routing_options reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/deleted.yaml new file mode 100644 index 000000000..bf5a7906b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/deleted.yaml @@ -0,0 +1,25 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_options deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + - ansible.builtin.set_fact: + config: {} + - name: Delete all ospf config from the device + junipernetworks.junos.junos_routing_options: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_routing_options deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..3065f768f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/empty_config.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: + START junos_routing_options empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_routing_options: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_routing_options: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_routing_options: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_routing_options: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_routing_options: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..c430edf7f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <routing-options> + <router-id>12.12.12.12</router-id> + <autonomous-system> + <as-number>2</as-number> + <loops>4</loops> + <asdot-notation/> + </autonomous-system> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/gathered.yaml new file mode 100644 index 000000000..cc2369a2b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/gathered.yaml @@ -0,0 +1,24 @@ +--- +- ansible.builtin.debug: + msg: START junos_routing_options gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_routing_options: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ merged['updated'] == result['gathered'] }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_routing_options gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/merged.yaml new file mode 100644 index 000000000..48b4fad6f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/merged.yaml @@ -0,0 +1,59 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_options merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_routing_options: &merged + config: + autonomous_system: + as_number: 2 + asdot_notation: true + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_routing_options: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Update the running configuration with providede configuration + junipernetworks.junos.junos_routing_options: + config: + autonomous_system: + as_number: 2 + loops: 4 + router_id: "12.12.12.12" + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result['after'] }}" + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_routing_options merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/overridden.yaml new file mode 100644 index 000000000..63d5e08dd --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/overridden.yaml @@ -0,0 +1,44 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_options overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_routing_options: &overridden + config: + autonomous_system: + as_number: 1 + asdot_notation: true + router_id: "10.10.10.10" + + state: overridden + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['updated'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_routing_options: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_routing_options overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/parsed.yaml new file mode 100644 index 000000000..04e98a0a6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/parsed.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: + START junos_routing_options parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided routing_options config to agnostic model + register: result + junipernetworks.junos.junos_routing_options: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ merged['updated'] == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_routing_options parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/rendered.yaml new file mode 100644 index 000000000..6429cb1ca --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/rendered.yaml @@ -0,0 +1,27 @@ +--- +- ansible.builtin.debug: + msg: START junos_routing_options rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:autonomous-system>2<nc:loops>4</nc:loops><nc:asdot-notation/></nc:autonomous-system><nc:router-id>12.12.12.12</nc:router-id></nc:routing-options>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_routing_options: + config: + autonomous_system: + as_number: 2 + asdot_notation: true + loops: 4 + router_id: 12.12.12.12 + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_routing_options rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/replaced.yaml new file mode 100644 index 000000000..60c0c9aff --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/replaced.yaml @@ -0,0 +1,44 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_options overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_routing_options: &replaced + config: + autonomous_system: + as_number: 1 + asdot_notation: true + router_id: "10.10.10.10" + + state: replaced + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['updated'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_routing_options: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_routing_options overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/rtt.yml new file mode 100644 index 000000000..b23153fd7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/tests/netconf/rtt.yml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg: + START junos_routing_options round trip integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_routing_options: + config: + autonomous_system: + as_number: 2 + asdot_notation: true + lo ops: 4 + router_id: 12.12.12.12 + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - routing_options + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_routing_options: + config: + autonomous_system: + as_number: 1 + asdot_notation: true + router_id: "10.10.10.10" + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_routing_options: + config: "{{ ansible_facts['network_resources']['routing_options'] }}" + state: replaced + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] == revert['before'] }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] == revert['after'] }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_routing_options round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/vars/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/vars/main.yaml new file mode 100644 index 000000000..d9e9d26f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_routing_options/vars/main.yaml @@ -0,0 +1,21 @@ +--- +merged: + before: {} + + after: + autonomous_system: + as_number: "2" + asdot_notation: true + + updated: + autonomous_system: + as_number: "2" + asdot_notation: true + loops: 4 + router_id: "12.12.12.12" +replaced: + after: + autonomous_system: + as_number: "1" + asdot_notation: true + router_id: "10.10.10.10" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/defaults/main.yaml new file mode 100644 index 000000000..9ef5ba516 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/tasks/main.yaml new file mode 100644 index 000000000..ac951c8f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/tasks/netconf.yaml new file mode 100644 index 000000000..3fa0553b5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/tasks/netconf.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + register: test_cases + connection: local + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/tests/netconf/rpc.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/tests/netconf/rpc.yaml new file mode 100644 index 000000000..3036980c8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_rpc/tests/netconf/rpc.yaml @@ -0,0 +1,69 @@ +--- +- ansible.builtin.debug: msg="START netconf/rpc.yaml on connection={{ ansible_connection }}" + +- name: Execute RPC on device + register: result + junipernetworks.junos.junos_rpc: + rpc: get-interface-information + +- ansible.builtin.assert: + that: + - result.changed == false + - "'<interface-information' in result['xml']" + - result.output is defined + +- name: Execute RPC with args on device + register: result + junipernetworks.junos.junos_rpc: + rpc: get-interface-information + args: + interface-name: lo0 + media: true + +- ansible.builtin.assert: + that: + - result.changed == false + - "'<name>\nlo0\n</name>' in result['xml']" + - "'<name>\nem0\n</name>' not in result['xml']" + - "'<name>\fxp0\n</name>' not in result['xml']" + +- name: Execute RPC on device and get output in text format + register: result + junipernetworks.junos.junos_rpc: + rpc: get-interface-information + output: text + +- ansible.builtin.assert: + that: + - result.changed == false + - result.output is defined + - result.output_lines is defined + - "'Physical interface' in result['output']" + +- name: Execute RPC on device and get output in json format + register: result + junipernetworks.junos.junos_rpc: + rpc: get-interface-information + output: json + args: + interface-name: lo0 + media: true + +- ansible.builtin.assert: + that: + - result.changed == false + - result.output is defined + - result['output']['interface-information'][0]['physical-interface'][0]['name'][0]['data'] + == "lo0" + +- name: Execute invalid RPC + register: result + ignore_errors: true + junipernetworks.junos.junos_rpc: + rpc: show-interface-information + +- ansible.builtin.assert: + that: + - result.failed == true + +- ansible.builtin.debug: msg="END netconf/rpc.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..11b82c1a4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/_initial_config.yaml @@ -0,0 +1,37 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies initial config on connection={{ ansible_connection }}" + +- name: Generate ssl certificates for ssl proxy profile-name + junipernetworks.junos.junos_command: + commands: + - request security pki generate-key-pair certificate-id SECURITY-cert size 2048 type rsa + - request security pki local-certificate generate-self-signed certificate-id SECURITY-cert domain-name labs.abc.net subject DC=mydomain.net,L=Sunnyvale,O=Mydomain,OU=LAB,CN=SECURITY email lab@labs.abc.net add-ca-constraint + +- name: Configure basic config relevant to security policies + junipernetworks.junos.junos_config: + lines: + - set class-of-service application-traffic-control rule-sets test_traffic_control rule test_rule match application-known + - set class-of-service application-traffic-control rule-sets test_traffic_control rule test_rule then log + - set security address-book global address a1 200.0.113.0/24 + - set security address-book global address a2 201.0.113.0/24 + - set security address-book global address a3 202.0.113.0/24 + - set security address-book global address a4 203.0.113.0/24 + - set security dynamic-application profile test_dyn_app redirect-message type custom-text content hello_world + - set security gprs gtp profile gtp1 + - set interfaces ge-0/0/0 unit 0 family inet address 200.0.113.1/24 + - set interfaces ge-0/0/1 unit 0 family inet address 201.0.113.1/24 + - set interfaces ge-0/0/2 unit 0 family inet address 202.0.113.1/24 + - set security zones security-zone one interfaces ge-0/0/0 + - set security zones security-zone two interfaces ge-0/0/1 + - set security zones security-zone three interfaces ge-0/0/2 + - set services icap-redirect profile test_icap server test_icap_server host 10.10.10.11 + - set services user-identification device-information end-user-profile profile-name test_end_user_profile attribute device-identity string Windows + - set services user-identification device-information end-user-profile profile-name test_end_user_profile domain-name test_domain + - set services ssl proxy profile SECURITY-SSL-PROXY root-ca SECURITY-cert + - set access profile WEBAUTH client FWClient1 firewall-user password pwd + - set access firewall-authentication web-authentication default-profile WEBAUTH + - set services ssl termination profile test_ssl_term server-certificate SECURITY-cert + +- ansible.builtin.debug: + msg: "END junos_security_policies initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/_populate_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/_populate_config.yaml new file mode 100644 index 000000000..b32dc1af8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/_populate_config.yaml @@ -0,0 +1,53 @@ +--- +- name: Populate config + junipernetworks.junos.junos_config: + lines: + - set security policies from-zone one to-zone two policy test_policy_1 match source-address a1 + - set security policies from-zone one to-zone two policy test_policy_1 match source-address a3 + - set security policies from-zone one to-zone two policy test_policy_1 match destination-address a2 + - set security policies from-zone one to-zone two policy test_policy_1 match destination-address a4 + - set security policies from-zone one to-zone two policy test_policy_1 match application junos-dhcp-relay + - set security policies from-zone one to-zone two policy test_policy_1 match application junos-finger + - set security policies from-zone one to-zone two policy test_policy_1 match source-identity authenticated-user + - set security policies from-zone one to-zone two policy test_policy_1 match source-identity unknown-user + - set security policies from-zone one to-zone two policy test_policy_1 match source-end-user-profile test_end_user_profile + - set security policies from-zone one to-zone two policy test_policy_1 match source-address-excluded + - set security policies from-zone one to-zone two policy test_policy_1 match destination-address-excluded + - set security policies from-zone one to-zone two policy test_policy_1 match dynamic-application any + - set security policies from-zone one to-zone two policy test_policy_1 match url-category Enhanced_Web_Chat + - set security policies from-zone one to-zone two policy test_policy_1 then deny + - set security policies from-zone one to-zone two policy test_policy_1 then log session-close + - set security policies from-zone one to-zone two policy test_policy_1 then count + - set security policies from-zone one to-zone two policy test_policy_2 match source-address a1 + - set security policies from-zone one to-zone two policy test_policy_2 match destination-address any-ipv6 + - set security policies from-zone one to-zone two policy test_policy_2 match application any + - set security policies from-zone one to-zone two policy test_policy_2 then reject + - set security policies from-zone one to-zone two policy test_policy_2 then reject profile test_dyn_app + - set security policies from-zone one to-zone two policy test_policy_2 then reject ssl-proxy profile-name SECURITY-SSL-PROXY + - set security policies from-zone one to-zone three policy test_policy_3 match source-address a1 + - set security policies from-zone one to-zone three policy test_policy_3 match destination-address a2 + - set security policies from-zone one to-zone three policy test_policy_3 match application any + - set security policies from-zone one to-zone three policy test_policy_3 then permit application-services application-traffic-control rule-set test_traffic_control + - set security policies from-zone one to-zone three policy test_policy_3 then permit application-services gprs-gtp-profile gtp1 + - set security policies from-zone one to-zone three policy test_policy_3 then permit application-services icap-redirect test_icap + - set security policies from-zone one to-zone three policy test_policy_3 then permit application-services reverse-redirect-wx + - set security policies from-zone one to-zone three policy test_policy_3 then permit application-services uac-policy + - set security policies from-zone one to-zone three policy test_policy_3 then permit destination-address drop-untranslated + - set security policies from-zone one to-zone three policy test_policy_3 then permit firewall-authentication pass-through auth-user-agent Opera1 + - set security policies from-zone one to-zone three policy test_policy_3 then permit firewall-authentication pass-through auth-only-browser + - set security policies from-zone one to-zone three policy test_policy_3 then permit firewall-authentication push-to-identity-management + - set security policies from-zone one to-zone three policy test_policy_3 then permit firewall-authentication user-firewall access-profile WEBAUTH + - set security policies from-zone one to-zone three policy test_policy_3 then permit firewall-authentication user-firewall auth-only-browser + - set security policies from-zone one to-zone three policy test_policy_3 then permit firewall-authentication user-firewall auth-user-agent Opera1 + - set security policies from-zone one to-zone three policy test_policy_3 then permit firewall-authentication user-firewall web-redirect-to-https + - set security policies from-zone one to-zone three policy test_policy_3 then permit firewall-authentication web-authentication client-match FWClient1 + - set security policies from-zone one to-zone three policy test_policy_3 then permit tcp-options initial-tcp-mss 64 + - set security policies from-zone one to-zone three policy test_policy_3 then permit tcp-options window-scale + - set security policies global policy test_glob_1 match source-address any-ipv6 + - set security policies global policy test_glob_1 match destination-address any-ipv6 + - set security policies global policy test_glob_1 match application any + - set security policies global policy test_glob_1 then deny + - set security policies global policy test_glob_2 match source-address any-ipv6 + - set security policies global policy test_glob_2 match destination-address any-ipv6 + - set security policies global policy test_glob_2 match application any + - set security policies global policy test_glob_2 then deny diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..746e64090 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/_reset_config.yaml @@ -0,0 +1,22 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to security policies resources + junipernetworks.junos.junos_config: + lines: + - delete security + - delete services + - delete class-of-service + - delete access + - delete interfaces ge-0/0/0 + - delete interfaces ge-0/0/1 + - delete interfaces ge-0/0/2 + +- name: Reset the generated security certificates + junipernetworks.junos.junos_command: + commands: + - clear security pki local-certificate all + +- ansible.builtin.debug: + msg: "END junos_security_policies reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/deleted.yaml new file mode 100644 index 000000000..caf0ec02a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/deleted.yaml @@ -0,0 +1,27 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + - ansible.builtin.set_fact: + config: {} + + - name: Delete all security policies from the device + junipernetworks.junos.junos_security_policies: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_policies deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..c4e646fa6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/empty_config.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: + START junos_security_policies empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_security_policies: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_security_policies: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_security_policies: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_security_policies: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_security_policies: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/fixtures/parsed.xml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/fixtures/parsed.xml new file mode 100644 index 000000000..48895bce7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/fixtures/parsed.xml @@ -0,0 +1,301 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply> + <configuration> + <version>18.4R1-S3.1</version> + <services> + <ssl> + <termination> + <profile> + <name>test_ssl_term</name> + <server-certificate>SECURITY-cert</server-certificate> + </profile> + </termination> + <proxy> + <profile> + <name>SECURITY-SSL-PROXY</name> + <root-ca>SECURITY-cert</root-ca> + </profile> + </proxy> + </ssl> + <icap-redirect> + <profile> + <name>test_icap</name> + <server> + <name>test_icap_server</name> + <host>10.10.10.11</host> + </server> + </profile> + </icap-redirect> + <user-identification> + <device-information> + <end-user-profile> + <profile-name> + <name>test_end_user_profile</name> + <domain-name>test_domain</domain-name> + <attribute> + <name>device-identity</name> + <string>Windows</string> + </attribute> + </profile-name> + </end-user-profile> + </device-information> + </user-identification> + </services> + <security> + <address-book> + <name>global</name> + <address> + <name>a1</name> + <ip-prefix>200.0.113.0/24</ip-prefix> + </address> + <address> + <name>a2</name> + <ip-prefix>201.0.113.0/24</ip-prefix> + </address> + <address> + <name>a3</name> + <ip-prefix>202.0.113.0/24</ip-prefix> + </address> + <address> + <name>a4</name> + <ip-prefix>203.0.113.0/24</ip-prefix> + </address> + </address-book> + <dynamic-application> + <profile> + <name>test_dyn_app</name> + <redirect-message> + <type> + <custom-text> + <content>hello_world</content> + </custom-text> + </type> + </redirect-message> + </profile> + </dynamic-application> + <policies> + <policy> + <from-zone-name>one</from-zone-name> + <to-zone-name>two</to-zone-name> + <policy> + <name>test_policy_1</name> + <match> + <source-address>a1</source-address> + <source-address>a3</source-address> + <destination-address>a2</destination-address> + <destination-address>a4</destination-address> + <source-address-excluded /> + <destination-address-excluded /> + <application>junos-dhcp-relay</application> + <application>junos-finger</application> + <source-identity>authenticated-user</source-identity> + <source-identity>unknown-user</source-identity> + <source-end-user-profile> + <source-end-user-profile-name>test_end_user_profile</source-end-user-profile-name> + </source-end-user-profile> + <dynamic-application>any</dynamic-application> + <url-category>Enhanced_Web_Chat</url-category> + </match> + <then> + <deny /> + <log> + <session-close /> + </log> + <count></count> + </then> + </policy> + <policy> + <name>test_policy_2</name> + <match> + <source-address>a1</source-address> + <destination-address>any-ipv6</destination-address> + <application>any</application> + </match> + <then> + <reject> + <profile>test_dyn_app</profile> + <ssl-proxy> + <profile-name>SECURITY-SSL-PROXY</profile-name> + </ssl-proxy> + </reject> + </then> + </policy> + </policy> + <policy> + <from-zone-name>one</from-zone-name> + <to-zone-name>three</to-zone-name> + <policy> + <name>test_policy_3</name> + <match> + <source-address>a1</source-address> + <destination-address>a2</destination-address> + <application>any</application> + </match> + <then> + <permit> + <firewall-authentication> + <web-authentication> + <client-match>FWClient1</client-match> + </web-authentication> + <push-to-identity-management /> + </firewall-authentication> + <destination-address> + <drop-untranslated /> + </destination-address> + <application-services> + <gprs-gtp-profile>gtp1</gprs-gtp-profile> + <uac-policy></uac-policy> + <icap-redirect>test_icap</icap-redirect> + <application-traffic-control> + <rule-set>test_traffic_control</rule-set> + </application-traffic-control> + <reverse-redirect-wx /> + </application-services> + <tcp-options> + <initial-tcp-mss>64</initial-tcp-mss> + <window-scale /> + </tcp-options> + </permit> + </then> + </policy> + </policy> + <global> + <policy> + <name>test_glob_1</name> + <match> + <source-address>any-ipv6</source-address> + <destination-address>any-ipv6</destination-address> + <application>any</application> + </match> + <then> + <deny /> + </then> + </policy> + <policy> + <name>test_glob_2</name> + <match> + <source-address>any-ipv6</source-address> + <destination-address>any-ipv6</destination-address> + <application>any</application> + </match> + <then> + <deny /> + </then> + </policy> + </global> + </policies> + <zones> + <security-zone> + <name>one</name> + <interfaces> + <name>ge-0/0/0.0</name> + </interfaces> + </security-zone> + <security-zone> + <name>two</name> + <interfaces> + <name>ge-0/0/1.0</name> + </interfaces> + </security-zone> + <security-zone> + <name>three</name> + <interfaces> + <name>ge-0/0/2.0</name> + </interfaces> + </security-zone> + </zones> + <gprs> + <gtp> + <profile> + <name>gtp1</name> + </profile> + </gtp> + </gprs> + </security> + <interfaces> + <interface> + <name>ge-0/0/0</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>200.0.113.1/24</name> + </address> + </inet> + </family> + </unit> + </interface> + <interface> + <name>ge-0/0/1</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>201.0.113.1/24</name> + </address> + </inet> + </family> + </unit> + </interface> + <interface> + <name>ge-0/0/2</name> + <unit> + <name>0</name> + <family> + <inet> + <address> + <name>202.0.113.1/24</name> + </address> + </inet> + </family> + </unit> + </interface> + <interface> + <name>fxp0</name> + <unit> + <name>0</name> + <family> + <inet> + <dhcp></dhcp> + </inet> + </family> + </unit> + </interface> + </interfaces> + <class-of-service> + <application-traffic-control> + <rule-sets> + <name>test_traffic_control</name> + <rule> + <name>test_rule</name> + <match> + <application-known /> + </match> + <then> + <log /> + </then> + </rule> + </rule-sets> + </application-traffic-control> + </class-of-service> + <access> + <profile> + <name>WEBAUTH</name> + <client> + <name>FWClient1</name> + <firewall-user> + <password>$9$kq5Ftu1cSe</password> + </firewall-user> + </client> + </profile> + <firewall-authentication> + <web-authentication> + <default-profile>WEBAUTH</default-profile> + </web-authentication> + </firewall-authentication> + </access> + </configuration> + <database-status-information></database-status-information> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/gathered.yaml new file mode 100644 index 000000000..585837f36 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/gathered.yaml @@ -0,0 +1,31 @@ +--- +- ansible.builtin.debug: + msg: START junos_security_policies gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Gather security policies facts using gathered state + register: result + junipernetworks.junos.junos_security_policies: + state: gathered + + - ansible.builtin.debug: + msg: "{{ result['gathered'] }}" + + - ansible.builtin.debug: + msg: "{{ merged['after'] }}" + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['gathered'] }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_security_policies gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/merged.yaml new file mode 100644 index 000000000..4b8a5915d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/merged.yaml @@ -0,0 +1,171 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_security_policies: &merged + config: + from_zones: + - name: one + to_zones: + - name: two + policies: + - match: + application: + names: + - junos-dhcp-relay + - junos-finger + destination_address: + addresses: + - a2 + - a4 + destination_address_excluded: true + dynamic_application: + names: + - any + source_address: + addresses: + - a1 + - a3 + source_address_excluded: true + source_end_user_profile: test_end_user_profile + source_identity: + authenticated_user: true + unknown_user: true + url_category: + names: + - Enhanced_Web_Chat + name: test_policy_1 + then: + count: true + deny: true + log: + session_close: true + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + name: test_policy_2 + then: + reject: + enable: true + profile: test_dyn_app + ssl_proxy: + enable: true + profile_name: SECURITY-SSL-PROXY + - name: three + policies: + - match: + application: + any: true + destination_address: + addresses: + - a2 + source_address: + addresses: + - a1 + name: test_policy_3 + then: + permit: + application_services: + application_traffic_control_rule_set: test_traffic_control + gprs_gtp_profile: gtp1 + icap_redirect: test_icap + reverse_redirect_wx: "True" + uac_policy: + enable: true + firewall_authentication: + push_to_identity_management: true + web_authentication: + - FWClient1 + tcp_options: + initial_tcp_mss: 64 + window_scale: true + global: + policies: + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any_ipv6: true + name: test_glob_1 + then: + deny: true + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any_ipv6: true + name: test_glob_2 + then: + deny: true + + state: merged + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_security_policies: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Update the running configuration with provided configuration + junipernetworks.junos.junos_security_policies: + config: + global: + policies: + - name: test_glob_3 + description: test update + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any: true + then: + deny: true + state: merged + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result['after'] }}" + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_policies merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/overridden.yaml new file mode 100644 index 000000000..fcb34c0b0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/overridden.yaml @@ -0,0 +1,53 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_security_policies: &overridden + config: + global: + policies: + - description: test update + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any: true + name: test_glob_3 + then: + deny: true + state: overridden + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result['changed'] == True + - "{{ replaced['after'] == result['after'] }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_security_policies: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_policies overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/parsed.yaml new file mode 100644 index 000000000..08e14d1b8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/parsed.yaml @@ -0,0 +1,23 @@ +--- +- ansible.builtin.debug: + msg: + START junos_security_policies parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided security_policies config to agnostic model + register: result + junipernetworks.junos.junos_security_policies: + running_config: "{{ lookup('file', './fixtures/parsed.xml') }}" + state: parsed + +- ansible.builtin.debug: + msg: "{{ result['parsed'] }}" + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ merged['after'] == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_security_policies parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/rendered.yaml new file mode 100644 index 000000000..acb1b00e6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/rendered.yaml @@ -0,0 +1,124 @@ +--- +- ansible.builtin.debug: + msg: + START junos_security_policies rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies><nc:policy><nc:from-zone-name>one</nc:from-zone-name><nc:to-zone-name>two</nc:to-zone-name><nc:policy><nc:name>test_policy_1</nc:name><nc:match><nc:source-address>a1</nc:source-address><nc:source-address>a3</nc:source-address><nc:source-address-excluded/><nc:destination-address>a2</nc:destination-address><nc:destination-address>a4</nc:destination-address><nc:destination-address-excluded/><nc:application>junos-dhcp-relay</nc:application><nc:application>junos-finger</nc:application><nc:source-end-user-profile>test_end_user_profile</nc:source-end-user-profile><nc:source-identity>unknown-user</nc:source-identity><nc:url-category>Enhanced_Web_Chat</nc:url-category><nc:dynamic-application>any</nc:dynamic-application></nc:match><nc:then><nc:deny/><nc:count> </nc:count><nc:log><nc:session-close/></nc:log></nc:then></nc:policy><nc:policy><nc:name>test_policy_2</nc:name><nc:match><nc:source-address>a1</nc:source-address><nc:destination-address>any-ipv6</nc:destination-address><nc:application>any</nc:application></nc:match><nc:then><nc:reject> <nc:profile>test_dyn_app</nc:profile><nc:ssl-proxy> <nc:profile-name>SECURITY-SSL-PROXY</nc:profile-name></nc:ssl-proxy></nc:reject></nc:then></nc:policy></nc:policy><nc:policy><nc:from-zone-name>one</nc:from-zone-name><nc:to-zone-name>three</nc:to-zone-name><nc:policy><nc:name>test_policy_3</nc:name><nc:match><nc:source-address>a1</nc:source-address><nc:destination-address>a2</nc:destination-address><nc:application>any</nc:application></nc:match><nc:then><nc:permit><nc:application-services><nc:application-traffic-control><nc:rule-set>test_traffic_control</nc:rule-set></nc:application-traffic-control><nc:gprs-gtp-profile>gtp1</nc:gprs-gtp-profile><nc:icap-redirect>test_icap</nc:icap-redirect><nc:reverse-redirect-wx/><nc:uac-policy> </nc:uac-policy></nc:application-services><nc:firewall-authentication><nc:push-to-identity-management/><nc:web-authentication> <nc:client-match>FWClient1</nc:client-match></nc:web-authentication></nc:firewall-authentication><nc:tcp-options> <nc:initial-tcp-mss>64</nc:initial-tcp-mss><nc:window-scale/></nc:tcp-options></nc:permit></nc:then></nc:policy></nc:policy><nc:global><nc:policy><nc:name>test_glob_1</nc:name><nc:match><nc:source-address>any-ipv6</nc:source-address><nc:destination-address>any-ipv6</nc:destination-address><nc:application>any</nc:application></nc:match><nc:then><nc:deny/></nc:then></nc:policy><nc:policy><nc:name>test_glob_2</nc:name><nc:match><nc:source-address>any-ipv6</nc:source-address><nc:destination-address>any-ipv6</nc:destination-address><nc:application>any</nc:application></nc:match><nc:then><nc:deny/></nc:then></nc:policy></nc:global></nc:policies></nc:security>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_security_policies: + config: + from_zones: + - name: one + to_zones: + - name: two + policies: + - match: + application: + names: + - junos-dhcp-relay + - junos-finger + destination_address: + addresses: + - a2 + - a4 + destination_address_excluded: true + dynamic_application: + names: + - any + source_address: + addresses: + - a1 + - a3 + source_address_excluded: true + source_end_user_profile: test_end_user_profile + source_identity: + unknown_user: true + url_category: + names: + - Enhanced_Web_Chat + name: test_policy_1 + then: + count: true + deny: true + log: + session_close: true + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + name: test_policy_2 + then: + reject: + enable: true + profile: test_dyn_app + ssl_proxy: + enable: true + profile_name: SECURITY-SSL-PROXY + - name: three + policies: + - match: + application: + any: true + destination_address: + addresses: + - a2 + source_address: + addresses: + - a1 + name: test_policy_3 + then: + permit: + application_services: + application_traffic_control_rule_set: test_traffic_control + gprs_gtp_profile: gtp1 + icap_redirect: test_icap + reverse_redirect_wx: "True" + uac_policy: + enable: true + firewall_authentication: + push_to_identity_management: true + web_authentication: + - FWClient1 + tcp_options: + initial_tcp_mss: 64 + window_scale: true + global: + policies: + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any_ipv6: true + name: test_glob_1 + then: + deny: true + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any_ipv6: true + name: test_glob_2 + then: + deny: true + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_security_policies rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/replaced.yaml new file mode 100644 index 000000000..a9c835c0b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/replaced.yaml @@ -0,0 +1,53 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Replace configuration + junipernetworks.junos.junos_security_policies: &replaced + config: + global: + policies: + - description: test update + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any: true + name: test_glob_3 + then: + deny: true + state: replaced + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_security_policies: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_policies replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/rtt.yml new file mode 100644 index 000000000..a35e2e9ae --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/tests/netconf/rtt.yml @@ -0,0 +1,197 @@ +--- +- ansible.builtin.debug: + msg: + START junos_security_policies round trip integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_security_policies: + config: + from_zones: + - name: one + to_zones: + - name: two + policies: + - name: test_policy_1 + description: "hello world" + match: + application: + names: + - junos-dhcp-relay + - junos-finger + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + - a2 + source_identity: + authenticated_user: true + unknown_user: true + source_end_user_profile: test_end_user_profile + source_address_excluded: true + destination_address_excluded: true + dynamic_application: + any: true + url_category: + names: + - Enhanced_Web_Chat + then: + deny: true + log: + session_close: true + count: true + - name: test_policy_2 + description: hello world + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + then: + reject: + profile: test_dyn_app + ssl_proxy: + profile_name: SECURITY-SSL-PROXY + - name: two + policies: + - name: test_policy_2 + description: hello world + match: + application: + any: true + destination_address: + addresses: + - a2 + source_address: + addresses: + - a1 + then: + permit: + application_services: + application_traffic_control_rule_set: test_traffic_control + gprs_gtp_profile: gtp1 + icap_redirect: test_icap + reverse_redirect_wx: true + uac_policy: + enable: true + destination_address: drop-untranslated + firewall_authentication: + pass_through: + auth_user_agent: Opera1 + auth_only_browser: true + push_to_identity_management: true + user_firewall: + access_profile: WEBAUTH + auth_only_browser: true + auth_user_agent: Opera1 + web_redirect_to_https: true + web_authentication: + - client_match: FWClient1 + tcp_options: + initial_tcp_mss: 64 + window_scale: true + - name: two + to_zones: + - name: three + policies: + - name: test_policy_4 + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + then: + deny: true + global: + policies: + - name: test_glob_1 + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + then: + deny: true + - name: test_glob_2 + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + then: + deny: true + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - security_policies + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_security_policies: + config: + global: + policies: + - name: test_glob_1 + description: replaced + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + then: + deny: true + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_security_policies: + config: "{{ ansible_facts['network_resources']['security_policies'] }}" + state: replaced + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] == revert['before'] }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] == revert['after'] }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_security_policies round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/vars/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/vars/main.yaml new file mode 100644 index 000000000..9076a631e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies/vars/main.yaml @@ -0,0 +1,235 @@ +--- +merged: + before: {} + + after: + from_zones: + - name: one + to_zones: + - name: two + policies: + - match: + application: + names: + - junos-dhcp-relay + - junos-finger + destination_address: + addresses: + - a2 + - a4 + destination_address_excluded: true + dynamic_application: + any: true + source_address: + addresses: + - a1 + - a3 + source_address_excluded: true + source_end_user_profile: test_end_user_profile + source_identity: + authenticated_user: true + unknown_user: true + url_category: + names: + - Enhanced_Web_Chat + name: test_policy_1 + then: + count: true + deny: true + log: + session_close: true + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + name: test_policy_2 + then: + reject: + enable: true + profile: test_dyn_app + ssl_proxy: + enable: true + profile_name: SECURITY-SSL-PROXY + - name: three + policies: + - match: + application: + any: true + destination_address: + addresses: + - a2 + source_address: + addresses: + - a1 + name: test_policy_3 + then: + permit: + application_services: + application_traffic_control_rule_set: test_traffic_control + gprs_gtp_profile: gtp1 + icap_redirect: test_icap + reverse_redirect_wx: true + uac_policy: + enable: true + firewall_authentication: + push_to_identity_management: true + web_authentication: + - FWClient1 + tcp_options: + initial_tcp_mss: 64 + window_scale: true + global: + policies: + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any_ipv6: true + name: test_glob_1 + then: + deny: true + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any_ipv6: true + name: test_glob_2 + then: + deny: true + updated: + from_zones: + - name: one + to_zones: + - name: two + policies: + - match: + application: + names: + - junos-dhcp-relay + - junos-finger + destination_address: + addresses: + - a2 + - a4 + destination_address_excluded: true + dynamic_application: + any: true + source_address: + addresses: + - a1 + - a3 + source_address_excluded: true + source_end_user_profile: test_end_user_profile + source_identity: + authenticated_user: true + unknown_user: true + url_category: + names: + - Enhanced_Web_Chat + name: test_policy_1 + then: + count: true + deny: true + log: + session_close: true + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + addresses: + - a1 + name: test_policy_2 + then: + reject: + enable: true + profile: test_dyn_app + ssl_proxy: + enable: true + profile_name: SECURITY-SSL-PROXY + - name: three + policies: + - match: + application: + any: true + destination_address: + addresses: + - a2 + source_address: + addresses: + - a1 + name: test_policy_3 + then: + permit: + application_services: + application_traffic_control_rule_set: test_traffic_control + gprs_gtp_profile: gtp1 + icap_redirect: test_icap + reverse_redirect_wx: true + uac_policy: + enable: true + firewall_authentication: + push_to_identity_management: true + web_authentication: + - FWClient1 + tcp_options: + initial_tcp_mss: 64 + window_scale: true + global: + policies: + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any_ipv6: true + name: test_glob_1 + then: + deny: true + - match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any_ipv6: true + name: test_glob_2 + then: + deny: true + - description: test update + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any: true + name: test_glob_3 + then: + deny: true + +replaced: + after: + global: + policies: + - description: test update + match: + application: + any: true + destination_address: + any_ipv6: true + source_address: + any: true + name: test_glob_3 + then: + deny: true diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..abfb5cff2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/_initial_config.yaml @@ -0,0 +1,11 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies_global initial config on connection={{ ansible_connection }}" + +- name: Configure basic config relevant to security policies global + junipernetworks.junos.junos_config: + lines: + - set system tracing destination-override syslog host 10.0.0.4 + +- ansible.builtin.debug: + msg: "END junos_security_policies_global initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/_populate_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/_populate_config.yaml new file mode 100644 index 000000000..47fc2c9ea --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/_populate_config.yaml @@ -0,0 +1,22 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies_global populate config on connection={{ ansible_connection }}" + +- name: Populate config + junipernetworks.junos.junos_config: + lines: + - set security policies default-policy permit-all + - set security policies policy-rematch extensive + - set security policies policy-stats system-wide enable + - set security policies pre-id-default-policy then log session-init + - set security policies pre-id-default-policy then session-timeout icmp 10 + - set security policies pre-id-default-policy then session-timeout others 10 + - set security policies traceoptions no-remote-trace + - set security policies traceoptions flag all + - set security policies traceoptions file files 3 + - set security policies traceoptions file match /[A-Z]*/gm + - set security policies traceoptions file size 10240 + - set security policies traceoptions file no-world-readable + +- ansible.builtin.debug: + msg: "END junos_security_policies_global populate config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..d925b154a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/_reset_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies_global reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to security policies global resource + junipernetworks.junos.junos_config: + lines: + - delete security policies + - delete system tracing + +- ansible.builtin.debug: + msg: "END junos_security_policies_global reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/deleted.yaml new file mode 100644 index 000000000..086dda3a2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/deleted.yaml @@ -0,0 +1,26 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies_global deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + - ansible.builtin.set_fact: + config: {} + - name: Delete all security policy config from the device + junipernetworks.junos.junos_security_policies_global: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_policies_global deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..e9b49b596 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/empty_config.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: + START junos_security_policies_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_security_policies_global: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_security_policies_global: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_security_policies_global: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_security_policies_global: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_security_policies_global: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..72bd2d81e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <policies> + <traceoptions> + <no-remote-trace /> + <file> + <size>10k</size> + <files>3</files> + <no-world-readable /> + <match>/[A-Z]*/gm</match> + </file> + <flag> + <name>all</name> + </flag> + </traceoptions> + <default-policy> + <permit-all /> + </default-policy> + <policy-rematch> + <extensive /> + </policy-rematch> + <policy-stats> + <system-wide>enable</system-wide> + </policy-stats> + <pre-id-default-policy> + <then> + <log> + <session-init /> + </log> + <session-timeout> + <icmp>10</icmp> + <others>10</others> + </session-timeout> + </then> + </pre-id-default-policy> + </policies> + </security> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/gathered.yaml new file mode 100644 index 000000000..3bfd2f37f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/gathered.yaml @@ -0,0 +1,25 @@ +--- +- ansible.builtin.debug: + msg: START junos_security_policies_global gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_security_policies_global: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['gathered'] }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_security_policies_global gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/merged.yaml new file mode 100644 index 000000000..c03a1e262 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/merged.yaml @@ -0,0 +1,95 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies_global merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_security_policies_global: &merged + config: + default_policy: permit-all + policy_rematch: + enable: true + extensive: true + policy_stats: + enable: true + system_wide: true + pre_id_default_policy_action: + log: + session_init: true + session_timeout: + icmp: 10 + others: 10 + traceoptions: + file: + files: 3 + match: /[A-Z]*/gm + size: 10k + no_world_readable: true + flag: all + no_remote_trace: true + state: merged + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_security_policies_global: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Update the running configuration with provided configuration + junipernetworks.junos.junos_security_policies_global: + config: + default_policy: deny-all + policy_rematch: + enable: true + policy_stats: + enable: true + pre_id_default_policy_action: + log: + session_init: true + session_timeout: + icmp: 10 + others: 10 + traceoptions: + file: + files: 4 + match: /[A-Z]*/gm + size: 10k + no_world_readable: true + flag: all + no_remote_trace: true + state: merged + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result['after'] }}" + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_policies_global merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/overridden.yaml new file mode 100644 index 000000000..fe53769db --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/overridden.yaml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies_global overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_security_policies_global: + config: + state: gathered + + - name: Override configuration + junipernetworks.junos.junos_security_policies_global: &overridden + config: + default_policy: deny-all + policy_rematch: + enable: true + policy_stats: + enable: true + pre_id_default_policy_action: + log: + session_init: true + traceoptions: + file: + files: 4 + match: /[A-Z]*/gm + size: 10k + flag: all + state: overridden + register: result + + - ansible.builtin.debug: + msg: "{{ merged['after'] }}" + + - ansible.builtin.debug: + msg: "{{ result['before'] }}" + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_security_policies_global: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_policies_global overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/parsed.yaml new file mode 100644 index 000000000..115a5d076 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/parsed.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: + START junos_security_policies_global parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided security_policies_global config to agnostic model + register: result + junipernetworks.junos.junos_security_policies_global: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ merged['after'] == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_security_policies_global parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/rendered.yaml new file mode 100644 index 000000000..82db58810 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/rendered.yaml @@ -0,0 +1,44 @@ +--- +- ansible.builtin.debug: + msg: + START junos_security_policies_global rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies><nc:default-policy><nc:permit-all/></nc:default-policy><nc:policy-rematch> <nc:extensive/></nc:policy-rematch><nc:policy-stats> <nc:system-wide>enable</nc:system-wide></nc:policy-stats><nc:pre-id-default-policy><nc:then><nc:log><nc:session-close/></nc:log><nc:session-timeout><nc:icmp>10</nc:icmp><nc:others>10</nc:others></nc:session-timeout></nc:then></nc:pre-id-default-policy><nc:traceoptions><nc:file><nc:files>3</nc:files><nc:match>/[A-Z]*/gm</nc:match><nc:size>10k</nc:size><nc:no-world-readable/></nc:file><nc:no-remote-trace/></nc:traceoptions></nc:policies></nc:security>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_security_policies_global: + config: + default_policy: permit-all + policy_rematch: + enable: true + extensive: true + policy_stats: + enable: true + system_wide: true + pre_id_default_policy_action: + log: + session_close: true + session_timeout: + icmp: 10 + others: 10 + traceoptions: + file: + files: 3 + match: "/[A-Z]*/gm" + no_world_readable: true + size: 10k + no_remote_trace: true + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: + END junos_security_policies_global rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/replaced.yaml new file mode 100644 index 000000000..d475025a7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/replaced.yaml @@ -0,0 +1,54 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_policies_global replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Replace configuration + junipernetworks.junos.junos_security_policies_global: &replaced + config: + default_policy: deny-all + policy_rematch: + enable: true + policy_stats: + enable: true + pre_id_default_policy_action: + log: + session_init: true + traceoptions: + file: + files: 4 + match: /[A-Z]*/gm + size: 10k + flag: all + state: replaced + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_security_policies_global: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_policies_global replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/rtt.yml new file mode 100644 index 000000000..83aaecee3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/tests/netconf/rtt.yml @@ -0,0 +1,91 @@ +--- +- ansible.builtin.debug: + msg: + START junos_security_policies_global round trip integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_security_policies_global: + config: + default_policy: permit-all + policy_rematch: + enable: true + extensive: true + policy_stats: + enable: true + system_wide: true + pre_id_default_policy_action: + log: + session_close: true + session_timeout: + icmp: 10 + others: 10 + traceoptions: + file: + files: 3 + match: "/[A-Z]*/gm" + no_world_readable: true + size: 10k + no_remote_trace: true + state: merged + + - name: Gather security policy facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - security_policies_global + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_security_policies_global: + config: + default_policy: deny-all + policy_rematch: + enable: true + policy_stats: + enable: true + pre_id_default_policy_action: + log: + session_init: true + traceoptions: + file: + files: 4 + match: /[A-Z]*/gm + size: 10k + flag: all + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_security_policies_global: + config: "{{ ansible_facts['network_resources']['security_policies_global'] }}" + state: replaced + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] == revert['before'] }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] == revert['after'] }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_security_policies_global round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/vars/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/vars/main.yaml new file mode 100644 index 000000000..76ea4dfc7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_policies_global/vars/main.yaml @@ -0,0 +1,65 @@ +--- +merged: + before: {} + + after: + default_policy: permit-all + policy_rematch: + enable: true + extensive: true + policy_stats: + enable: true + system_wide: true + pre_id_default_policy_action: + log: + session_init: true + session_timeout: + icmp: 10 + others: 10 + traceoptions: + file: + files: 3 + match: "/[A-Z]*/gm" + no_world_readable: true + size: 10k + flag: all + no_remote_trace: true + + updated: + default_policy: deny-all + policy_rematch: + enable: true + extensive: true + policy_stats: + enable: true + system_wide: true + pre_id_default_policy_action: + log: + session_init: true + session_timeout: + icmp: 10 + others: 10 + traceoptions: + file: + files: 4 + match: /[A-Z]*/gm + size: 10k + no_world_readable: true + flag: all + no_remote_trace: true +replaced: + after: + default_policy: deny-all + policy_rematch: + enable: true + policy_stats: + enable: true + pre_id_default_policy_action: + log: + session_init: true + traceoptions: + file: + files: 4 + match: /[A-Z]*/gm + size: 10k + flag: all diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..aa0bb0a7a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/_initial_config.yaml @@ -0,0 +1,18 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_zones initial config on connection={{ ansible_connection }}" + +- name: Configure basic config relevant to security zones + junipernetworks.junos.junos_config: + lines: + - set security screen ids-option test_screen ip block-frag + - set interfaces ge-0/0/1 unit 0 family inet address 200.0.0.1/24 + - set interfaces ge-0/0/2 unit 0 family inet address 201.0.0.1/24 + - set interfaces ge-0/0/3 unit 0 family inet address 202.0.0.1/24 + - set interfaces ge-0/0/4 unit 0 family inet address 204.0.0.1/24 + - set security advance-policy-based-routing profile test_profile rule test_rule match category Enhanced_Bandwidth + - set routing-instances test_inst instance-type forwarding + - set security advance-policy-based-routing profile test_profile rule test_rule then routing-instance test_inst + +- ansible.builtin.debug: + msg: "END junos_security_zones initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/_populate_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/_populate_config.yaml new file mode 100644 index 000000000..77d36131a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/_populate_config.yaml @@ -0,0 +1,38 @@ +--- +- name: Populate config + junipernetworks.junos.junos_config: + lines: + - set security zones functional-zone management description "test description" + - set security zones functional-zone management screen test_screen + - set security zones functional-zone management interfaces ge-0/0/1 + - set security zones functional-zone management interfaces ge-0/0/2 + - set security zones functional-zone management host-inbound-traffic protocols all + - set security zones functional-zone management host-inbound-traffic protocols bgp except + - set security zones functional-zone management host-inbound-traffic system-services all + - set security zones functional-zone management host-inbound-traffic system-services dhcp except + - set security zones security-zone test_sec_zone1 screen test_screen + - set security zones security-zone test_sec_zone1 interfaces ge-0/0/3 + - set security zones security-zone test_sec_zone1 interfaces ge-0/0/4 + - set security zones security-zone test_sec_zone1 source-identity-log + - set security zones security-zone test_sec_zone1 tcp-rst + - set security zones security-zone test_sec_zone1 enable-reverse-reroute + - set security zones security-zone test_sec_zone1 description "test description" + - set security zones security-zone test_sec_zone1 application-tracking + - set security zones security-zone test_sec_zone1 advance-policy-based-routing-profile test_profile + - set security zones security-zone test_sec_zone1 host-inbound-traffic protocols all + - set security zones security-zone test_sec_zone1 host-inbound-traffic protocols bgp except + - set security zones security-zone test_sec_zone1 host-inbound-traffic system-services all + - set security zones security-zone test_sec_zone1 host-inbound-traffic system-services dhcp except + - set security zones security-zone test_sec_zone1 address-book address test_adr1 10.0.0.0/24 description "test desc" + - set security zones security-zone test_sec_zone1 address-book address test_adr2 dns-name 1.1.1.1 ipv6-only + - set security zones security-zone test_sec_zone1 address-book address test_adr3 range-address 10.2.0.1 to 10.2.0.2 + - set security zones security-zone test_sec_zone1 address-book address test_adr4 wildcard-address 10.3.0.1/24 + - set security zones security-zone test_sec_zone1 address-book address test_adr5 10.1.0.0/24 description "test desc" + - set security zones security-zone test_sec_zone1 address-book address-set test_adrset1 address test_adr1 + - set security zones security-zone test_sec_zone1 address-book address-set test_adrset1 address test_adr2 + - set security zones security-zone test_sec_zone1 address-book address-set test_adrset2 address test_adr3 + - set security zones security-zone test_sec_zone1 address-book address-set test_adrset2 address test_adr4 + - set security zones security-zone test_sec_zone1 address-book address-set test_adrset3 address test_adr5 + - set security zones security-zone test_sec_zone1 address-book address-set test_adrset3 address-set test_adrset1 + - set security zones security-zone test_sec_zone1 address-book address-set test_adrset3 address-set test_adrset2 + - set security zones security-zone test_sec_zone1 address-book address-set test_adrset3 description "test description" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..309e0d573 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/_reset_config.yaml @@ -0,0 +1,16 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_zones reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to security zones resource + junipernetworks.junos.junos_config: + lines: + - delete security + - delete routing-instances + - delete interfaces ge-0/0/1 + - delete interfaces ge-0/0/2 + - delete interfaces ge-0/0/3 + - delete interfaces ge-0/0/4 + +- ansible.builtin.debug: + msg: "END junos_security_zones reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/deleted.yaml new file mode 100644 index 000000000..1fc72a490 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/deleted.yaml @@ -0,0 +1,26 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_zones deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + - ansible.builtin.set_fact: + config: {} + - name: Delete all security zones config from the device + junipernetworks.junos.junos_security_zones: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_zones deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..b2deccd43 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/empty_config.yaml @@ -0,0 +1,61 @@ +--- +- ansible.builtin.debug: + msg: + START junos_security_zones empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_security_zones: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_security_zones: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_security_zones: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_security_zones: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_security_zones: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..4c346a09f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,137 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <zones> + <functional-zone> + <management> + <description>test description</description> + <host-inbound-traffic> + <protocols> + <name>all</name> + </protocols> + <protocols> + <name>bgp</name> + <except /> + </protocols> + <system-services> + <name>all</name> + </system-services> + <system-services> + <name>dhcp</name> + <except /> + </system-services> + </host-inbound-traffic> + <interfaces> + <name>ge-0/0/1.0</name> + </interfaces> + <interfaces> + <name>ge-0/0/2.0</name> + </interfaces> + <screen>test_screen</screen> + </management> + </functional-zone> + <security-zone> + <name>test_sec_zone1</name> + <address-book> + <address> + <name>test_adr1</name> + <ip-prefix>10.0.0.0/24</ip-prefix> + <description>test desc</description> + </address> + <address> + <name>test_adr2</name> + <dns-name> + <name>1.1.1.1</name> + <ipv6-only /> + </dns-name> + </address> + <address> + <name>test_adr3</name> + <range-address> + <name>10.2.0.1</name> + <to> + <range-high>10.2.0.2</range-high> + </to> + </range-address> + </address> + <address> + <name>test_adr4</name> + <wildcard-address> + <name>10.3.0.1/24</name> + </wildcard-address> + </address> + <address> + <name>test_adr5</name> + <ip-prefix>10.1.0.0/24</ip-prefix> + <description>test desc</description> + </address> + <address-set> + <name>test_adrset1</name> + <address> + <name>test_adr1</name> + </address> + <address> + <name>test_adr2</name> + </address> + </address-set> + <address-set> + <name>test_adrset2</name> + <address> + <name>test_adr3</name> + </address> + <address> + <name>test_adr4</name> + </address> + </address-set> + <address-set> + <name>test_adrset3</name> + <address> + <name>test_adr5</name> + </address> + <address-set> + <name>test_adrset1</name> + </address-set> + <address-set> + <name>test_adrset2</name> + </address-set> + <description>test description</description> + </address-set> + </address-book> + <advance-policy-based-routing-profile> + <profile>test_profile</profile> + </advance-policy-based-routing-profile> + <application-tracking /> + <description>test description</description> + <enable-reverse-reroute /> + <host-inbound-traffic> + <protocols> + <name>all</name> + </protocols> + <protocols> + <name>bgp</name> + <except /> + </protocols> + <system-services> + <name>all</name> + </system-services> + <system-services> + <name>dhcp</name> + <except /> + </system-services> + </host-inbound-traffic> + <interfaces> + <name>ge-0/0/3.0</name> + </interfaces> + <interfaces> + <name>ge-0/0/4.0</name> + </interfaces> + <screen>test_screen</screen> + <source-identity-log /> + <tcp-rst /> + </security-zone> + </zones> + </security> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/gathered.yaml new file mode 100644 index 000000000..5c389667f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/gathered.yaml @@ -0,0 +1,23 @@ +--- +- ansible.builtin.debug: + msg: START junos_security_zones gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_security_zones: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['gathered'] }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: END junos_security_zones gathered integration tests on connection={{ ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/merged.yaml new file mode 100644 index 000000000..d9099f679 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/merged.yaml @@ -0,0 +1,143 @@ +--- +- ansible.builtin.debug: + msg: "START junos_security_zones merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_security_zones: &merged + config: + functional_zone_management: + description: test description + host_inbound_traffic: + protocols: + - name: all + - name: bgp + except: true + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/1.0 + - ge-0/0/2.0 + screen: test_screen + zones: + - address_book: + address_sets: + - addresses: + - test_adr1 + - test_adr2 + name: test_adrset1 + - addresses: + - test_adr3 + - test_adr4 + name: test_adrset2 + - address_sets: + - test_adrset1 + - test_adrset2 + addresses: + - test_adr5 + description: test description + name: test_adrset3 + addresses: + - description: test desc + ip_prefix: 10.0.0.0/24 + name: test_adr1 + - dns_name: + ipv6_only: true + name: 1.1.1.1 + name: test_adr2 + - name: test_adr3 + range_address: + from: 10.2.0.1 + to: 10.2.0.2 + - name: test_adr4 + wildcard_address: 10.3.0.1/24 + - description: test desc + ip_prefix: 10.1.0.0/24 + name: test_adr5 + advance_policy_based_routing_profile: test_profile + application_tracking: true + description: test description + enable_reverse_reroute: true + host_inbound_traffic: + protocols: + - name: all + - except: true + name: bgp + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/3.0 + - ge-0/0/4.0 + name: test_sec_zone1 + screen: test_screen + source_identity_log: true + tcp_rst: true + state: merged + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junipernetworks.junos.junos_security_zones: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Update the running configuration with providede configuration + junipernetworks.junos.junos_security_zones: + config: + functional_zone_management: + description: test description 2 + host_inbound_traffic: + protocols: + - name: all + - name: bgp + except: true + - name: bfd + except: true + system_services: + - except: true + name: dhcp + - except: true + name: dhcpv6 + - name: all + zones: + - name: test_sec_zone2 + source_identity_log: true + tcp_rst: true + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result['after'] }}" + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_security_zones merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/overridden.yaml new file mode 100644 index 000000000..375d0fd57 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/overridden.yaml @@ -0,0 +1,104 @@ +--- +- ansible.builtin.debug: + msg: >- + START junos_security_zones overridden integration tests on connection={{ + ansible_connection }} +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + - name: Override configuration + junipernetworks.junos.junos_security_zones: &ref_0 + config: + functional_zone_management: + description: test description 2 + host_inbound_traffic: + protocols: + - name: all + system_services: + - name: all + interfaces: + - ge-0/0/1.0 + - ge-0/0/2.0 + screen: test_screen + zones: + - address_book: + address_sets: + - addresses: + - test_adr1 + - test_adr2 + name: test_adrset1 + - addresses: + - test_adr3 + - test_adr4 + name: test_adrset2 + - address_sets: + - test_adrset1 + - test_adrset2 + addresses: + - test_adr5 + description: test description + name: test_adrset3 + addresses: + - description: test desc + ip_prefix: 10.0.0.0/24 + name: test_adr1 + - dns_name: + ipv6_only: true + name: 1.1.1.1 + name: test_adr2 + - name: test_adr3 + range_address: + from: 10.2.0.1 + to: 10.2.0.2 + - name: test_adr4 + wildcard_address: 10.3.0.1/24 + - description: test desc + ip_prefix: 10.1.0.0/24 + name: test_adr5 + advance_policy_based_routing_profile: test_profile + application_tracking: true + description: test description + enable_reverse_reroute: true + host_inbound_traffic: + protocols: + - name: all + - except: true + name: bgp + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/3.0 + - ge-0/0/4.0 + name: test_sec_zone1 + screen: test_screen + source_identity_log: true + tcp_rst: true + state: overridden + register: result + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + - name: >- + Replaced the provided configuration with the existing running + configuration (IDEMPOTENT) + junipernetworks.junos.junos_security_zones: *ref_0 + register: result + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml +- ansible.builtin.debug: + msg: >- + END junos_security_zones overridden integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/parsed.yaml new file mode 100644 index 000000000..63e8dc391 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/parsed.yaml @@ -0,0 +1,18 @@ +--- +- ansible.builtin.debug: + msg: >- + START junos_security_zones parsed integration tests on connection={{ + ansible_connection }} +- name: Parse externally provided security_zones config to agnostic model + register: result + junipernetworks.junos.junos_security_zones: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ merged['after'] == result['parsed'] }}" +- ansible.builtin.debug: + msg: >- + END junos_security_zones parsed integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/rendered.yaml new file mode 100644 index 000000000..c144a48f0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/rendered.yaml @@ -0,0 +1,90 @@ +--- +- ansible.builtin.debug: + msg: >- + START junos_security_zones rendered integration tests on connection={{ + ansible_connection }} +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:zones><nc:functional-zone><nc:management><nc:description>test description</nc:description><nc:host-inbound-traffic><nc:protocols><nc:name>all</nc:name></nc:protocols><nc:protocols><nc:name>bgp</nc:name><nc:except/></nc:protocols><nc:system-services><nc:name>all</nc:name></nc:system-services><nc:system-services><nc:name>dhcp</nc:name><nc:except/></nc:system-services></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0/0/1.0</nc:name></nc:interfaces><nc:interfaces><nc:name>ge-0/0/2.0</nc:name></nc:interfaces><nc:screen>test_screen</nc:screen></nc:management></nc:functional-zone><nc:security-zone><nc:name>test_sec_zone1</nc:name><nc:address-book><nc:address><nc:name>test_adr1</nc:name><nc:ip-prefix>10.0.0.0/24</nc:ip-prefix><nc:description>test desc</nc:description></nc:address><nc:address><nc:name>test_adr2</nc:name><nc:dns-name><nc:name>1.1.1.1</nc:name><nc:ipv6-only/></nc:dns-name></nc:address><nc:address><nc:name>test_adr3</nc:name><nc:range-address><nc:name>10.2.0.1</nc:name><nc:to><nc:range-high>10.2.0.2</nc:range-high></nc:to></nc:range-address></nc:address><nc:address><nc:name>test_adr4</nc:name><nc:wildcard-address><nc:name>10.3.0.1/24</nc:name></nc:wildcard-address></nc:address><nc:address><nc:name>test_adr5</nc:name><nc:ip-prefix>10.1.0.0/24</nc:ip-prefix><nc:description>test desc</nc:description></nc:address><nc:address-set><nc:name>test_adrset1</nc:name><nc:address><nc:name>test_adr1</nc:name></nc:address><nc:address><nc:name>test_adr2</nc:name></nc:address></nc:address-set><nc:address-set><nc:name>test_adrset2</nc:name><nc:address><nc:name>test_adr3</nc:name></nc:address><nc:address><nc:name>test_adr4</nc:name></nc:address></nc:address-set><nc:address-set><nc:name>test_adrset3</nc:name><nc:address><nc:name>test_adr5</nc:name></nc:address><nc:address-set><nc:name>test_adrset1</nc:name></nc:address-set><nc:address-set><nc:name>test_adrset2</nc:name></nc:address-set><nc:description>test description</nc:description></nc:address-set></nc:address-book><nc:advance-policy-based-routing-profile><nc:profile>test_profile</nc:profile></nc:advance-policy-based-routing-profile><nc:application-tracking/><nc:description>test description</nc:description><nc:enable-reverse-reroute/><nc:host-inbound-traffic><nc:protocols><nc:name>all</nc:name></nc:protocols><nc:protocols><nc:name>bgp</nc:name><nc:except/></nc:protocols><nc:system-services><nc:name>all</nc:name></nc:system-services><nc:system-services><nc:name>dhcp</nc:name><nc:except/></nc:system-services></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0/0/3.0</nc:name></nc:interfaces><nc:interfaces><nc:name>ge-0/0/4.0</nc:name></nc:interfaces><nc:screen>test_screen</nc:screen><nc:source-identity-log/><nc:tcp-rst/></nc:security-zone></nc:zones></nc:security>' +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_security_zones: + config: + functional_zone_management: + description: test description + host_inbound_traffic: + protocols: + - name: all + - name: bgp + except: true + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/1.0 + - ge-0/0/2.0 + screen: test_screen + zones: + - address_book: + address_sets: + - addresses: + - test_adr1 + - test_adr2 + name: test_adrset1 + - addresses: + - test_adr3 + - test_adr4 + name: test_adrset2 + - address_sets: + - test_adrset1 + - test_adrset2 + addresses: + - test_adr5 + description: test description + name: test_adrset3 + addresses: + - description: test desc + ip_prefix: 10.0.0.0/24 + name: test_adr1 + - dns_name: + ipv6_only: true + name: 1.1.1.1 + name: test_adr2 + - name: test_adr3 + range_address: + from: 10.2.0.1 + to: 10.2.0.2 + - name: test_adr4 + wildcard_address: 10.3.0.1/24 + - description: test desc + ip_prefix: 10.1.0.0/24 + name: test_adr5 + advance_policy_based_routing_profile: test_profile + application_tracking: true + description: test description + enable_reverse_reroute: true + host_inbound_traffic: + protocols: + - name: all + - except: true + name: bgp + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/3.0 + - ge-0/0/4.0 + name: test_sec_zone1 + screen: test_screen + source_identity_log: true + tcp_rst: true + state: rendered +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" +- ansible.builtin.debug: + msg: >- + END junos_security_zones rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/replaced.yaml new file mode 100644 index 000000000..168463579 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/replaced.yaml @@ -0,0 +1,104 @@ +--- +- ansible.builtin.debug: + msg: >- + START junos_security_zones replaced integration tests on connection={{ + ansible_connection }} +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + - name: Override configuration + junipernetworks.junos.junos_security_zones: &ref_0 + config: + functional_zone_management: + description: test description 2 + host_inbound_traffic: + protocols: + - name: all + system_services: + - name: all + interfaces: + - ge-0/0/1.0 + - ge-0/0/2.0 + screen: test_screen + zones: + - address_book: + address_sets: + - addresses: + - test_adr1 + - test_adr2 + name: test_adrset1 + - addresses: + - test_adr3 + - test_adr4 + name: test_adrset2 + - address_sets: + - test_adrset1 + - test_adrset2 + addresses: + - test_adr5 + description: test description + name: test_adrset3 + addresses: + - description: test desc + ip_prefix: 10.0.0.0/24 + name: test_adr1 + - dns_name: + ipv6_only: true + name: 1.1.1.1 + name: test_adr2 + - name: test_adr3 + range_address: + from: 10.2.0.1 + to: 10.2.0.2 + - name: test_adr4 + wildcard_address: 10.3.0.1/24 + - description: test desc + ip_prefix: 10.1.0.0/24 + name: test_adr5 + advance_policy_based_routing_profile: test_profile + application_tracking: true + description: test description + enable_reverse_reroute: true + host_inbound_traffic: + protocols: + - name: all + - except: true + name: bgp + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/3.0 + - ge-0/0/4.0 + name: test_sec_zone1 + screen: test_screen + source_identity_log: true + tcp_rst: true + state: replaced + register: result + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result.after }}" + - name: >- + Replaced the provided configuration with the existing running + configuration (IDEMPOTENT) + junipernetworks.junos.junos_security_zones: *ref_0 + register: result + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml +- ansible.builtin.debug: + msg: >- + END junos_security_zones replaced integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/rtt.yml new file mode 100644 index 000000000..30ba201b9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/tests/netconf/rtt.yml @@ -0,0 +1,184 @@ +--- +- ansible.builtin.debug: + msg: >- + START junos_security_zones round trip integration tests on connection={{ + ansible_connection }} +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_security_zones: + config: + functional_zone_management: + description: test description + host_inbound_traffic: + protocols: + - name: all + - name: bgp + except: true + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/1.0 + - ge-0/0/2.0 + screen: test_screen + zones: + - address_book: + address_sets: + - addresses: + - test_adr1 + - test_adr2 + name: test_adrset1 + - addresses: + - test_adr3 + - test_adr4 + name: test_adrset2 + - address_sets: + - test_adrset1 + - test_adrset2 + addresses: + - test_adr5 + description: test description + name: test_adrset3 + addresses: + - description: test desc + ip_prefix: 10.0.0.0/24 + name: test_adr1 + - dns_name: + ipv6_only: true + name: 1.1.1.1 + name: test_adr2 + - name: test_adr3 + range_address: + from: 10.2.0.1 + to: 10.2.0.2 + - name: test_adr4 + wildcard_address: 10.3.0.1/24 + - description: test desc + ip_prefix: 10.1.0.0/24 + name: test_adr5 + advance_policy_based_routing_profile: test_profile + application_tracking: true + description: test description + enable_reverse_reroute: true + host_inbound_traffic: + protocols: + - name: all + - except: true + name: bgp + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/3.0 + - ge-0/0/4.0 + name: test_sec_zone1 + screen: test_screen + source_identity_log: true + tcp_rst: true + state: merged + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - security_zones + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_security_zones: + config: + functional_zone_management: + description: test description 2 + host_inbound_traffic: + protocols: + - name: all + system_services: + - name: all + interfaces: + - ge-0/0/1.0 + - ge-0/0/2.0 + screen: test_screen + zones: + - address_book: + address_sets: + - addresses: + - test_adr1 + - test_adr2 + name: test_adrset1 + - addresses: + - test_adr3 + - test_adr4 + name: test_adrset2 + - address_sets: + - test_adrset1 + - test_adrset2 + addresses: + - test_adr5 + description: test description + name: test_adrset3 + addresses: + - description: test desc + ip_prefix: 10.0.0.0/24 + name: test_adr1 + - dns_name: + ipv6_only: true + name: 1.1.1.1 + name: test_adr2 + - name: test_adr3 + range_address: + from: 10.2.0.1 + to: 10.2.0.2 + - name: test_adr4 + wildcard_address: 10.3.0.1/24 + - description: test desc + ip_prefix: 10.1.0.0/24 + name: test_adr5 + advance_policy_based_routing_profile: test_profile + application_tracking: true + description: test description + enable_reverse_reroute: true + host_inbound_traffic: + protocols: + - name: all + - except: true + name: bgp + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/3.0 + - ge-0/0/4.0 + name: test_sec_zone1 + screen: test_screen + source_identity_log: true + tcp_rst: true + state: replaced + - name: Assert that changes were applied + ansible.builtin.assert: + that: "result['changed'] == true" + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_security_zones: + config: "{{ ansible_facts['network_resources']['security_zones'] }}" + state: replaced + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] == revert['before'] }}" + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] == revert['after'] }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml +- ansible.builtin.debug: + msg: >- + END junos_security_zones round trip integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/vars/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/vars/main.yaml new file mode 100644 index 000000000..418236a9f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_security_zones/vars/main.yaml @@ -0,0 +1,220 @@ +--- +merged: + before: {} + after: + functional_zone_management: + description: test description + host_inbound_traffic: + protocols: + - name: all + - name: bgp + except: true + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/1.0 + - ge-0/0/2.0 + screen: test_screen + zones: + - address_book: + address_sets: + - addresses: + - test_adr1 + - test_adr2 + name: test_adrset1 + - addresses: + - test_adr3 + - test_adr4 + name: test_adrset2 + - address_sets: + - test_adrset1 + - test_adrset2 + addresses: + - test_adr5 + description: test description + name: test_adrset3 + addresses: + - description: test desc + ip_prefix: 10.0.0.0/24 + name: test_adr1 + - dns_name: + ipv6_only: true + name: 1.1.1.1 + name: test_adr2 + - name: test_adr3 + range_address: + from: 10.2.0.1 + to: 10.2.0.2 + - name: test_adr4 + wildcard_address: 10.3.0.1/24 + - description: test desc + ip_prefix: 10.1.0.0/24 + name: test_adr5 + advance_policy_based_routing_profile: test_profile + application_tracking: true + description: test description + enable_reverse_reroute: true + host_inbound_traffic: + protocols: + - name: all + - except: true + name: bgp + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/3.0 + - ge-0/0/4.0 + name: test_sec_zone1 + screen: test_screen + source_identity_log: true + tcp_rst: true + updated: + functional_zone_management: + description: test description 2 + host_inbound_traffic: + protocols: + - name: all + - name: bgp + except: true + - name: bfd + except: true + system_services: + - name: all + - except: true + name: dhcp + - except: true + name: dhcpv6 + interfaces: + - ge-0/0/1.0 + - ge-0/0/2.0 + screen: test_screen + zones: + - address_book: + address_sets: + - addresses: + - test_adr1 + - test_adr2 + name: test_adrset1 + - addresses: + - test_adr3 + - test_adr4 + name: test_adrset2 + - address_sets: + - test_adrset1 + - test_adrset2 + addresses: + - test_adr5 + description: test description + name: test_adrset3 + addresses: + - description: test desc + ip_prefix: 10.0.0.0/24 + name: test_adr1 + - dns_name: + ipv6_only: true + name: 1.1.1.1 + name: test_adr2 + - name: test_adr3 + range_address: + from: 10.2.0.1 + to: 10.2.0.2 + - name: test_adr4 + wildcard_address: 10.3.0.1/24 + - description: test desc + ip_prefix: 10.1.0.0/24 + name: test_adr5 + advance_policy_based_routing_profile: test_profile + application_tracking: true + description: test description + enable_reverse_reroute: true + host_inbound_traffic: + protocols: + - name: all + - except: true + name: bgp + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/3.0 + - ge-0/0/4.0 + name: test_sec_zone1 + screen: test_screen + source_identity_log: true + tcp_rst: true + - name: test_sec_zone2 + source_identity_log: true + tcp_rst: true +replaced: + after: + functional_zone_management: + description: test description 2 + host_inbound_traffic: + protocols: + - name: all + system_services: + - name: all + interfaces: + - ge-0/0/1.0 + - ge-0/0/2.0 + screen: test_screen + zones: + - address_book: + address_sets: + - addresses: + - test_adr1 + - test_adr2 + name: test_adrset1 + - addresses: + - test_adr3 + - test_adr4 + name: test_adrset2 + - address_sets: + - test_adrset1 + - test_adrset2 + addresses: + - test_adr5 + description: test description + name: test_adrset3 + addresses: + - description: test desc + ip_prefix: 10.0.0.0/24 + name: test_adr1 + - dns_name: + ipv6_only: true + name: 1.1.1.1 + name: test_adr2 + - name: test_adr3 + range_address: + from: 10.2.0.1 + to: 10.2.0.2 + - name: test_adr4 + wildcard_address: 10.3.0.1/24 + - description: test desc + ip_prefix: 10.1.0.0/24 + name: test_adr5 + advance_policy_based_routing_profile: test_profile + application_tracking: true + description: test description + enable_reverse_reroute: true + host_inbound_traffic: + protocols: + - name: all + - except: true + name: bgp + system_services: + - name: all + - except: true + name: dhcp + interfaces: + - ge-0/0/3.0 + - ge-0/0/4.0 + name: test_sec_zone1 + screen: test_screen + source_identity_log: true + tcp_rst: true diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/defaults/main.yaml new file mode 100644 index 000000000..9ef5ba516 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tasks/cli.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tasks/cli.yaml new file mode 100644 index 000000000..0092e0d5d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tasks/cli.yaml @@ -0,0 +1,29 @@ +--- +- name: Collect cli test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.network_cli) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.network_cli + +- name: Run test cases with single_user_mode (connection=ansible.netcommon.network_cli) + ansible.builtin.include_tasks: "{{ role_path }}/tests/cli/caching.yaml" + vars: + ansible_connection: ansible.netcommon.network_cli + ansible_network_single_user_mode: "True" + connection: "{{ cli }}" + + tags: + - network_cli diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tasks/main.yaml new file mode 100644 index 000000000..08ec42d9a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tasks/main.yaml @@ -0,0 +1,8 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: cli.yaml + tags: ["network_cli"] + +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: ["netconf"] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tasks/netconf.yaml new file mode 100644 index 000000000..ab7d6689b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tasks/netconf.yaml @@ -0,0 +1,19 @@ +--- +- name: Collect netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/cli/caching.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/cli/caching.yaml new file mode 100644 index 000000000..86d005032 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/cli/caching.yaml @@ -0,0 +1,52 @@ +--- +- block: + - ansible.builtin.debug: msg="START connection={{ ansible_connection }} cli/caching.yaml" + + - name: Remove description from interface + ignore_errors: true + junipernetworks.junos.junos_command: &rem + commands: + - configure + - delete interfaces ge-0/0/1 description + - commit + - exit + + - name: Fetch configuration + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show configuration interfaces ge-0/0/1 + register: result + + - ansible.builtin.assert: + that: + - '"description test-1;" not in result.stdout_lines' + + - name: Fetch configuration again (from cache) + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show configuration interfaces ge-0/0/1 + + - name: Configure description on interface + ignore_errors: true + junipernetworks.junos.junos_command: + commands: + - configure + - set interfaces ge-0/0/1 description test-1 + - commit + - exit + + - name: Fetch configuration from appliance + ignore_errors: true + junipernetworks.junos.junos_command: + commands: show configuration interfaces ge-0/0/1 + register: result + + - ansible.builtin.assert: + that: + - '"description test-1;" in result.stdout_lines[0]' + + always: + - name: Remove description from interface + ignore_errors: true + junipernetworks.junos.junos_command: *rem + when: ansible_connection == "ansible.netcommon.network_cli" and ansible_network_single_user_mode|d(False) diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/cli/reboot.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/cli/reboot.yaml new file mode 100644 index 000000000..4ed3094ee --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/cli/reboot.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: START cli/cli_reboot.yaml on connection={{ ansible_connection }} +- block: + - ansible.netcommon.cli_command: + command: request system reboot + prompt: + - Reboot the system? + answer: + - y + + - wait_for_connection: + delay: 30 + sleep: 20 + + - ansible.netcommon.cli_command: + command: show version + when: ansible_connection == 'ansible.netcommon.network_cli' + +- ansible.builtin.debug: msg="END cli/reboot.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/netconf/common_utils.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/netconf/common_utils.yaml new file mode 100644 index 000000000..015c05ad8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/netconf/common_utils.yaml @@ -0,0 +1,24 @@ +--- +# junos interface -> remove_default_spec() conditional() +- ansible.builtin.debug: msg="START junos_interface netconf/common_utils.yaml on connection={{ ansible_connection }}" + +- name: get facts + junos_facts: + register: result + +- name: Define interface name for vSRX + ansible.builtin.set_fact: + intf_name: pp0 + when: result['ansible_facts']['ansible_net_model'] is search("vSRX*") + +- name: Define interface name for vsrx + ansible.builtin.set_fact: + intf_name: pp0 + when: result['ansible_facts']['ansible_net_model'] is search("vsrx") + +- name: Define interface name for vQFX + ansible.builtin.set_fact: + intf_name: gr-0/0/0 + when: result['ansible_facts']['ansible_net_model'] is search("vqfx*") + +- ansible.builtin.debug: msg="END junos_interface netconf/common_utils.yaml on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/netconf/module_utils_junos.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/netconf/module_utils_junos.yaml new file mode 100644 index 000000000..b5549a214 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_smoke/tests/netconf/module_utils_junos.yaml @@ -0,0 +1,53 @@ +--- +- ansible.builtin.debug: msg="START netconf/module_utils_junos.yaml on connection={{ ansible_connection }}" + +# hit get_capabilities() + +- name: get output for single command + junos_command: + commands: ["show version"] + format: json + register: result + +- ansible.builtin.assert: + that: + - "result.changed == false" + - "result.stdout is defined" + - "result.stdout_lines is defined" + +# hit commit_configuration() +- name: setup - remove login banner + junos_banner: + banner: login + state: absent + +- name: Create login banner + junos_banner: + banner: login + text: this is my login banner + state: present + register: result + +- name: Get running configuration + junos_rpc: + rpc: get-configuration + register: config + +- ansible.builtin.assert: + that: + - "result.changed == true" + - "'<message>this is my login banner</message>' in config.xml" + +# hit discard_changes() +- name: check mode + junos_banner: + banner: login + text: this is not the banner you're looking for + state: present + register: result + check_mode: true + +- ansible.builtin.assert: + that: + - "result.changed == true" + - "result.failed == false" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..5cfd90cfe --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/_initial_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_snmp_server initial config on connection={{ ansible_connection }}" + +- name: Configure basic config relevant to ntp global + junipernetworks.junos.junos_config: + lines: + - set routing-instances clv1 description "clv1" + - set routing-instances clv2 description "clv2" + +- ansible.builtin.debug: + msg: "END junos_snmp_server initial config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/_populate_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/_populate_config.yaml new file mode 100644 index 000000000..9c0038236 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/_populate_config.yaml @@ -0,0 +1,23 @@ +--- +- name: Populate config + junipernetworks.junos.junos_config: + lines: + - "set snmp arp" + - "set snmp arp host-name-resolution" + - "set snmp client-list cl1" + - "set snmp client-list cl2" + - "set snmp client-list cl1 192.16.1.0/24" + - "set snmp client-list cl1 192.16.2.0/24" + - "set snmp client-list cl1 11.11.11.11 restrict" + - "set snmp client-list cl2 192.16.4.0/24" + - "set snmp community comm1" + - "set snmp community comm2" + - "set snmp community comm1 authorization read-write" + - "set snmp community comm1 client-list-name cl1" + - "set snmp community comm1 clients 24.0.0.0/32 restrict" + - "set snmp community comm1 clients 30.0.0.0/32 restrict" + - 'set routing-instances clv1 description "clv1"' + - 'set routing-instances clv2 description "clv2"' + - "set snmp routing-instance-access" + - "set snmp routing-instance-access access-list clv1" + - "set snmp routing-instance-access access-list clv2" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/_reset_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/_reset_config.yaml new file mode 100644 index 000000000..4bf7a9664 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/_reset_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_snmp_server reset config on connection={{ ansible_connection }}" + +- name: Reset the config releavent to ntp global resource + junipernetworks.junos.junos_config: + lines: + - delete snmp + - delete routing-instances + +- ansible.builtin.debug: + msg: "END junos_snmp_server reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/backups/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/backups/empty_config.yaml new file mode 100644 index 000000000..c2d74d60a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/backups/empty_config.yaml @@ -0,0 +1,49 @@ +--- +- ansible.builtin.debug: + msg: START junos_bgp_global empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_global: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_bgp_global: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_bgp_global: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_bgp_global: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/deleted.yaml new file mode 100644 index 000000000..a3651cc0d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/deleted.yaml @@ -0,0 +1,26 @@ +--- +- ansible.builtin.debug: + msg: "START junos_snmp_server deleted integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + - ansible.builtin.set_fact: + config: {} + - name: Delete all snmp_server config from the device + junipernetworks.junos.junos_snmp_server: + state: deleted + register: result + + - name: Assert changed + ansible.builtin.assert: + that: + - result.changed == True + - "{{ config == result.after }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_snmp_server deleted integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..472ad0e3a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- ansible.builtin.debug: + msg: START junos_snmp_server empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_snmp_server: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_snmp_server: + config: + state: replaced + +- ansible.builtin.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 + junipernetworks.junos.junos_snmp_server: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_snmp_server: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_snmp_server: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..9c1a5a962 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <snmp> + <client-list> + <name>cl1</name> + <client-address-list> + <name>192.16.1.0/24</name> + </client-address-list> + <client-address-list> + <name>192.16.2.0/24</name> + </client-address-list> + <client-address-list> + <name>11.11.11.11/32</name> + <restrict/> + </client-address-list> + </client-list> + <client-list> + <name>cl2</name> + <client-address-list> + <name>192.16.4.0/24</name> + </client-address-list> + </client-list> + <routing-instance-access> + <access-list> + <name>clv1</name> + </access-list> + <access-list> + <name>clv2</name> + </access-list> + </routing-instance-access> + <arp> + <host-name-resolution/> + </arp> + </snmp> + <interfaces xmlns="http://yang.juniper.net/junos-es/conf/interfaces"> + <interface> + <name>fxp0</name> + <unit> + <name>0</name> + <family> + <inet> + <dhcp> + </dhcp> + </inet> + </family> + </unit> + </interface> + </interfaces> + <routing-instances xmlns="http://yang.juniper.net/junos-es/conf/routing-instances"> + <instance> + <name>rt1</name> + <description>rt1</description> + </instance> + <instance> + <name>rt2</name> + <description>rt2</description> + </instance> + </routing-instances> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/gathered.yaml new file mode 100644 index 000000000..819e63cc9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/gathered.yaml @@ -0,0 +1,25 @@ +--- +- ansible.builtin.debug: + msg: START junos_snmp_server gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Gather interfaces facts using gathered state + register: result + junipernetworks.junos.junos_snmp_server: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: "{{ gathered['facts'] == result['gathered'] }}" + + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_snmp_server gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/merged.yaml new file mode 100644 index 000000000..f689a69e5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/merged.yaml @@ -0,0 +1,88 @@ +--- +- ansible.builtin.debug: + msg: "START junos_snmp_server merged integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Merge the provided configuration with the exisiting running configuration + junipernetworks.junos.junos_snmp_server: &merged + config: + arp: + set: true + host_name_resolution: true + client_lists: + - name: cl1 + addresses: + - address: "192.16.1.0/24" + - address: "192.16.2.0/24" + - address: "11.11.11.11" + restrict: true + - name: cl2 + addresses: + - address: "192.16.4.0/24" + routing_instance_access: + set: true + access_lists: + - "clv1" + - "clv2" + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + junos_snmp_server: *merged + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + - name: Update the running configuration with providede configuration + junipernetworks.junos.junos_snmp_server: + config: + communities: + - name: "comm1" + clients: + - address: "24.0.0.0/32" + restrict: true + - address: "30.0.0.0/32" + restrict: true + routing_instances: + - name: "clv1" + clients: + - address: "13.13.13.13/24" + restrict: true + - address: "24.0.0.0/32" + - address: "30.0.0.0/32" + - name: "clv2" + clients: + - address: "15.15.15.15/24" + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ merged['after'] == result['before'] }}" + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - result.changed == True + - "{{ merged['updated'] == result['after'] }}" + + tags: merged + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_snmp_server merged integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/overridden.yaml new file mode 100644 index 000000000..4f40e59e2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/overridden.yaml @@ -0,0 +1,53 @@ +--- +- ansible.builtin.debug: + msg: "START junos_snmp_server overridden integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_snmp_server: &overridden + config: + contact: "ansiblesupport11@redhat.com" + customization: + ether_stats_ifd_only: true + description: "Local SNMP Server" + engine_id: + use_mac_address: true + filter_duplicates: true + filter_interfaces: + all_internal_interfaces: true + interfaces: + - "eth1" + - "eth2" + set: true + state: overridden + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ gathered['facts'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result['after'] }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_snmp_server: *overridden + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: overridden + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_snmp_server overridden integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/parsed.yaml new file mode 100644 index 000000000..209a7acf7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/parsed.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: + START junos_snmp_server parsed integration tests on connection={{ ansible_connection + }} + +- name: Parse externally provided snmp_server config to agnostic model + register: result + junipernetworks.junos.junos_snmp_server: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ merged['after'] == result['parsed'] }}" +- ansible.builtin.debug: + msg: + END junos_snmp_server parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/rendered.yaml new file mode 100644 index 000000000..abd27545a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/rendered.yaml @@ -0,0 +1,30 @@ +--- +- ansible.builtin.debug: + msg: START junos_snmp_server rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:arp><nc:host-name-resolution/></nc:arp><nc:routing-instance-access><nc:access-list><nc:name>clv1</nc:name></nc:access-list><nc:access-list><nc:name>clv2</nc:name></nc:access-list></nc:routing-instance-access></nc:snmp>' + +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_snmp_server: + config: + arp: + set: true + host_name_resolution: true + routing_instance_access: + set: true + access_lists: + - "clv1" + - "clv2" + state: rendered + +- name: Assert that correct set of commands were rendered + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + +- ansible.builtin.debug: + msg: END junos_snmp_server rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/replaced.yaml new file mode 100644 index 000000000..d8b66546b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/replaced.yaml @@ -0,0 +1,53 @@ +--- +- ansible.builtin.debug: + msg: "START junos_snmp_server replaced integration tests on connection={{ ansible_connection }}" + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + - ansible.builtin.include_tasks: _populate_config.yaml + + - name: Override configuration + junipernetworks.junos.junos_snmp_server: &replaced + config: + contact: "ansiblesupport11@redhat.com" + customization: + ether_stats_ifd_only: true + description: "Local SNMP Server" + engine_id: + use_mac_address: true + filter_duplicates: true + filter_interfaces: + all_internal_interfaces: true + interfaces: + - "eth1" + - "eth2" + set: true + state: replaced + register: result + + - name: Assert that before dicts were correctly generated + ansible.builtin.assert: + that: "{{ gathered['facts'] == result['before'] }}" + + - name: Assert configuration + ansible.builtin.assert: + that: + - result.changed == True + - "{{ replaced['after'] == result['after'] }}" + + - name: Replaced the provided configuration with the existing running configuration (IDEMPOTENT) + junos_snmp_server: *replaced + register: result + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == False + + tags: replaced + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: "END junos_snmp_server replaced integration tests on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/rtt.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/rtt.yaml new file mode 100644 index 000000000..581b874fb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/tests/netconf/rtt.yaml @@ -0,0 +1,86 @@ +--- +- ansible.builtin.debug: + msg: START junos_snmp_server round trip integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _reset_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_snmp_server: + config: + arp: + set: true + host_name_resolution: true + client_lists: + - name: cl1 + addresses: + - address: "192.16.1.0/24" + - address: "192.16.2.0/24" + - address: "11.11.11.11" + restrict: true + - name: cl2 + addresses: + - address: "192.16.4.0/24" + routing_instance_access: + set: true + access_lists: + - "clv1" + - "clv2" + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - snmp_server + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_snmp_server: + config: + contact: "ansiblesupport11@redhat.com" + customization: + ether_stats_ifd_only: true + description: "Local SNMP Server" + engine_id: + use_mac_address: true + filter_duplicates: true + filter_interfaces: + set: true + all_internal_interfaces: true + interfaces: + - "eth1" + - "eth2" + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_snmp_server: + config: "{{ ansible_facts['network_resources']['snmp_server'] }}" + state: replaced + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] == revert['before'] }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] == revert['after'] }}" + always: + - ansible.builtin.include_tasks: _reset_config.yaml + +- ansible.builtin.debug: + msg: + END junos_snmp_server round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/vars/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/vars/main.yaml new file mode 100644 index 000000000..fdb1d777c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_snmp_server/vars/main.yaml @@ -0,0 +1,97 @@ +--- +merged: + before: {} + after: + arp: + host_name_resolution: true + client_lists: + - addresses: + - address: "192.16.1.0/24" + - address: "192.16.2.0/24" + - address: "11.11.11.11/32" + restrict: true + name: "cl1" + - addresses: + - address: "192.16.4.0/24" + name: "cl2" + routing_instance_access: + access_lists: + - "clv1" + - "clv2" + + updated: + arp: + host_name_resolution: true + client_lists: + - addresses: + - address: "192.16.1.0/24" + - address: "192.16.2.0/24" + - address: "11.11.11.11/32" + restrict: true + name: "cl1" + - addresses: + - address: "192.16.4.0/24" + name: "cl2" + communities: + - clients: + - address: "24.0.0.0/32" + restrict: true + - address: "30.0.0.0/32" + restrict: true + name: "comm1" + routing_instances: + - clients: + - address: "13.13.13.13/24" + restrict: true + - address: "24.0.0.0/32" + - address: "30.0.0.0/32" + name: "clv1" + - clients: + - address: "15.15.15.15/24" + name: "clv2" + routing_instance_access: + access_lists: + - "clv1" + - "clv2" +gathered: + facts: + arp: + host_name_resolution: true + client_lists: + - addresses: + - address: "192.16.1.0/24" + - address: "192.16.2.0/24" + - address: "11.11.11.11/32" + restrict: true + name: "cl1" + - addresses: + - address: "192.16.4.0/24" + name: "cl2" + communities: + - authorization: "read-write" + clients: + - address: "24.0.0.0/32" + restrict: true + - address: "30.0.0.0/32" + restrict: true + name: "comm1" + - name: "comm2" + routing_instance_access: + access_lists: + - "clv1" + - "clv2" + +replaced: + after: + contact: "ansiblesupport11@redhat.com" + customization: + ether_stats_ifd_only: true + description: "Local SNMP Server" + engine_id: + use_mac_address: true + filter_duplicates: true + filter_interfaces: + all_internal_interfaces: true + interfaces: + - "eth1" + - "eth2" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/meta/main.yaml new file mode 100644 index 000000000..7f867d73b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/_base_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/_base_config.yaml new file mode 100644 index 000000000..c1acaf7ae --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/_base_config.yaml @@ -0,0 +1,25 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_static_routes base config ansible_connection={{ ansible_connection + }} + +- name: Configure base static_routes + junipernetworks.junos.junos_static_routes: + config: + - address_families: + - afi: ipv4 + routes: + - dest: 192.168.0.0/24 + next_hop: + - forward_router_address: 192.168.0.1 + - afi: ipv6 + routes: + - dest: 2001:db8::5/128 + next_hop: + - forward_router_address: 2001:db8:0:1:2a0:a502:0:19da + +- ansible.builtin.debug: + msg: + End junos_static_routes base config ansible_connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/_remove_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/_remove_config.yaml new file mode 100644 index 000000000..f8e907599 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/_remove_config.yaml @@ -0,0 +1,18 @@ +--- +- ansible.builtin.debug: + msg: + Start junos_static_routes teardown ansible_connection={{ ansible_connection + }} + +- name: Remove static route config + junipernetworks.junos.junos_static_routes: + config: + - address_families: + - afi: ipv4 + - afi: ipv6 + state: deleted + +- ansible.builtin.debug: + msg: + End junos_static_routes teardown ansible_connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/deleted.yaml new file mode 100644 index 000000000..3c701d9ca --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/deleted.yaml @@ -0,0 +1,43 @@ +--- +- ansible.builtin.debug: + msg: + START junos_static_routes deleted integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- block: + - name: Delete the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_static_routes: &id001 + config: + - address_families: + - afi: ipv4 + - afi: ipv6 + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - not result.after + debugger: on_failed + + - name: + Delete the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_static_routes: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_static_routes deleted integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/merged.yaml new file mode 100644 index 000000000..aeaa6d058 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/merged.yaml @@ -0,0 +1,78 @@ +--- +- ansible.builtin.debug: + msg: + START junos_static_routes merged integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - address_families: + - afi: ipv6 + routes: + - dest: 2001:db8::5/128 + next_hop: + - forward_router_address: 2001:db8:0:1:2a0:a502:0:19da + - dest: ::/0 + next_hop: + - forward_router_address: 2001:db8:0:1:2a0:a502:0:19da + - afi: ipv4 + routes: + - dest: 192.168.0.0/24 + next_hop: + - forward_router_address: 192.168.0.1 + - dest: 192.168.1.0/24 + metric: 2 + next_hop: + - forward_router_address: 192.168.1.1 + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_static_routes: &id001 + config: + - address_families: + - afi: ipv4 + routes: + - dest: 192.168.0.0/24 + next_hop: + - forward_router_address: 192.168.0.1 + - dest: 192.168.1.0/24 + next_hop: + - forward_router_address: 192.168.1.1 + metric: 2 + - afi: ipv6 + routes: + - dest: 2001:db8::5/128 + next_hop: + - forward_router_address: 2001:db8:0:1:2a0:a502:0:19da + - dest: ::/0 + next_hop: + - forward_router_address: 2001:db8:0:1:2a0:a502:0:19da + state: merged + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + debugger: on_failed + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_static_routes: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_static_routes merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/overridden.yaml new file mode 100644 index 000000000..a24b890a1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/overridden.yaml @@ -0,0 +1,57 @@ +--- +- ansible.builtin.debug: + msg: START junos_static_routes overridden integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_overridden_output: + - address_families: + - afi: ipv4 + routes: + - dest: 192.168.20.0/24 + next_hop: + - forward_router_address: 192.168.20.1 + metric: 10 + +- block: + - name: Override the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_static_routes: &id001 + config: + - address_families: + - afi: ipv4 + routes: + - dest: 192.168.20.0/24 + next_hop: + - forward_router_address: 192.168.20.1 + metric: 10 + state: overridden + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_overridden_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + debugger: on_failed + + - name: + Override the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_static_routes: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_static_routes overridden integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/replaced.yaml new file mode 100644 index 000000000..b0aa7b8c7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_static_routes/tests/netconf/replaced.yaml @@ -0,0 +1,60 @@ +--- +- ansible.builtin.debug: + msg: START junos_static_routes overridden integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_overridden_output: + - address_families: + - afi: ipv6 + routes: + - dest: 2001:db8::5/128 + next_hop: + - forward_router_address: 2001:db8:0:1:2a0:a502:0:19da + - afi: ipv4 + routes: + - dest: 192.168.0.0/24 + next_hop: + - forward_router_address: 192.168.20.1 + +- block: + - name: Replace the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_static_routes: &id001 + config: + - address_families: + - afi: ipv4 + routes: + - dest: 192.168.0.0/24 + next_hop: + - forward_router_address: 192.168.20.1 + state: replaced + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_overridden_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + debugger: on_failed + + - name: + Override the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_static_routes: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_static_routes overridden integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/aliases b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/aliases new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/aliases diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/defaults/main.yaml new file mode 100644 index 000000000..9ef5ba516 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/tasks/main.yaml new file mode 100644 index 000000000..ac951c8f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/tasks/netconf.yaml new file mode 100644 index 000000000..6071adcfe --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/tasks/netconf.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + register: test_cases + connection: local + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/tests/netconf/basic.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/tests/netconf/basic.yaml new file mode 100644 index 000000000..ef24717f0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_system/tests/netconf/basic.yaml @@ -0,0 +1,370 @@ +--- +- ansible.builtin.debug: + msg="START junos_system netconf/basic.yaml on connection={{ ansible_connection + }}" + +- name: setup - remove hostname + junipernetworks.junos.junos_system: + hostname: vsrx01 + state: absent + +- name: Set hostname + register: result + junipernetworks.junos.junos_system: + hostname: vsrx01 + state: present + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<host-name>vsrx01</host-name>' in config.xml" + +- name: Set hostname (idempotent) + register: result + junipernetworks.junos.junos_system: + hostname: vsrx01 + state: present + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Deactivate hostname configuration + register: result + junipernetworks.junos.junos_system: + hostname: vsrx01 + state: present + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - '''<host-name inactive="inactive">'' in config.xml' + +- name: Activate hostname configuration + register: result + junipernetworks.junos.junos_system: + hostname: vsrx01 + state: present + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<host-name>vsrx01</host-name>' in config.xml" + +- name: Delete hostname configuration + register: result + junipernetworks.junos.junos_system: + hostname: vsrx01 + state: absent + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<host-name>vsrx01</host-name>' in config.xml" + +- name: Teardown - set hostname + junipernetworks.junos.junos_system: + hostname: vsrx01 + state: present + +- name: setup - remove domain name + junipernetworks.junos.junos_system: + domain_name: ansible.com + state: absent + +- name: Set domain name + register: result + junipernetworks.junos.junos_system: + domain_name: ansible.com + state: present + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<domain-name>ansible.com</domain-name>' in config.xml" + +- name: Set domain name (idempotent) + register: result + junipernetworks.junos.junos_system: + domain_name: ansible.com + state: present + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Deactivate domain name + register: result + junipernetworks.junos.junos_system: + domain_name: ansible.com + state: present + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - '''<domain-name inactive="inactive">'' in config.xml' + +- name: Activate domain name + register: result + junipernetworks.junos.junos_system: + domain_name: ansible.com + state: present + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<domain-name>ansible.com</domain-name>' in config.xml" + +- name: Delete domain name + register: result + junipernetworks.junos.junos_system: + domain_name: ansible.com + state: absent + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<domain-name>ansible.com</domain-name>' not in config.xml" + +- name: Teardown - set domain name + junipernetworks.junos.junos_system: + domain_name: ansible.com + state: present + +- name: Setup - delete domain search + register: result + junipernetworks.junos.junos_system: + domain_search: + - test.com + - sample.com + state: absent + +- name: Set domain search + register: result + junipernetworks.junos.junos_system: + domain_search: + - test.com + - sample.com + state: present + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<domain-search>test.com</domain-search>' in config.xml" + - "'<domain-search>sample.com</domain-search>' in config.xml" + +- name: Set domain search (idempotency) + register: result + junipernetworks.junos.junos_system: + domain_search: + - test.com + - sample.com + state: present + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Deactivate domain search + register: result + junipernetworks.junos.junos_system: + domain_search: + - test.com + - sample.com + state: present + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - '''<domain-search inactive="inactive">test.com</domain-search>'' in config.xml' + - '''<domain-search inactive="inactive">sample.com</domain-search>'' in config.xml' + +- name: Activate domain search + register: result + junipernetworks.junos.junos_system: + domain_search: + - test.com + - sample.com + state: present + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<domain-search>test.com</domain-search>' in config.xml" + - "'<domain-search>sample.com</domain-search>' in config.xml" + +- name: Delete domain search + register: result + junipernetworks.junos.junos_system: + domain_search: + - test.com + - sample.com + state: absent + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<domain-search>test.com</domain-search>' not in config.xml" + - "'<domain-search>sample.com</domain-search>' not in config.xml" + +- name: Setup - delete name servers + register: result + junipernetworks.junos.junos_system: + name_servers: + - 8.8.8.8 + - 8.8.4.4 + state: absent + +- name: Set name servers + register: result + junipernetworks.junos.junos_system: + name_servers: + - 8.8.8.8 + - 8.8.4.4 + state: present + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>8.8.8.8</name>' in config.xml" + - "'<name>8.8.4.4</name>' in config.xml" + +- name: Set name servers (idempotent) + register: result + junipernetworks.junos.junos_system: + name_servers: + - 8.8.8.8 + - 8.8.4.4 + state: present + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Deactivate name servers + register: result + junipernetworks.junos.junos_system: + name_servers: + - 8.8.8.8 + - 8.8.4.4 + state: present + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - '''<name-server inactive="inactive">'' in config.xml' + +- name: Activate name servers + register: result + junipernetworks.junos.junos_system: + name_servers: + - 8.8.8.8 + - 8.8.4.4 + state: present + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>8.8.8.8</name>' in config.xml" + - "'<name>8.8.4.4</name>' in config.xml" + +- name: Delete name servers + register: result + junipernetworks.junos.junos_system: + name_servers: + - 8.8.8.8 + - 8.8.4.4 + state: absent + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>8.8.8.8</name>' not in config.xml" + - "'<name>8.8.4.4</name>' not in config.xml" + +- ansible.builtin.debug: + msg="END junos_system netconf/basic.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/defaults/main.yaml new file mode 100644 index 000000000..822f2213a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_cases: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/tasks/main.yaml new file mode 100644 index 000000000..ac951c8f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/tasks/netconf.yaml new file mode 100644 index 000000000..2f24bb1a3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/tasks/netconf.yaml @@ -0,0 +1,21 @@ +--- +- name: collect netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + register: test_cases + connection: local + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/tests/netconf/basic.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/tests/netconf/basic.yaml new file mode 100644 index 000000000..119519a68 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_user/tests/netconf/basic.yaml @@ -0,0 +1,204 @@ +--- +- ansible.builtin.debug: + msg="START junos_user netconf/basic.yaml on connection={{ ansible_connection + }}" + +- name: setup - remove user + junipernetworks.junos.junos_user: + name: test_user + state: absent + +- name: Create user + register: result + junipernetworks.junos.junos_user: + name: test_user + state: present + full_name: test_user + role: operator + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>test_user</name>' in config.xml" + - "'<full-name>test_user</full-name>' in config.xml" + - "'<class>operator</class>' in config.xml" + +- name: Create user again (idempotent) + register: result + junipernetworks.junos.junos_user: + name: test_user + state: present + full_name: test_user + role: operator + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Deactivate user + register: result + junipernetworks.junos.junos_user: + name: test_user + state: present + full_name: test_user + role: operator + active: false + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - '''<user inactive="inactive">'' in config.xml' + - "'<name>test_user</name>' in config.xml" + +- name: Activate user + register: result + junipernetworks.junos.junos_user: + name: test_user + state: present + full_name: test_user + role: operator + active: true + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>test_user</name>' in config.xml" + - "'<full-name>test_user</full-name>' in config.xml" + - "'<class>operator</class>' in config.xml" + +- name: Delete user + register: result + junipernetworks.junos.junos_user: + name: test_user + state: absent + full_name: test_user + role: operator + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>test_user</name>' not in config.xml" + - "'<full-name>test_user</full-name>' not in config.xml" + +- name: Delete user again (idempotent check) + register: result + junipernetworks.junos.junos_user: + name: test_user + state: absent + full_name: test_user + role: operator + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Teardown list of users + register: result + junipernetworks.junos.junos_user: + aggregate: + - name: test_user1 + state: absent + + - name: test_user2 + state: absent + +- name: Create list of users + register: result + junipernetworks.junos.junos_user: + aggregate: + - name: test_user1 + full_name: test_user2 + role: operator + state: present + + - name: test_user2 + full_name: test_user2 + role: read-only + state: present + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>test_user1</name>' in config.xml" + - "'<name>test_user2</name>' in config.xml" + +- name: Delete list of users + register: result + junipernetworks.junos.junos_user: + aggregate: + - name: test_user1 + full_name: test_user2 + role: operator + state: absent + + - name: test_user2 + full_name: test_user2 + role: read-only + state: absent + +- name: Get running configuration + register: config + junipernetworks.junos.junos_rpc: + rpc: get-configuration + +- ansible.builtin.assert: + that: + - result.changed == true + - "'<name>test_user1</name>' not in config.xml" + - "'<name>test_user2</name>' not in config.xml" + +- name: Create list of users + register: result + junipernetworks.junos.junos_user: + aggregate: + - name: "{{ ansible_user|default('ansible') }}" + + - name: test_user1 + full_name: test_user2 + role: operator + + - name: test_user2 + full_name: test_user2 + role: read-only + +- name: Purge users except the users in aggregate + register: result + junipernetworks.junos.junos_user: + aggregate: + - name: "{{ ansible_user|default('ansible') }}" + purge: true + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("\- *user test_user1") + - result.diff.prepared is search("\- *user test_user2") + +- ansible.builtin.debug: + msg="END junos_user netconf/basic.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/meta/main.yaml new file mode 100644 index 000000000..7f867d73b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tasks/main.yaml new file mode 100644 index 000000000..ee273606c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tasks/netconf.yaml new file mode 100644 index 000000000..3db81d098 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tasks/netconf.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + use_regex: true + connection: local + register: test_cases + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/_base_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/_base_config.yaml new file mode 100644 index 000000000..99fc71c5f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/_base_config.yaml @@ -0,0 +1,13 @@ +--- +- ansible.builtin.debug: + msg: Start junos_vlans base config ansible_connection={{ ansible_connection + }} + +- name: Configure base vlans + junipernetworks.junos.junos_config: + lines: + - set vlans vlan1 vlan-id 1 + - set vlans vlan2 vlan-id 2 + +- ansible.builtin.debug: + msg: End junos_vlans base config ansible_connection={{ ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/_initial_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/_initial_config.yaml new file mode 100644 index 000000000..0ef2c2347 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/_initial_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: "START junos_routing_instances reset config on connection={{ ansible_connection }}" + +- name: Configure policy options w.r.t routing-instances + junipernetworks.junos.junos_config: + lines: + - set vlans vlan1 vlan-id 1 + - set vlans vlan2 vlan-id 2 + - set vlans vlan2 vlan-id 2 l3-interface irb.12 +- ansible.builtin.debug: + msg: "END junos_routing_instances reset config on connection={{ ansible_connection }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/_remove_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/_remove_config.yaml new file mode 100644 index 000000000..11176a318 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/_remove_config.yaml @@ -0,0 +1,12 @@ +--- +- ansible.builtin.debug: + msg: Start junos_vlans teardown ansible_connection={{ ansible_connection }} + +- name: Remove interface config + junipernetworks.junos.junos_config: + lines: + - delete vlans vlan1 + - delete vlans vlan2 + +- ansible.builtin.debug: + msg: End junos_vlans teardown ansible_connection={{ ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/deleted.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/deleted.yaml new file mode 100644 index 000000000..25e75c370 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/deleted.yaml @@ -0,0 +1,39 @@ +--- +- ansible.builtin.debug: + msg: + START junos_vlans deleted integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- block: + - name: Delete the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_vlans: &id001 + config: + state: deleted + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - not result.after + + - name: + Delete the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_vlans: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_vlans deleted integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/empty_config.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/empty_config.yaml new file mode 100644 index 000000000..61e29a1e1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/empty_config.yaml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg: START junos_vlans empty_config integration tests on connection={{ + ansible_connection }} + +- name: Merged with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_vlans: + config: + state: merged + +- ansible.builtin.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 + junipernetworks.junos.junos_vlans: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Override with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_vlans: + config: + state: overridden + +- ansible.builtin.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 + junipernetworks.junos.junos_vlans: + running_config: + state: parsed + +- ansible.builtin.debug: + msg: result +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + junipernetworks.junos.junos_vlans: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' + +- ansible.builtin.debug: + msg: END junos_vlans empty_config integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/fixtures/parsed.cfg b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/fixtures/parsed.cfg new file mode 100644 index 000000000..ae9fbe0f7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/fixtures/parsed.cfg @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <vlans> + <vlan> + <name>vlan1</name> + <vlan-id>1</vlan-id> + </vlan> + <vlan> + <name>vlan2</name> + <vlan-id>2</vlan-id> + <l3-interface>irb.12</l3-interface> + </vlan> + </vlans> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/gathered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/gathered.yaml new file mode 100644 index 000000000..bd5c270b1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/gathered.yaml @@ -0,0 +1,35 @@ +--- +- ansible.builtin.debug: + msg: START junos_vlans gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + + - ansible.builtin.include_tasks: _initial_config.yaml + + - ansible.builtin.set_fact: + expected_gathered_output: + - name: vlan1 + vlan_id: 1 + - name: vlan2 + vlan_id: 2 + l3_interface: "irb.12" + + - name: Gather bgp address family facts using gathered state + register: result + junipernetworks.junos.junos_vlans: + state: gathered + + - name: Assert that facts were correctly generated + ansible.builtin.assert: + that: + - "{{ expected_gathered_output | symmetric_difference(result['gathered']) |length\ + \ == 0 }}" + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_vlans gathered integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/merged.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/merged.yaml new file mode 100644 index 000000000..6456a2d23 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/merged.yaml @@ -0,0 +1,53 @@ +--- +- ansible.builtin.debug: + msg: + START junos_vlans merged integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.set_fact: + expected_merged_output: + - name: vlan1 + vlan_id: 1 + + - name: vlan2 + vlan_id: 2 + l3_interface: "irb.12" + +- block: + - name: Merge the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_vlans: &id001 + config: + - name: vlan1 + vlan_id: 1 + + - name: vlan2 + vlan_id: 2 + l3_interface: "irb.12" + state: merged + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_merged_output | symmetric_difference(result['after']) |length\ + \ == 0 }}" + + - name: + Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_vlans: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_vlans merged integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/overridden.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/overridden.yaml new file mode 100644 index 000000000..3341f8f25 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/overridden.yaml @@ -0,0 +1,47 @@ +--- +- ansible.builtin.debug: + msg: + START junos_vlans overridden integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_overridden_output: + - name: vlan1 + vlan_id: 100 + +- block: + - name: Override the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_vlans: &id001 + config: + - name: vlan1 + vlan_id: 100 + state: overridden + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_overridden_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Override the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_vlans: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_vlans overridden integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/parsed.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/parsed.yaml new file mode 100644 index 000000000..4fa120c2b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/parsed.yaml @@ -0,0 +1,29 @@ +--- +- ansible.builtin.debug: + msg: + START junos_vlans parsed integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.set_fact: + expected_parsed_output: + - name: vlan1 + vlan_id: 1 + - name: vlan2 + vlan_id: 2 + l3_interface: "irb.12" + +- name: Parse externally provided vlans config to agnostic model + register: result + junipernetworks.junos.junos_vlans: + running_config: "{{ lookup('file', './fixtures/parsed.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + ansible.builtin.assert: + that: + - "{{ expected_parsed_output == result['parsed'] }}" + - result['changed'] == false +- ansible.builtin.debug: + msg: + END junos_vlans parsed integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/rendered.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/rendered.yaml new file mode 100644 index 000000000..95e7af258 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/rendered.yaml @@ -0,0 +1,28 @@ +--- +- ansible.builtin.debug: + msg: START junos_vlans rendered integration tests on connection={{ + ansible_connection }} + +- ansible.builtin.set_fact: + expected_rendered_output: '<nc:vlans xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:vlan><nc:name>vlan1</nc:name><nc:vlan-id>1</nc:vlan-id></nc:vlan><nc:vlan><nc:name>vlan2</nc:name><nc:vlan-id>2</nc:vlan-id><nc:l3-interface>irb.12</nc:l3-interface></nc:vlan></nc:vlans>' +- name: Render platform specific commands from task input using rendered state + register: result + junipernetworks.junos.junos_vlans: + config: + - name: vlan1 + vlan_id: 1 + + - name: vlan2 + vlan_id: 2 + l3_interface: "irb.12" + state: rendered + +- name: Assert that correct set of commands were rendered and task changed is false. + ansible.builtin.assert: + that: + - "{{ expected_rendered_output == result['rendered'] }}" + - result['changed'] == false + +- ansible.builtin.debug: + msg: END junos_vlans rendered integration tests on connection={{ + ansible_connection }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/replaced.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/replaced.yaml new file mode 100644 index 000000000..d9f102c64 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/replaced.yaml @@ -0,0 +1,50 @@ +--- +- ansible.builtin.debug: + msg: + START junos_vlans replaced integration tests on connection={{ ansible_connection + }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _base_config.yaml + +- ansible.builtin.set_fact: + expected_replaced_output: + - name: vlan1 + vlan_id: 10 + + - name: vlan2 + vlan_id: 2 + +- block: + - name: Replace the provided configuration with the exisiting running configuration + register: result + junipernetworks.junos.junos_vlans: &id001 + config: + - name: vlan1 + vlan_id: 10 + state: replaced + + - name: Assert the configuration is reflected on host + ansible.builtin.assert: + that: + - "{{ expected_replaced_output | symmetric_difference(result['after'])\ + \ |length == 0 }}" + + - name: + Replace the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + junipernetworks.junos.junos_vlans: *id001 + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_vlans replaced integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/rtt.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/rtt.yml new file mode 100644 index 000000000..dbd77cd82 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vlans/tests/netconf/rtt.yml @@ -0,0 +1,65 @@ +--- +- ansible.builtin.debug: + msg: START junos_vlans round trip integration tests on connection={{ + ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _remove_config.yaml + - ansible.builtin.include_tasks: _initial_config.yaml + + - name: Apply the provided configuration (base config) + register: base_config + junipernetworks.junos.junos_vlans: + config: + - name: vlan1 + vlan_id: 1 + - name: vlan2 + vlan_id: 2 + l3_interface: "irb.12" + state: merged + + - name: Gather interfaces facts + junipernetworks.junos.junos_facts: + gather_subset: + - default + gather_network_resources: + - vlans + + - name: Apply the provided configuration (config to be reverted) + register: result + junipernetworks.junos.junos_vlans: + config: + - name: vlan1 + vlan_id: 10 + state: replaced + + - name: Assert that changes were applied + ansible.builtin.assert: + that: result['changed'] == true + + - name: Revert back to base config using facts round trip + register: revert + junipernetworks.junos.junos_vlans: + config: "{{ ansible_facts['network_resources']['vlans'] }}" + state: replaced + + - name: Assert that before dicts are correct + ansible.builtin.assert: + that: + - result.changed == True + - "{{ result['after'] | symmetric_difference( revert['before'])\ + \ |length == 0 }}" + + - name: Assert that config was reverted + ansible.builtin.assert: + that: + - result.changed == True + - "{{ base_config['after'] | symmetric_difference( revert['after'])\ + \ |length == 0 }}" + always: + - ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.debug: + msg: + END junos_vlans round trip integration tests on connection={{ ansible_connection + }} diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/defaults/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/defaults/main.yaml new file mode 100644 index 000000000..9ef5ba516 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/meta/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/meta/main.yml new file mode 100644 index 000000000..d80f5fbf3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_junos_tests diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/tasks/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/tasks/main.yaml new file mode 100644 index 000000000..ac951c8f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Invoke netconf tasks + ansible.builtin.include_tasks: netconf.yaml diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/tasks/netconf.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/tasks/netconf.yaml new file mode 100644 index 000000000..3fa0553b5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/tasks/netconf.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect netconf test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + register: test_cases + connection: local + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.netconf) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + vars: + ansible_connection: ansible.netcommon.netconf + tags: + - netconf diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/tests/netconf/basic.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/tests/netconf/basic.yaml new file mode 100644 index 000000000..160500f9c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_vrf/tests/netconf/basic.yaml @@ -0,0 +1,320 @@ +--- +- ansible.builtin.debug: + msg="START junos_vrf netconf/basic.yaml on connection={{ ansible_connection + }}" + +- name: setup - remove vrf + junipernetworks.junos.junos_vrf: + name: test-1 + state: absent + +- name: Configure vrf and its parameter + register: result + junipernetworks.junos.junos_vrf: + name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/6 + - ge-0/0/5 + rd: 192.0.2.3:10 + target: target:65513:111 + state: present + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("\+ *test-1") + - result.diff.prepared is search("\+ *description test-vrf-1") + - result.diff.prepared is search("\+ *instance-type vrf") + - result.diff.prepared is search("\+ *interface ge-0/0/5.0") + - result.diff.prepared is search("\+ *interface ge-0/0/6.0") + - result.diff.prepared is search("\+ *route-distinguisher 192.0.2.3:10") + - result.diff.prepared is search("\+ *vrf-target target:65513:111") + +- name: Configure vrf and its parameter (idempotent) + register: result + junipernetworks.junos.junos_vrf: + name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/6 + - ge-0/0/5 + rd: 192.0.2.3:10 + target: target:65513:111 + state: present + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Change vrf parameter + register: result + junipernetworks.junos.junos_vrf: + name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/3 + - ge-0/0/2 + rd: 192.0.2.1:10 + target: target:65514:113 + state: present + +- ansible.builtin.assert: + that: + - result.changed == true + - "'[edit routing-instances test-1]' in result.diff.prepared" + - result.diff.prepared is search("\+ *interface ge-0/0/2.0") + - result.diff.prepared is search("\+ *interface ge-0/0/3.0") + - "'[edit routing-instances test-1]' in result.diff.prepared" + - result.diff.prepared is search("\+ *route-distinguisher 192.0.2.1:10") + - result.diff.prepared is search("\+ *vrf-target target:65514:113") + +- name: Deactivate vrf + register: result + junipernetworks.junos.junos_vrf: + name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/3 + - ge-0/0/2 + rd: 192.0.2.1:10 + target: target:65514:113 + state: present + active: false + +- ansible.builtin.assert: + that: + - result.changed == true + - "'[edit routing-instances]' in result.diff.prepared" + - result.diff.prepared is search("! *inactive[:] test-1") + - "'[edit routing-instances test-1]' in result.diff.prepared" + - result.diff.prepared is search("! *inactive[:] interface ge-0/0/2.0") + - result.diff.prepared is search("! *inactive[:] interface ge-0/0/3.0") + - "'[edit routing-instances test-1]' in result.diff.prepared" + - result.diff.prepared is search("! *inactive[:] route-distinguisher") + - result.diff.prepared is search("! *inactive[:] vrf-target") + +- name: Activate vrf + register: result + junipernetworks.junos.junos_vrf: + name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/3 + - ge-0/0/2 + rd: 192.0.2.1:10 + target: target:65514:113 + state: present + active: true + +- ansible.builtin.assert: + that: + - result.changed == true + - "'[edit routing-instances]' in result.diff.prepared" + - result.diff.prepared is search("! *active[:] test-1") + - "'[edit routing-instances test-1]' in result.diff.prepared" + - result.diff.prepared is search("! *active[:] interface ge-0/0/2.0") + - result.diff.prepared is search("! *active[:] interface ge-0/0/3.0") + - "'[edit routing-instances test-1]' in result.diff.prepared" + - result.diff.prepared is search("! *active[:] route-distinguisher") + - result.diff.prepared is search("! *active[:] vrf-target") + +- name: Delete vrf + register: result + junipernetworks.junos.junos_vrf: + name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/3 + - ge-0/0/2 + rd: 192.0.2.1:10 + target: target:65514:113 + state: absent + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("\- *test-1") + - result.diff.prepared is search("\- *description test-vrf-1") + - result.diff.prepared is search("\- *instance-type vrf") + - result.diff.prepared is search("\- *interface ge-0/0/2.0") + - result.diff.prepared is search("\- *interface ge-0/0/3.0") + - result.diff.prepared is search("\- *route-distinguisher 192.0.2.1:10") + - result.diff.prepared is search("\- *vrf-target target:65514:113") + +- name: Delete vrf (idempotent) + register: result + junipernetworks.junos.junos_vrf: + name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/3 + - ge-0/0/2 + rd: 192.0.2.1:10 + target: target:65514:113 + state: absent + +- ansible.builtin.assert: + that: + - result.changed == false + +- name: Setup vrf using aggregate + register: result + junipernetworks.junos.junos_vrf: + aggregate: + - name: test-1 + + - name: test-2 + state: absent + +- name: Create vrf using aggregate + register: result + junipernetworks.junos.junos_vrf: + aggregate: + - name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/3 + - ge-0/0/2 + rd: 192.0.2.1:10 + target: target:65514:113 + + - name: test-2 + description: test-vrf-2 + interfaces: + - ge-0/0/4 + - ge-0/0/5 + rd: 192.0.2.2:10 + target: target:65515:114 + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("\+ *test-1") + - result.diff.prepared is search("\+ *description test-vrf-1") + - result.diff.prepared is search("\+ *instance-type vrf") + - result.diff.prepared is search("\+ *interface ge-0/0/2.0") + - result.diff.prepared is search("\+ *interface ge-0/0/3.0") + - result.diff.prepared is search("\+ *route-distinguisher 192.0.2.1:10") + - result.diff.prepared is search("\+ *vrf-target target:65514:113") + - result.diff.prepared is search("\+ *test-2") + - result.diff.prepared is search("\+ *description test-vrf-2") + - result.diff.prepared is search("\+ *instance-type vrf") + - result.diff.prepared is search("\+ *interface ge-0/0/4.0") + - result.diff.prepared is search("\+ *interface ge-0/0/5.0") + - result.diff.prepared is search("\+ *route-distinguisher 192.0.2.2:10") + - result.diff.prepared is search("\+ *vrf-target target:65515:114") + +- name: Deactivate vrf configuration using aggregate + register: result + junipernetworks.junos.junos_vrf: + aggregate: + - name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/3 + - ge-0/0/2 + rd: 192.0.2.1:10 + target: target:65514:113 + + - name: test-2 + description: test-vrf-2 + interfaces: + - ge-0/0/4 + - ge-0/0/5 + rd: 192.0.2.2:10 + target: target:65515:114 + active: false + +- ansible.builtin.assert: + that: + - result.changed == true + - "'edit routing-instances test-1' in result.diff.prepared" + - result.diff.prepared is search("! *inactive[:] interface ge-0/0/2.0") + - result.diff.prepared is search("! *inactive[:] interface ge-0/0/3.0") + - result.diff.prepared is search("! *inactive[:] route-distinguisher") + - result.diff.prepared is search("! *inactive[:] vrf-target") + - "'edit routing-instances test-2' in result.diff.prepared" + - result.diff.prepared is search("! *inactive[:] interface ge-0/0/4.0") + - result.diff.prepared is search("! *inactive[:] interface ge-0/0/5.0") + - result.diff.prepared is search("! *inactive[:] route-distinguisher") + - result.diff.prepared is search("! *inactive[:] vrf-target") + +- name: Deactivate vrf configuration using aggregate + register: result + junipernetworks.junos.junos_vrf: + aggregate: + - name: test-1 + description: test-vrf-1 + interfaces: + - ge-0/0/3 + - ge-0/0/2 + rd: 192.0.2.1:10 + target: target:65514:113 + + - name: test-2 + description: test-vrf-2 + interfaces: + - ge-0/0/4 + - ge-0/0/5 + rd: 192.0.2.2:10 + target: target:65515:114 + active: true + +- ansible.builtin.assert: + that: + - result.changed == true + - "'edit routing-instances test-1' in result.diff.prepared" + - result.diff.prepared is search("! *active[:] interface ge-0/0/2.0") + - result.diff.prepared is search("! *active[:] interface ge-0/0/3.0") + - result.diff.prepared is search("! *active[:] route-distinguisher") + - result.diff.prepared is search("! *active[:] vrf-target") + - "'edit routing-instances test-2' in result.diff.prepared" + - result.diff.prepared is search("! *active[:] interface ge-0/0/4.0") + - result.diff.prepared is search("! *active[:] interface ge-0/0/5.0") + - result.diff.prepared is search("! *active[:] route-distinguisher") + - result.diff.prepared is search("! *active[:] vrf-target") + +- name: Delete vrf configuration using aggregate + register: result + junipernetworks.junos.junos_vrf: + aggregate: + - name: test-1 + + - name: test-2 + state: absent + +- ansible.builtin.assert: + that: + - result.changed == true + - result.diff.prepared is search("\- *test-1") + - result.diff.prepared is search("\- *description test-vrf-1") + - result.diff.prepared is search("\- *instance-type vrf") + - result.diff.prepared is search("\- *interface ge-0/0/2.0") + - result.diff.prepared is search("\- *interface ge-0/0/3.0") + - result.diff.prepared is search("\- *route-distinguisher 192.0.2.1:10") + - result.diff.prepared is search("\- *vrf-target target:65514:113") + - result.diff.prepared is search("\- *test-2") + - result.diff.prepared is search("\- *description test-vrf-2") + - result.diff.prepared is search("\- *instance-type vrf") + - result.diff.prepared is search("\- *interface ge-0/0/4.0") + - result.diff.prepared is search("\- *interface ge-0/0/5.0") + - result.diff.prepared is search("\- *route-distinguisher 192.0.2.2:10") + - result.diff.prepared is search("\- *vrf-target target:65515:114") + +- name: Delete vrf configuration using aggregate (idempotent) + register: result + junipernetworks.junos.junos_vrf: + aggregate: + - name: test-1 + + - name: test-2 + state: absent + +- ansible.builtin.assert: + that: + - result.changed == false + +- ansible.builtin.debug: + msg="END junos_vrf netconf/basic.yaml on connection={{ ansible_connection + }}" diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/meta/main.yaml b/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/meta/main.yaml new file mode 100644 index 000000000..61d3ffe4f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/meta/main.yaml @@ -0,0 +1,2 @@ +--- +allow_duplicates: true diff --git a/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/tasks/main.yml b/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/tasks/main.yml new file mode 100644 index 000000000..1b9977466 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/integration/targets/prepare_junos_tests/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: Debug task + ansible.builtin.debug: msg="START prepare_junos_tests/main.yaml" + +- name: Ensure netconf is enabled + connection: ansible.netcommon.network_cli + tags: netconf + junipernetworks.junos.junos_netconf: + state: present + +- name: Wait for netconf server to come up + delegate_to: localhost + tags: netconf + ansible.builtin.wait_for: + host: "{{ hostvars[item].ansible_host }}" + port: 830 + with_inventory_hostnames: junos diff --git a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.10.txt b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.10.txt new file mode 100644 index 000000000..ed6d78dfe --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.10.txt @@ -0,0 +1 @@ +plugins/action/junos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.11.txt b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.11.txt new file mode 100644 index 000000000..ed6d78dfe --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.11.txt @@ -0,0 +1 @@ +plugins/action/junos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.12.txt b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.12.txt new file mode 100644 index 000000000..95ef681f4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.12.txt @@ -0,0 +1,3 @@ +plugins/action/junos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` +plugins/cliconf/junos.py pylint:arguments-renamed +tests/unit/mock/loader.py pylint:arguments-renamed diff --git a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.13.txt b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.13.txt new file mode 100644 index 000000000..95ef681f4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.13.txt @@ -0,0 +1,3 @@ +plugins/action/junos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` +plugins/cliconf/junos.py pylint:arguments-renamed +tests/unit/mock/loader.py pylint:arguments-renamed diff --git a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.14.txt b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.14.txt new file mode 100644 index 000000000..95ef681f4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.14.txt @@ -0,0 +1,3 @@ +plugins/action/junos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` +plugins/cliconf/junos.py pylint:arguments-renamed +tests/unit/mock/loader.py pylint:arguments-renamed diff --git a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.15.txt b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.15.txt new file mode 100644 index 000000000..95ef681f4 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.15.txt @@ -0,0 +1,3 @@ +plugins/action/junos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` +plugins/cliconf/junos.py pylint:arguments-renamed +tests/unit/mock/loader.py pylint:arguments-renamed diff --git a/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.9.txt b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.9.txt new file mode 100644 index 000000000..127be176d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/sanity/ignore-2.9.txt @@ -0,0 +1,3 @@ +plugins/action/junos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` +plugins/modules/junos_logging.py validate-modules:deprecation-mismatch # 2.9 expects METADATA +plugins/modules/junos_logging.py validate-modules:invalid-documentation # removed_at_date not supported in `deprecated` dict diff --git a/ansible_collections/junipernetworks/junos/tests/unit/__init__.py b/ansible_collections/junipernetworks/junos/tests/unit/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/__init__.py diff --git a/ansible_collections/junipernetworks/junos/tests/unit/compat/__init__.py b/ansible_collections/junipernetworks/junos/tests/unit/compat/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/compat/__init__.py diff --git a/ansible_collections/junipernetworks/junos/tests/unit/compat/builtins.py b/ansible_collections/junipernetworks/junos/tests/unit/compat/builtins.py new file mode 100644 index 000000000..e898a081e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/compat/builtins.py @@ -0,0 +1,35 @@ +# (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/ansible_collections/junipernetworks/junos/tests/unit/compat/mock.py b/ansible_collections/junipernetworks/junos/tests/unit/compat/mock.py new file mode 100644 index 000000000..1d51d36e8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/compat/mock.py @@ -0,0 +1,131 @@ +# (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 + +import _io + + +""" +Compat module for Python3.x's unittest.mock module +""" +import sys + + +# Python 2.7 + +# Note: Could use the pypi mock library on python3.x as well as python2.x. It +# is the same as the python3 stdlib mock library + +try: + # Allow wildcard import because we really do want to import all of mock's + # symbols into this compat shim + # pylint: disable=wildcard-import,unused-wildcard-import + from unittest.mock import * +except ImportError: + # Python 2 + # pylint: disable=wildcard-import,unused-wildcard-import + try: + from mock import * + except ImportError: + print("You need the mock library installed on python2.x to run tests") + + +# Prior to 3.4.4, mock_open cannot handle binary read_data +if sys.version_info >= (3,) and sys.version_info < (3, 4, 4): + file_spec = None + + def _iterate_read_data(read_data): + # Helper for mock_open: + # Retrieve lines from read_data via a generator so that separate calls to + # readline, read, and readlines are properly interleaved + sep = b"\n" if isinstance(read_data, bytes) else "\n" + data_as_list = [l + sep for l in read_data.split(sep)] + + if data_as_list[-1] == sep: + # If the last line ended in a newline, the list comprehension will have an + # extra entry that's just a newline. Remove this. + data_as_list = data_as_list[:-1] + else: + # If there wasn't an extra newline by itself, then the file being + # emulated doesn't have a newline to end the last line remove the + # newline that our naive format() added + data_as_list[-1] = data_as_list[-1][:-1] + + for line in data_as_list: + yield line + + def mock_open(mock=None, read_data=""): + """ + A helper function to create a mock to replace the use of `open`. It works + for `open` called directly or used as a context manager. + + The `mock` argument is the mock object to configure. If `None` (the + default) then a `MagicMock` will be created for you, with the API limited + to methods or attributes available on standard file handles. + + `read_data` is a string for the `read` methoddline`, and `readlines` of the + file handle to return. This is an empty string by default. + """ + + def _readlines_side_effect(*args, **kwargs): + if handle.readlines.return_value is not None: + return handle.readlines.return_value + return list(_data) + + def _read_side_effect(*args, **kwargs): + if handle.read.return_value is not None: + return handle.read.return_value + return type(read_data)().join(_data) + + def _readline_side_effect(): + if handle.readline.return_value is not None: + while True: + yield handle.readline.return_value + for line in _data: + yield line + + global file_spec + if file_spec is None: + + 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/ansible_collections/junipernetworks/junos/tests/unit/compat/unittest.py b/ansible_collections/junipernetworks/junos/tests/unit/compat/unittest.py new file mode 100644 index 000000000..df4266ec9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/compat/unittest.py @@ -0,0 +1,41 @@ +# (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/ansible_collections/junipernetworks/junos/tests/unit/mock/__init__.py b/ansible_collections/junipernetworks/junos/tests/unit/mock/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/mock/__init__.py diff --git a/ansible_collections/junipernetworks/junos/tests/unit/mock/loader.py b/ansible_collections/junipernetworks/junos/tests/unit/mock/loader.py new file mode 100644 index 000000000..2b5eb36a1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/mock/loader.py @@ -0,0 +1,117 @@ +# (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.module_utils._text import to_bytes, to_text +from ansible.parsing.dataloader import DataLoader + + +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/ansible_collections/junipernetworks/junos/tests/unit/mock/path.py b/ansible_collections/junipernetworks/junos/tests/unit/mock/path.py new file mode 100644 index 000000000..a7171080e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/mock/path.py @@ -0,0 +1,13 @@ +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type +from ansible.utils.path import unfrackpath + +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import MagicMock + + +mock_unfrackpath_noop = MagicMock( + spec_set=unfrackpath, + side_effect=lambda x, *args, **kwargs: x, +) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/mock/procenv.py b/ansible_collections/junipernetworks/junos/tests/unit/mock/procenv.py new file mode 100644 index 000000000..79f2f97ca --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/mock/procenv.py @@ -0,0 +1,97 @@ +# (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 json +import sys + +from contextlib import contextmanager +from io import BytesIO, StringIO + +from ansible.module_utils._text import to_bytes +from ansible.module_utils.six import PY3 + +from ansible_collections.junipernetworks.junos.tests.unit.compat import unittest + + +@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/ansible_collections/junipernetworks/junos/tests/unit/mock/vault_helper.py b/ansible_collections/junipernetworks/junos/tests/unit/mock/vault_helper.py new file mode 100644 index 000000000..82d01f5c5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/mock/vault_helper.py @@ -0,0 +1,44 @@ +# 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/ansible_collections/junipernetworks/junos/tests/unit/mock/yaml_helper.py b/ansible_collections/junipernetworks/junos/tests/unit/mock/yaml_helper.py new file mode 100644 index 000000000..e46d3180b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/mock/yaml_helper.py @@ -0,0 +1,177 @@ +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.dumper import AnsibleDumper +from ansible.parsing.yaml.loader import AnsibleLoader + + +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/ansible_collections/junipernetworks/junos/tests/unit/modules/__init__.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/__init__.py diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/conftest.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/conftest.py new file mode 100644 index 000000000..349e71ada --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/conftest.py @@ -0,0 +1,34 @@ +# 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._text import to_bytes +from ansible.module_utils.common._collections_compat import MutableMapping +from ansible.module_utils.six import string_types + + +@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/ansible_collections/junipernetworks/junos/tests/unit/modules/network/__init__.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/__init__.py diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/__init__.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/__init__.py diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/__init__.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/__init__.py diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply.txt new file mode 100644 index 000000000..4bb5afa02 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply.txt @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="urn:uuid:72c481b8"> + <configuration-set> + set version 15.1X49-D15.4 + set system host-name vsrx01 + set system domain-name ansible.com + </configuration-set> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_diff.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_diff.txt new file mode 100644 index 000000000..c2b803f82 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_diff.txt @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="urn:uuid:6fcc8e22"> +<configuration-information> +<configuration-output> +[edit interfaces] ++ ae11 { ++ unit 0 { ++ description Test; ++ } ++ } +</configuration-output> +</configuration-information> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_json.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_json.txt new file mode 100644 index 000000000..a1d7345a3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_json.txt @@ -0,0 +1,190 @@ +<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="urn:uuid:72c481b8"> +{ + "configuration" : [ + { + "system" : [ + { + "host-name" : [ + { + "data" : "vsrx01" + } + ], + "domain-name" : [ + { + "data" : "junos.com" + } + ], + "name-server" : [ + { + "name" : + { + "data" : "172.26.1.1" + } + }, + { + "name" : + { + "data" : "8.8.8.8" + } + } + ], + "services" : [ + { + "ssh" : [ + { + } + ], + "telnet" : [ + { + } + ], + "netconf" : [ + { + "ssh" : [ + { + "port" : [ + { + "data" : "830" + } + ] + } + ], + "traceoptions" : [ + { + "file" : [ + { + "filename" : [ + { + "data" : "netconf-ops.log" + } + ] + } + ], + "flag" : [ + { + "name" : + { + "data" : "all" + } + } + ] + } + ] + } + ], + "web-management" : [ + { + "http" : [ + { + "interface" : [ + { + "data" : "fxp0.0" + } + ] + } + ] + } + ] + } + ], + "syslog" : [ + { + "user" : [ + { + "name" : + { + "data" : "*" + }, + "contents" : [ + { + "name" : + { + "data" : "any" + }, + "emergency" : [ + { + "data" : null + } + ] + } + ] + } + ], + "file" : [ + { + "name" : + { + "data" : "messages" + }, + "contents" : [ + { + "name" : + { + "data" : "any" + }, + "any" : [ + { + "data" : null + } + ] + }, + { + "name" : + { + "data" : "authorization" + }, + "info" : [ + { + "data" : null + } + ] + } + ] + }, + { + "name" : + { + "data" : "interactive-commands" + }, + "contents" : [ + { + "name" : + { + "data" : "interactive-commands" + }, + "any" : [ + { + "data" : null + } + ] + } + ] + }, + { + "name" : + { + "data" : "test1" + }, + "contents" : [ + { + "name" : + { + "data" : "any" + }, + "any" : [ + { + "data" : null + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_set.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_set.txt new file mode 100644 index 000000000..c5ec7fb0b --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_set.txt @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="urn:uuid:72c481b8"> + <configuration-set> + set version 15.1X49-D15.4 + set system host-name vsrx01 + set system domain-name ansible.com + </configuration-set> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_text.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_text.txt new file mode 100644 index 000000000..c1ba1ad9f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_text.txt @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="urn:uuid:72c481b8"> + <configuration-text> + version 20.3R2.9; + system { + host-name vsrx01; + domain-name ansible.com; + } + </configuration-text> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_xml.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_xml.txt new file mode 100644 index 000000000..87cd765dd --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/get_configuration_rpc_reply_xml.txt @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?><rpc-reply message-id="urn:uuid:72c481b8"> + <configuration> + <version>20.3R2.9</version> + <system> + <host-name>vsrx01</host-name> + <domain-name>ansible.com</domain-name> + </system> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_address_family.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_address_family.cfg new file mode 100644 index 000000000..c1d2042fa --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_address_family.cfg @@ -0,0 +1,22 @@ +description "This is configured with Junos_bgp resource module replace"; +preference 2; +hold-time 5; +advertise-inactive; +out-delay 10; +bgp-error-tolerance { + malformed-route-limit 40000000; +} +authentication-algorithm md5; +advertise-bgp-static { + policy static-to-bgp; +} +bfd-liveness-detection { + version automatic; + minimum-receive-interval 8; + multiplier 30; + no-adaptation; + transmit-interval { + minimum-interval 4; + } +} +egress-te-sid-stats; diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_address_family_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_address_family_config.cfg new file mode 100644 index 000000000..18712c323 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_address_family_config.cfg @@ -0,0 +1,137 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <precision-timers/> + <advertise-from-main-vpn-tables/> + <holddown-all-stale-labels/> + <description>This is configured with Junos_bgp resource module</description> + <accept-remote-nexthop/> + <preference>2</preference> + <hold-time>5</hold-time> + <advertise-inactive/> + <no-advertise-peer-as/> + <no-aggregator-id/> + <out-delay>10</out-delay> + <log-updown/> + <damping/> + <bgp-error-tolerance> + <malformed-route-limit>20000000</malformed-route-limit> + </bgp-error-tolerance> + <family> + <inet> + <unicast> + <local-ipv4-address>11.11.11.11</local-ipv4-address> + <graceful-restart> + <forwarding-state-bit>set</forwarding-state-bit> + </graceful-restart> + </unicast> + <flow> + <loops> + <loops>3</loops> + </loops> + <no-install/> + <output-queue-priority> + <priority>15</priority> + </output-queue-priority> + <legacy-redirect-ip-action> + <receive/> + <send/> + </legacy-redirect-ip-action> + <secondary-independent-resolution/> + </flow> + <labeled-unicast> + <prefix-limit> + <maximum>4294967290</maximum> + <teardown> + <limit-threshold>22</limit-threshold> + <idle-timeout> + <timeout>2200</timeout> + </idle-timeout> + </teardown> + </prefix-limit> + <per-prefix-label/> + <explicit-null> + <connected-only/> + </explicit-null> + <resolve-vpn/> + <entropy-label> + <no-next-hop-validation/> + </entropy-label> + </labeled-unicast> + </inet> + <inet6> + <unicast> + <extended-nexthop-color/> + </unicast> + <labeled-unicast> + <aigp> + <disable/> + </aigp> + <damping/> + <delay-route-advertisements> + <minimum-delay> + <routing-uptime>8000</routing-uptime> + <inbound-convergence>8000</inbound-convergence> + </minimum-delay> + <maximum-delay> + <route-age>12000</route-age> + <routing-uptime>12000</routing-uptime> + </maximum-delay> + </delay-route-advertisements> + <defer-initial-multipath-build> + <maximum-delay>1200</maximum-delay> + </defer-initial-multipath-build> + <route-refresh-priority> + <priority>15</priority> + </route-refresh-priority> + <per-group-label/> + <rib> + <inet6.3/> + </rib> + </labeled-unicast> + </inet6> + </family> + <authentication-algorithm>md5</authentication-algorithm> + <no-client-reflect/> + <include-mp-next-hop/> + <bmp> + <monitor>enable</monitor> + </bmp> + <add-path-display-ipv4-address/> + <egress-te-sid-stats/> + <group> + <name>internal</name> + <out-delay>12</out-delay> + </group> + <group> + <name>ebgp</name> + <family> + <inet> + <unicast> + <topology> + <name>voice</name> + <community>target:40:40</community> + </topology> + </unicast> + </inet> + </family> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_global.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_global.cfg new file mode 100644 index 000000000..c1d2042fa --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_global.cfg @@ -0,0 +1,22 @@ +description "This is configured with Junos_bgp resource module replace"; +preference 2; +hold-time 5; +advertise-inactive; +out-delay 10; +bgp-error-tolerance { + malformed-route-limit 40000000; +} +authentication-algorithm md5; +advertise-bgp-static { + policy static-to-bgp; +} +bfd-liveness-detection { + version automatic; + minimum-receive-interval 8; + multiplier 30; + no-adaptation; + transmit-interval { + minimum-interval 4; + } +} +egress-te-sid-stats; diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_global_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_global_config.cfg new file mode 100644 index 000000000..a8c11bc08 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_bgp_global_config.cfg @@ -0,0 +1,37 @@ +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <advertise-from-main-vpn-tables /> + <holddown-all-stale-labels /> + <description>This is configured with Junos_bgp resource module</description> + <accept-remote-nexthop /> + <preference>2</preference> + <hold-time>5</hold-time> + <advertise-inactive /> + <no-advertise-peer-as /> + <no-aggregator-id /> + <out-delay>10</out-delay> + <log-updown /> + <damping /> + <bgp-error-tolerance> + <malformed-route-limit>30000000</malformed-route-limit> + </bgp-error-tolerance> + <authentication-algorithm>md5</authentication-algorithm> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.json b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.json new file mode 100644 index 000000000..8a2959960 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.json @@ -0,0 +1,25 @@ +{ + "interfaces": [ + { + "interface": [ + { + "name": { + "data": "ae11" + }, + "unit": [ + { + "name": { + "data": "0" + }, + "description": [ + { + "data": "Test" + } + ] + } + ] + } + ] + } + ] +} diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.set b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.set new file mode 100644 index 000000000..f67ea05d2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.set @@ -0,0 +1,2 @@ +delete interfaces ae11 +set interfaces ae11 unit 0 description Test diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.text b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.text new file mode 100644 index 000000000..2f89ac2b3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.text @@ -0,0 +1,8 @@ + +interfaces { + ae11 { + unit 0 { + description Test + } + } + } diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.xml b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.xml new file mode 100644 index 000000000..a0e8fe1b7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_config.xml @@ -0,0 +1,9 @@ +<interfaces> + <interface> + <name>ae11</name> + <unit> + <name>0</name> + <description>Test</description> + </unit> + </interface> +</interfaces> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_hostname_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_hostname_config.cfg new file mode 100644 index 000000000..1e6830e00 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_hostname_config.cfg @@ -0,0 +1,8 @@ +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <host-name>vsrx12</host-name> + </system> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_interfaces.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_interfaces.cfg new file mode 100644 index 000000000..8a707327a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_interfaces.cfg @@ -0,0 +1,10 @@ +ge-0/0/0 { + description "Configured by Ansi-Team"; +} +fxp0 { + unit 0 { + family inet { + dhcp; + } + } +} diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_interfaces_config.xml b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_interfaces_config.xml new file mode 100644 index 000000000..26d323fcc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_interfaces_config.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <interfaces> + <interface> + <name>ge-0/0/1</name> + <description>Configured by Ansible</description> + <disable/> + <speed>100m</speed> + <mtu>1024</mtu> + <hold-time> + <up>2000</up> + <down>2200</down> + </hold-time> + <link-mode>full-duplex</link-mode> + <unit> + <name>0</name> + <family> + <ethernet-switching> + <interface-mode>access</interface-mode> + <vlan> + <members>vlan100</members> + </vlan> + </ethernet-switching> + </family> + </unit> + </interface> + <interface> + <name>ge-0/0/2</name> + <description>Configured by Ansible</description> + <native-vlan-id>400</native-vlan-id> + <speed>10m</speed> + <mtu>2048</mtu> + <hold-time> + <up>3000</up> + <down>3200</down> + </hold-time> + <unit> + <name>0</name> + <family> + <ethernet-switching> + <interface-mode>trunk</interface-mode> + <vlan> + <members>vlan200</members> + <members>vlan300</members> + </vlan> + </ethernet-switching> + </family> + </unit> + </interface> + </interfaces> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l2_interfaces.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l2_interfaces.cfg new file mode 100644 index 000000000..3f39ed785 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l2_interfaces.cfg @@ -0,0 +1,31 @@ +ge-0/0/0 { + description "Configured by Ansi-Team"; +} +ge-0/0/1 { + unit 0 { + family ethernet-switching { + interface-mode access; + vlan { + members vlan100; + } + } + } +} +ge-0/0/2 { + native-vlan-id 400; + unit 0 { + family ethernet-switching { + interface-mode trunk; + vlan { + members [ vlan200 vlan300 ]; + } + } + } +} +fxp0 { + unit 0 { + family inet { + dhcp; + } + } +} diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l3_interfaces.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l3_interfaces.cfg new file mode 100644 index 000000000..fe81e715a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_l3_interfaces.cfg @@ -0,0 +1,39 @@ +ge-0/0/0 { + description "Configured by Ansi-Team"; +} +ge-0/0/1 { + unit 0 { + family ethernet-switching { + interface-mode access; + vlan { + members vlan100; + } + } + } +} +ge-0/0/2 { + native-vlan-id 400; + unit 0 { + family ethernet-switching { + interface-mode trunk; + vlan { + members [ vlan200 vlan300 ]; + } + } + } +} +ge-1/0/0 { + unit 0 { + family inet { + address 100.64.0.1/10; + address 100.64.0.2/10; + } + } +} +fxp0 { + unit 0 { + family inet { + dhcp; + } + } +} diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_logging_global_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_logging_global_config.cfg new file mode 100644 index 000000000..e554b73ad --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_logging_global_config.cfg @@ -0,0 +1,66 @@ +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <login> + <user> + <name>vagrant</name> + <uid>2000</uid> + <class>super-user</class> + <authentication> + <encrypted-password>$6$QiBkxU5N$QY11GzNuFs1sfY0OAacyJ/0WFmP9ciovUAmM425yYAo9OjccxvjWlEZNo8SeqCQxYeM86cfd9V.N1RiiHW2zN0</encrypted-password> + <ssh-rsa> + <name>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key</name> + </ssh-rsa> + </authentication> + </user> + </login> + <root-authentication> + <encrypted-password>$1$nq.N1UsY$JxA/ESAj3KuXseXE597gg0</encrypted-password> + <ssh-rsa> + <name>ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key</name> + </ssh-rsa> + </root-authentication> + <services> + <ssh> + </ssh> + <netconf> + <ssh> + <port>830</port> + </ssh> + <rfc-compliant/> + </netconf> + </services> + <host-name>vsrx</host-name> + <syslog> + <host> + <name>host111</name> + <contents> + <name>any</name> + <any/> + </contents> + <match>^set*</match> + <allow-duplicates/> + <port>1231</port> + <facility-override>ftp</facility-override> + <log-prefix>field</log-prefix> + <source-address>11.1.1.11</source-address> + <routing-instance>inst11</routing-instance> + <exclude-hostname/> + <match-strings>^delete</match-strings> + <match-strings>^prompt</match-strings> + <structured-data> + <brief/> + </structured-data> + </host> + </syslog> + <license> + <autoupdate> + <url> + <name>https://ae1.juniper.net/junos/key_retrieval</name> + </url> + </autoupdate> + </license> + </system> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ntp_global_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ntp_global_config.cfg new file mode 100644 index 000000000..f99d998eb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ntp_global_config.cfg @@ -0,0 +1,20 @@ +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <ntp> + <authentication-key> + <name>3</name> + <type>md5</type> + <value>$9$GxDjqfT3CA0UjfzF6u0RhS</value> + </authentication-key> + <authentication-key> + <name>4</name> + <type>sha1</type> + <value>$9$ZsUDk.mT3/toJGiHqQz</value> + </authentication-key> + </ntp> + + </system> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospf_interfaces.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospf_interfaces.cfg new file mode 100644 index 000000000..0ec7941f3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospf_interfaces.cfg @@ -0,0 +1,6 @@ +area 0.0.0.2 { + interface ge-0/0/2.0 { + metric 5; + priority 3; + } +} diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospf_interfaces_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospf_interfaces_config.cfg new file mode 100644 index 000000000..a34481048 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospf_interfaces_config.cfg @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <protocols> + <ospf3> + <area> + <name>0.0.0.10</name> + <stub> + <default-metric>200</default-metric> + </stub> + <interface> + <name>so-0/0/0.0</name> + <passive></passive> + <metric>5</metric> + <priority>3</priority> + <flood-reduction/> + </interface> + </area> + <area> + <name>0.0.0.20</name> + <interface> + <name>ge-1/1/0.0</name> + </interface> + <interface> + <name>ge-2/2/0.0</name> + </interface> + </area> + </ospf3> + </protocols> + <routing-options> + <router-id>10.200.16.77</router-id> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2.cfg new file mode 100644 index 000000000..7df43d60c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2.cfg @@ -0,0 +1,6 @@ +Sun Jun 14 12:10:47.455 UTC +router ospf 30 + area 100 + default-metric 10 + ! +! diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2_config.cfg new file mode 100644 index 000000000..67b18028c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv2_config.cfg @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <protocols> + <ospf> + <area> + <name>0.0.0.10</name> + <stub> + <default-metric>200</default-metric> + </stub> + <interface> + <name>so-0/0/0.0</name> + <passive></passive> + <metric>5</metric> + <priority>3</priority> + <flood-reduction/> + </interface> + </area> + <area> + <name>0.0.0.20</name> + <interface> + <name>ge-1/1/0.0</name> + </interface> + <interface> + <name>ge-2/2/0.0</name> + </interface> + </area> + </ospf> + </protocols> + <routing-options> + <router-id>10.200.16.77</router-id> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv3.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv3.cfg new file mode 100644 index 000000000..132413630 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv3.cfg @@ -0,0 +1,6 @@ +Sun Jun 14 12:10:47.455 UTC +router ospfv3 30 + area 100 + default-metric 10 + ! +! diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv3_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv3_config.cfg new file mode 100644 index 000000000..a34481048 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ospfv3_config.cfg @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <protocols> + <ospf3> + <area> + <name>0.0.0.10</name> + <stub> + <default-metric>200</default-metric> + </stub> + <interface> + <name>so-0/0/0.0</name> + <passive></passive> + <metric>5</metric> + <priority>3</priority> + <flood-reduction/> + </interface> + </area> + <area> + <name>0.0.0.20</name> + <interface> + <name>ge-1/1/0.0</name> + </interface> + <interface> + <name>ge-2/2/0.0</name> + </interface> + </area> + </ospf3> + </protocols> + <routing-options> + <router-id>10.200.16.77</router-id> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.10_count_2 b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.10_count_2 new file mode 100644 index 000000000..9fcc94a6c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.10_count_2 @@ -0,0 +1,7 @@ +PING 10.10.10.10 (10.10.10.10): 56 data bytes +64 bytes from 10.10.10.10: icmp_seq=0 ttl=64 time=18.041 ms +64 bytes from 10.10.10.10: icmp_seq=1 ttl=64 time=15.710 ms + +--- 10.10.10.10 ping statistics --- +2 packets transmitted, 2 packets received, 0% packet loss +round-trip min/avg/max/stddev = 15.710/16.876/18.041/1.165 ms diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.11_count_5_size_512_interval_2 b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.11_count_5_size_512_interval_2 new file mode 100644 index 000000000..68d44d7f5 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.11_count_5_size_512_interval_2 @@ -0,0 +1,11 @@ +PING 10.10.10.11 (10.10.10.11): 56 data bytes +64 bytes from 10.10.10.11: icmp_seq=0 ttl=64 time=18.041 ms +64 bytes from 10.10.10.11: icmp_seq=1 ttl=64 time=15.710 ms +64 bytes from 10.10.10.11: icmp_seq=0 ttl=64 time=16.051 ms +64 bytes from 10.10.10.11: icmp_seq=0 ttl=64 time=17.024 ms +64 bytes from 10.10.10.11: icmp_seq=0 ttl=64 time=20.090 ms + + +--- 10.10.10.11 ping statistics --- +5 packets transmitted, 5 packets received, 0% packet loss +round-trip min/avg/max/stddev = 18.710/17.876/20.041/2.165 ms diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.12_count_5_do-not-fragment_rapid b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.12_count_5_do-not-fragment_rapid new file mode 100644 index 000000000..26d6e8ee0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.12_count_5_do-not-fragment_rapid @@ -0,0 +1,5 @@ +PING 8.8.8.8 (8.8.8.8): 56 data bytes +!!!!! +--- 8.8.8.8 ping statistics --- +5 packets transmitted, 5 packets received, 0% packet loss +round-trip min/avg/max/stddev = 2.587/2.631/2.740/0.058 ms diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.20_count_4 b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.20_count_4 new file mode 100644 index 000000000..70cff3bc9 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_ping_ping_10.10.10.20_count_4 @@ -0,0 +1,4 @@ +PING 10.10.10.20 (10.10.10.20): 56 data bytes + +--- 10.10.10.20 ping statistics --- +4 packets transmitted, 0 packets received, 100% packet loss diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_prefix_lists_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_prefix_lists_config.cfg new file mode 100644 index 000000000..2a171419a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_prefix_lists_config.cfg @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <policy-options> + <prefix-list> + <name>customer_64510</name> + </prefix-list> + <prefix-list> + <name>customer_64500</name> + <dynamic-db/> + <prefix-list-item> + <name>172.16.1.16/28</name> + </prefix-list-item> + <prefix-list-item> + <name>172.16.1.32/28</name> + </prefix-list-item> + </prefix-list> + </policy-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_routing_instances_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_routing_instances_config.cfg new file mode 100644 index 000000000..afd7b91dc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_routing_instances_config.cfg @@ -0,0 +1,32 @@ +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <policy-options> + <policy-statement> + <name>test-policy</name> + <term> + <name>t1</name> + <then> + <reject/> + </then> + </term> + </policy-statement> + <policy-statement> + <name>test-policy-1</name> + <term> + <name>t1</name> + <then> + <reject/> + </then> + </term> + </policy-statement> + </policy-options> + <routing-instances> + <instance> + <name>forwardinst</name> + <description>Configured by Ansible Content Team</description> + <instance-type>forwarding</instance-type> + </instance> + </routing-instances> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_routing_options_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_routing_options_config.cfg new file mode 100644 index 000000000..f852d95a6 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_routing_options_config.cfg @@ -0,0 +1,13 @@ +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <routing-options> + <router-id>12.12.12.12</router-id> + <autonomous-system> + <as-number>2</as-number> + <loops>4</loops> + <asdot-notation/> + </autonomous-system> + </routing-options> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_security_policies_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_security_policies_config.cfg new file mode 100644 index 000000000..c61ab77ad --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_security_policies_config.cfg @@ -0,0 +1,172 @@ +<rpc-reply> + <configuration> + <security> + <policies> + <policy> + <from-zone-name>one</from-zone-name> + <to-zone-name>two</to-zone-name> + <policy> + <name>test_policy_1</name> + <match> + <source-address>a1</source-address> + <source-address>a3</source-address> + <destination-address>a2</destination-address> + <destination-address>a4</destination-address> + <source-address-excluded /> + <destination-address-excluded /> + <application>junos-dhcp-relay</application> + <application>junos-finger</application> + <source-identity>authenticated-user</source-identity> + <source-identity>unknown-user</source-identity> + <source-identity>any</source-identity> + <source-identity>unauthenticated-user</source-identity> + <source-identity>test</source-identity> + <source-end-user-profile> + <source-end-user-profile-name>test_end_user_profile</source-end-user-profile-name> + </source-end-user-profile> + <dynamic-application>any</dynamic-application> + <dynamic-application>none</dynamic-application> + <dynamic-application>test</dynamic-application> + <url-category>Enhanced_Web_Chat</url-category> + <url-category>any</url-category> + <url-category>none</url-category> + <url-category>Enhanced_Web_Collaboration</url-category> + </match> + <then> + <deny /> + <log> + <session-close /> + </log> + <count></count> + </then> + </policy> + <policy> + <name>test_policy_2</name> + <match> + <source-address>a1</source-address> + <destination-address>a2</destination-address> + <application>junos-dhcp-relay</application> + </match> + <then> + <reject> + <profile>test_dyn_app</profile> + <ssl-proxy> + <profile-name>SECURITY-SSL-PROXY</profile-name> + </ssl-proxy> + </reject> + </then> + </policy> + </policy> + <policy> + <from-zone-name>one</from-zone-name> + <to-zone-name>three</to-zone-name> + <policy> + <name>test_policy_3</name> + <match> + <source-address>any</source-address> + <source-address>any-ipv6</source-address> + <source-address>any-ipv4</source-address> + <destination-address>any</destination-address> + <destination-address>any-ipv4</destination-address> + <destination-address>any-ipv6</destination-address> + <application>any</application> + </match> + <then> + <permit> + <firewall-authentication> + <web-authentication> + <client-match>FWClient1</client-match> + <client-match>FWClient2</client-match> + </web-authentication> + <pass-through> + <access-profile>WEBAUTH</access-profile> + <auth-only-browser /> + <auth-user-agent>Opera1</auth-user-agent> + <client-match>test-client</client-match> + <ssl-termination-profile>test_ssl_term</ssl-termination-profile> + <web-redirect /> + <web-redirect-to-https /> + </pass-through> + <user-firewall> + <access-profile>WEBAUTH</access-profile> + <auth-only-browser /> + <auth-user-agent>Opera1</auth-user-agent> + <client-match>test-client</client-match> + <ssl-termination-profile>test_ssl_term</ssl-termination-profile> + <web-redirect /> + <domain>test</domain> + <web-redirect-to-https /> + </user-firewall> + <push-to-identity-management /> + </firewall-authentication> + <destination-address> + <drop-untranslated /> + </destination-address> + <application-services> + <gprs-gtp-profile>gtp1</gprs-gtp-profile> + <gprs-sctp-profile>sctp1</gprs-sctp-profile> + <idp-policy>test_idp</idp-policy> + <ssl-proxy> + <profile-name>SECURITY-SSL-PROXY</profile-name> + </ssl-proxy> + <uac-policy> + <captive-portal>test</captive-portal> + </uac-policy> + <idp /> + <utm-policy>test_utm</utm-policy> + <icap-redirect>test_icap</icap-redirect> + <application-traffic-control> + <rule-set>test_traffic_control</rule-set> + </application-traffic-control> + <reverse-redirect-wx /> + <redirect-wx /> + <security-intelligence-policy>test</security-intelligence-policy> + <advanced-anti-malware-policy>test_anti_malware</advanced-anti-malware-policy> + </application-services> + <tcp-options> + <initial-tcp-mss>64</initial-tcp-mss> + <reverse-tcp-mss>64</reverse-tcp-mss> + <window-scale /> + <sequence-check-required /> + <syn-check-required /> + </tcp-options> + <tunnel> + <ipsec-vpn>test</ipsec-vpn> + <pair-policy>test</pair-policy> + </tunnel> + </permit> + </then> + </policy> + </policy> + <global> + <policy> + <name>test_glob_1</name> + <match> + <source-address>a1</source-address> + <destination-address>a2</destination-address> + <application>junos-dhcp-relay</application> + </match> + <then> + <deny /> + <log> + <session-init /> + </log> + </then> + </policy> + <policy> + <name>test_glob_2</name> + <match> + <source-address>a1</source-address> + <destination-address>a2</destination-address> + <application>junos-dhcp-relay</application> + </match> + <then> + <deny /> + </then> + </policy> + </global> + </policies> + </security> + </configuration> + <database-status-information></database-status-information> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_security_policies_global_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_security_policies_global_config.cfg new file mode 100644 index 000000000..d0b370f8a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_security_policies_global_config.cfg @@ -0,0 +1,41 @@ +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <policies> + <traceoptions> + <no-remote-trace /> + <file> + <size>10k</size> + <files>3</files> + <no-world-readable /> + <match>/[A-Z]*/gm</match> + </file> + <flag> + <name>lookup</name> + </flag> + </traceoptions> + <default-policy> + <permit-all /> + </default-policy> + <policy-rematch> + <extensive /> + </policy-rematch> + <policy-stats> + <system-wide>enable</system-wide> + </policy-stats> + <pre-id-default-policy> + <then> + <log> + <session-init /> + </log> + <session-timeout> + <icmp>10</icmp> + <others>10</others> + </session-timeout> + </then> + </pre-id-default-policy> + </policies> + </security> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_security_zones_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_security_zones_config.cfg new file mode 100644 index 000000000..4c346a09f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_security_zones_config.cfg @@ -0,0 +1,137 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <zones> + <functional-zone> + <management> + <description>test description</description> + <host-inbound-traffic> + <protocols> + <name>all</name> + </protocols> + <protocols> + <name>bgp</name> + <except /> + </protocols> + <system-services> + <name>all</name> + </system-services> + <system-services> + <name>dhcp</name> + <except /> + </system-services> + </host-inbound-traffic> + <interfaces> + <name>ge-0/0/1.0</name> + </interfaces> + <interfaces> + <name>ge-0/0/2.0</name> + </interfaces> + <screen>test_screen</screen> + </management> + </functional-zone> + <security-zone> + <name>test_sec_zone1</name> + <address-book> + <address> + <name>test_adr1</name> + <ip-prefix>10.0.0.0/24</ip-prefix> + <description>test desc</description> + </address> + <address> + <name>test_adr2</name> + <dns-name> + <name>1.1.1.1</name> + <ipv6-only /> + </dns-name> + </address> + <address> + <name>test_adr3</name> + <range-address> + <name>10.2.0.1</name> + <to> + <range-high>10.2.0.2</range-high> + </to> + </range-address> + </address> + <address> + <name>test_adr4</name> + <wildcard-address> + <name>10.3.0.1/24</name> + </wildcard-address> + </address> + <address> + <name>test_adr5</name> + <ip-prefix>10.1.0.0/24</ip-prefix> + <description>test desc</description> + </address> + <address-set> + <name>test_adrset1</name> + <address> + <name>test_adr1</name> + </address> + <address> + <name>test_adr2</name> + </address> + </address-set> + <address-set> + <name>test_adrset2</name> + <address> + <name>test_adr3</name> + </address> + <address> + <name>test_adr4</name> + </address> + </address-set> + <address-set> + <name>test_adrset3</name> + <address> + <name>test_adr5</name> + </address> + <address-set> + <name>test_adrset1</name> + </address-set> + <address-set> + <name>test_adrset2</name> + </address-set> + <description>test description</description> + </address-set> + </address-book> + <advance-policy-based-routing-profile> + <profile>test_profile</profile> + </advance-policy-based-routing-profile> + <application-tracking /> + <description>test description</description> + <enable-reverse-reroute /> + <host-inbound-traffic> + <protocols> + <name>all</name> + </protocols> + <protocols> + <name>bgp</name> + <except /> + </protocols> + <system-services> + <name>all</name> + </system-services> + <system-services> + <name>dhcp</name> + <except /> + </system-services> + </host-inbound-traffic> + <interfaces> + <name>ge-0/0/3.0</name> + </interfaces> + <interfaces> + <name>ge-0/0/4.0</name> + </interfaces> + <screen>test_screen</screen> + <source-identity-log /> + <tcp-rst /> + </security-zone> + </zones> + </security> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_snmp_server_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_snmp_server_config.cfg new file mode 100644 index 000000000..01f821eaf --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_snmp_server_config.cfg @@ -0,0 +1,38 @@ +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <snmp> + <client-list> + <name>cl1</name> + <client-address-list> + <name>192.16.1.0/24</name> + </client-address-list> + <client-address-list> + <name>192.16.2.0/24</name> + </client-address-list> + <client-address-list> + <name>11.11.11.11/32</name> + <restrict/> + </client-address-list> + </client-list> + <client-list> + <name>cl2</name> + <client-address-list> + <name>192.16.4.0/24</name> + </client-address-list> + </client-list> + <routing-instance-access> + <access-list> + <name>clv1</name> + </access-list> + <access-list> + <name>clv2</name> + </access-list> + </routing-instance-access> + <arp> + <host-name-resolution/> + </arp> + </snmp> + + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_vlans_config.cfg b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_vlans_config.cfg new file mode 100644 index 000000000..ff54e6e79 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/junos_vlans_config.cfg @@ -0,0 +1,11 @@ +<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <vlans> + <vlan> + <name>vlan1</name> + <vlan-id>1</vlan-id> + </vlan> + </vlans> + </configuration> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/load_configuration_xml.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/load_configuration_xml.txt new file mode 100644 index 000000000..72ba03fcc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/load_configuration_xml.txt @@ -0,0 +1,6 @@ +<rpc-reply> + <load-configuration-results> + <load-success/> + <load-error-count>0</load-error-count> + </load-configuration-results> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_chassis_hardware_xml.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_chassis_hardware_xml.txt new file mode 100644 index 000000000..a0853b8cf --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_chassis_hardware_xml.txt @@ -0,0 +1,26 @@ +<rpc-reply> + <chassis-inventory> + <chassis> + <name>Chassis</name> + <serial-number>adc382ed18b0</serial-number> + <description>VSRX</description> + <chassis-module> + <name>Midplane</name> + </chassis-module> + <chassis-module> + <name>System IO</name> + </chassis-module> + <chassis-module> + <name>Routing Engine</name> + <description>VSRX RE</description> + </chassis-module> + <chassis-module> + <name>FPC 0</name> + <description>Virtual FPC</description> + </chassis-module> + <chassis-module> + <name>Power Supply 0</name> + </chassis-module> + </chassis> + </chassis-inventory> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_chassis_routing-engine_xml.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_chassis_routing-engine_xml.txt new file mode 100644 index 000000000..ccdcaca2e --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_chassis_routing-engine_xml.txt @@ -0,0 +1,52 @@ +<rpc-reply> + <route-engine-information> + <route-engine> + <slot>0</slot> + <mastership-state>master</mastership-state> + <mastership-priority>master (default)</mastership-priority> + <status>OK</status> + <temperature>30 degrees C / 86 degrees F</temperature> + <cpu-temperature>27 degrees C / 80 degrees F</cpu-temperature> + <memory-dram-size>16349 MB</memory-dram-size> + <memory-installed-size>(16384 MB installed)</memory-installed-size> + <memory-buffer-utilization>16</memory-buffer-utilization> + <cpu-user>3</cpu-user> + <cpu-background>0</cpu-background> + <cpu-system>5</cpu-system> + <cpu-interrupt>1</cpu-interrupt> + <cpu-idle>92</cpu-idle> + <model>RE-S-EX9200-1800X4</model> + <serial-number>0123456789</serial-number> + <start-time>2017-04-27 12:25:03 PDT</start-time> + <up-time>139 days, 3 hours, 12 minutes, 35 seconds</up-time> + <last-reboot-reason>Router rebooted after a normal shutdown.</last-reboot-reason> + <load-average-one>0.03</load-average-one> + <load-average-five>0.06</load-average-five> + <load-average-fifteen>0.02</load-average-fifteen> + </route-engine> + <route-engine> + <slot>1</slot> + <mastership-state>backup</mastership-state> + <mastership-priority>backup (default)</mastership-priority> + <status>OK</status> + <temperature>30 degrees C / 86 degrees F</temperature> + <cpu-temperature>27 degrees C / 80 degrees F</cpu-temperature> + <memory-dram-size>16349 MB</memory-dram-size> + <memory-installed-size>(16384 MB installed)</memory-installed-size> + <memory-buffer-utilization>10</memory-buffer-utilization> + <cpu-user>0</cpu-user> + <cpu-background>0</cpu-background> + <cpu-system>0</cpu-system> + <cpu-interrupt>0</cpu-interrupt> + <cpu-idle>100</cpu-idle> + <model>RE-S-EX9200-1800X4</model> + <serial-number>0123456789</serial-number> + <start-time>2017-09-13 10:24:59 PDT</start-time> + <up-time>5 hours, 12 minutes, 36 seconds</up-time> + <last-reboot-reason>Router rebooted after a normal shutdown.</last-reboot-reason> + <load-average-one>0.00</load-average-one> + <load-average-five>0.00</load-average-five> + <load-average-fifteen>0.00</load-average-fifteen> + </route-engine> + </route-engine-information> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_interfaces_details_xml.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_interfaces_details_xml.txt new file mode 100644 index 000000000..800cec058 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_interfaces_details_xml.txt @@ -0,0 +1,25 @@ +<rpc-reply> + <interface-information> + <physical-interface> + <name>em0</name> + <admin-status>up</admin-status> + <oper-status>up</oper-status> + <local-index>8</local-index> + <snmp-index>17</snmp-index> + <generation>1</generation> + <if-type>Ethernet</if-type> + <link-level-type>Ethernet</link-level-type> + <mtu>1514</mtu> + <speed>1000mbps</speed> + <clocking>Unspecified</clocking> + <physical-information>Unspecified</physical-information> + <up-hold-time>0</up-hold-time> + <down-hold-time>0</down-hold-time> + <current-physical-address>52:54:00:8a:af:30</current-physical-address> + <hardware-physical-address>52:54:00:8a:af:30</hardware-physical-address> + <alternate-physical-address>Unspecified</alternate-physical-address> + <interface-flapped>Never</interface-flapped> + <statistics-cleared>Never</statistics-cleared> + </physical-interface> + </interface-information> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_system_memory_xml.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_system_memory_xml.txt new file mode 100644 index 000000000..1b4202ea3 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_system_memory_xml.txt @@ -0,0 +1,20 @@ +<rpc-reply> + <system-memory-information> + <system-memory-summary-information> + <system-memory-total> 983500</system-memory-total> + <system-memory-total-percent>100%</system-memory-total-percent> + <system-memory-reserved> 17844</system-memory-reserved> + <system-memory-reserved-percent> 1%</system-memory-reserved-percent> + <system-memory-wired> 67284</system-memory-wired> + <system-memory-wired-percent> 6%</system-memory-wired-percent> + <system-memory-active> 148268</system-memory-active> + <system-memory-active-percent> 15%</system-memory-active-percent> + <system-memory-inactive> 288908</system-memory-inactive> + <system-memory-inactive-percent> 29%</system-memory-inactive-percent> + <system-memory-cache> 260500</system-memory-cache> + <system-memory-cache-percent> 26%</system-memory-cache-percent> + <system-memory-free> 200684</system-memory-free> + <system-memory-free-percent> 20%</system-memory-free-percent> + </system-memory-summary-information> + </system-memory-information> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_system_storage_xml.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_system_storage_xml.txt new file mode 100644 index 000000000..abe6a0337 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_system_storage_xml.txt @@ -0,0 +1,20 @@ +<rpc-reply> + <system-storage-information> + <filesystem> + <filesystem-name>/dev/vtbd0s1a</filesystem-name> + <total-blocks>1025132</total-blocks> + <used-blocks>583460</used-blocks> + <available-blocks>359664</available-blocks> + <used-percent> 62</used-percent> + <mounted-on>/</mounted-on> + </filesystem> + <filesystem> + <filesystem-name>devfs</filesystem-name> + <total-blocks>2</total-blocks> + <used-blocks>2</used-blocks> + <available-blocks>0</available-blocks> + <used-percent>100</used-percent> + <mounted-on>/dev</mounted-on> + </filesystem> + </system-storage-information> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_version_json.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_version_json.txt new file mode 100644 index 000000000..8209fc219 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_version_json.txt @@ -0,0 +1,42 @@ +<rpc-reply message-id="urn:uuid:aefb88cb-c296-4925-b298-ec69a6d61897"> +{ + "software-information" : [ + { + "host-name" : [ + { + "data" : "vsrx01" + } + ], + "product-model" : [ + { + "data" : "vSRX" + } + ], + "product-name" : [ + { + "data" : "vsrx" + } + ], + "junos-version" : [ + { + "data" : "15.1X49-D15.4" + } + ], + "package-information" : [ + { + "name" : [ + { + "data" : "junos" + } + ], + "comment" : [ + { + "data" : "JUNOS Software Release [15.1X49-D15.4]" + } + ] + } + ] + } + ] + } +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_version_text.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_version_text.txt new file mode 100644 index 000000000..ce2ded136 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_version_text.txt @@ -0,0 +1,8 @@ +<rpc-reply message-id="urn:uuid:0693e4e3-4208-4912-a51e-2e509be7d2d0"> + <output> + Hostname: vsrx01 + Model: vSRX + Junos: 15.1X49-D15.4 + JUNOS Software Release [15.1X49-D15.4] + </output> + </rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_version_xml.txt b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_version_xml.txt new file mode 100644 index 000000000..b5656293f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/fixtures/show_version_xml.txt @@ -0,0 +1,12 @@ +<rpc-reply message-id="urn:uuid:b7ee75e1-e043-4284-a4d5-8e2e8028dbc7"> + <software-information> + <host-name>vsrx01</host-name> + <product-model>vSRX</product-model> + <product-name>vsrx</product-name> + <junos-version>15.1X49-D15.4</junos-version> + <package-information> + <name>junos</name> + <comment>JUNOS Software Release [15.1X49-D15.4]</comment> + </package-information> + </software-information> +</rpc-reply> diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/junos_module.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/junos_module.py new file mode 100644 index 000000000..fe4c37b33 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/junos_module.py @@ -0,0 +1,105 @@ +# (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 + +import json +import os + + +try: + from lxml.etree import parse +except ImportError: + from xml.etree.ElementTree import parse + +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import ( + AnsibleExitJson, + AnsibleFailJson, + ModuleTestCase, +) + + +fixture_path = os.path.join(os.path.dirname(__file__), "fixtures") +fixture_data = {} + + +def load_fixture(name, content="xml"): + path = os.path.join(fixture_path, name) + if path in fixture_data: + return fixture_data[path] + + if content == "str": + with open(path) as f: + data = f.read() + try: + data = json.load(path) + except Exception: + pass + else: + try: + data = parse(path).getroot() + except Exception: + pass + + fixture_data[path] = data + return data + + +class TestJunosModule(ModuleTestCase): + def execute_module( + self, + failed=False, + changed=False, + commands=None, + sort=True, + defaults=False, + format="text", + ): + + self.load_fixtures(commands, format, changed=changed) + + if failed: + result = self.failed() + self.assertTrue(result["failed"], result) + else: + result = self.changed(changed) + self.assertEqual(result["changed"], changed, result) + + 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, format=None, changed=None): + pass diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py new file mode 100644 index 000000000..f28cb61a0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_address_family.py @@ -0,0 +1,3089 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_bgp_address_family +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosBgp_address_familyModule(TestJunosModule): + module = junos_bgp_address_family + + def setUp(self): + super(TestJunosBgp_address_familyModule, self).setUp() + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.bgp_address_family.bgp_address_family.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.bgp_address_family.bgp_address_family.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.bgp_address_family.bgp_address_family." + "Bgp_address_familyFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosBgp_address_familyModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + if filename: + output = load_fixture(filename) + else: + output = load_fixture("junos_bgp_address_family_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def test_junos_bgp_address_family_parsed(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <preference>2</preference> + <hold-time>5</hold-time> + <advertise-inactive/> + <out-delay>10</out-delay> + <family> + <inet> + <unicast> + <local-ipv4-address>9.9.9.9</local-ipv4-address> + <extended-nexthop/> + <extended-nexthop-color/> + </unicast> + <flow> + <loops> + <loops>4</loops> + </loops> + <no-install/> + <output-queue-priority> + <expedited/> + </output-queue-priority> + <legacy-redirect-ip-action> + <receive/> + <send/> + </legacy-redirect-ip-action> + <secondary-independent-resolution/> + </flow> + <any> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>99</limit-threshold> + <idle-timeout> + <timeout>2000</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <delay-route-advertisements> + <minimum-delay> + <routing-uptime>23000</routing-uptime> + <inbound-convergence>32000</inbound-convergence> + </minimum-delay> + <maximum-delay> + <route-age>20</route-age> + <routing-uptime>32000</routing-uptime> + </maximum-delay> + </delay-route-advertisements> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + <graceful-restart> + <forwarding-state-bit>from-fib</forwarding-state-bit> + </graceful-restart> + </any> + <labeled-unicast> + <prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>99</limit-threshold> + <idle-timeout> + <forever/> + </idle-timeout> + </teardown> + </prefix-limit> + <route-refresh-priority> + <priority>3</priority> + </route-refresh-priority> + <per-prefix-label/> + <per-group-label/> + <rib> + <inet.3/> + </rib> + <explicit-null> + <connected-only/> + </explicit-null> + <resolve-vpn/> + <entropy-label> + <no-next-hop-validation/> + </entropy-label> + </labeled-unicast> + </inet> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2000, + "limit_threshold": 99, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "delay_route_advertisements": { + "max_delay_route_age": 20, + "max_delay_routing_uptime": 32000, + "min_delay_inbound_convergence": 32000, + "min_delay_routing_uptime": 23000, + }, + "graceful_restart_forwarding_state_bit": "from-fib", + "type": "any", + }, + { + "legacy_redirect_ip_action": { + "receive": True, + "send": True, + }, + "loops": 4, + "no_install": True, + "output_queue_priority_expedited": True, + "secondary_independent_resolution": True, + "type": "flow", + }, + { + "entropy_label": {"no_next_hop_validation": True}, + "explicit_null": {"connected_only": True}, + "per_group_label": True, + "per_prefix_label": True, + "prefix_limit": { + "forever": True, + "limit_threshold": 99, + "maximum": 20, + }, + "resolve_vpn": True, + "rib": "inet.3", + "route_refresh_priority_priority": 3, + "type": "labeled-unicast", + }, + { + "extended_nexthop": True, + "extended_nexthop_color": True, + "local_ipv4_address": "9.9.9.9", + "type": "unicast", + }, + ], + "afi": "inet", + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_groups_single_entry_parsed(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <group> + <name>internal</name> + <out-delay>12</out-delay> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "groups": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "name": "internal", + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_groups_multiple_entry_parsed(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <group> + <name>internal</name> + <out-delay>12</out-delay> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + </group> + <group> + <name>external</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + <peer-as>65438</peer-as> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "groups": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "name": "internal", + }, + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "name": "external", + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_groups_neighbors_single_entry_parsed( + self, + ): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <group> + <name>internal</name> + <out-delay>12</out-delay> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + </group> + <group> + <name>external</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + <peer-as>65438</peer-as> + <neighbor> + <name>10.10.10.1</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + </teardown> + </accepted-prefix-limit> + </signaling> + </evpn> + </family> + </neighbor> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "groups": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "name": "internal", + }, + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "name": "external", + "neighbors": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "limit_threshold": 98, + "maximum": 20, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "neighbor_address": "10.10.10.1", + }, + ], + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_groups_neighbors_multiple_entry_parsed( + self, + ): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <group> + <name>internal</name> + <out-delay>12</out-delay> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + </group> + <group> + <name>external</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + <peer-as>65438</peer-as> + <neighbor> + <name>10.10.10.1</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + </teardown> + </accepted-prefix-limit> + </signaling> + </evpn> + </family> + </neighbor> + <neighbor> + <name>10.10.10.10</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + </teardown> + </accepted-prefix-limit> + </signaling> + </evpn> + </family> + </neighbor> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "groups": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "name": "internal", + }, + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "name": "external", + "neighbors": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "limit_threshold": 98, + "maximum": 20, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "neighbor_address": "10.10.10.1", + }, + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "limit_threshold": 98, + "maximum": 20, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "neighbor_address": "10.10.10.10", + }, + ], + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_single_groups_neighbors_multiple_entry_parsed( + self, + ): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <group> + <name>external</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + <peer-as>65438</peer-as> + <neighbor> + <name>10.10.10.1</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + </teardown> + </accepted-prefix-limit> + </signaling> + </evpn> + </family> + </neighbor> + <neighbor> + <name>10.10.10.10</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + </teardown> + </accepted-prefix-limit> + </signaling> + </evpn> + </family> + </neighbor> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "groups": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "name": "external", + "neighbors": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "limit_threshold": 98, + "maximum": 20, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "neighbor_address": "10.10.10.1", + }, + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "limit_threshold": 98, + "maximum": 20, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "neighbor_address": "10.10.10.10", + }, + ], + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_single_groups_neighbors_single_entry_parsed( + self, + ): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <group> + <name>external</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + <inet> + <any> + <withdraw-priority> + <expedited/> + </withdraw-priority> + </any> + </inet> + </family> + <peer-as>65438</peer-as> + <neighbor> + <name>10.10.10.1</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + </teardown> + </accepted-prefix-limit> + </signaling> + </evpn> + </family> + </neighbor> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "groups": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + { + "af_type": [ + { + "type": "any", + "withdraw_priority_expedited": True, + }, + ], + "afi": "inet", + }, + ], + "name": "external", + "neighbors": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "limit_threshold": 98, + "maximum": 20, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "neighbor_address": "10.10.10.1", + }, + ], + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_single_groups_withdrow_priority_parser( + self, + ): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <group> + <name>external</name> + <family> + <inet> + <any> + <withdraw-priority> + <priority>13</priority> + </withdraw-priority> + </any> + </inet> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + </signaling> + </evpn> + </family> + <peer-as>65438</peer-as> + <neighbor> + <name>10.10.10.1</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + </teardown> + </accepted-prefix-limit> + </signaling> + </evpn> + </family> + </neighbor> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "groups": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + { + "af_type": [ + { + "type": "any", + "withdraw_priority_priority": 13, + }, + ], + "afi": "inet", + }, + ], + "name": "external", + "neighbors": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "limit_threshold": 98, + "maximum": 20, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "neighbor_address": "10.10.10.1", + }, + ], + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_single_groups_add_path_parser(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <group> + <name>external</name> + <family> + <inet> + <any> + <withdraw-priority> + <priority>13</priority> + </withdraw-priority> + </any> + <labeled-unicast> + <traffic-statistics> + </traffic-statistics> + </labeled-unicast> + </inet> + <inet6> + <unicast> + <topology> + <name>12</name> + <community>cm123</community> + </topology> + <topology> + <name>12</name> + <community>cm1123</community> + </topology> + </unicast> + </inet6> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + <add-path> + <receive/> + <send> + <multipath/> + <include-backup-path>1</include-backup-path> + <path-count>10</path-count> + <prefix-policy>customer65443</prefix-policy> + <path-selection-mode> + <all-paths/> + <equal-cost-paths/> + </path-selection-mode> + </send> + </add-path> + </signaling> + </evpn> + </family> + <peer-as>65438</peer-as> + <neighbor> + <name>10.10.10.1</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + </teardown> + </accepted-prefix-limit> + </signaling> + </evpn> + </family> + </neighbor> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "groups": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "add_path": { + "receive": True, + "send": { + "multipath": True, + "include_backup_path": 1, + "path_count": 10, + "prefix_policy": "customer65443", + "path_selection_mode": { + "all_paths": True, + "equal_cost_paths": True, + }, + }, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + { + "af_type": [ + { + "type": "any", + "withdraw_priority_priority": 13, + }, + { + "traffic_statistics": {"set": True}, + "type": "labeled-unicast", + }, + ], + "afi": "inet", + }, + { + "af_type": [ + { + "topology": [ + { + "community": ["cm123", "cm1123"], + "name": "12", + }, + ], + "type": "unicast", + }, + ], + "afi": "inet6", + }, + ], + "name": "external", + "neighbors": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "limit_threshold": 98, + "maximum": 20, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "neighbor_address": "10.10.10.1", + }, + ], + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_single_groups_add_path_nested_parser( + self, + ): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <group> + <name>external</name> + <family> + <inet> + <any> + <withdraw-priority> + <priority>13</priority> + </withdraw-priority> + </any> + <labeled-unicast> + <traffic-statistics> + <interval>10</interval> + <labeled-path/> + <file> + <files>2</files> + <no-world-readable/> + <size>12</size> + <world-readable/> + </file> + </traffic-statistics> + </labeled-unicast> + </inet> + <inet6> + <unicast> + <topology> + <name>12</name> + <community>cm123</community> + </topology> + </unicast> + </inet6> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + <idle-timeout> + <timeout>2001</timeout> + </idle-timeout> + </teardown> + </accepted-prefix-limit> + <damping/> + <defer-initial-multipath-build> + <maximum-delay>2</maximum-delay> + </defer-initial-multipath-build> + <add-path> + <receive/> + <send> + <multipath/> + <include-backup-path>1</include-backup-path> + <path-count>10</path-count> + <prefix-policy>customer65443</prefix-policy> + <path-selection-mode> + <all-paths/> + <equal-cost-paths/> + </path-selection-mode> + </send> + </add-path> + </signaling> + </evpn> + </family> + <peer-as>65438</peer-as> + <neighbor> + <name>10.10.10.1</name> + <family> + <evpn> + <signaling> + <accepted-prefix-limit> + <maximum>20</maximum> + <teardown> + <limit-threshold>98</limit-threshold> + </teardown> + </accepted-prefix-limit> + </signaling> + </evpn> + </family> + </neighbor> + </group> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "groups": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "idle_timeout_value": 2001, + "limit_threshold": 98, + "maximum": 20, + }, + "damping": True, + "defer_initial_multipath_build": { + "maximum_delay": 2, + }, + "add_path": { + "receive": True, + "send": { + "multipath": True, + "include_backup_path": 1, + "path_count": 10, + "prefix_policy": "customer65443", + "path_selection_mode": { + "all_paths": True, + "equal_cost_paths": True, + }, + }, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + { + "af_type": [ + { + "type": "any", + "withdraw_priority_priority": 13, + }, + { + "traffic_statistics": { + "interval": 10, + "file": { + "files": 2, + "size": 12, + "world_readable": True, + "no_world_readable": True, + }, + }, + "type": "labeled-unicast", + }, + ], + "afi": "inet", + }, + { + "af_type": [ + { + "topology": [ + {"community": ["cm123"], "name": "12"}, + ], + "type": "unicast", + }, + ], + "afi": "inet6", + }, + ], + "name": "external", + "neighbors": [ + { + "address_family": [ + { + "af_type": [ + { + "accepted_prefix_limit": { + "limit_threshold": 98, + "maximum": 20, + }, + "type": "signaling", + }, + ], + "afi": "evpn", + }, + ], + "neighbor_address": "10.10.10.1", + }, + ], + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_address_family_config_001(self): + """ + This function generate the commands to configure attributes: + - af_type + - afi + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="evpn", + af_type=[dict(type="signaling", set=True)], + ), + ], + ), + state="merged", + ), + ) + + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:evpn><nc:signaling/></nc:evpn></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_002(self): + """ + This function generate the commands to configure attributes: + - accepted_prefix_limit + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="evpn", + af_type=[ + dict( + type="signaling", + accepted_prefix_limit=dict( + limit_threshold=98, + idle_timeout_value=2001, + maximum=20, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:evpn><nc:signaling><nc:accepted-prefix-limit>" + "<nc:maximum>20</nc:maximum><nc:teardown><nc:limit-threshold>98</nc:limit-threshold>" + "<nc:idle-timeout><nc:timeout>2001</nc:timeout></nc:idle-timeout></nc:teardown>" + "</nc:accepted-prefix-limit></nc:signaling></nc:evpn></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_002_001(self): + """ + This function generate the commands to configure attributes: + - accepted_prefix_limit + forever: true + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="evpn", + af_type=[ + dict( + type="signaling", + accepted_prefix_limit=dict( + maximum=20, + limit_threshold=98, + forever=True, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:evpn><nc:signaling><nc:accepted-prefix-limit>" + "<nc:maximum>20</nc:maximum><nc:teardown><nc:limit-threshold>98</nc:limit-threshold>" + "<nc:idle-timeout/><nc:idle-timeout><nc:forever/></nc:idle-timeout></nc:teardown>" + "</nc:accepted-prefix-limit></nc:signaling></nc:evpn></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_003(self): + """ + This function generate the commands to configure attributes: + - add_path + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="evpn", + af_type=[ + dict( + type="signaling", + add_path=dict( + receive=True, + send=dict( + multipath=True, + include_backup_path=1, + path_count=10, + prefix_policy="customer65443", + path_selection_mode=dict( + all_paths=True, + equal_cost_paths=True, + ), + ), + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:evpn><nc:signaling><nc:add-path><nc:receive/>" + "<nc:send><nc:path-count>10</nc:path-count>" + "<nc:include-backup-path>1</nc:include-backup-path>" + "<nc:path-selection-mode><nc:all-paths/><nc:equal-cost-paths/>" + "</nc:path-selection-mode><nc:prefix-policy>customer65443</nc:prefix-policy></nc:send>" + "</nc:add-path></nc:signaling></nc:evpn></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_004(self): + """ + This function generate the commands to configure attributes: + - aggregate_label + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="evpn", + af_type=[ + dict( + type="signaling", + aggregate_label=dict( + set=True, + community="cuastomerapn1", + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:evpn><nc:signaling><nc:aggregate_label>" + "<nc:community>cuastomerapn1</nc:community></nc:aggregate_label>" + "</nc:signaling></nc:evpn></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_005(self): + """ + This function generate the commands to configure attributes: + - aigp + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="labeled-unicast", + aigp=dict(set=True), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:aigp/>" + "</nc:labeled-unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_005_001(self): + """ + This function generate the commands to configure attributes: + - aigp + disable: true + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="labeled-unicast", + aigp=dict(disable=True), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:aigp><nc:disable/>" + "</nc:aigp></nc:labeled-unicast></nc:inet6></nc:family></nc:bgp>" + "</nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_006(self): + """ + This function generate the commands to configure attributes: + - aigp + damping: true + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict(type="labeled-unicast", damping=True), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:damping/>" + "</nc:labeled-unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_007(self): + """ + This function generate the commands to configure attributes: + - aigp + defer_initial_multipath_build + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="labeled-unicast", + defer_initial_multipath_build=dict( + set=True, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:defer-initial-multipath-build/>" + "</nc:labeled-unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_007_001(self): + """ + This function generate the commands to configure attributes: + defer_initial_multipath_build + maximum_delay + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="labeled-unicast", + defer_initial_multipath_build=dict( + maximum_delay=1200, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:defer-initial-multipath-build>" + "<nc:maximum-delay>1200</nc:maximum-delay></nc:defer-initial-multipath-build>" + "</nc:labeled-unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_008(self): + """ + This function generate the commands to configure attributes: + - delay_route_advertisements + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="labeled-unicast", + delay_route_advertisements=dict( + set=True, + max_delay_route_age=12000, + max_delay_routing_uptime=12000, + min_delay_inbound_convergence=8000, + min_delay_routing_uptime=8000, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:delay-route-advertisements>" + "<nc:maximum-delay><nc:route-age>12000</nc:route-age><nc:routing-uptime>12000</nc:routing-uptime>" + "</nc:maximum-delay><nc:minimum-delay><nc:inbound-convergence>8000</nc:inbound-convergence>" + "<nc:routing-uptime>8000</nc:routing-uptime></nc:minimum-delay></nc:delay-route-advertisements>" + "</nc:labeled-unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_009(self): + """ + This function generate the commands to configure attributes: + - entropy_label + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="labeled-unicast", + entropy_label=dict( + set=True, + no_next_hop_validation=True, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:labeled-unicast><nc:entropy-label>" + "<nc:no-next-hop-validation/></nc:entropy-label></nc:labeled-unicast>" + "</nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_010(self): + """ + This function generate the commands to configure attributes: + - explicit_null + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="labeled-unicast", + explicit_null=dict( + set=True, + connected_only=True, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:labeled-unicast><nc:explicit-null>" + "<nc:connected-only/></nc:explicit-null></nc:labeled-unicast></nc:inet>" + "</nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_011(self): + """ + This function generate the commands to configure attributes: + - extended_nexthop + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict(type="unicast", extended_nexthop=True), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:unicast><nc:extended-nexthop/>" + "</nc:unicast></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_012(self): + """ + This function generate the commands to configure attributes: + - extended_nexthop_color + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="unicast", + extended_nexthop_color=True, + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:unicast><nc:extended-nexthop-color/>" + "</nc:unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_013(self): + """ + This function generate the commands to configure attributes: + - graceful_restart_forwarding_state_bit: from-fib + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="unicast", + graceful_restart_forwarding_state_bit="from-fib", + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:unicast><nc:graceful-restart>" + "<nc:forwarding-state-bit>from-fib</nc:forwarding-state-bit>" + "</nc:graceful-restart></nc:unicast></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_013_001(self): + """ + This function generate the commands to configure attributes: + - graceful_restart_forwarding_state_bit: set + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="unicast", + graceful_restart_forwarding_state_bit="set", + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:unicast><nc:graceful-restart>" + "<nc:forwarding-state-bit>set</nc:forwarding-state-bit></nc:graceful-restart>" + "</nc:unicast></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_014(self): + """ + This function generate the commands to configure attributes: + - local_ipv4_address + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="unicast", + local_ipv4_address="11.11.11.11", + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:bgp>' + "<nc:family><nc:inet><nc:unicast><nc:local-ipv4-address>11.11.11.11</nc:local-ipv4-address>" + "</nc:unicast></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_015(self): + """ + This function generate the commands to configure attributes: + - legacy_redirect_ip_action + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="flow", + legacy_redirect_ip_action=dict( + set=True, + send=True, + receive=True, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:flow><nc:legacy-redirect-ip-action>" + "<nc:send/><nc:receive/></nc:legacy-redirect-ip-action></nc:flow>" + "</nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_016(self): + """ + This function generate the commands to configure attributes: + - loops + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict(afi="inet", af_type=[dict(type="flow", loops=3)]), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:flow><nc:loops>3</nc:loops></nc:flow>" + "</nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_017(self): + """ + This function generate the commands to configure attributes: + - no_install + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[dict(type="flow", no_install=True)], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:flow><nc:no-install/></nc:flow></nc:inet>" + "</nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_018(self): + """ + This function generate the commands to configure attributes: + - no_validate + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[dict(type="flow", no_validate="sample")], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:flow><nc:no-validate>sample</nc:no-validate>" + "</nc:flow></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_019(self): + """ + This function generate the commands to configure attributes: + - output_queue_priority_expedited + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="flow", + output_queue_priority_expedited=True, + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:bgp>' + "<nc:family><nc:inet><nc:flow><nc:output-queue-priority><nc:expedited/>" + "</nc:output-queue-priority></nc:flow></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_020(self): + """ + This function generate the commands to configure attributes: + - output_queue_priority_priority + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="flow", + output_queue_priority_priority=15, + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:flow><nc:output-queue-priority>" + "<nc:priority>15</nc:priority></nc:output-queue-priority></nc:flow>" + "</nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_021(self): + """ + This function generate the commands to configure attributes: + - per_group_label + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="labeled-unicast", + per_group_label=True, + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:per-group-label/>" + "</nc:labeled-unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_022(self): + """ + This function generate the commands to configure attributes: + - per_prefix_label + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="labeled-unicast", + per_prefix_label=True, + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:labeled-unicast><nc:per-prefix-label/>" + "</nc:labeled-unicast></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_023(self): + """ + This function generate the commands to configure attributes: + - prefix_limit + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="labeled-unicast", + prefix_limit=dict( + maximum=4294967290, + teardown=True, + limit_threshold=22, + idle_timeout=True, + idle_timeout_value=2200, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:labeled-unicast><nc:prefix-limit>" + "<nc:maximum>4294967290</nc:maximum><nc:teardown>22<nc:idle-timeout>2200</nc:idle-timeout>" + "</nc:teardown></nc:prefix-limit></nc:labeled-unicast>" + "</nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_023_001(self): + """ + This function generate the commands to configure attributes: + - prefix_limit + forever: true + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="labeled-unicast", + prefix_limit=dict( + teardown=True, + forever=True, + ), + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:labeled-unicast><nc:prefix-limit>" + "<nc:teardown><nc:idle-timeout><nc:forever/></nc:idle-timeout></nc:teardown>" + "</nc:prefix-limit></nc:labeled-unicast></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_024(self): + """ + This function generate the commands to configure attributes: + - resolve_vpn + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict(type="labeled-unicast", resolve_vpn=True), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:labeled-unicast><nc:resolve-vpn/>" + "</nc:labeled-unicast></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_025(self): + """ + This function generate the commands to configure attributes: + - rib + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict(type="labeled-unicast", rib="inet.3"), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:rib><nc:inet.3/>" + "</nc:rib></nc:labeled-unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_026(self): + """ + This function generate the commands to configure attributes: + - ribgroup_name + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="labeled-unicast", + ribgroup_name="inet3", + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:rib-group>inet3</nc:rib-group>" + "</nc:labeled-unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_027(self): + """ + This function generate the commands to configure attributes: + - route_refresh_priority_expedited + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="labeled-unicast", + route_refresh_priority_expedited=True, + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast><nc:route-refresh-priority>" + "<nc:expedited/></nc:route-refresh-priority></nc:labeled-unicast></nc:inet6>" + "</nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_028(self): + """ + This function generate the commands to configure attributes: + - route_refresh_priority_priority + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet6", + af_type=[ + dict( + type="labeled-unicast", + route_refresh_priority_priority=15, + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet6><nc:labeled-unicast>" + "<nc:route-refresh-priority><nc:priority>15</nc:priority>" + "</nc:route-refresh-priority></nc:labeled-unicast></nc:inet6></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_029(self): + """ + This function generate the commands to configure attributes: + - secondary_independent_resolution + """ + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="flow", + secondary_independent_resolution=True, + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:family><nc:inet><nc:flow><nc:secondary-independent-resolution/>" + "</nc:flow></nc:inet></nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_030(self): + """ + This function generate the commands to configure attributes: + - groups: + address_family: + topology + """ + set_module_args( + dict( + config=dict( + groups=[ + dict( + name="ebgp", + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="unicast", + topology=[ + dict( + name="voice", + community=["target:40:40"], + ), + ], + ), + ], + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:group><nc:name>ebgp</nc:name><nc:family><nc:inet>" + "<nc:unicast><nc:topology><nc:name>voice</nc:name>" + "<nc:community>target:40:40</nc:community></nc:topology>" + "</nc:unicast></nc:inet></nc:family></nc:group><nc:family/></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_deleted_031(self): + """ + This function generate the commands to to delete bgp_address family completely: + """ + set_module_args(dict(config=dict(), state="deleted")) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:group><nc:name>internal</nc:name>" + "</nc:group><nc:group><nc:name>ebgp</nc:name><nc:family>" + '<nc:inet delete="delete"/></nc:family></nc:group>' + '<nc:family><nc:inet delete="delete"/><nc:inet6 delete="delete"/>' + "</nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_deleted_032(self): + """ + This function generate the commands to to delete bgp_address family completely: + """ + set_module_args( + dict( + config=dict( + groups=[ + dict( + name="ebgp", + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="unicast", + topology=[ + dict( + name="voice", + community=["target:40:40"], + ), + ], + ), + ], + ), + ], + ), + ], + ), + state="overridden", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:group><nc:name>internal</nc:name></nc:group>" + '<nc:family><nc:inet delete="delete"/><nc:inet6 delete="delete"/>' + "</nc:family><nc:group><nc:name>ebgp</nc:name><nc:family>" + '<nc:inet delete="delete"/></nc:family></nc:group>' + '<nc:family><nc:inet delete="delete"/><nc:inet6 delete="delete"/>' + "</nc:family><nc:group><nc:name>ebgp</nc:name><nc:family>" + "<nc:inet><nc:unicast><nc:topology><nc:name>voice</nc:name>" + "<nc:community>target:40:40</nc:community></nc:topology>" + "</nc:unicast></nc:inet></nc:family>" + "</nc:group><nc:family/></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_address_family_config_033(self): + """ + This function generate the commands to configure attributes: + - groups: + address_family: + topology + """ + set_module_args( + dict( + config=dict( + groups=[ + dict( + name="ebgp", + neighbors=[ + dict( + neighbor_address="14.14.14.14", + address_family=[ + dict( + afi="inet", + af_type=[ + dict( + type="unicast", + no_install=True, + ), + ], + ), + ], + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:group><nc:name>ebgp</nc:name><nc:family/><nc:neighbor>" + "<nc:name>14.14.14.14</nc:name><nc:family><nc:inet><nc:unicast>" + "<nc:no-install/></nc:unicast></nc:inet></nc:family></nc:neighbor>" + "</nc:group><nc:family/></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + """ + def test_junos_bgp_address_family_merged_idempotent(self): + self.get_connection.return_value = load_fixture( + "junos_bgp_address_family_config.cfg" + ) + src = load_fixture("junos_bgp_address_family.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=dict( + address_family=[ + dict( + afi="evpn", + af_type=[dict(type="flow", damping=True)], + ) + ] + ), + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_bgp_group_address_family_add(self): + set_module_args( + dict( + config=dict( + groups=[ + dict( + name="external", + address_family=[ + dict( + afi="evpn", + af_type=[dict(type="flow", damping=True)], + ) + ], + ) + ], + address_family=[ + dict( + afi="evpn", + af_type=[dict(type="flow", damping=True)], + ) + ], + ), + state="merged", + ) + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:bgp>' + "<nc:group><nc:name>external</nc:name>" + "<nc:family><nc:evpn><nc:flow><nc:damping/>" + "</nc:flow></nc:evpn></nc:family></nc:group>" + "<nc:family><nc:evpn><nc:flow><nc:damping/></nc:flow></nc:evpn>" + "</nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_bgp_group_address_family_rep(self): + set_module_args( + dict( + config=dict( + groups=[ + dict( + name="external", + address_family=[ + dict( + afi="evpn", + af_type=[dict(type="flow", damping=True)], + ) + ], + ) + ], + address_family=[ + dict( + afi="evpn", + af_type=[dict(type="flow", damping=True)], + ) + ], + ), + state="replaced", + ) + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:bgp>' + "<nc:group><nc:name>external</nc:name>" + "<nc:family><nc:evpn><nc:flow><nc:damping/>" + "</nc:flow></nc:evpn></nc:family></nc:group>" + "<nc:family><nc:evpn><nc:flow><nc:damping/></nc:flow></nc:evpn>" + "</nc:family></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_bgp_address_family_rep_idempotent(self): + self.get_connection.return_value = load_fixture( + "junos_bgp_address_family_config.cfg" + ) + src = load_fixture("junos_bgp_address_family.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=dict( + groups=[ + dict( + name="external", + address_family=[ + dict( + afi="evpn", + af_type=[dict(type="flow", damping=True)], + ) + ], + ) + ], + address_family=[ + dict( + afi="evpn", + af_type=[dict(type="flow", damping=True)], + ) + ], + ), + state="replaced", + ) + ) + + self.execute_module(changed=False, commands=[]) + """ diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py new file mode 100644 index 000000000..f1d377494 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_bgp_global.py @@ -0,0 +1,1189 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_bgp_global +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosBgp_globalModule(TestJunosModule): + module = junos_bgp_global + + def setUp(self): + super(TestJunosBgp_globalModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.bgp_global.bgp_global.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.bgp_global.bgp_global.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.bgp_global.bgp_global." + "Bgp_globalFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosBgp_globalModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + if filename: + output = load_fixture(filename) + else: + output = load_fixture("junos_bgp_global_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def test_junos_bgp_global_merged(self): + set_module_args( + dict( + config=dict( + damping=True, + description="This is configured with Junos_bgp resource module", + preference="2", + bfd_liveness_detection=dict( + minimum_receive_interval=4, + multiplier=10, + no_adaptation=True, + version="automatic", + ), + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:damping/><nc:description>This is configured with Junos_bgp resource module</nc:description>" + "<nc:preference>2</nc:preference><nc:bfd-liveness-detection>" + "<nc:minimum-receive-interval>4</nc:minimum-receive-interval>" + "<nc:multiplier>10</nc:multiplier>" + "<nc:no-adaptation/><nc:version>automatic</nc:version></nc:bfd-liveness-detection></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_idempotent(self): + set_module_args( + dict( + config=dict( + accept_remote_nexthop=True, + advertise_from_main_vpn_tables=True, + advertise_inactive=True, + as_number="65432", + authentication_algorithm="md5", + bgp_error_tolerance=dict(malformed_route_limit=30000000), + damping=True, + description="This is configured with Junos_bgp resource module", + hold_time=5, + holddown_all_stale_labels=True, + log_updown=True, + no_advertise_peer_as=True, + no_aggregator_id=True, + out_delay=10, + preference="2", + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_bgp_global_replaced(self): + """ + :return: + """ + set_module_args( + dict( + config=dict( + accept_remote_nexthop=True, + advertise_from_main_vpn_tables=True, + advertise_inactive=True, + as_number="65432", + authentication_algorithm="md5", + bgp_error_tolerance=dict(malformed_route_limit=20000000), + damping=True, + description="This is configured with Junos_bgp resource module", + groups=[ + dict(name="internal", out_delay=22), + dict(name="external", out_delay=20), + ], + hold_time=4, + holddown_all_stale_labels=True, + log_updown=True, + keep="all", + mtu_discovery=True, + no_precision_timers=True, + no_advertise_peer_as=True, + no_aggregator_id=True, + out_delay=10, + preference="2", + ), + state="replaced", + ), + ) + + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:bgp><nc:accept-remote-nexthop delete="delete"/>' + '<nc:add-path-display-ipv4-address delete="delete"/>' + '<nc:advertise-bgp-static delete="delete"/>' + '<nc:advertise-external delete="delete"/>' + '<nc:advertise-from-main-vpn-tables delete="delete"/>' + '<nc:advertise-inactive delete="delete"/>' + '<nc:advertise-peer-as delete="delete"/>' + '<nc:authentication-algorithm delete="delete"/>' + '<nc:authentication-key delete="delete"/>' + '<nc:authentication-key-chain delete="delete"/>' + '<nc:bfd-liveness-detection delete="delete"/>' + '<nc:bgp-error-tolerance delete="delete"/><nc:bmp delete="delete"/>' + '<nc:group delete="delete"/><nc:cluster delete="delete"/>' + '<nc:damping delete="delete"/><nc:description delete="delete"/>' + '<nc:disable delete="delete"/><nc:egress-te-sid-stats delete="delete"/>' + '<nc:enforce-first-as delete="delete"/><nc:export delete="delete"/>' + '<nc:forwarding-context delete="delete"/><nc:hold-time delete="delete"/>' + '<nc:holddown-all-stale-labels delete="delete"/><nc:import delete="delete"/>' + '<nc:include-mp-next-hop delete="delete"/><nc:ipsec-sa delete="delete"/>' + '<nc:keep delete="delete"/><nc:local-address delete="delete"/>' + '<nc:local-interface delete="delete"/><nc:local-preference delete="delete"/>' + '<nc:log-updown delete="delete"/><nc:mtu-discovery delete="delete"/>' + '<nc:no-advertise-peer-as delete="delete"/><nc:no-aggregator-id delete="delete"/>' + '<nc:no-client-reflect delete="delete"/><nc:no-precision-timers delete="delete"/>' + '<nc:passive delete="delete"/><nc:peer-as delete="delete"/>' + '<nc:precision-timers delete="delete"/><nc:preference delete="delete"/>' + '<nc:out-delay delete="delete"/><nc:rfc6514-compliant-safi129 delete="delete"/>' + '<nc:route-server-client delete="delete"/><nc:send-addpath-optimization delete="delete"/>' + '<nc:sr-preference-override delete="delete"/>' + '<nc:stale-labels-holddown-period delete="delete"/><nc:tcp-aggressive-transmission delete="delete"/>' + '<nc:tcp-mss delete="delete"/><nc:ttl delete="delete"/>' + '<nc:unconfigured-peer-graceful-restart delete="delete"/>' + '<nc:vpn-apply-export delete="delete"/></nc:bgp><nc:bgp>' + "<nc:accept-remote-nexthop/><nc:advertise-from-main-vpn-tables/>" + "<nc:advertise-inactive/><nc:damping/><nc:holddown-all-stale-labels/>" + "<nc:log-updown/><nc:mtu-discovery/><nc:no-advertise-peer-as/>" + "<nc:no-aggregator-id/><nc:no-precision-timers/>" + "<nc:authentication-algorithm>md5</nc:authentication-algorithm>" + "<nc:description>This is configured with Junos_bgp resource module</nc:description>" + "<nc:hold-time>4</nc:hold-time><nc:keep>all</nc:keep><nc:preference>2</nc:preference>" + "<nc:out-delay>10</nc:out-delay><nc:bgp-error-tolerance>" + "<nc:malformed-route-limit>20000000</nc:malformed-route-limit>" + "</nc:bgp-error-tolerance><nc:group><nc:name>internal</nc:name>" + "<nc:out-delay>22</nc:out-delay></nc:group><nc:group><nc:name>external</nc:name>" + "<nc:out-delay>20</nc:out-delay></nc:group></nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:autonomous-system delete="delete"/>' + "<nc:autonomous-system>65432</nc:autonomous-system></nc:routing-options>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_replaced_idempotent(self): + set_module_args( + dict( + config=dict( + accept_remote_nexthop=True, + advertise_from_main_vpn_tables=True, + advertise_inactive=True, + as_number="65432", + authentication_algorithm="md5", + bgp_error_tolerance=dict(malformed_route_limit=30000000), + damping=True, + description="This is configured with Junos_bgp resource module", + hold_time=5, + holddown_all_stale_labels=True, + log_updown=True, + no_advertise_peer_as=True, + no_aggregator_id=True, + out_delay=10, + preference="2", + ), + state="replaced", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_bgp_global_rendered(self): + """ + :return: + """ + set_module_args( + dict( + config=dict( + description="This is configured with Junos_bgp resource module", + groups=[dict(name="internal", out_delay=22)], + hold_time=4, + holddown_all_stale_labels=True, + include_mp_next_hop=True, + log_updown=True, + loops=5, + keep="all", + mtu_discovery=True, + out_delay=10, + preference="2", + ), + state="rendered", + ), + ) + + rendered = ( + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:bgp>' + "<nc:holddown-all-stale-labels/><nc:include-mp-next-hop/><nc:log-updown/>" + "<nc:mtu-discovery/>" + "<nc:description>This is configured with Junos_bgp resource module</nc:description>" + "<nc:hold-time>4</nc:hold-time><nc:keep>all</nc:keep><nc:preference>2</nc:preference>" + "<nc:out-delay>10</nc:out-delay><nc:group>" + "<nc:name>internal</nc:name><nc:out-delay>22</nc:out-delay>" + "</nc:group></nc:bgp></nc:protocols>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_bgp_global_rendered_empty(self): + """ + :return: + """ + set_module_args(dict(config=dict(description=""), state="rendered")) + rendered = "" + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_bgp_global_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_dict = { + "accept_remote_nexthop": True, + "advertise_from_main_vpn_tables": True, + "advertise_inactive": True, + "as_number": "65432", + "authentication_algorithm": "md5", + "bgp_error_tolerance": {"malformed_route_limit": "30000000"}, + "damping": True, + "description": "This is configured with Junos_bgp resource module", + "hold_time": "5", + "holddown_all_stale_labels": True, + "log_updown": True, + "no_advertise_peer_as": True, + "no_aggregator_id": True, + "out_delay": "10", + "preference": "2", + } + self.assertEqual(sorted(gather_dict), sorted(result["gathered"])) + + def test_junos_bgp_global_parsed(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <advertise-from-main-vpn-tables /> + <holddown-all-stale-labels /> + <description>This is configured with Junos_bgp resource module</description> + <accept-remote-nexthop /> + <preference>2</preference> + <hold-time>5</hold-time> + <advertise-inactive /> + <no-advertise-peer-as /> + <no-aggregator-id /> + <out-delay>10</out-delay> + <log-updown /> + <damping /> + <bgp-error-tolerance> + <malformed-route-limit>30000000</malformed-route-limit> + </bgp-error-tolerance> + <authentication-algorithm>md5</authentication-algorithm> + </bgp> + </protocols> + <routing-options> + <static> + <route> + <name>172.16.17.0/24</name> + <discard /> + </route> + </static> + <router-id>10.200.16.75</router-id> + <autonomous-system> + <as-number>65432</as-number> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "accept_remote_nexthop": "True", + "advertise_from_main_vpn_tables": "True", + "advertise_inactive": "True", + "as_number": "65534", + "authentication_algorithm": "md5", + "bgp_error_tolerance": {"malformed_route_limit": "30000000"}, + "damping": "True", + "description": "This is configured with Junos_bgp resource module", + "hold_time": "5", + "holddown_all_stale_labels": "True", + "log_updown": "true", + "no_advertise_peer_as": "true", + "no_aggregator_id": "true", + "out_delay": "10", + "preference": "2", + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_bgp_global_parsed_empty_running_config(self): + set_module_args(dict(running_config="", state="parsed")) + try: + self.execute_module(changed=False) + except Exception: + pass + + def test_junos_bgp_global_delete(self): + set_module_args(dict(config=dict(), state="deleted")) + + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:bgp><nc:accept-remote-nexthop delete="delete"/><nc:add-path-display-ipv4-address delete="delete"/>' + '<nc:advertise-bgp-static delete="delete"/><nc:advertise-external delete="delete"/>' + '<nc:advertise-from-main-vpn-tables delete="delete"/><nc:advertise-inactive delete="delete"/>' + '<nc:advertise-peer-as delete="delete"/><nc:authentication-algorithm delete="delete"/>' + '<nc:authentication-key delete="delete"/><nc:authentication-key-chain delete="delete"/>' + '<nc:bfd-liveness-detection delete="delete"/><nc:bgp-error-tolerance delete="delete"/>' + '<nc:bmp delete="delete"/><nc:group delete="delete"/><nc:cluster delete="delete"/>' + '<nc:damping delete="delete"/><nc:description delete="delete"/><nc:disable delete="delete"/>' + '<nc:egress-te-sid-stats delete="delete"/><nc:enforce-first-as delete="delete"/>' + '<nc:export delete="delete"/><nc:forwarding-context delete="delete"/>' + '<nc:hold-time delete="delete"/><nc:holddown-all-stale-labels delete="delete"/>' + '<nc:import delete="delete"/><nc:include-mp-next-hop delete="delete"/>' + '<nc:ipsec-sa delete="delete"/><nc:keep delete="delete"/><nc:local-address delete="delete"/>' + '<nc:local-interface delete="delete"/>' + '<nc:local-preference delete="delete"/><nc:log-updown delete="delete"/>' + '<nc:mtu-discovery delete="delete"/><nc:no-advertise-peer-as delete="delete"/>' + '<nc:no-aggregator-id delete="delete"/><nc:no-client-reflect delete="delete"/>' + '<nc:no-precision-timers delete="delete"/><nc:passive delete="delete"/>' + '<nc:peer-as delete="delete"/><nc:precision-timers delete="delete"/>' + '<nc:preference delete="delete"/><nc:out-delay delete="delete"/>' + '<nc:rfc6514-compliant-safi129 delete="delete"/><nc:route-server-client delete="delete"/>' + '<nc:send-addpath-optimization delete="delete"/><nc:sr-preference-override delete="delete"/>' + '<nc:stale-labels-holddown-period delete="delete"/><nc:tcp-aggressive-transmission delete="delete"/>' + '<nc:tcp-mss delete="delete"/><nc:ttl delete="delete"/>' + '<nc:unconfigured-peer-graceful-restart delete="delete"/>' + '<nc:vpn-apply-export delete="delete"/>' + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:autonomous-system delete="delete"/></nc:routing-options>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_delete_purged(self): + set_module_args(dict(config=dict(), state="purged")) + + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:bgp delete="delete"/></nc:protocols>', + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:autonomous-system delete="delete"/></nc:routing-options>', + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_routing_options(self): + """ + configure routing-options attributes: + - loops + - as_number + - asdot_notation + """ + set_module_args( + dict( + config=dict(as_number="65432", loops=5, asdot_notation=True), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp/></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:autonomous-system>65432<nc:loops>5</nc:loops><nc:asdot-notation/></nc:autonomous-system>" + "</nc:routing-options>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merge_groups(self): + """ + description: configure groups attributes: + """ + set_module_args( + dict( + config=dict( + groups=[ + dict( + name="internal", + neighbors=[ + dict( + neighbor_address="11.11.11.11", + peer_as="65534", + out_delay=11, + accept_remote_nexthop=True, + ), + dict( + neighbor_address="11.11.11.12", + peer_as="65534", + out_delay=12, + accept_remote_nexthop=True, + ), + ], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:group><nc:name>internal</nc:name>" + "<nc:neighbor><nc:name>11.11.11.11</nc:name>" + "<nc:accept-remote-nexthop/><nc:peer-as>65534</nc:peer-as>" + "<nc:out-delay>11</nc:out-delay></nc:neighbor>" + "<nc:neighbor><nc:name>11.11.11.12</nc:name><nc:accept-remote-nexthop/>" + "<nc:peer-as>65534</nc:peer-as><nc:out-delay>12</nc:out-delay></nc:neighbor></nc:group>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_advertise_bgp_static(self): + """ + configure advertise_bgp_static attributes: + """ + set_module_args( + dict( + config=dict(advertise_bgp_static=dict(policy="static-to-bgp")), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:advertise-bgp-static><nc:policy>static-to-bgp</nc:policy>" + "</nc:advertise-bgp-static>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_advertise_external(self): + """ + configure advertise_external attributes: + """ + set_module_args( + dict( + config=dict( + advertise_external=dict(set=True, conditional=True), + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:advertise-external><nc:conditional/></nc:advertise-external>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_bfd_liveness_detection(self): + """ + configure bfd_liveness_detection attributes: + """ + set_module_args( + dict( + config=dict( + bfd_liveness_detection=dict( + minimum_receive_interval=8, + no_adaptation=True, + authentication=dict( + algorithm="keyed-md5", + key_chain="junos", + loose_check=True, + ), + detection_time=dict(threshold=1000000), + transmit_interval=dict( + minimum_interval=20, + threshold=100000, + ), + holddown_interval=20, + multiplier=20, + session_mode="multihop", + version="1", + ), + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:bfd-liveness-detection><nc:authentication>" + "<nc:algorithm>keyed-md5</nc:algorithm><nc:key-chain>junos</nc:key-chain>" + "<nc:loose-check/></nc:authentication><nc:detection-time>" + "<nc:threshold>1000000</nc:threshold></nc:detection-time><nc:transmit-interval>" + "<nc:minimum-interval>20</nc:minimum-interval></nc:transmit-interval>" + "<nc:holddown-interval>20</nc:holddown-interval><nc:minimum-receive-interval>8</nc:minimum-receive-interval>" + "<nc:multiplier>20</nc:multiplier><nc:no-adaptation/>" + "<nc:session-mode>multihop</nc:session-mode>" + "<nc:version>1</nc:version></nc:bfd-liveness-detection>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_bgp_error_tolerance(self): + """ + configure bgp_error_tolerance attributes: + """ + set_module_args( + dict( + config=dict( + bgp_error_tolerance=dict( + set=True, + malformed_route_limit=10, + malformed_update_log_interval=15, + no_malformed_route_limit=True, + ), + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:bgp-error-tolerance><nc:malformed-route-limit>10</nc:malformed-route-limit>" + "<nc:malformed-update-log-interval>15</nc:malformed-update-log-interval>" + "<nc:no-malformed-route-limit/></nc:bgp-error-tolerance>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_bmp(self): + """ + configure bmp attributes: + """ + set_module_args( + dict( + config=dict( + bmp=dict( + monitor=True, + route_monitoring=dict( + none=True, + post_policy=True, + post_policy_exclude_non_eligible=True, + pre_policy=True, + post_policy_exclude_non_feasible=True, + ), + ), + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:bmp><nc:monitor>enable</nc:monitor><nc:route-monitoring><nc:none/>" + "<nc:post-policy><nc:exclude-non-eligible/></nc:post-policy></nc:route-monitoring></nc:bmp>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_bmp_2(self): + """ + configure bmp attributes: + """ + set_module_args( + dict( + config=dict( + bmp=dict( + monitor=False, + route_monitoring=dict( + none=False, + post_policy=False, + post_policy_exclude_non_eligible=False, + pre_policy=False, + post_policy_exclude_non_feasible=False, + ), + ), + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:bmp><nc:monitor>disable</nc:monitor><nc:route-monitoring/></nc:bmp>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_egress_te(self): + """ + configure egress_te attributes: + """ + set_module_args( + dict( + config=dict(egress_te=dict(set=True, backup_path="sample")), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:egress-te><nc:backup-path>sample</nc:backup-path></nc:egress-te>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_egress_te_backup_paths(self): + """ + configure egress_te_backup_paths attributes: + """ + set_module_args( + dict( + config=dict( + egress_te_backup_paths=dict( + templates=[ + dict( + path_name="temp", + ip_forward=dict(set=True, rti_name="sample"), + peers=["10.10.10.10", "11.11.11.11"], + remote_nexthop="11.1.1.1", + ), + ], + ), + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:egress-te-backup-paths><nc:template><nc:name>temp</nc:name><nc:peer>" + "<nc:name>10.10.10.10</nc:name></nc:peer><nc:peer><nc:name>11.11.11.11</nc:name>" + "</nc:peer><nc:remote-nexthop>11.1.1.1</nc:remote-nexthop><nc:ip-forward/>" + "</nc:template></nc:egress-te-backup-paths>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_groups_allow(self): + """ + configure allow attributes: + """ + set_module_args( + dict( + config=dict( + groups=[dict(name="internal", allow=["all", "1.1.1.0/24"])], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:group><nc:name>internal</nc:name><nc:allow>all</nc:allow>" + "<nc:allow>1.1.1.0/24</nc:allow></nc:group>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_merged_optimal_route_reflection(self): + """ + configure optimal_route_reflection attributes: + """ + set_module_args( + dict( + config=dict( + groups=[ + dict( + name="internal", + optimal_route_reflection=dict( + igp_backup="test_igp", + igp_primary="test_primary", + ), + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:bgp><nc:group><nc:name>internal</nc:name><nc:optimal-route-reflection>" + "<nc:igp-backup>test_igp</nc:igp-backup><nc:igp-primary>test_primary</nc:igp-primary>" + "</nc:optimal-route-reflection></nc:group>" + "</nc:bgp></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_bgp_global_parsed_bgp_global(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <bgp-error-tolerance> + <malformed-update-log-interval>10000</malformed-update-log-interval> + <no-malformed-route-limit/> + </bgp-error-tolerance> + <advertise-peer-as/> + <advertise-external> + <conditional/> + </advertise-external> + <precision-timers/> + <advertise-from-main-vpn-tables/> + <holddown-all-stale-labels/> + <description>Config is updated with merged operation</description> + <accept-remote-nexthop/> + <preference>3</preference> + <hold-time>15</hold-time> + <advertise-inactive/> + <no-advertise-peer-as/> + <keep>all</keep> + <no-aggregator-id/> + <mtu-discovery/> + <out-delay>20</out-delay> + <log-updown/> + <damping/> + <authentication-algorithm>md5</authentication-algorithm> + <no-client-reflect/> + <include-mp-next-hop/> + <bmp> + <monitor>enable</monitor> + <route-monitoring> + <pre-policy> + <exclude-non-feasible/> + </pre-policy> + <post-policy> + <exclude-non-eligible/> + </post-policy> + </route-monitoring> + </bmp>> + <add-path-display-ipv4-address/> + <egress-te-sid-stats/> + <egress-te-set-segment> + <name>est1</name> + <label> + <label-value>1048400</label-value> + </label> + <egress-te-backup-segment> + <label> + <label-value>1048300</label-value> + </label> + </egress-te-backup-segment> + </egress-te-set-segment> + <egress-te-set-segment> + <name>est2</name> + <label> + <label-value>1048400</label-value> + </label> + </egress-te-set-segment> + <egress-te-backup-paths> + <template> + <name>mpls</name> + <peer> + <name>1.1.1.1</name> + </peer> + <ip-forward> + </ip-forward> + </template> + <template> + <name>mpls2</name> + <peer> + <name>1.1.1.1</name> + </peer> + <peer> + <name>1.1.1.2</name> + </peer> + <remote-nexthop> + <remote-nh-addr>10.10.10.11</remote-nh-addr> + </remote-nexthop> + </template> + </egress-te-backup-paths> + <group> + <name>internal</name> + <out-delay>22</out-delay> + <neighbor> + <name>11.11.11.1</name> + <peer-as>65432</peer-as> + </neighbor> + </group> + <graceful-restart> + <disable/> + </graceful-restart> + <metric-out> + <metric-value>4294967291</metric-value> + </metric-out> + <multipath> + <disable/> + <multiple-as/> + </multipath> + </bgp> + </protocols> + <routing-options> + <autonomous-system> + <as-number>65534</as-number> + <loops>5</loops> + <asdot-notation/> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + self.execute_module(changed=False) + + def test_junos_bgp_global_parsed_bgp_group_neighbors_list(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <disable/> + <egress-te-set-segment> + <name>est2</name> + <label> + <label-value>1048400</label-value> + </label> + </egress-te-set-segment> + <bfd-liveness-detection> + <minimum-interval>1000</minimum-interval> + <holddown-interval>1000</holddown-interval> + <minimum-receive-interval>100</minimum-receive-interval> + <multiplier>400</multiplier> + <no-adaptation/> + <session-mode>multihop</session-mode> + <version>1</version> + </bfd-liveness-detection> + <bgp-error-tolerance> + <malformed-update-log-interval>10000</malformed-update-log-interval> + <malformed-route-limit>4294967285</malformed-route-limit> + </bgp-error-tolerance> + <bmp> + <monitor>enable</monitor> + <route-monitoring> + <none/> + </route-monitoring> + </bmp> + <authentication-key>$9$6HxBAtOrlMXNbp0MX</authentication-key> + <advertise-external/> + <cluster>0.0.4.198</cluster> + <egress-te-backup-segment> + <label> + <label-value>1048300</label-value> + </label> + </egress-te-backup-segment> + <egress-te-backup-paths> + <template> + <name>mpls</name> + <peer> + <name>1.1.1.1</name> + </peer> + <ip-forward> + </ip-forward> + </template> + </egress-te-backup-paths> + <group> + <name>internal</name> + <out-delay>22</out-delay> + <neighbor> + <name>11.11.11.1</name> + <peer-as>65432</peer-as> + </neighbor> + <neighbor> + <name>11.11.11.2</name> + <peer-as>65432</peer-as> + </neighbor> + </group> + <idle-after-switch-over> + <timeout>4294967291</timeout> + </idle-after-switch-over> + <graceful-restart> + </graceful-restart> + <import>art1</import> + <metric-out> + <igp> + <delay-med-update/> + </igp> + </metric-out> + <multihop> + </multihop> + <multipath> + </multipath> + <no-precision-timers/> + </bgp> + </protocols> + <routing-options xmlns="http://yang.juniper.net/junos-es/conf/routing-options"> + <autonomous-system> + <as-number>65534</as-number> + <loops>5</loops> + <asdot-notation/> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + self.execute_module(changed=False) + + def test_junos_bgp_global_parsed_bgp_group_neighbors_list_2(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <bgp> + <graceful-restart> + <forwarding-state-bit>from-fib</forwarding-state-bit> + <restart-time>1700</restart-time> + <stale-routes-time>1500</stale-routes-time> + <long-lived> + <receiver> + <disable/> + </receiver> + <advertise-to-non-llgr-neighbor> + </advertise-to-non-llgr-neighbor> + </long-lived> + </graceful-restart> + <idle-after-switch-over> + <forever/> + </idle-after-switch-over> + <import>art1</import> + <import>art12</import> + <local-as> + <as-number>65432</as-number> + <private/> + <alias/> + <no-prepend-global-as/> + </local-as> + <local-interface>ge-0/0/1.0</local-interface> + <local-preference>12</local-preference> + <metric-out> + <minimum-igp> + <metric-offset>100</metric-offset> + </minimum-igp> + </metric-out> + <traceoptions> + <file> + <filename>temp_trace</filename> + <size>4294967100</size> + <files>3</files> + <no-world-readable/> + </file> + <flag> + <name>4byte-as</name> + <receive/> + <detail/> + </flag> + <flag> + <name>all</name> + <send/> + </flag> + <flag> + <name>state</name> + <receive/> + </flag> + <flag> + <name>task</name> + <disable/> + </flag> + <flag> + <name>update</name> + <filter> + <match-on>prefix</match-on> + <policy>pol1</policy> + </filter> + </flag> + </traceoptions> + <multihop> + <ttl>200</ttl> + <no-nexthop-change/> + </multihop> + <traffic-statistics-labeled-path> + <file> + <filename>traffic_temp</filename> + <size>20000</size> + <files>10</files> + <world-readable/> + </file> + </traffic-statistics-labeled-path> + <path-selection> + <cisco-non-deterministic/> + <always-compare-med/> + <med-plus-igp> + <igp-multiplier>500</igp-multiplier> + </med-plus-igp> + <external-router-id/> + <as-path-ignore/> + <l2vpn-use-bgp-rules/> + </path-selection> + <outbound-route-filter> + <bgp-orf-cisco-mode/> + <prefix-based> + <accept> + <inet/> + </accept> + </prefix-based> + </outbound-route-filter> + <output-queue-priority> + <expedited> + <update-tokens>10</update-tokens> + </expedited> + <priority> + <name>13</name> + <update-tokens>20</update-tokens> + </priority> + <defaults> + <low> + <priority>14</priority> + </low> + <high> + <priority>15</priority> + </high> + </defaults> + </output-queue-priority> + <remove-private> + <all> + <replace> + <nearest/> + </replace> + </all> + </remove-private> + <rfc6514-compliant-safi129/> + <route-server-client/> + <send-addpath-optimization/> + <tcp-aggressive-transmission/> + <group> + <name>internal</name> + <out-delay>22</out-delay> + <neighbor> + <name>11.11.11.1</name> + <peer-as>65432</peer-as> + </neighbor> + </group> + <bfd-liveness-detection> + <minimum-interval>1000</minimum-interval> + <transmit-interval> + <minimum-interval>220000</minimum-interval> + <threshold>2000</threshold> + </transmit-interval> + <detection-time> + <threshold>10000</threshold> + </detection-time> + <authentication> + <key-chain>cisco</key-chain> + <loose-check/> + <algorithm>keyed-md5</algorithm> + </authentication> + </bfd-liveness-detection> + </bgp> + </protocols> + <routing-options xmlns="http://yang.juniper.net/junos-es/conf/routing-options"> + <autonomous-system> + <as-number>65534</as-number> + <loops>5</loops> + <asdot-notation/> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + self.execute_module(changed=False) + + def test_junos_bgp_global_parsed_only_routing_options(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <routing-options> + <autonomous-system> + <as-number>65534</as-number> + <loops>5</loops> + <asdot-notation/> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + self.execute_module(changed=False) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py new file mode 100644 index 000000000..9494eb2b2 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_command.py @@ -0,0 +1,182 @@ +# (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 + +try: + from lxml.etree import fromstring +except ImportError: + from xml.etree.ElementTree import fromstring + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_command +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +RPC_CLI_MAP = {"get-software-information": "show version"} + + +class TestJunosCommandModule(TestJunosModule): + + module = junos_command + + def setUp(self): + super(TestJunosCommandModule, self).setUp() + + self.mock_conn = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.Connection", + ) + self.conn = self.mock_conn.start() + + self.mock_netconf = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + ) + self.netconf_conn = self.mock_netconf.start() + + self.mock_exec_rpc = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_command.exec_rpc", + ) + self.exec_rpc = self.mock_exec_rpc.start() + + self.mock_netconf_rpc = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.netconf.NetconfConnection", + ) + self.netconf_rpc = self.mock_netconf_rpc.start() + + self.mock_get_connection = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_command.get_connection", + ) + self.get_connection = self.mock_get_connection.start() + + self.mock_get_capabilities = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_command.get_capabilities", + ) + self.get_capabilities = self.mock_get_capabilities.start() + self.get_capabilities.return_value = {"network_api": "netconf"} + + def tearDown(self): + super(TestJunosCommandModule, self).tearDown() + self.mock_conn.stop() + self.mock_netconf.stop() + self.mock_get_capabilities.stop() + self.mock_netconf_rpc.stop() + self.mock_exec_rpc.stop() + self.mock_get_connection.stop() + + def load_fixtures(self, commands=None, format="text", changed=False): + def load_from_file(*args, **kwargs): + element = fromstring(args[1]) + if element.text: + path = str(element.text) + else: + path = RPC_CLI_MAP[str(element.tag)] + + filename = path.replace(" ", "_") + filename = "%s_%s.txt" % (filename, format) + return load_fixture(filename) + + self.exec_rpc.side_effect = load_from_file + + def test_junos_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("Hostname:")) + + def test_junos_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("Hostname:")) + + def test_junos_command_wait_for(self): + wait_for = 'result[0] contains "Junos:"' + set_module_args(dict(commands=["show version"], wait_for=wait_for)) + self.execute_module() + + def test_junos_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.exec_rpc.call_count, 10) + + def test_junos_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.exec_rpc.call_count, 2) + + def test_junos_command_match_any(self): + wait_for = [ + 'result[0] contains "Junos:"', + 'result[0] contains "test string"', + ] + set_module_args( + dict(commands=["show version"], wait_for=wait_for, match="any"), + ) + self.execute_module() + + def test_junos_command_match_all(self): + wait_for = [ + 'result[0] contains "Junos:"', + 'result[0] contains "JUNOS Software Release"', + ] + set_module_args( + dict(commands=["show version"], wait_for=wait_for, match="all"), + ) + self.execute_module() + + def test_junos_command_match_all_failure(self): + wait_for = [ + 'result[0] contains "Junos:"', + 'result[0] contains "test string"', + ] + commands = ["show version", "show version"] + set_module_args( + dict(commands=commands, wait_for=wait_for, match="all"), + ) + self.execute_module(failed=True) + + def test_junos_command_simple_json(self): + set_module_args(dict(commands=["show version"], display="json")) + result = self.execute_module(format="json") + self.assertEqual(len(result["stdout"]), 1) + self.assertTrue("software-information" in result["stdout"][0]) + + def test_junos_command_simple_rpc_text(self): + set_module_args( + dict(rpcs=["get-software-information"], display="text"), + ) + result = self.execute_module(format="text") + self.assertEqual(len(result["stdout"]), 1) + self.assertTrue(result["stdout"][0].startswith("Hostname:")) + + def test_junos_command_simple_rpc_json(self): + set_module_args( + dict(rpcs=["get-software-information"], display="json"), + ) + result = self.execute_module(format="json") + self.assertEqual(len(result["stdout"]), 1) + self.assertTrue("software-information" in result["stdout"][0]) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py new file mode 100644 index 000000000..a8e134050 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_config.py @@ -0,0 +1,227 @@ +# +# (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.module_utils._text import to_text + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_config +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosConfigModule(TestJunosModule): + + module = junos_config + + def setUp(self): + super(TestJunosConfigModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.get_configuration", + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_load_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.load_configuration", + ) + self.load_configuration = self.mock_load_configuration.start() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.commit_configuration", + ) + self.commit_configuration = self.mock_commit_configuration.start() + + self.mock_get_diff = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.get_diff", + ) + self.get_diff = self.mock_get_diff.start() + + self.mock_conn = patch("ansible.module_utils.connection.Connection") + self.conn = self.mock_conn.start() + + self.mock_netconf = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + ) + self.netconf_conn = self.mock_netconf.start() + + self.mock_exec_rpc = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_config.exec_rpc", + ) + self.exec_rpc = self.mock_exec_rpc.start() + + self.mock_netconf_rpc = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.netconf.NetconfConnection", + ) + self.netconf_rpc = self.mock_netconf_rpc.start() + + def tearDown(self): + super(TestJunosConfigModule, self).tearDown() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_get_diff.stop() + self.load_configuration.stop() + self.mock_conn.stop() + self.mock_netconf.stop() + self.mock_exec_rpc.stop() + self.mock_netconf_rpc.stop() + + def load_fixtures(self, commands=None, format="text", changed=False): + self.get_config.return_value = load_fixture( + "get_configuration_rpc_reply.txt", + ) + if changed: + self.load_config.return_value = load_fixture( + "get_configuration_rpc_reply_diff.txt", + ) + else: + self.load_config.return_value = None + + def test_junos_config_unchanged(self): + src = load_fixture("junos_config.set", content="str") + set_module_args(dict(src=src)) + self.execute_module() + + def test_junos_config_src_set(self): + src = load_fixture("junos_config.set", content="str") + set_module_args(dict(src=src)) + self.execute_module(changed=True) + args, kwargs = self.load_config.call_args + self.assertEqual(kwargs["action"], "set") + self.assertEqual(kwargs["format"], "text") + + def test_junos_config_backup(self): + set_module_args(dict(backup=True)) + result = self.execute_module() + self.assertIn("__backup__", result) + + def test_junos_config_lines(self): + set_module_args( + dict( + lines=[ + "delete interfaces ae11", + "set interfaces ae11 unit 0 description Test", + ], + ), + ) + self.execute_module(changed=True) + args, kwargs = self.load_config.call_args + self.assertEqual( + args[1][0], + "set interfaces ae11 unit 0 description Test", + ) + self.assertEqual(kwargs["action"], "set") + self.assertEqual(kwargs["format"], "text") + + def test_junos_config_confirm(self): + src = load_fixture("junos_config.set", content="str") + set_module_args(dict(src=src, confirm=40)) + self.execute_module(changed=True) + args, kwargs = self.commit_configuration.call_args + self.assertEqual(kwargs["confirm_timeout"], to_text(40)) + + def test_junos_config_rollback(self): + rollback = 10 + set_module_args(dict(rollback=rollback)) + self.execute_module(changed=True) + self.assertEqual(self.get_diff.call_count, 1) + self.assertEqual(self.load_configuration.call_count, 1) + self.assertEqual(self.commit_configuration.call_count, 1) + load_configuration_args = self.load_configuration.call_args + self.assertEqual(rollback, load_configuration_args[1].get("rollback")) + + def test_junos_config_src_text(self): + src = load_fixture("junos_config.text", content="str") + set_module_args(dict(src=src)) + self.execute_module(changed=True) + args, kwargs = self.load_config.call_args + self.assertEqual(kwargs["action"], "merge") + self.assertEqual(kwargs["format"], "text") + + def test_junos_config_src_xml(self): + src = load_fixture("junos_config.xml", content="str") + set_module_args(dict(src=src)) + self.execute_module(changed=True) + args, kwargs = self.load_config.call_args + self.assertEqual(kwargs["action"], "merge") + self.assertEqual(kwargs["format"], "xml") + + def test_junos_config_src_json(self): + src = load_fixture("junos_config.json", content="str") + set_module_args(dict(src=src)) + self.execute_module(changed=True) + args, kwargs = self.load_config.call_args + self.assertEqual(kwargs["action"], "merge") + self.assertEqual(kwargs["format"], "json") + + def test_junos_config_update_override(self): + src = load_fixture("junos_config.xml", content="str") + set_module_args(dict(src=src, update="override")) + self.execute_module() + args, kwargs = self.load_config.call_args + self.assertEqual(kwargs["action"], "override") + self.assertEqual(kwargs["format"], "xml") + + def test_junos_config_update_replace(self): + src = load_fixture("junos_config.json", content="str") + set_module_args(dict(src=src, update="replace")) + self.execute_module() + args, kwargs = self.load_config.call_args + self.assertEqual(kwargs["action"], "replace") + self.assertEqual(kwargs["format"], "json") + + def test_junos_config_zeroize(self): + set_module_args(dict(zeroize="yes")) + self.execute_module(changed=True) + self.assertEqual(self.exec_rpc.call_count, 1) + + def test_junos_config_src_format_xml(self): + src = load_fixture("junos_config.json", content="str") + set_module_args(dict(src=src, src_format="xml")) + self.execute_module() + args, kwargs = self.load_config.call_args + self.assertEqual(kwargs["format"], "xml") + + def test_junos_config_confirm_commit(self): + set_module_args(dict(confirm_commit=True)) + self.execute_module(changed=True) + self.assertEqual(self.commit_configuration.call_count, 1) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py new file mode 100644 index 000000000..0b5b7890c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_facts.py @@ -0,0 +1,171 @@ +# (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 + +try: + from lxml.etree import fromstring +except ImportError: + from xml.etree.ElementTree import fromstring + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_facts +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +RPC_CLI_MAP = { + "get-software-information": "show version", + "get-interface-information": "show interfaces details", + "get-system-memory-information": "show system memory", + "get-chassis-inventory": "show chassis hardware", + "get-route-engine-information": "show chassis routing-engine", + "get-system-storage": "show system storage", +} + + +class TestJunosCommandModule(TestJunosModule): + + module = junos_facts + + def setUp(self): + super(TestJunosCommandModule, self).setUp() + + self.mock_get_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.legacy.base.get_configuration", + ) + self.get_config = self.mock_get_config.start() + + self.mock_netconf = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + ) + self.netconf_conn = self.mock_netconf.start() + + self.mock_exec_rpc = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.legacy.base.exec_rpc", + ) + self.exec_rpc = self.mock_exec_rpc.start() + + self.mock_netconf_rpc = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.netconf.NetconfConnection", + ) + self.netconf_rpc = self.mock_netconf_rpc.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.junipernetworks.junos.plugins.module_utils.network.junos.facts.legacy.base.get_capabilities", + ) + self.get_capabilities = self.mock_get_capabilities.start() + + self.get_capabilities.return_value = { + "device_info": { + "network_os": "junos", + "network_os_hostname": "vsrx01", + "network_os_model": "vsrx", + "network_os_version": "17.3R1.10", + }, + "network_api": "netconf", + } + + def tearDown(self): + super(TestJunosCommandModule, self).tearDown() + self.mock_netconf.stop() + self.mock_exec_rpc.stop() + self.mock_netconf_rpc.stop() + self.mock_get_capabilities.stop() + self.mock_get_resource_connection.stop() + + def load_fixtures(self, commands=None, format="text", changed=False): + def load_from_file(*args, **kwargs): + element = fromstring(args[1]) + + if element.text: + path = str(element.text) + else: + path = RPC_CLI_MAP[str(element.tag)] + + filename = path.replace(" ", "_") + filename = "%s_%s.txt" % (filename, format) + return load_fixture(filename) + + self.exec_rpc.side_effect = load_from_file + + def test_junos_get_facts(self): + set_module_args(dict()) + result = self.execute_module(format="xml") + facts = result["ansible_facts"] + + self.assertEqual(facts["ansible_net_hostname"], "vsrx01") + self.assertEqual(facts["ansible_network_resources"], {}) + self.assertEqual(facts["ansible_net_system"], "junos") + self.assertTrue("ansible_net_model" in facts) + self.assertTrue("ansible_net_version" in facts) + self.assertTrue("ansible_network_resources" in facts) + self.assertTrue("ansible_net_serialnum" in facts) + + def test_junos_get_facts_subset_config_set(self): + self.get_config.return_value = load_fixture( + "get_configuration_rpc_reply.txt", + ) + set_module_args(dict(gather_subset="config", config_format="set")) + result = self.execute_module(format="xml") + facts = result["ansible_facts"] + + self.assertTrue("ansible_net_config" in facts) + self.assertTrue(facts["ansible_net_config"].startswith("set")) + self.assertEqual(facts["ansible_net_hostname"], "vsrx01") + self.assertTrue("ansible_net_interfaces" not in facts) + + def test_junos_get_facts_subset_config_json(self): + self.get_config.return_value = load_fixture( + "get_configuration_rpc_reply_json.txt", + ) + set_module_args(dict(gather_subset="config", config_format="json")) + result = self.execute_module(format="xml") + facts = result["ansible_facts"] + + self.assertTrue("ansible_net_config" in facts) + self.assertTrue("configuration" in facts["ansible_net_config"]) + self.assertEqual(facts["ansible_net_hostname"], "vsrx01") + self.assertTrue("ansible_net_interfaces" not in facts) + + def test_junos_get_facts_subset_list(self): + set_module_args(dict(gather_subset=["hardware", "interfaces"])) + result = self.execute_module(format="xml") + facts = result["ansible_facts"] + + self.assertTrue("ansible_net_config" not in facts) + self.assertEqual( + facts["ansible_net_interfaces"]["em0"]["oper-status"], + "up", + ) + self.assertEqual(facts["ansible_net_memfree_mb"], 200684) + + def test_junos_get_facts_wrong_subset(self): + set_module_args(dict(gather_subset=["hardware", "interfaces", "test"])) + result = self.execute_module(format="xml", failed=True) + + self.assertTrue(result["msg"].startswith("Subset must be one")) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py new file mode 100644 index 000000000..a6c40395f --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_hostname.py @@ -0,0 +1,147 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_hostname +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosHostnameModule(TestJunosModule): + module = junos_hostname + + def setUp(self): + super(TestJunosHostnameModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.hostname.hostname.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.hostname.hostname.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.hostname.hostname." + "HostnameFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosHostnameModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_hostname_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def test_junos_hostname_merged_01(self): + set_module_args(dict(config=dict(hostname="vsrx"), state="merged")) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:host-name>vsrx</nc:host-name>", + str(result["commands"]), + ) + + def test_junos_hostname_parsed_01(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <host-name>vsrx</host-name> + </system> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = {"hostname": "vsrx"} + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_hostname_overridden_01(self): + set_module_args( + dict(config=dict(hostname="vsrx12"), state="overridden"), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:host-name>vsrx12</nc:host-name>", + str(result["commands"]), + ) + + def test_junos_hostname_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gathered_hostname = {"hostname": "vsrx10"} + self.assertEqual(sorted(gathered_hostname), sorted(result["gathered"])) + + def test_junos_hostname_rendered(self): + set_module_args(dict(config=dict(hostname="vsrx10"), state="rendered")) + rendered = ( + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:host-name>vsrx10</nc:host-name></nc:system>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_hostname_replaced(self): + set_module_args(dict(config=dict(hostname="vsrx12"), state="replaced")) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:host-name>vsrx12</nc:host-name>", + str(result["commands"]), + ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py new file mode 100644 index 000000000..ad4efe9ef --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_interfaces.py @@ -0,0 +1,257 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_interfaces +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosInterfacesModule(TestJunosModule): + module = junos_interfaces + + def setUp(self): + super(TestJunosInterfacesModule, self).setUp() + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.interfaces.interfaces.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_validate_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils.validate_config", + ) + self.validate_config = self.mock_validate_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.interfaces.interfaces.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_get_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.interfaces.interfaces." + "InterfacesFacts.get_config", + ) + self.get_config = self.mock_get_config.start() + + def tearDown(self): + super(TestJunosInterfacesModule, self).tearDown() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_validate_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + + def load_fixtures(self, commands=None, format="text", changed=False): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + if changed: + self.load_config.return_value = load_fixture( + "get_configuration_rpc_reply_diff.txt", + ) + else: + self.load_config.return_value = None + + def test_junos_interfaces_merged(self): + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/1", + description="This is configured with ansible resource module", + mtu=1024, + speed="100m", + ), + ], + state="merged", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:interface><nc:name>ge-0/0/1</nc:name>" + "<nc:description>This is configured with ansible resource module</nc:description>" + "<nc:speed>100m</nc:speed>" + "<nc:mtu>1024</nc:mtu>" + "</nc:interface></nc:interfaces>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_interfaces_merged_idempotent(self): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/0", + description="Configured by Ansi-Team", + ), + ], + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_interfaces_replaced(self): + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/2", + description="This is configured with ansible", + mtu=1024, + speed="100m", + ), + ], + state="replaced", + ), + ) + result = self.execute_module(changed=True) + + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:interface><nc:name>ge-0/0/2</nc:name>" + "<nc:description>This is configured with ansible</nc:description>" + "<nc:speed>100m</nc:speed><nc:mtu>1024</nc:mtu></nc:interface></nc:interfaces>", + ] + + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_interfaces_replaced_idempotent(self): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/0", + description="Configured by Ansi-Team", + ), + ], + state="replaced", + ), + ) + + self.execute_module(changed=False, commands=[]) + + def test_junos_interfaces_overridden(self): + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/2", + description="This is configured with ansible", + mtu=1024, + speed="100m", + ), + ], + state="overridden", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:interface><nc:name>ge-0/0/2</nc:name>" + "<nc:description>This is configured with ansible</nc:description>" + "<nc:speed>100m</nc:speed><nc:mtu>1024</nc:mtu></nc:interface></nc:interfaces>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_interfaces_overridden_idempotent(self): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/0", + description="Configured by Ansi-Team", + ), + ], + state="overridden", + ), + ) + + self.execute_module(changed=False, commands=[]) + + def test_junos_interfaces_delete(self): + set_module_args(dict(config=[dict(name="ge-0/0/2")], state="deleted")) + + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_interfaces_delete_idempotent(self): + set_module_args(dict(config=[dict(name="ge-0/0/4")], state="deleted")) + self.execute_module(changed=False, commands=[]) + + def test_junos_interfaces_rendered(self): + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/1", + description="This is configured with ansible resource module", + mtu=1024, + speed="100m", + ), + ], + state="rendered", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:interface><nc:name>ge-0/0/1</nc:name>" + "<nc:description>This is configured with ansible resource module</nc:description>" + "<nc:speed>100m</nc:speed>" + "<nc:mtu>1024</nc:mtu>" + "</nc:interface></nc:interfaces>", + ] + self.execute_module(changed=False, commands=commands) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py new file mode 100644 index 000000000..d2dd5c687 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l2_interfaces.py @@ -0,0 +1,237 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_l2_interfaces +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosL2InterfacesModule(TestJunosModule): + module = junos_l2_interfaces + + def setUp(self): + super(TestJunosL2InterfacesModule, self).setUp() + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_validate_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils.validate_config", + ) + self.validate_config = self.mock_validate_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_get_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.l2_interfaces.l2_interfaces." + "L2_interfacesFacts.get_config", + ) + self.get_config = self.mock_get_config.start() + + self.mock_get_res_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l2_interfaces.l2_interfaces." + "L2_interfaces.get_res_config", + ) + self.get_res_config = self.mock_get_res_config.start() + + def tearDown(self): + super(TestJunosL2InterfacesModule, self).tearDown() + self.mock_get_config.stop() + self.mock_get_res_config.stop() + self.mock_load_config.stop() + self.mock_validate_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + + def load_fixtures(self, commands=None, format="text", changed=False): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + if changed: + self.load_config.return_value = load_fixture( + "get_configuration_rpc_reply_diff.txt", + ) + else: + self.load_config.return_value = None + + def test_junos_l2_interfaces_merged(self): + set_module_args( + dict( + config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"))], + state="merged", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>' + "<nc:name>ge-0/0/1</nc:name><nc:unit><nc:name>0</nc:name>" + "<nc:family><nc:ethernet-switching><nc:interface-mode>access</nc:interface-mode>" + "<nc:vlan><nc:members>vlan100</nc:members>" + "</nc:vlan></nc:ethernet-switching></nc:family></nc:unit>" + "</nc:interface></nc:interfaces>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_l2_interfaces_merged_idempotent(self): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_l2_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"))], + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_l2_interfaces_replaced(self): + self.get_res_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + set_module_args( + dict( + config=[dict(name="ge-0/0/2", access=dict(vlan="vlan200"))], + state="replaced", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>' + "<nc:name>ge-0/0/2</nc:name><nc:unit><nc:name>0</nc:name>" + "<nc:family><nc:ethernet-switching>" + '<nc:interface-mode delete="delete"/><nc:vlan delete="delete"/>' + '</nc:ethernet-switching></nc:family></nc:unit><nc:native-vlan-id delete="delete"/>' + "</nc:interface><nc:interface><nc:name>ge-0/0/2</nc:name>" + "<nc:unit><nc:name>0</nc:name><nc:family>" + "<nc:ethernet-switching><nc:interface-mode>access</nc:interface-mode>" + "<nc:vlan><nc:members>vlan200</nc:members></nc:vlan>" + "</nc:ethernet-switching></nc:family></nc:unit></nc:interface></nc:interfaces>", + ] + result = self.execute_module(changed=True) + + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_l2_interfaces_replaced_idempotent(self): + self.get_res_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_l2_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"))], + state="replaced", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_l2_interfaces_overridden(self): + set_module_args( + dict( + config=[dict(name="ge-0/0/3", access=dict(vlan="vlan300"))], + state="overridden", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>' + "<nc:name>ge-0/0/3</nc:name><nc:unit><nc:name>0</nc:name>" + "<nc:family><nc:ethernet-switching>" + "<nc:interface-mode>access</nc:interface-mode><nc:vlan><nc:members>vlan300</nc:members></nc:vlan>" + "</nc:ethernet-switching></nc:family></nc:unit></nc:interface></nc:interfaces>", + ] + result = self.execute_module(changed=True) + + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_l2_interfaces_overridden_idempotent(self): + self.get_res_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_l2_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"))], + state="overridden", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_l2_interfaces_delete(self): + self.get_res_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_l2_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args(dict(config=[dict(name="ge-0/0/1")], state="deleted")) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>' + "<nc:name>ge-0/0/1</nc:name><nc:unit><nc:name>0</nc:name>" + '<nc:family><nc:ethernet-switching><nc:interface-mode delete="delete"/>' + '<nc:vlan delete="delete"/></nc:ethernet-switching></nc:family></nc:unit>' + '<nc:native-vlan-id delete="delete"/></nc:interface></nc:interfaces>', + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_l2_interfaces_delete_idempotent(self): + set_module_args(dict(config=[dict(name="ge-0/0/4")], state="deleted")) + self.execute_module(changed=False, commands=[]) + + def test_junos_l2_interfaces_rendered(self): + set_module_args( + dict( + config=[dict(name="ge-0/0/1", access=dict(vlan="vlan100"))], + state="merged", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>' + "<nc:name>ge-0/0/1</nc:name><nc:unit><nc:name>0</nc:name>" + "<nc:family><nc:ethernet-switching><nc:interface-mode>access</nc:interface-mode>" + "<nc:vlan><nc:members>vlan100</nc:members>" + "</nc:vlan></nc:ethernet-switching></nc:family></nc:unit>" + "</nc:interface></nc:interfaces>", + ] + self.execute_module(changed=False, commands=commands) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py new file mode 100644 index 000000000..dba2e4b7d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_l3_interfaces.py @@ -0,0 +1,255 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_l3_interfaces +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosL3InterfacesModule(TestJunosModule): + module = junos_l3_interfaces + + def setUp(self): + super(TestJunosL3InterfacesModule, self).setUp() + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l3_interfaces.l3_interfaces.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_validate_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils.validate_config", + ) + self.validate_config = self.mock_validate_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.l3_interfaces.l3_interfaces.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_get_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.l3_interfaces.l3_interfaces." + "L3_interfacesFacts.get_config", + ) + self.get_config = self.mock_get_config.start() + + def tearDown(self): + super(TestJunosL3InterfacesModule, self).tearDown() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_validate_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + + def load_fixtures(self, commands=None, format="text", changed=False): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + if changed: + self.load_config.return_value = load_fixture( + "get_configuration_rpc_reply_diff.txt", + ) + else: + self.load_config.return_value = None + + def test_junos_l3_interfaces_merged(self): + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/1", + ipv4=[ + dict(address="100.64.0.1/10"), + dict(address="100.64.0.2/10"), + ], + ), + ], + state="merged", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>' + "<nc:name>ge-0/0/1</nc:name><nc:unit><nc:name>0</nc:name>" + "<nc:family><nc:inet><nc:address><nc:name>100.64.0.1/10</nc:name></nc:address>" + "<nc:address><nc:name>100.64.0.2/10</nc:name></nc:address></nc:inet></nc:family>" + "</nc:unit></nc:interface></nc:interfaces>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_l3_interfaces_merged_idempotent(self): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_l3_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/1", + ipv4=[ + dict(address="100.64.0.1/10"), + dict(address="100.64.0.2/10"), + ], + ), + ], + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_l3_interfaces_replaced(self): + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/2", + ipv4=[ + dict(address="100.64.0.1/10"), + dict(address="100.64.0.2/10"), + ], + ), + ], + state="replaced", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>' + "<nc:name>ge-0/0/2</nc:name><nc:unit><nc:name>0</nc:name>" + "<nc:family><nc:inet><nc:address><nc:name>100.64.0.1/10</nc:name></nc:address>" + "<nc:address><nc:name>100.64.0.2/10</nc:name></nc:address></nc:inet></nc:family>" + "</nc:unit></nc:interface></nc:interfaces>", + ] + result = self.execute_module(changed=True) + + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_l3_interfaces_replaced_idempotent(self): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_l3_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/1", + ipv4=[ + dict(address="100.64.0.1/10"), + dict(address="100.64.0.2/10"), + ], + ), + ], + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_l3_interfaces_overridden(self): + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/1", + ipv4=[ + dict(address="100.64.0.1/10"), + dict(address="100.64.0.2/10"), + ], + ), + ], + state="overridden", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>' + "<nc:name>ge-0/0/1</nc:name><nc:unit><nc:name>0</nc:name>" + "<nc:family><nc:inet><nc:address><nc:name>100.64.0.1/10</nc:name></nc:address>" + "<nc:address><nc:name>100.64.0.2/10</nc:name></nc:address></nc:inet></nc:family>" + "</nc:unit></nc:interface></nc:interfaces>", + ] + result = self.execute_module(changed=True) + + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_l3_interfaces_overridden_idempotent(self): + self.get_config.return_value = load_fixture( + "junos_interfaces_config.xml", + ) + src = load_fixture("junos_l3_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/1", + ipv4=[ + dict(address="100.64.0.1/10"), + dict(address="100.64.0.2/10"), + ], + ), + ], + state="overridden", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_l3_interfaces_rendered(self): + set_module_args( + dict( + config=[ + dict( + name="ge-0/0/1", + ipv4=[ + dict(address="100.64.0.1/10"), + dict(address="100.64.0.2/10"), + ], + ), + ], + state="rendered", + ), + ) + commands = [ + '<nc:interfaces xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:interface>' + "<nc:name>ge-0/0/1</nc:name><nc:unit><nc:name>0</nc:name>" + "<nc:family><nc:inet><nc:address><nc:name>100.64.0.1/10</nc:name></nc:address>" + "<nc:address><nc:name>100.64.0.2/10</nc:name></nc:address></nc:inet></nc:family>" + "</nc:unit></nc:interface></nc:interfaces>", + ] + self.execute_module(changed=False, commands=commands) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py new file mode 100644 index 000000000..d1046c14c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_logging_global.py @@ -0,0 +1,1028 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_logging_global +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosLogging_globalModule(TestJunosModule): + module = junos_logging_global + + def setUp(self): + super(TestJunosLogging_globalModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.logging_global.logging_global.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.logging_global.logging_global.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.logging_global.logging_global." + "Logging_globalFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosLogging_globalModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_logging_global_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def test_junos_logging_global_merged_archive_01(self): + set_module_args( + dict( + config=dict( + archive=dict( + set=True, + files=10, + file_size=65578, + no_binary_data=True, + no_world_readable=True, + ), + ), + state="merged", + ), + ) + commands = [ + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:syslog><nc:archive><nc:files>10</nc:files>" + "<nc:no-binary-data/><nc:size>65578</nc:size><nc:no-world-readable/>" + "</nc:archive></nc:syslog></nc:system>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_logging_global_merged_console_02(self): + set_module_args( + dict( + config=dict( + console=dict( + any=dict(level="info"), + authorization=dict(level="any"), + change_log=dict(level="critical"), + ftp=dict(level="none"), + ), + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:console><nc:name>any</nc:name><nc:info/>", + str(result["commands"]), + ) + self.assertIn( + "<nc:console><nc:name>authorization</nc:name><nc:any/>", + str(result["commands"]), + ) + self.assertIn( + "<nc:console><nc:name>change-log</nc:name><nc:critical/>", + str(result["commands"]), + ) + self.assertIn( + "<nc:console><nc:name>ftp</nc:name><nc:none/>", + str(result["commands"]), + ) + + def test_junos_logging_global_merged_files_03(self): + set_module_args( + dict( + config=dict( + files=[dict(name="file101", allow_duplicates=True)], + ), + state="merged", + ), + ) + commands = [ + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:syslog><nc:file><nc:name>file101</nc:name>" + "<nc:allow-duplicates/></nc:file></nc:syslog></nc:system>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_logging_global_merged_files_04(self): + set_module_args( + dict( + config=dict( + files=[ + dict( + name="file102", + allow_duplicates=True, + any=dict(level="any"), + structured_data=dict(set=True), + ), + dict( + name="file103", + archive=dict( + set=True, + no_binary_data=True, + files=10, + file_size=65578, + no_world_readable=True, + ), + explicit_priority=True, + match="^set*", + match_strings=["^delete", "^prompt"], + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:syslog><nc:file><nc:name>file102</nc:name><nc:allow-duplicates/>" + "<nc:contents><nc:name>any</nc:name><nc:any/></nc:contents>" + "<nc:structured-data/></nc:file><nc:file><nc:name>file103</nc:name>" + "<nc:archive><nc:files>10</nc:files><nc:no-binary-data/>" + "<nc:size>65578</nc:size><nc:no-world-readable/>" + "</nc:archive><nc:explicit-priority/><nc:match>^set*</nc:match>" + "<nc:match-strings>^delete</nc:match-strings>" + "<nc:match-strings>^prompt</nc:match-strings></nc:file></nc:syslog></nc:system>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_logging_global_merged_hosts_05(self): + set_module_args( + dict( + config=dict( + hosts=[ + dict( + name="host222", + exclude_hostname=True, + allow_duplicates=True, + ), + ], + ), + state="merged", + ), + ) + commands = [ + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:syslog><nc:host><nc:name>host222</nc:name><nc:allow-duplicates/>" + "<nc:exclude-hostname/></nc:host></nc:syslog></nc:system>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_logging_global_merged_hosts_idempotent_06(self): + set_module_args( + dict( + config=dict( + hosts=[ + dict( + name="host111", + exclude_hostname=True, + allow_duplicates=True, + any=dict(level="any"), + structured_data=dict(set=True, brief=True), + facility_override="ftp", + log_prefix="field", + match="^set*", + match_strings=["^delete", "^prompt"], + port=1231, + routing_instance="inst11", + source_address="11.11.11.11", + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_logging_global_merged_07(self): + set_module_args( + dict( + config=dict( + allow_duplicates=True, + routing_instance="inst11", + log_rotate_frequency=45, + source_address="33.33.33.33", + time_format=dict(millisecond=True, year=True), + ), + state="merged", + ), + ) + commands = [ + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:syslog><nc:allow-duplicates/><nc:log-rotate-frequency>45</nc:log-rotate-frequency>" + "<nc:routing-instance>inst11</nc:routing-instance><nc:source-address>33.33.33.33</nc:source-address>" + "<nc:time-format><nc:millisecond/><nc:year/></nc:time-format></nc:syslog></nc:system>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_logging_global_merged_user_08(self): + set_module_args( + dict( + config=dict( + users=[ + dict(name="user1", allow_duplicates=True), + dict( + name="user2", + allow_duplicates=True, + any=dict(level="any"), + user=dict(level="info"), + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:user><nc:name>user1</nc:name><nc:allow-duplicates/>", + str(result["commands"]), + ) + self.assertIn( + "<nc:user><nc:name>user2</nc:name><nc:allow-duplicates/>", + str(result["commands"]), + ) + self.assertIn( + "<nc:contents><nc:name>any</nc:name><nc:any/></nc:contents>", + str(result["commands"]), + ) + + def test_junos_logging_global_replaced_user_09(self): + set_module_args( + dict( + config=dict( + users=[ + dict(name="user1", allow_duplicates=True), + dict( + name="user2", + allow_duplicates=True, + any=dict(level="any"), + user=dict(level="info"), + ), + ], + ), + state="replaced", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + '<nc:syslog delete="delete"/><nc:syslog><nc:user><nc:name>user1</nc:name>', + str(result["commands"]), + ) + self.assertIn( + "<nc:allow-duplicates/></nc:user><nc:user><nc:name>user2</nc:name>", + str(result["commands"]), + ) + self.assertIn( + "</nc:contents></nc:user></nc:syslog></nc:system>", + str(result["commands"]), + ) + + def test_junos_logging_global_overridden_user_10(self): + set_module_args( + dict( + config=dict( + users=[ + dict(name="user1", allow_duplicates=True), + dict( + name="user2", + allow_duplicates=True, + any=dict(level="any"), + user=dict(level="info"), + ), + ], + ), + state="overridden", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + '<nc:syslog delete="delete"/><nc:syslog><nc:user><nc:name>user1</nc:name>', + str(result["commands"]), + ) + self.assertIn( + "<nc:allow-duplicates/></nc:user><nc:user><nc:name>user2</nc:name>", + str(result["commands"]), + ) + + def test_junos_logging_global_deleted_user_11(self): + set_module_args(dict(config=dict(), state="deleted")) + commands = [ + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:syslog delete="delete"/></nc:system>', + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_logging_global_rendered_12(self): + set_module_args( + dict( + config=dict( + archive=dict( + set=True, + files=10, + file_size=65578, + no_binary_data=True, + no_world_readable=True, + ), + ), + state="rendered", + ), + ) + rendered = ( + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:syslog><nc:archive><nc:files>10</nc:files><nc:no-binary-data/>" + "<nc:size>65578</nc:size><nc:no-world-readable/></nc:archive></nc:syslog></nc:system>" + ) + result = self.execute_module(changed=False) + + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_logging_global_parsed_13(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <syslog> + <archive> + <size>65578</size> + <files>10</files> + <no-world-readable/> + <no-binary-data/> + </archive> + <user> + <name>user1</name> + <allow-duplicates/> + </user> + <user> + <name>user2</name> + <contents> + <name>any</name> + <any/> + </contents> + <contents> + <name>user</name> + <info/> + </contents> + <allow-duplicates/> + </user> + <host> + <name>host111</name> + <contents> + <name>any</name> + <any/> + </contents> + <match>^set*</match> + <allow-duplicates/> + <port>1231</port> + <facility-override>ftp</facility-override> + <log-prefix>field</log-prefix> + <source-address>11.1.1.11</source-address> + <routing-instance>inst11</routing-instance> + <exclude-hostname/> + <match-strings>^delete</match-strings> + <match-strings>^prompt</match-strings> + <structured-data> + <brief/> + </structured-data> + </host> + <allow-duplicates/> + <file> + <name>file101</name> + <allow-duplicates/> + </file> + <file> + <name>file102</name> + <contents> + <name>any</name> + <any/> + </contents> + <allow-duplicates/> + <structured-data> + </structured-data> + </file> + <file> + <name>file103</name> + <match>^set*</match> + <archive> + <size>65578</size> + <files>10</files> + <no-world-readable/> + <no-binary-data/> + </archive> + <explicit-priority/> + <match-strings>^delete</match-strings> + <match-strings>^prompt</match-strings> + </file> + <console> + <name>any</name> + <info/> + </console> + <console> + <name>authorization</name> + <any/> + </console> + <console> + <name>ftp</name> + <none/> + </console> + <console> + <name>change-log</name> + <critical/> + </console> + <time-format> + <year/> + <millisecond/> + </time-format> + <source-address>33.33.33.33</source-address> + <routing-instance>inst11</routing-instance> + <log-rotate-frequency>45</log-rotate-frequency> + </syslog> + </system> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "allow_duplicates": True, + "archive": { + "file_size": 65578, + "files": 10, + "no_binary_data": True, + "no_world_readable": True, + }, + "console": { + "any": {"level": "info"}, + "authorization": {"level": "any"}, + "change_log": {"level": "critical"}, + "ftp": {"level": "none"}, + }, + "files": [ + {"allow_duplicates": True, "name": "file101"}, + { + "allow_duplicates": True, + "any": {"level": "any"}, + "name": "file102", + "structured_data": {"set": True}, + }, + { + "archive": { + "file_size": 65578, + "files": 10, + "no_binary_data": True, + "no_world_readable": True, + }, + "explicit_priority": True, + "match": "^set*", + "match_strings": ["^delete", "^prompt"], + "name": "file103", + }, + ], + "hosts": [ + { + "allow_duplicates": True, + "any": {"level": "any"}, + "exclude_hostname": True, + "facility_override": "ftp", + "log_prefix": "field", + "match": "^set*", + "match_strings": ["^delete", "^prompt"], + "name": "host111", + "port": 1231, + "routing_instance": "inst11", + "source_address": "11.1.1.11", + "structured_data": {"brief": True}, + }, + ], + "log_rotate_frequency": 45, + "routing_instance": "inst11", + "source_address": "33.33.33.33", + "time_format": {"millisecond": True, "year": True}, + "users": [ + {"allow_duplicates": True, "name": "user1"}, + { + "allow_duplicates": True, + "any": {"level": "any"}, + "name": "user2", + "user": {"level": "info"}, + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_logging_global_gathered_14(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = { + "hosts": [ + { + "name": "host111", + "allow_duplicates": True, + "any": {"level": "any"}, + "exclude_hostname": True, + "facility_override": "ftp", + "log_prefix": "field", + "match": "^set*", + "match_strings": ["^delete", "^prompt"], + "port": 1231, + "routing_instance": "inst11", + "source_address": "11.1.1.11", + "structured_data": {"brief": True}, + }, + ], + } + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + def test_junos_logging_global_parsed_15(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <syslog> + <archive> + <size>65578</size> + <files>10</files> + <world-readable/> + <binary-data/> + </archive> + <user> + <name>user1</name> + <allow-duplicates/> + </user> + <user> + <name>user2</name> + <contents> + <name>any</name> + <any/> + </contents> + <contents> + <name>user</name> + <info/> + </contents> + <allow-duplicates/> + </user> + <host> + <name>host111</name> + <contents> + <name>any</name> + <any/> + </contents> + <match>^set*</match> + <allow-duplicates/> + <port>1231</port> + <facility-override>ftp</facility-override> + <log-prefix>field</log-prefix> + <source-address>11.1.1.11</source-address> + <routing-instance>inst11</routing-instance> + <exclude-hostname/> + <match-strings>^delete</match-strings> + <match-strings>^prompt</match-strings> + <structured-data> + <brief/> + </structured-data> + </host> + <allow-duplicates/> + <file> + <name>file101</name> + <allow-duplicates/> + <archive-sites> + <name>www.antsiblr.com</name> + </archive-sites> + </file> + <file> + <name>file102</name> + <contents> + <name>any</name> + <any/> + </contents> + <allow-duplicates/> + <structured-data> + </structured-data> + </file> + <file> + <name>file103</name> + <match>^set*</match> + <archive> + <size>65578</size> + <files>10</files> + <no-world-readable/> + <no-binary-data/> + </archive> + <explicit-priority/> + <match-strings>^delete</match-strings> + <match-strings>^prompt</match-strings> + </file> + <console> + <name>any</name> + <info/> + </console> + <console> + <name>authorization</name> + <any/> + </console> + <console> + <name>ftp</name> + <none/> + </console> + <console> + <name>change-log</name> + <critical/> + </console> + <time-format> + </time-format> + <source-address>33.33.33.33</source-address> + <routing-instance>inst11</routing-instance> + <log-rotate-frequency>45</log-rotate-frequency> + </syslog> + </system> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "allow_duplicates": True, + "archive": { + "file_size": 65578, + "files": 10, + "no_binary_data": True, + "no_world_readable": True, + }, + "console": { + "any": {"level": "info"}, + "authorization": {"level": "any"}, + "change_log": {"level": "critical"}, + "ftp": {"level": "none"}, + }, + "files": [ + { + "allow_duplicates": True, + "name": "file101", + "archive_sites": ["www.antsiblr.com"], + }, + { + "allow_duplicates": True, + "any": {"level": "any"}, + "name": "file102", + "structured_data": {"set": True}, + }, + { + "archive": { + "file_size": 65578, + "files": 10, + "binary_data": True, + "world_readable": True, + }, + "explicit_priority": True, + "match": "^set*", + "match_strings": ["^delete", "^prompt"], + "name": "file103", + }, + ], + "hosts": [ + { + "allow_duplicates": True, + "any": {"level": "any"}, + "exclude_hostname": True, + "facility_override": "ftp", + "log_prefix": "field", + "match": "^set*", + "match_strings": ["^delete", "^prompt"], + "name": "host111", + "port": 1231, + "routing_instance": "inst11", + "source_address": "11.1.1.11", + "structured_data": {"brief": True}, + }, + ], + "log_rotate_frequency": 45, + "routing_instance": "inst11", + "source_address": "33.33.33.33", + "time_format": {"set": True}, + "users": [ + {"allow_duplicates": True, "name": "user1"}, + { + "allow_duplicates": True, + "any": {"level": "any"}, + "name": "user2", + "user": {"level": "info"}, + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_logging_global_parsed_16(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <syslog> + <archive> + <size>65578</size> + <files>10</files> + <world-readable/> + <binary-data/> + </archive> + <user> + <name>user1</name> + <allow-duplicates/> + <match-strings>^delete</match-strings> + <match-strings>^prompt</match-strings> + </user> + <user> + <name>user2</name> + <contents> + <name>any</name> + <any/> + </contents> + <contents> + <name>user</name> + <info/> + </contents> + <allow-duplicates/> + </user> + <host> + <name>host111</name> + <contents> + <name>any</name> + <any/> + </contents> + <match>^set*</match> + <allow-duplicates/> + <port>1231</port> + <facility-override>ftp</facility-override> + <log-prefix>field</log-prefix> + <source-address>11.1.1.11</source-address> + <routing-instance>inst11</routing-instance> + <exclude-hostname/> + <match-strings>^delete</match-strings> + <match-strings>^prompt</match-strings> + <structured-data> + <brief/> + </structured-data> + </host> + <allow-duplicates/> + <file> + <name>file101</name> + <allow-duplicates/> + <archive-sites> + <name>www.antsiblr.com</name> + <name>www.antsiblr2.com</name> + </archive-sites> + <contents> + <name>any</name> + <any/> + </contents> + <contents> + <name>authorization</name> + <any/> + </contents> + <structured-data> + <brief/> + </structured-data> + </file> + <console> + <name>any</name> + <info/> + </console> + <console> + <name>authorization</name> + <any/> + </console> + <console> + <name>ftp</name> + <none/> + </console> + <console> + <name>change-log</name> + <critical/> + </console> + <time-format> + </time-format> + <source-address>33.33.33.33</source-address> + <routing-instance>inst11</routing-instance> + <log-rotate-frequency>45</log-rotate-frequency> + </syslog> + </system> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "allow_duplicates": True, + "archive": { + "file_size": 65578, + "files": 10, + "no_binary_data": True, + "no_world_readable": True, + }, + "console": { + "any": {"level": "info"}, + "authorization": {"level": "any"}, + "change_log": {"level": "critical"}, + "ftp": {"level": "none"}, + }, + "files": [ + { + "allow_duplicates": True, + "name": "file101", + "archive_sites": ["www.antsiblr.com", "www.antsiblr2.com"], + "any": {"level": "any"}, + "authorization": {"level": "any"}, + "structured_data": {"brief": True}, + }, + ], + "hosts": [ + { + "allow_duplicates": True, + "any": {"level": "any"}, + "exclude_hostname": True, + "facility_override": "ftp", + "log_prefix": "field", + "match": "^set*", + "match_strings": ["^delete", "^prompt"], + "name": "host111", + "port": 1231, + "routing_instance": "inst11", + "source_address": "11.1.1.11", + "structured_data": {"brief": True}, + }, + ], + "log_rotate_frequency": 45, + "routing_instance": "inst11", + "source_address": "33.33.33.33", + "time_format": {"set": True}, + "users": [ + { + "allow_duplicates": True, + "name": "user1", + "match_strings": ["^delete", "^prompt"], + }, + { + "allow_duplicates": True, + "any": {"level": "any"}, + "name": "user2", + "user": {"level": "info"}, + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_logging_global_parsed_17(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <syslog> + <user> + <name>user1</name> + <match>^set*</match> + <match-strings>^delete</match-strings> + <contents> + <name>user</name> + <info/> + </contents> + </user> + <host> + <name>host111</name> + <contents> + <name>any</name> + <any/> + </contents> + <contents> + <name>authorization</name> + <any/> + </contents> + <match-strings>^delete</match-strings> + <structured-data> + </structured-data> + </host> + <file> + <name>file101</name> + <match-strings>^delete</match-strings> + <archive> + <archive-sites> + <name>www.antsiblr.com</name> + </archive-sites> + <archive-sites> + <name>www.antsiblr2.com</name> + </archive-sites> + </archive> + </file> + </syslog> + </system> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "files": [ + { + "allow_duplicates": True, + "name": "file101", + "archive": { + "archive_sites": [ + "www.antsiblr.com", + "www.antsiblr2.com", + ], + }, + "any": {"level": "any"}, + "authorization": {"level": "any"}, + "structured_data": {"brief": True}, + }, + ], + "hosts": [ + { + "any": {"level": "any"}, + "authorization": {"level": "any"}, + "match_strings": ["^delete"], + "name": "host111", + "structured_data": {"set": True}, + }, + ], + "users": [ + { + "name": "user1", + "user": {"level": "info"}, + "match": "^set*", + "match_strings": ["^delete"], + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py new file mode 100644 index 000000000..2a4806839 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_netconf.py @@ -0,0 +1,131 @@ +# (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.junipernetworks.junos.plugins.modules import junos_netconf +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule + + +class TestJunosCommandModule(TestJunosModule): + + module = junos_netconf + + def setUp(self): + super(TestJunosCommandModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_conn = patch("ansible.module_utils.connection.Connection") + self.conn = self.mock_conn.start() + + self.mock_netconf = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + ) + self.netconf_conn = self.mock_netconf.start() + + self.mock_netconf_rpc = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.netconf.NetconfConnection", + ) + self.netconf_rpc = self.mock_netconf_rpc.start() + + self.mock_get_capabilities = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.get_capabilities", + ) + self.get_capabilities = self.mock_get_capabilities.start() + self.get_capabilities.return_value = {"network_api": "netconf"} + + def tearDown(self): + super(TestJunosCommandModule, self).tearDown() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_conn.stop() + self.mock_netconf.stop() + self.mock_netconf_rpc.stop() + self.mock_get_capabilities.stop() + + def test_junos_netconf_enable(self): + self.netconf_conn().get.return_value = "" + set_module_args(dict(state="present")) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["set system services netconf ssh port 830"], + ) + + def test_junos_netconf_disable(self): + out = """ + ssh { + port 830; + } + """ + self.netconf_conn().get.return_value = out + set_module_args(dict(state="absent")) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["delete system services netconf"], + ) + + def test_junos_netconf_port_change(self): + out = """ + ssh { + port 830; + } + """ + self.netconf_conn().get.return_value = out + set_module_args(dict(state="present", netconf_port=22)) + result = self.execute_module(changed=True) + self.assertEqual( + result["commands"], + ["set system services netconf ssh port 22"], + ) + + def test_junos_netconf_port_error(self): + out = """ + ssh { + port 22; + } + """ + self.netconf_conn().get.return_value = out + set_module_args(dict(state="present", netconf_port=0)) + result = self.execute_module(changed=True, failed=True) + self.assertEqual( + result["msg"], + "netconf_port must be between 1 and 65535", + ) + + def test_junos_netconf_config_error(self): + self.netconf_conn().get.return_value = None + set_module_args(dict(state="present")) + result = self.execute_module(failed=True) + self.assertEqual(result["msg"], "unable to retrieve current config") diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py new file mode 100644 index 000000000..d99faf11a --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ntp_global.py @@ -0,0 +1,717 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_ntp_global +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosNtp_globalModule(TestJunosModule): + module = junos_ntp_global + + def setUp(self): + super(TestJunosNtp_globalModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ntp_global.ntp_global.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ntp_global.ntp_global.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ntp_global.ntp_global." + "Ntp_globalFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosNtp_globalModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_ntp_global_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def test_junos_ntp_global_merged_01(self): + set_module_args( + dict( + config=dict( + boot_server="78.46.194.186", + broadcasts=[ + dict( + address="172.16.255.255", + key="50", + ttl=200, + version=3, + routing_instance_name="rt1", + ), + dict( + address="192.16.255.255", + key="50", + ttl=200, + version=3, + routing_instance_name="rt1", + ), + ], + broadcast_client=True, + interval_range=2, + multicast_client="224.0.0.1", + peers=[ + dict(peer="78.44.194.186"), + dict( + peer="172.44.194.186", + key_id="10000", + prefer=True, + version=3, + ), + ], + servers=[ + dict( + server="48.46.194.186", + key_id=34, + prefer=True, + version=2, + routing_instance="rt1", + ), + dict( + server="48.45.194.186", + key_id=34, + prefer=True, + version=2, + ), + ], + source_addresses=[ + dict( + source_address="172.45.194.186", + routing_instance="rt1", + ), + dict( + source_address="171.45.194.186", + routing_instance="rt2", + ), + ], + threshold=dict(action="accept", value=300), + trusted_keys=[dict(key_id=3000), dict(key_id=2000)], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:ntp><nc:boot-server>78.46.194.186</nc:boot-server>", + str(result["commands"]), + ) + self.assertIn( + "<nc:broadcast><nc:name>172.16.255.255</nc:name><nc:key>50</nc:key>", + str(result["commands"]), + ) + self.assertIn( + "<nc:routing-instance-name>rt1</nc:routing-instance-name><nc:ttl>200</nc:ttl>", + str(result["commands"]), + ) + self.assertIn( + "<nc:version>3</nc:version></nc:broadcast><nc:broadcast>", + str(result["commands"]), + ) + self.assertIn( + "<nc:name>192.16.255.255</nc:name><nc:key>50</nc:key>", + str(result["commands"]), + ) + + def test_junos_ntp_global_merged_02(self): + set_module_args( + dict( + config=dict( + boot_server="78.46.194.186", + authentication_keys=[ + dict(id="2", algorithm="md5", key="asdfghd"), + dict(id="5", algorithm="sha1", key="aasdad"), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:ntp><nc:authentication-key><nc:name>2</nc:name><nc:type>md5</nc:type><nc:value>asdfghd</nc:value></nc:authentication-key>", + str(result["commands"]), + ) + self.assertIn( + "<nc:authentication-key><nc:name>5</nc:name><nc:type>sha1</nc:type><nc:value>aasdad</nc:value>", + str(result["commands"]), + ) + + def test_junos_ntp_global_parsed_01(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <ntp> + <boot-server>78.46.194.186</boot-server> + <interval-range> + <value>2</value> + </interval-range> + <peer> + <name>78.44.194.186</name> + </peer> + <peer> + <name>172.44.194.186</name> + <key>10000</key> + <version>3</version> + <prefer/> + </peer> + <server> + <name>48.46.194.186</name> + <key>34</key> + <version>2</version> + <prefer/> + <routing-instance>rt1</routing-instance> + </server> + <server> + <name>48.45.194.186</name> + <key>34</key> + <version>2</version> + <prefer/> + </server> + <broadcast> + <name>172.16.255.255</name> + <routing-instance-name>rt1</routing-instance-name> + <key>50</key> + <version>3</version> + <ttl>200</ttl> + </broadcast> + <broadcast> + <name>192.16.255.255</name> + <routing-instance-name>rt2</routing-instance-name> + <key>50</key> + <version>3</version> + <ttl>200</ttl> + </broadcast> + <broadcast-client/> + <multicast-client> + <address>224.0.0.1</address> + </multicast-client> + <trusted-key>3000</trusted-key> + <trusted-key>2000</trusted-key> + <threshold> + <value>300</value> + <action>accept</action> + </threshold> + <source-address> + <name>172.45.194.186</name> + <routing-instance>rt1</routing-instance> + </source-address> + <source-address> + <name>171.45.194.186</name> + <routing-instance>rt2</routing-instance> + </source-address> + </ntp> + </system> + <interfaces xmlns="http://yang.juniper.net/junos-es/conf/interfaces"> + <interface> + <name>fxp0</name> + <unit> + <name>0</name> + <family> + <inet> + <dhcp> + </dhcp> + </inet> + </family> + </unit> + </interface> + </interfaces> + <routing-instances xmlns="http://yang.juniper.net/junos-es/conf/routing-instances"> + <instance> + <name>rt1</name> + <description>rt1</description> + </instance> + <instance> + <name>rt2</name> + <description>rt2</description> + </instance> + </routing-instances> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "boot_server": "78.46.194.186", + "broadcast_client": True, + "broadcasts": [ + { + "address": "172.16.255.255", + "key": "50", + "routing_instance_name": "rt1", + "ttl": 200, + "version": 3, + }, + { + "address": "192.16.255.255", + "key": "50", + "routing_instance_name": "rt2", + "ttl": 200, + "version": 3, + }, + ], + "interval_range": 2, + "multicast_client": "224.0.0.1", + "peers": [ + {"peer": "78.44.194.186"}, + { + "key_id": 10000, + "peer": "172.44.194.186", + "prefer": True, + "version": 3, + }, + ], + "servers": [ + { + "key_id": 34, + "prefer": True, + "routing_instance": "rt1", + "server": "48.46.194.186", + "version": 2, + }, + { + "key_id": 34, + "prefer": True, + "server": "48.45.194.186", + "version": 2, + }, + ], + "source_addresses": [ + { + "routing_instance": "rt1", + "source_address": "172.45.194.186", + }, + { + "routing_instance": "rt2", + "source_address": "171.45.194.186", + }, + ], + "threshold": {"action": "accept", "value": 300}, + "trusted_keys": [{"key_id": 2000}, {"key_id": 3000}], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_ntp_global_parsed_02(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <ntp> + <boot-server>78.46.194.186</boot-server> + <interval-range> + <value>2</value> + </interval-range> + <peer> + <name>172.44.194.186</name> + <key>10000</key> + <version>3</version> + <prefer/> + </peer> + <server> + <name>48.45.194.186</name> + <key>34</key> + <version>2</version> + <prefer/> + </server> + <broadcast> + <name>192.16.255.255</name> + <routing-instance-name>rt2</routing-instance-name> + <key>50</key> + <version>3</version> + <ttl>200</ttl> + </broadcast> + <broadcast-client/> + <multicast-client> + <address>224.0.0.1</address> + </multicast-client> + <trusted-key>2000</trusted-key> + <threshold> + <value>300</value> + <action>accept</action> + </threshold> + <source-address> + <name>171.45.194.186</name> + <routing-instance>rt2</routing-instance> + </source-address> + </ntp> + </system> + <routing-instances xmlns="http://yang.juniper.net/junos-es/conf/routing-instances"> + <instance> + <name>rt1</name> + <description>rt1</description> + </instance> + <instance> + <name>rt2</name> + <description>rt2</description> + </instance> + </routing-instances> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "boot_server": "78.46.194.186", + "broadcast_client": True, + "broadcasts": [ + { + "address": "192.16.255.255", + "key": "50", + "routing_instance_name": "rt2", + "ttl": 200, + "version": 3, + }, + ], + "interval_range": 2, + "multicast_client": "224.0.0.1", + "peers": [ + { + "key_id": 10000, + "peer": "172.44.194.186", + "prefer": True, + "version": 3, + }, + ], + "servers": [ + { + "key_id": 34, + "prefer": True, + "server": "48.45.194.186", + "version": 2, + }, + ], + "source_addresses": [ + {"routing_instance": "rt2", "source_address": "171.45.194.186"}, + ], + "threshold": {"action": "accept", "value": 300}, + "trusted_keys": [{"key_id": 2000}], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_ntp_global_parsed_03(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <system> + <ntp> + <authentication-key> + <name>2</name> + <type>md5</type> + <value>$9$GxDjqfT3CA0UjfzF6u0RhS</value> + </authentication-key> + <authentication-key> + <name>5</name> + <type>sha1</type> + <value>$9$ZsUDk.mT3/toJGiHqQz</value> + </authentication-key> + </ntp> + </system> + <routing-instances xmlns="http://yang.juniper.net/junos-es/conf/routing-instances"> + <instance> + <name>rt1</name> + <description>rt1</description> + </instance> + <instance> + <name>rt2</name> + <description>rt2</description> + </instance> + </routing-instances> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "authentication_keys": [ + { + "algorithm": "md5", + "id": 2, + "key": "$9$GxDjqfT3CA0UjfzF6u0RhS", + }, + { + "algorithm": "sha1", + "id": 5, + "key": "$9$ZsUDk.mT3/toJGiHqQz", + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_ntp_global_overridden_01(self): + set_module_args( + dict( + config=dict( + boot_server="78.46.194.186", + broadcasts=[ + dict( + address="172.16.255.255", + key="50", + ttl=200, + version=3, + routing_instance_name="rt1", + ), + dict( + address="192.16.255.255", + key="50", + ttl=200, + version=3, + routing_instance_name="rt1", + ), + ], + broadcast_client=True, + interval_range=2, + multicast_client="224.0.0.1", + peers=[ + dict(peer="78.44.194.186"), + dict( + peer="172.44.194.186", + key_id="10000", + prefer=True, + version=3, + ), + ], + servers=[ + dict( + server="48.46.194.186", + key_id=34, + prefer=True, + version=2, + routing_instance="rt1", + ), + dict( + server="48.45.194.186", + key_id=34, + prefer=True, + version=2, + ), + ], + source_addresses=[ + dict( + source_address="172.45.194.186", + routing_instance="rt1", + ), + dict( + source_address="171.45.194.186", + routing_instance="rt2", + ), + ], + threshold=dict(action="accept", value=300), + trusted_keys=[dict(key_id=3000), dict(key_id=2000)], + ), + state="overridden", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:ntp><nc:boot-server>78.46.194.186</nc:boot-server>", + str(result["commands"]), + ) + self.assertIn( + "<nc:broadcast><nc:name>172.16.255.255</nc:name><nc:key>50</nc:key>", + str(result["commands"]), + ) + self.assertIn( + "<nc:routing-instance-name>rt1</nc:routing-instance-name><nc:ttl>200</nc:ttl>", + str(result["commands"]), + ) + self.assertIn( + "<nc:version>3</nc:version></nc:broadcast><nc:broadcast>", + str(result["commands"]), + ) + self.assertIn( + "<nc:name>192.16.255.255</nc:name><nc:key>50</nc:key>", + str(result["commands"]), + ) + + def test_junos_ntp_global_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = { + "authentication_keys": [ + { + "algorithm": "md5", + "id": 3, + "key": "$9$GxDjqfT3CA0UjfzF6u0RhS", + }, + { + "algorithm": "sha1", + "id": 4, + "key": "$9$ZsUDk.mT3/toJGiHqQz", + }, + ], + } + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + def test_junos_ntp_global_rendered(self): + set_module_args( + dict( + config=dict( + boot_server="78.46.194.186", + authentication_keys=[ + dict(id="2", algorithm="md5", key="asdfghd"), + dict(id="5", algorithm="sha1", key="aasdad"), + ], + ), + state="rendered", + ), + ) + rendered = ( + '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:ntp><nc:authentication-key><nc:name>2</nc:name><nc:type>md5</nc:type>" + "<nc:value>asdfghd</nc:value></nc:authentication-key><nc:authentication-key>" + "<nc:name>5</nc:name><nc:type>sha1</nc:type><nc:value>aasdad</nc:value>" + "</nc:authentication-key><nc:boot-server>78.46.194.186</nc:boot-server></nc:ntp></nc:system>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_ntp_global_replaced_01(self): + set_module_args( + dict( + config=dict( + boot_server="78.46.194.186", + broadcasts=[ + dict( + address="172.16.255.255", + key="50", + ttl=200, + version=3, + routing_instance_name="rt1", + ), + dict( + address="192.16.255.255", + key="50", + ttl=200, + version=3, + routing_instance_name="rt1", + ), + ], + broadcast_client=True, + interval_range=2, + multicast_client="224.0.0.1", + peers=[ + dict(peer="78.44.194.186"), + dict( + peer="172.44.194.186", + key_id="10000", + prefer=True, + version=3, + ), + ], + servers=[ + dict( + server="48.46.194.186", + key_id=34, + prefer=True, + version=2, + routing_instance="rt1", + ), + dict( + server="48.45.194.186", + key_id=34, + prefer=True, + version=2, + ), + ], + source_addresses=[ + dict( + source_address="172.45.194.186", + routing_instance="rt1", + ), + dict( + source_address="171.45.194.186", + routing_instance="rt2", + ), + ], + threshold=dict(action="accept", value=300), + trusted_keys=[dict(key_id=3000), dict(key_id=2000)], + ), + state="replaced", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:ntp><nc:boot-server>78.46.194.186</nc:boot-server>", + str(result["commands"]), + ) + self.assertIn( + "<nc:broadcast><nc:name>172.16.255.255</nc:name><nc:key>50</nc:key>", + str(result["commands"]), + ) + self.assertIn( + "<nc:routing-instance-name>rt1</nc:routing-instance-name><nc:ttl>200</nc:ttl>", + str(result["commands"]), + ) + self.assertIn( + "<nc:version>3</nc:version></nc:broadcast><nc:broadcast>", + str(result["commands"]), + ) + self.assertIn( + "<nc:name>192.16.255.255</nc:name><nc:key>50</nc:key>", + str(result["commands"]), + ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py new file mode 100644 index 000000000..e57a65955 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospf_interfaces.py @@ -0,0 +1,343 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_ospf_interfaces +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import MagicMock, patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosOspfv3Module(TestJunosModule): + module = junos_ospf_interfaces + + def setUp(self): + super(TestJunosOspfv3Module, self).setUp() + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospf_interfaces.ospf_interfaces.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_validate_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils.validate_config", + ) + self.validate_config = self.mock_validate_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospf_interfaces.ospf_interfaces.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_get_connection = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospf_interfaces.ospf_interfaces." + "Ospf_interfacesFacts.get_connection", + ) + self.get_connection = self.mock_get_connection.start() + + self.conn = self.get_connection() + self.conn.get = MagicMock() + + self.mock_get_xml_dict = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts." + "ospf_interfaces.ospf_interfaces.Ospf_interfacesFacts._get_xml_dict", + ) + self._get_xml_dict = self.mock_get_xml_dict.start() + + def tearDown(self): + super(TestJunosOspfv3Module, self).tearDown() + self.mock_get_connection.stop() + self.mock_load_config.stop() + self.mock_validate_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + + def load_fixtures(self, commands=None, format="text", changed=False): + self.get_connection.return_value = load_fixture( + "junos_ospf_interfaces_config.cfg", + ) + if changed: + self.load_config.return_value = load_fixture( + "get_configuration_rpc_reply_diff.txt", + ) + else: + self.load_config.return_value = None + + def test_junos_ospf_interfaces_merged(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + name="ge-0/0/2.0", + address_family=[ + dict( + afi="ipv4", + processes=dict( + area=dict(area_id="0.0.0.2"), + priority=3, + metric=5, + ), + ), + ], + ), + ], + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf>' + "<nc:area><nc:name>0.0.0.2</nc:name><nc:interface><nc:name>ge-0/0/2.0</nc:name>" + "<nc:priority>3</nc:priority><nc:metric>5</nc:metric></nc:interface></nc:area></nc:ospf></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_ospf_interfaces_merged_idempotent(self): + self.get_connection.return_value = load_fixture( + "junos_ospf_interfaces_config.cfg", + ) + src = load_fixture("junos_ospf_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.77", + name="so-0/0/0.0", + address_family=[ + dict( + afi="ipv4", + processes=dict( + area=dict(area_id="0.0.0.10"), + priority=3, + metric=5, + ), + ), + ], + ), + ], + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_ospf_interfaces_replaced(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + name="ge-0/0/2.0", + address_family=[ + dict( + afi="ipv4", + processes=dict( + area=dict(area_id="0.0.0.1"), + priority=6, + metric=7, + ), + ), + ], + ), + ], + state="replaced", + ), + ) + result = self.execute_module(changed=True) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf/><nc:ospf>' + "<nc:area><nc:name>0.0.0.1</nc:name><nc:interface><nc:name>ge-0/0/2.0</nc:name>" + "<nc:priority>6</nc:priority><nc:metric>7</nc:metric></nc:interface></nc:area></nc:ospf></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + ] + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_ospf_interfaces_replaced_idempotent(self): + self.get_connection.return_value = load_fixture( + "junos_ospf_interfaces_config.cfg", + ) + src = load_fixture("junos_ospf_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + name="ge-0/0/2.0", + address_family=[ + dict( + afi="ipv4", + processes=dict( + area=dict(area_id="0.0.0.1"), + priority=6, + metric=7, + ), + ), + ], + ), + ], + state="replaced", + ), + ) + + self.execute_module(changed=False, commands=[]) + + def test_junos_ospf_interfaces_overridden(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + name="ge-0/0/2.0", + address_family=[ + dict( + afi="ipv4", + processes=dict( + area=dict(area_id="0.0.0.1"), + priority=6, + metric=7, + ), + ), + ], + ), + ], + state="overridden", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf/><nc:ospf>' + "<nc:area><nc:name>0.0.0.1</nc:name><nc:interface><nc:name>ge-0/0/2.0</nc:name>" + "<nc:priority>6</nc:priority><nc:metric>7</nc:metric></nc:interface></nc:area></nc:ospf></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_ospf_interfaces_overridden_idempotent(self): + self.get_connection.return_value = load_fixture( + "junos_ospf_interfaces_config.cfg", + ) + src = load_fixture("junos_ospf_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + name="ge-0/0/2.0", + address_family=[ + dict( + afi="ipv4", + processes=dict( + area=dict(area_id="0.0.0.1"), + priority=6, + metric=7, + ), + ), + ], + ), + ], + state="overridden", + ), + ) + + self.execute_module(changed=False, commands=[]) + + def test_junos_ospf_interfaces_delete(self): + self.get_connection.return_value = load_fixture( + "junos_ospf_interfaces_config.cfg", + ) + src = load_fixture("junos_ospf_interfaces.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[dict(router_id="10.200.16.75", name="ge-0/0/2.0")], + state="deleted", + ), + ) + + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf/></nc:protocols>', + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"/>', + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_ospf_interfaces_delete_idempotent(self): + set_module_args( + dict( + config=[dict(router_id="10.200.16.75", name="ge-0/0/2.0")], + state="deleted", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_ospf_interfaces_rendered(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + name="ge-0/0/2.0", + address_family=[ + dict( + afi="ipv4", + processes=dict( + area=dict(area_id="0.0.0.1"), + priority=6, + metric=7, + ), + ), + ], + ), + ], + state="rendered", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf/><nc:ospf>' + "<nc:area><nc:name>0.0.0.1</nc:name><nc:interface><nc:name>ge-0/0/2.0</nc:name>" + "<nc:priority>6</nc:priority><nc:metric>7</nc:metric></nc:interface></nc:area></nc:ospf></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + ] + self.execute_module(changed=False, commands=commands) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py new file mode 100644 index 000000000..786057021 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv2.py @@ -0,0 +1,673 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v2.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_ospfv2 +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosOspfv2Module(TestJunosModule): + module = junos_ospfv2 + + def setUp(self): + super(TestJunosOspfv2Module, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospfv2.ospfv2.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospfv2.ospfv2.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv2.ospfv2." + "Ospfv2Facts.get_connection", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosOspfv2Module, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_ospfv2_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def sort_ospf(self, entry_list): + entry_list.sort(key=lambda i: i.get("name")) + + def test_junos_ospfv2_merged(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + areas=[ + dict( + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + ), + ], + ), + ], + ), + ], + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf>' + "<nc:area><nc:name>0.0.0.100</nc:name><nc:interface><nc:name>so-0/0/0.0</nc:name>" + "<nc:priority>3</nc:priority><nc:metric>5</nc:metric></nc:interface><nc:stub>" + "<nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_ospfv2_merged_bandwith(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.77", + areas=[ + dict( + area_id="0.0.0.10", + interfaces=[ + dict( + name="so-0/0/0.0", + metric=5, + bandwidth_based_metrics=[ + dict(bandwidth="10g", metric=5), + ], + ), + ], + ), + ], + ), + ], + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn("<nc:name>0.0.0.10</nc:name>", str(result["commands"])) + self.assertIn( + "<nc:interface><nc:name>so-0/0/0.0</nc:name>", + str(result["commands"]), + ) + self.assertIn( + "<nc:bandwidth-based-metrics><nc:bandwidth><nc:name>10g</nc:name>", + str(result["commands"]), + ) + self.assertIn("<nc:metric>5</nc:metric>", str(result["commands"])) + + def test_junos_ospfv2_merged_02(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + areas=[ + dict( + area_id="0.0.0.100", + area_range="3:3::/64", + stub=dict(set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + flood_reduction=True, + passive=True, + timers=dict( + dead_interval=100, + hello_interval=80, + retransmit_interval=90, + transit_delay=True, + ), + ), + ], + ), + ], + ), + ], + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + "<nc:ospf><nc:area><nc:name>0.0.0.100</nc:name>", + str(result["commands"]), + ) + self.assertIn( + "<nc:interface><nc:name>so-0/0/0.0</nc:name>", + str(result["commands"]), + ) + self.assertIn("<nc:priority>3</nc:priority>", str(result["commands"])) + self.assertIn("<nc:flood-reduction/>", str(result["commands"])) + self.assertIn("<nc:metric>5</nc:metric>", str(result["commands"])) + self.assertIn("<nc:passive/>", str(result["commands"])) + self.assertIn( + "<nc:dead-interval>100</nc:dead-interval>", + str(result["commands"]), + ) + self.assertIn( + "<nc:hello-interval>80</nc:hello-interval>", + str(result["commands"]), + ) + self.assertIn( + "<nc:retransmit-interval>90</nc:retransmit-interval>", + str(result["commands"]), + ) + self.assertIn("</nc:interface>", str(result["commands"])) + self.assertIn( + "<nc:stub/></nc:area></nc:ospf></nc:protocols>", + str(result["commands"]), + ) + self.assertIn("</nc:interface>", str(result["commands"])) + self.assertIn( + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + str(result["commands"]), + ) + + def test_junos_ospfv2_merged_03(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + external_preference=2, + overload=dict(timeout=80), + preference=1, + prefix_export_limit=20000, + reference_bandwidth="10g", + rfc1583compatibility=False, + spf_options=dict( + delay=1000, + holddown=15000, + rapid_runs=9, + ), + ), + ], + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + "<nc:spf-options><nc:delay>1000</nc:delay>", + str(result["commands"]), + ) + self.assertIn( + "<nc:overload><nc:timeout>80</nc:timeout></nc:overload>", + str(result["commands"]), + ) + self.assertIn( + "<nc:external-preference>2</nc:external-preference>", + str(result["commands"]), + ) + self.assertIn( + "<nc:preference>1</nc:preference>", + str(result["commands"]), + ) + self.assertIn( + "<nc:prefix-export-limit>20000</nc:prefix-export-limit>", + str(result["commands"]), + ) + self.assertIn( + "<nc:reference-bandwidth>10g</nc:reference-bandwidth>", + str(result["commands"]), + ) + self.assertIn("<nc:no-rfc-1583/>", str(result["commands"])) + self.assertIn( + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + str(result["commands"]), + ) + + def test_junos_ospfv2_replaced_01(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.77", + areas=[ + dict( + area_id="0.0.0.10", + stub=dict(default_metric=200, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=2, + passive=True, + ), + dict( + name="so-0/0/0.1", + priority=4, + metric=4, + ), + ], + ), + dict( + area_id="0.0.0.1=30", + interfaces=[ + dict(name="ge-1/1/1.0"), + dict(name="ge-2/2/2.0"), + ], + ), + ], + ), + ], + state="replaced", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + '<nc:ospf><nc:area delete="delete">0.0.0.20</nc:area></nc:ospf>', + str(result["commands"]), + ) + self.assertIn( + '<nc:ospf><nc:area delete="delete">0.0.0.10</nc:area></nc:ospf>', + str(result["commands"]), + ) + self.assertIn( + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn("<nc:metric>2</nc:metric>", str(result["commands"])) + self.assertIn("<nc:priority>3</nc:priority>", str(result["commands"])) + self.assertIn( + "<nc:interface><nc:name>so-0/0/0.1</nc:name>", + str(result["commands"]), + ) + self.assertIn( + "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub>", + str(result["commands"]), + ) + self.assertIn( + "<nc:router-id>10.200.16.77</nc:router-id></nc:routing-options>", + str(result["commands"]), + ) + + def test_junos_ospfv2_merged_01(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.77", + areas=[ + dict( + area_id="0.0.0.10", + stub=dict(default_metric=200, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=2, + passive=True, + ), + dict( + name="so-0/0/0.1", + priority=4, + metric=4, + ), + ], + ), + dict( + area_id="0.0.0.1=30", + interfaces=[ + dict(name="ge-1/1/1.0"), + dict(name="ge-2/2/2.0"), + ], + ), + ], + ), + ], + state="overridden", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + '<nc:ospf><nc:area delete="delete">0.0.0.20</nc:area></nc:ospf>', + str(result["commands"]), + ) + self.assertIn( + '<nc:ospf><nc:area delete="delete">0.0.0.10</nc:area></nc:ospf>', + str(result["commands"]), + ) + self.assertIn( + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn("<nc:metric>2</nc:metric>", str(result["commands"])) + self.assertIn("<nc:priority>3</nc:priority>", str(result["commands"])) + self.assertIn( + "<nc:interface><nc:name>so-0/0/0.1</nc:name>", + str(result["commands"]), + ) + self.assertIn( + "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub>", + str(result["commands"]), + ) + self.assertIn( + "<nc:router-id>10.200.16.77</nc:router-id></nc:routing-options>", + str(result["commands"]), + ) + + def test_junos_ospfv2_deleted(self): + """ + :return: + """ + set_module_args(dict(config=[], state="deleted")) + + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:ospf><nc:area delete="delete">0.0.0.10</nc:area></nc:ospf>' + '<nc:ospf><nc:area delete="delete">0.0.0.20</nc:area></nc:ospf>' + "</nc:protocols>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_ospfv2_rendered(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + areas=[ + dict( + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + ), + ], + ), + ], + ), + ], + state="rendered", + ), + ) + rendered = ( + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:ospf><nc:area><nc:name>0.0.0.100</nc:name><nc:interface>" + "<nc:name>so-0/0/0.0</nc:name><nc:priority>3</nc:priority>" + "<nc:metric>5</nc:metric></nc:interface>" + "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf></nc:protocols>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_vlans_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = [ + dict( + router_id="10.200.16.77", + areas=[ + dict( + area_id="0.0.0.10", + stub=dict(default_metric=200, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + passive=True, + flood_reduction=True, + ), + ], + ), + dict( + area_id="0.0.0.20", + interfaces=[ + dict(name="ge-1/1/0.0"), + dict(name="ge-2/2/0.0"), + ], + ), + ], + ), + ] + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + def test_junos_vlans_parsed(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <ospf> + <area> + <name>0.0.0.200</name> + <interface> + <name>so-0/0/0.1</name> + <metric>3</metric> + <priority>5</priority> + </interface> + </area> + <area> + <name>0.0.0.100</name> + <stub> + <default-metric>200</default-metric> + </stub> + <interface> + <name>so-0/0/0.0</name> + <metric>5</metric> + <priority>3</priority> + <bandwidth-based-metrics> + <bandwidth> + <name>10g</name> + <metric>5</metric> + </bandwidth> + </bandwidth-based-metrics> + </interface> + </area> + </ospf> + </protocols> + <routing-options> + <router-id>10.200.16.7</router-id> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = [ + { + "areas": [ + { + "area_id": "0.0.0.200", + "interfaces": [ + {"metric": 3, "name": "so-0/0/0.1", "priority": 5}, + ], + }, + { + "area_id": "0.0.0.100", + "interfaces": [ + { + "bandwidth_based_metrics": [ + {"metric": 5, "bandwidth": "10g"}, + ], + "metric": 5, + "name": "so-0/0/0.0", + "priority": 3, + }, + ], + "stub": {"default_metric": 200, "set": True}, + }, + ], + "router_id": "10.200.16.7", + }, + ] + self.assertEqual(result["parsed"], parsed_list) + + def test_junos_vlans_parsed_02(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <protocols> + <ospf> + <area> + <name>0.0.0.200</name> + <interface> + <name>so-0/0/0.1</name> + <metric>3</metric> + <priority>5</priority> + </interface> + </area> + <area> + <name>0.0.0.100</name> + <stub> + <default-metric>200</default-metric> + </stub> + <interface> + <name>so-0/0/0.0</name> + <metric>5</metric> + <priority>3</priority> + <bandwidth-based-metrics> + <bandwidth> + <name>10g</name> + <metric>5</metric> + </bandwidth> + <bandwidth> + <name>1g</name> + <metric>5</metric> + </bandwidth> + </bandwidth-based-metrics> + </interface> + </area> + </ospf> + </protocols> + <routing-options> + <router-id>10.200.16.7</router-id> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = [ + { + "areas": [ + { + "area_id": "0.0.0.200", + "interfaces": [ + {"metric": 3, "name": "so-0/0/0.1", "priority": 5}, + ], + }, + { + "area_id": "0.0.0.100", + "interfaces": [ + { + "bandwidth_based_metrics": [ + {"metric": 5, "bandwidth": "10g"}, + {"metric": 5, "bandwidth": "1g"}, + ], + "metric": 5, + "name": "so-0/0/0.0", + "priority": 3, + }, + ], + "stub": {"default_metric": 200, "set": True}, + }, + ], + "router_id": "10.200.16.7", + }, + ] + self.assertEqual(result["parsed"], parsed_list) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py new file mode 100644 index 000000000..054947448 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ospfv3.py @@ -0,0 +1,403 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_ospfv3 +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import MagicMock, patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosOspfv3Module(TestJunosModule): + module = junos_ospfv3 + + def setUp(self): + super(TestJunosOspfv3Module, self).setUp() + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospfv3.ospfv3.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_validate_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils.validate_config", + ) + self.validate_config = self.mock_validate_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.ospfv3.ospfv3.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_get_connection = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv3.ospfv3." + "Ospfv3Facts.get_connection", + ) + self.get_connection = self.mock_get_connection.start() + + self.conn = self.get_connection() + self.conn.get = MagicMock() + + self.mock_get_xml_dict = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv3.ospfv3.Ospfv3Facts._get_xml_dict", + ) + self._get_xml_dict = self.mock_get_xml_dict.start() + + def tearDown(self): + super(TestJunosOspfv3Module, self).tearDown() + self.mock_get_connection.stop() + self.mock_load_config.stop() + self.mock_validate_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + + def load_fixtures(self, commands=None, format="text", changed=False): + self.get_connection.return_value = load_fixture( + "junos_ospfv3_config.cfg", + ) + if changed: + self.load_config.return_value = load_fixture( + "get_configuration_rpc_reply_diff.txt", + ) + else: + self.load_config.return_value = None + + def test_junos_ospfv3_merged(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + areas=[ + dict( + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + ), + ], + ), + ], + ), + ], + state="merged", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf3>' + "<nc:area><nc:name>0.0.0.100</nc:name><nc:interface><nc:name>so-0/0/0.0</nc:name>" + "<nc:priority>3</nc:priority><nc:metric>5</nc:metric></nc:interface><nc:stub>" + "<nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf3></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_ospfv3_merged_idempotent(self): + self.get_connection.return_value = load_fixture( + "junos_ospfv3_config.cfg", + ) + src = load_fixture("junos_ospfv3.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + router_id="30", + areas=[ + dict( + area_id="100", + stub=dict(default_metric=10, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + ), + ], + ), + ], + ), + ], + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_ospfv3_replaced(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + areas=[ + dict( + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + ), + ], + ), + ], + ), + ], + state="replaced", + ), + ) + result = self.execute_module(changed=True) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf3>' + "<nc:area><nc:name>0.0.0.100</nc:name><nc:interface><nc:name>so-0/0/0.0</nc:name>" + "<nc:priority>3</nc:priority>" + "<nc:metric>5</nc:metric></nc:interface>" + "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf3>" + "<nc:ospf3><nc:area><nc:name>0.0.0.100</nc:name>" + "<nc:interface><nc:name>so-0/0/0.0</nc:name>" + "<nc:priority>3</nc:priority><nc:metric>5</nc:metric></nc:interface>" + "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf3></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:router-id>10.200.16.75</nc:router-id><nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + ] + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_ospfv3_replaced_idempotent(self): + self.get_connection.return_value = load_fixture( + "junos_ospfv3_config.cfg", + ) + src = load_fixture("junos_ospfv3.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + router_id="30", + areas=[ + dict( + area_id="100", + stub=dict(default_metric=10, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + ), + ], + ), + ], + ), + ], + state="replaced", + ), + ) + + self.execute_module(changed=False, commands=[]) + + def test_junos_ospfv3_overridden(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + areas=[ + dict( + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + ), + ], + ), + ], + ), + ], + state="overridden", + ), + ) + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf3 delete="delete"/><nc:ospf3>' + "<nc:area><nc:name>0.0.0.100</nc:name><nc:interface><nc:name>so-0/0/0.0</nc:name>" + "<nc:priority>3</nc:priority>" + "<nc:metric>5</nc:metric></nc:interface>" + "<nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf3></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_ospfv3_overridden_idempotent(self): + self.get_connection.return_value = load_fixture( + "junos_ospfv3_config.cfg", + ) + src = load_fixture("junos_ospfv3.cfg", content="str") + set_module_args(dict(src=src)) + set_module_args( + dict( + config=[ + dict( + router_id="30", + areas=[ + dict( + area_id="100", + stub=dict(default_metric=10, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + ), + ], + ), + ], + ), + ], + state="overridden", + ), + ) + + self.execute_module(changed=False, commands=[]) + + def test_junos_ospfv3_delete(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + areas=[ + dict( + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + interfaces=[dict(name="so-0/0/0.0")], + ), + ], + ), + ], + state="deleted", + ), + ) + + commands = [ + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf3>' + "<nc:area><nc:name>0.0.0.100</nc:name><nc:interface><nc:name>so-0/0/0.0</nc:name>" + "</nc:interface><nc:stub><nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf3></nc:protocols>", + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:router-id>10.200.16.75</nc:router-id></nc:routing-options>", + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), commands) + + def test_junos_ospfv3_delete_idempotent(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.70", + areas=[ + dict( + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + interfaces=[dict(name="so-0/0/0.0")], + ), + ], + ), + ], + state="deleted", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_junos_ospfv3_parsed(self): + + set_module_args( + dict( + running_config='<?xml version="1.0" encoding="UTF-8"?>\n' + '<rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f">\n' + '<configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC">' + "\n<protocols>\n<ospf3>\n<area>\n<name>0.0.0.100</name>\n<stub>\n" + "<default-metric>200</default-metric>\n</stub>\n<interface>\n<name>so-0/0/0.0</name>" + "\n<passive></passive>\n<metric>5</metric>\n<priority>3</priority>\n" + "</interface>\n</area>\n</ospf3>\n</protocols>\n<routing-options>\n" + "<router-id>10.200.16.75</router-id>\n</routing-options>\n" + "</configuration>\n</rpc-reply>", + state="parsed", + ), + ) + result = self.execute_module(changed=False) + self.assertEqual([], result["parsed"]) + + def test_junos_ospfv3_rendered(self): + set_module_args( + dict( + config=[ + dict( + router_id="10.200.16.75", + areas=[ + dict( + area_id="0.0.0.100", + stub=dict(default_metric=200, set=True), + interfaces=[ + dict( + name="so-0/0/0.0", + priority=3, + metric=5, + ), + ], + ), + ], + ), + ], + state="rendered", + ), + ) + commands = ( + '<nc:protocols xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:ospf3>' + "<nc:area><nc:name>0.0.0.100</nc:name><nc:interface><nc:name>so-0/0/0.0</nc:name>" + "<nc:priority>3</nc:priority><nc:metric>5</nc:metric></nc:interface><nc:stub>" + "<nc:default-metric>200</nc:default-metric></nc:stub></nc:area></nc:ospf3></nc:protocols>" + ) + self.execute_module(changed=False, commands=commands) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py new file mode 100644 index 000000000..38e3599d0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_package.py @@ -0,0 +1,81 @@ +# (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.junipernetworks.junos.tests.unit.compat.mock import MagicMock, patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule + + +jnpr_mock = MagicMock() +modules = { + "jnpr": jnpr_mock, + "jnpr.junos": jnpr_mock.junos, + "jnpr.junos.utils": jnpr_mock.junos.utils, + "jnpr.junos.utils.sw": jnpr_mock.junos.utils.sw, +} +module_patcher = patch.dict("sys.modules", modules) +module_patcher.start() + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_package + + +class TestJunosPackageModule(TestJunosModule): + + module = junos_package + + def setUp(self): + super(TestJunosPackageModule, self).setUp() + self.mock_get_device = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_package.get_device", + ) + self.get_device = self.mock_get_device.start() + + def tearDown(self): + super(TestJunosPackageModule, self).tearDown() + self.mock_get_device.stop() + + def test_junos_package_src(self): + set_module_args(dict(src="junos-vsrx-12.1X46-D10.2-domestic.tgz")) + self.execute_module(changed=True) + + args, _kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args + self.assertEqual(args, ("junos-vsrx-12.1X46-D10.2-domestic.tgz",)) + + def test_junos_package_src_fail(self): + jnpr_mock.junos.utils.sw.SW().install.return_value = 0 + set_module_args(dict(src="junos-vsrx-12.1X46-D10.2-domestic.tgz")) + result = self.execute_module(changed=True, failed=True) + + self.assertEqual(result["msg"], "Unable to install package on device") + + def test_junos_package_src_no_copy(self): + jnpr_mock.junos.utils.sw.SW().install.return_value = 1 + set_module_args( + dict(src="junos-vsrx-12.1X46-D10.2-domestic.tgz", no_copy=True), + ) + self.execute_module(changed=True) + + args, kwargs = jnpr_mock.junos.utils.sw.SW().install.call_args + self.assertEqual(args, ("junos-vsrx-12.1X46-D10.2-domestic.tgz",)) + self.assertEqual(kwargs["no_copy"], True) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py new file mode 100644 index 000000000..da101d418 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_ping.py @@ -0,0 +1,167 @@ +# (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.junipernetworks.junos.plugins.modules import junos_ping +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import MagicMock, patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosPingModule(TestJunosModule): + module = junos_ping + + def setUp(self): + super(TestJunosPingModule, self).setUp() + + self.mock_get_connection = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_ping.get_connection", + ) + self.get_connection = self.mock_get_connection.start() + + self.conn = self.get_connection() + self.conn.get = MagicMock() + + def tearDown(self): + super(TestJunosPingModule, self).tearDown() + self.mock_get_connection.stop() + + def test_junos_ping_expected_success(self): + set_module_args(dict(count=2, dest="10.10.10.10")) + self.conn.get = MagicMock( + return_value=load_fixture( + "junos_ping_ping_10.10.10.10_count_2", + content="str", + ), + ) + result = self.execute_module() + self.assertEqual(result["commands"], "ping 10.10.10.10 count 2") + + def test_junos_ping_expected_failure(self): + set_module_args(dict(count=4, dest="10.10.10.20", state="absent")) + self.conn.get = MagicMock( + return_value=load_fixture( + "junos_ping_ping_10.10.10.20_count_4", + content="str", + ), + ) + result = self.execute_module() + self.assertEqual(result["commands"], "ping 10.10.10.20 count 4") + + def test_junos_ping_unexpected_success(self): + """Test for successful pings when destination should not be reachable - FAIL.""" + set_module_args(dict(count=2, dest="10.10.10.10", state="absent")) + self.conn.get = MagicMock( + return_value=load_fixture( + "junos_ping_ping_10.10.10.10_count_2", + content="str", + ), + ) + self.execute_module(failed=True) + + def test_junos_ping_unexpected_failure(self): + """Test for unsuccessful pings when destination should be reachable - FAIL.""" + set_module_args(dict(count=4, dest="10.10.10.20")) + self.conn.get = MagicMock( + return_value=load_fixture( + "junos_ping_ping_10.10.10.20_count_4", + content="str", + ), + ) + self.execute_module(failed=True) + + def test_junos_ping_failure_stats(self): + """Test for asserting stats when ping fails""" + set_module_args(dict(count=4, dest="10.10.10.20")) + self.conn.get = MagicMock( + return_value=load_fixture( + "junos_ping_ping_10.10.10.20_count_4", + content="str", + ), + ) + result = self.execute_module(failed=True) + self.assertEqual(result["packet_loss"], "100%") + self.assertEqual(result["packets_rx"], 0) + self.assertEqual(result["packets_tx"], 4) + + def test_junos_ping_success_stats(self): + set_module_args(dict(count=2, dest="10.10.10.10")) + self.conn.get = MagicMock( + return_value=load_fixture( + "junos_ping_ping_10.10.10.10_count_2", + content="str", + ), + ) + result = self.execute_module() + self.assertEqual(result["commands"], "ping 10.10.10.10 count 2") + self.assertEqual(result["packet_loss"], "0%") + self.assertEqual(result["packets_rx"], 2) + self.assertEqual(result["packets_tx"], 2) + self.assertEqual(result["rtt"]["min"], 15.71) + self.assertEqual(result["rtt"]["avg"], 16.87) + self.assertEqual(result["rtt"]["max"], 18.04) + self.assertEqual(result["rtt"]["stddev"], 1.165) + + def test_junos_ping_success_stats_with_options(self): + set_module_args( + dict(count=5, size=512, interval=2, dest="10.10.10.11"), + ) + self.conn.get = MagicMock( + return_value=load_fixture( + "junos_ping_ping_10.10.10.11_count_5_size_512_interval_2", + content="str", + ), + ) + result = self.execute_module() + self.assertEqual( + result["commands"], + "ping 10.10.10.11 count 5 size 512 interval 2", + ) + self.assertEqual(result["packet_loss"], "0%") + self.assertEqual(result["packets_rx"], 5) + self.assertEqual(result["packets_tx"], 5) + self.assertEqual(result["rtt"]["min"], 18.71) + self.assertEqual(result["rtt"]["avg"], 17.87) + self.assertEqual(result["rtt"]["max"], 20.04) + self.assertEqual(result["rtt"]["stddev"], 2.165) + + def test_junos_ping_success_stats_with_df_rapid(self): + set_module_args(dict(df_bit=True, rapid=True, dest="10.10.10.12")) + self.conn.get = MagicMock( + return_value=load_fixture( + "junos_ping_ping_10.10.10.12_count_5_do-not-fragment_rapid", + content="str", + ), + ) + result = self.execute_module() + self.assertEqual( + result["commands"], + "ping 10.10.10.12 count 5 do-not-fragment rapid", + ) + self.assertEqual(result["packet_loss"], "0%") + self.assertEqual(result["packets_rx"], 5) + self.assertEqual(result["packets_tx"], 5) + self.assertEqual(result["rtt"]["min"], 2.58) + self.assertEqual(result["rtt"]["avg"], 2.63) + self.assertEqual(result["rtt"]["max"], 2.74) + self.assertEqual(result["rtt"]["stddev"], 0.058) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py new file mode 100644 index 000000000..d46b38684 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_prefix_lists.py @@ -0,0 +1,326 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_prefix_lists +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosPrefix_listsModule(TestJunosModule): + module = junos_prefix_lists + + def setUp(self): + super(TestJunosPrefix_listsModule, self).setUp() + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.prefix_lists.prefix_lists.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.prefix_lists.prefix_lists.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.prefix_lists.prefix_lists." + "Prefix_listsFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosPrefix_listsModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + if filename: + output = load_fixture(filename) + else: + output = load_fixture("junos_prefix_lists_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def test_junos_prefix_lists_merged_01(self): + set_module_args( + dict( + config=[ + dict( + name="Internal", + address_prefixes=["172.16.1.32", "172.16.3.32"], + ), + dict(name="Test1", dynamic_db=True), + dict( + name="Test2", + address_prefixes=[ + "172.16.2.32", + "172.16.7.32", + "172.16.9.32", + ], + ), + ], + state="merged", + ), + ) + commands = [ + '<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:prefix-list><nc:name>Internal</nc:name><nc:prefix-list-item>" + "<nc:name>172.16.1.32</nc:name></nc:prefix-list-item>" + "<nc:prefix-list-item><nc:name>172.16.3.32</nc:name>" + "</nc:prefix-list-item></nc:prefix-list><nc:prefix-list>" + "<nc:name>Test1</nc:name><nc:dynamic-db/></nc:prefix-list>" + "<nc:prefix-list><nc:name>Test2</nc:name><nc:prefix-list-item>" + "<nc:name>172.16.2.32</nc:name></nc:prefix-list-item>" + "<nc:prefix-list-item><nc:name>172.16.7.32</nc:name>" + "</nc:prefix-list-item><nc:prefix-list-item>" + "<nc:name>172.16.9.32</nc:name></nc:prefix-list-item>" + "</nc:prefix-list></nc:policy-options>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_prefix_lists_merged_idempotent_01(self): + set_module_args( + dict( + config=[ + dict(name="customer_64510"), + dict( + name="customer_64500", + dynamic_db=True, + address_prefixes=["172.16.1.16/28", "172.16.1.32/28"], + ), + ], + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_prefix_lists_replaced_01(self): + set_module_args( + dict( + config=[ + dict( + name="customer_64510", + address_prefixes=["172.16.1.32/28", "172.16.3.32/28"], + ), + dict( + name="customer_64500", + address_prefixes=["172.16.2.16/28", "172.16.1.32/28"], + ), + ], + state="replaced", + ), + ) + commands = [ + '<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:prefix-list delete="delete"><nc:name>customer_64510</nc:name>' + '</nc:prefix-list><nc:prefix-list delete="delete">' + "<nc:name>customer_64500</nc:name></nc:prefix-list>" + "<nc:prefix-list><nc:name>customer_64510</nc:name>" + "<nc:prefix-list-item><nc:name>172.16.1.32/28</nc:name>" + "</nc:prefix-list-item><nc:prefix-list-item>" + "<nc:name>172.16.3.32/28</nc:name></nc:prefix-list-item>" + "</nc:prefix-list><nc:prefix-list><nc:name>customer_64500</nc:name>" + "<nc:prefix-list-item><nc:name>172.16.2.16/28</nc:name>" + "</nc:prefix-list-item><nc:prefix-list-item><nc:name>172.16.1.32/28</nc:name>" + "</nc:prefix-list-item></nc:prefix-list></nc:policy-options>", + ] + + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_prefix_lists_replaced_idempotent_01(self): + set_module_args( + dict( + config=[ + dict(name="customer_64510"), + dict( + name="customer_64500", + dynamic_db=True, + address_prefixes=["172.16.1.16/28", "172.16.1.32/28"], + ), + ], + state="replaced", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_prefix_lists_overridden_01(self): + set_module_args( + dict( + config=[ + dict( + name="customer_65500", + address_prefixes=["172.16.2.16/28", "172.16.1.32/28"], + ), + ], + state="overridden", + ), + ) + commands = [ + '<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:prefix-list delete="delete"><nc:name>customer_64510</nc:name></nc:prefix-list>' + '<nc:prefix-list delete="delete"><nc:name>customer_64500</nc:name>' + "</nc:prefix-list><nc:prefix-list><nc:name>customer_65500</nc:name>" + "<nc:prefix-list-item><nc:name>172.16.2.16/28</nc:name></nc:prefix-list-item>" + "<nc:prefix-list-item><nc:name>172.16.1.32/28</nc:name></nc:prefix-list-item>" + "</nc:prefix-list></nc:policy-options>", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_prefix_lists_overridden_idempotent_01(self): + set_module_args( + dict( + config=[ + dict(name="customer_64510"), + dict( + name="customer_64500", + dynamic_db=True, + address_prefixes=["172.16.1.16/28", "172.16.1.32/28"], + ), + ], + state="overridden", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_prefix_lists_parsed_01(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <policy-options> + <prefix-list> + <name>customer_64510</name> + </prefix-list> + <prefix-list> + <name>customer_64500</name> + <dynamic-db/> + <prefix-list-item> + <name>172.16.1.16/28</name> + </prefix-list-item> + <prefix-list-item> + <name>172.16.1.32/28</name> + </prefix-list-item> + </prefix-list> + </policy-options> + </configuration> + </rpc-reply>""" + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = [ + {"name": "customer_64510"}, + { + "name": "customer_64500", + "dynamic_db": True, + "address_prefixes": ["172.16.1.16/28", "172.16.1.32/28"], + }, + ] + self.assertEqual(result["parsed"], parsed_list) + + def test_junos_prefix_lists_gathered_01(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = [ + {"name": "customer_64510"}, + { + "name": "customer_64500", + "dynamic_db": True, + "address_prefixes": ["172.16.1.16/28", "172.16.1.32/28"], + }, + ] + self.assertEqual(gather_list, result["gathered"]) + + def test_junos_prefix_lists_rendered_01(self): + """ + :return: + """ + set_module_args( + dict( + config=[ + dict( + name="Internal", + address_prefixes=["172.16.1.32", "172.16.3.32"], + ), + dict(name="Test1", dynamic_db=True), + dict( + name="Test2", + address_prefixes=[ + "172.16.2.32", + "172.16.7.32", + "172.16.9.32", + ], + ), + ], + state="rendered", + ), + ) + + rendered = ( + '<nc:policy-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:prefix-list><nc:name>Internal</nc:name><nc:prefix-list-item>" + "<nc:name>172.16.1.32</nc:name></nc:prefix-list-item>" + "<nc:prefix-list-item><nc:name>172.16.3.32</nc:name>" + "</nc:prefix-list-item></nc:prefix-list><nc:prefix-list>" + "<nc:name>Test1</nc:name><nc:dynamic-db/></nc:prefix-list>" + "<nc:prefix-list><nc:name>Test2</nc:name><nc:prefix-list-item>" + "<nc:name>172.16.2.32</nc:name></nc:prefix-list-item>" + "<nc:prefix-list-item><nc:name>172.16.7.32</nc:name>" + "</nc:prefix-list-item><nc:prefix-list-item>" + "<nc:name>172.16.9.32</nc:name></nc:prefix-list-item>" + "</nc:prefix-list></nc:policy-options>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py new file mode 100644 index 000000000..5d656852d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_instances.py @@ -0,0 +1,439 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_routing_instances +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosRouting_instancesModule(TestJunosModule): + module = junos_routing_instances + + def setUp(self): + super(TestJunosRouting_instancesModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.routing_instances.routing_instances.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.routing_instances.routing_instances.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.routing_instances.routing_instances." + "Routing_instancesFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosRouting_instancesModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + if filename: + output = load_fixture(filename) + else: + output = load_fixture("junos_routing_instances_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def sort_routing_instances(self, entry_list): + for entry in entry_list: + if entry.get("instance"): + entry["routing_instances"].sort(key=lambda i: i.get("name")) + + def test_junos_routing_instances_merged(self): + set_module_args( + dict( + config=[ + dict( + name="test", + type="vrf", + route_distinguisher="10.58.255.1:37", + vrf_imports=["test-policy"], + vrf_exports=["test-policy", "test-policy-1"], + interfaces=[ + dict(name="sp-0/0/0.0"), + dict(name="gr-0/0/0.0"), + ], + connector_id_advertise=True, + ), + ], + state="merged", + ), + ) + commands = [ + '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:instance><nc:name>test</nc:name><nc:connector-id-advertise/>" + "<nc:instance-type>vrf</nc:instance-type><nc:interface><nc:name>sp-0/0/0.0</nc:name>" + "</nc:interface><nc:interface><nc:name>gr-0/0/0.0</nc:name>" + "</nc:interface><nc:route-distinguisher><nc:rd-type>10.58.255.1:37</nc:rd-type>" + "</nc:route-distinguisher><nc:vrf-import>test-policy</nc:vrf-import>" + "<nc:vrf-export>test-policy</nc:vrf-export><nc:vrf-export>test-policy-1</nc:vrf-export>" + "</nc:instance></nc:routing-instances>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_routing_instances_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="forwardinst", + type="forwarding", + description="Configured by Ansible Content Team", + ), + ], + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_routing_instances_replaced(self): + """ + :return: + """ + set_module_args( + dict( + config=[ + dict( + name="test", + type="vrf", + route_distinguisher="10.58.255.1:37", + vrf_imports=["test-policy"], + vrf_exports=["test-policy", "test-policy-1"], + interfaces=[ + dict(name="sp-0/0/0.0"), + dict(name="gr-0/0/0.0"), + ], + connector_id_advertise=True, + ), + dict( + name="forwardinst", + type="forwarding", + description="Replaced and Configured by Ansible Content Team", + ), + ], + state="replaced", + ), + ) + + commands = [ + '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:instance delete="delete"><nc:name>forwardinst</nc:name></nc:instance>' + "<nc:instance><nc:name>test</nc:name><nc:connector-id-advertise/>" + "<nc:instance-type>vrf</nc:instance-type><nc:interface><nc:name>sp-0/0/0.0</nc:name>" + "</nc:interface><nc:interface><nc:name>gr-0/0/0.0</nc:name>" + "</nc:interface><nc:route-distinguisher><nc:rd-type>10.58.255.1:37</nc:rd-type>" + "</nc:route-distinguisher><nc:vrf-import>test-policy</nc:vrf-import>" + "<nc:vrf-export>test-policy</nc:vrf-export><nc:vrf-export>test-policy-1</nc:vrf-export>" + "</nc:instance><nc:instance><nc:name>forwardinst</nc:name>" + "<nc:description>Replaced and Configured by Ansible Content Team</nc:description>" + "<nc:instance-type>forwarding</nc:instance-type>" + "</nc:instance></nc:routing-instances>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_routing_instances_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="forwardinst", + type="forwarding", + description="Configured by Ansible Content Team", + ), + ], + state="replaced", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_routing_instances_overridden(self): + """ + :return: + """ + set_module_args( + dict( + config=[ + dict( + name="test1", + type="vrf", + route_distinguisher="10.58.255.1:37", + vrf_imports=["test-policy"], + vrf_exports=["test-policy", "test-policy-1"], + interfaces=[ + dict(name="sp-0/0/0.0"), + dict(name="gr-0/0/0.0"), + ], + connector_id_advertise=True, + ), + ], + state="overridden", + ), + ) + + commands = [ + '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:instance delete="delete"><nc:name>forwardinst</nc:name></nc:instance>' + "<nc:instance><nc:name>test1</nc:name><nc:connector-id-advertise/>" + "<nc:instance-type>vrf</nc:instance-type><nc:interface><nc:name>sp-0/0/0.0</nc:name>" + "</nc:interface><nc:interface><nc:name>gr-0/0/0.0</nc:name></nc:interface>" + "<nc:route-distinguisher><nc:rd-type>10.58.255.1:37</nc:rd-type></nc:route-distinguisher>" + "<nc:vrf-import>test-policy</nc:vrf-import><nc:vrf-export>test-policy</nc:vrf-export>" + "<nc:vrf-export>test-policy-1</nc:vrf-export></nc:instance></nc:routing-instances>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_routing_instances_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="forwardinst", + type="forwarding", + description="Configured by Ansible Content Team", + ), + ], + state="overridden", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_routing_instances_rendered(self): + """ + :return: + """ + set_module_args( + dict( + config=[ + dict( + name="test", + type="vrf", + route_distinguisher="10.58.255.1:37", + vrf_imports=["test-policy"], + vrf_exports=["test-policy", "test-policy-1"], + interfaces=[ + dict(name="sp-0/0/0.0"), + dict(name="gr-0/0/0.0"), + ], + connector_id_advertise=True, + ), + ], + state="rendered", + ), + ) + + rendered = ( + '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:instance><nc:name>test</nc:name><nc:connector-id-advertise/>" + "<nc:instance-type>vrf</nc:instance-type><nc:interface><nc:name>sp-0/0/0.0</nc:name>" + "</nc:interface><nc:interface><nc:name>gr-0/0/0.0</nc:name>" + "</nc:interface><nc:route-distinguisher><nc:rd-type>10.58.255.1:37</nc:rd-type>" + "</nc:route-distinguisher><nc:vrf-import>test-policy</nc:vrf-import>" + "<nc:vrf-export>test-policy</nc:vrf-export><nc:vrf-export>test-policy-1</nc:vrf-export>" + "</nc:instance></nc:routing-instances>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_routing_instances_rendered_02(self): + """ + :return: + """ + set_module_args( + dict( + config=[ + dict( + name="test", + type="mac-vrf", + route_distinguisher="10.58.255.1:37", + vrf_imports=["test-policy"], + vrf_exports=["test-policy", "test-policy-1"], + interfaces=[ + dict(name="sp-0/0/0.0"), + dict(name="gr-0/0/0.0"), + ], + connector_id_advertise=True, + ), + ], + state="rendered", + ), + ) + + rendered = ( + '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:instance><nc:name>test</nc:name><nc:connector-id-advertise/>" + "<nc:instance-type>mac-vrf</nc:instance-type><nc:interface><nc:name>sp-0/0/0.0</nc:name>" + "</nc:interface><nc:interface><nc:name>gr-0/0/0.0</nc:name>" + "</nc:interface><nc:route-distinguisher><nc:rd-type>10.58.255.1:37</nc:rd-type>" + "</nc:route-distinguisher><nc:vrf-import>test-policy</nc:vrf-import>" + "<nc:vrf-export>test-policy</nc:vrf-export><nc:vrf-export>test-policy-1</nc:vrf-export>" + "</nc:instance></nc:routing-instances>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_routing_instances_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = [ + { + "name": "forwardinst", + "type": "forwarding", + "description": "Configured by Ansible Content Team", + }, + ] + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + def test_junos_routing_instances_deleted(self): + """ + :return: + """ + set_module_args(dict(config=[], state="deleted")) + + commands = [ + '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:instance delete="delete"/></nc:routing-instances>', + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_routing_instances_delted_single_entry(self): + """ + :return: + """ + set_module_args( + dict(config=[dict(name="forwardinst")], state="deleted"), + ) + + commands = [ + '<nc:routing-instances xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:instance delete="delete"><nc:name>forwardinst</nc:name></nc:instance></nc:routing-instances>', + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_routing_instances_parsed(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <routing-instances> + <instance> + <name>forwardinst</name> + <description>Configured by Ansible Content Team</description> + <instance-type>forwarding</instance-type> + </instance> + <instance> + <name>test</name> + <instance-type>vrf</instance-type> + <interface> + <name>gr-0/0/0.0</name> + </interface> + <interface> + <name>sp-0/0/0.0</name> + </interface> + <route-distinguisher> + <rd-type>10.58.255.1:37</rd-type> + </route-distinguisher> + <vrf-import>test-policy</vrf-import> + <vrf-export>test-policy</vrf-export> + <vrf-export>test-policy-1</vrf-export> + <no-local-switching/> + <no-vrf-advertise/> + <no-vrf-propagate-ttl/> + <qualified-bum-pruning-mode/> + <no-irb-layer2-copy/> + <connector-id-advertise/> + </instance> + </routing-instances> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = [ + { + "description": "Configured by Ansible Content Team", + "name": "forwardinst", + "type": "forwarding", + }, + { + "connector_id_advertise": True, + "interfaces": [{"name": "gr-0/0/0.0"}, {"name": "sp-0/0/0.0"}], + "name": "test", + "no_irb_layer_2_copy": True, + "no_local_switching": True, + "no_vrf_advertise": True, + "no_vrf_propagate_ttl": True, + "route_distinguisher": "10.58.255.1:37", + "type": "vrf", + "vrf_exports": ["test-policy", "test-policy-1"], + "vrf_imports": ["test-policy"], + }, + ] + self.sort_routing_instances(result["parsed"]) + self.sort_routing_instances(parsed_list) + self.assertEqual(result["parsed"], parsed_list) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py new file mode 100644 index 000000000..2f80838b0 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_routing_options.py @@ -0,0 +1,210 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_routing_options +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosRouting_optionsModule(TestJunosModule): + module = junos_routing_options + + def setUp(self): + super(TestJunosRouting_optionsModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.routing_options.routing_options.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.routing_options.routing_options.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.routing_options.routing_options." + "Routing_optionsFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosRouting_optionsModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_routing_options_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def test_junos_routing_options_merged_01(self): + set_module_args( + dict( + config=dict( + autonomous_system=dict( + as_number="2", + loops=4, + asdot_notation=True, + ), + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:autonomous-system>2<nc:loops>4</nc:loops><nc:asdot-notation/>", + str(result["commands"]), + ) + + def test_junos_routing_options_merged_idempotent(self): + self.execute_show_command.return_value = load_fixture( + "junos_routing_options_config.cfg", + ) + set_module_args( + dict( + config=dict( + router_id="12.12.12.13", + autonomous_system=dict(as_number="1"), + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_routing_options_parsed_01(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <routing-options> + <router-id>12.12.12.12</router-id> + <autonomous-system> + <as-number>2</as-number> + <loops>4</loops> + <asdot-notation/> + </autonomous-system> + </routing-options> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "autonomous_system": { + "as_number": "2", + "asdot_notation": True, + "loops": 4, + }, + "router_id": "12.12.12.12", + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_routing_options_replaced_01(self): + set_module_args( + dict( + config=dict( + autonomous_system=dict( + as_number="1", + loops=4, + asdot_notation=True, + ), + ), + state="replaced", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:autonomous-system>1<nc:loops>4</nc:loops><nc:asdot-notation/>", + str(result["commands"]), + ) + + def test_junos_routing_options_rendered(self): + set_module_args( + dict( + config=dict( + autonomous_system=dict( + as_number="2", + loops=4, + asdot_notation=True, + ), + router_id="12.12.12.12", + ), + state="rendered", + ), + ) + rendered = ( + '<nc:routing-options xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:autonomous-system>2<nc:loops>4</nc:loops><nc:asdot-notation/></nc:autonomous-system>" + "<nc:router-id>12.12.12.12</nc:router-id></nc:routing-options>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_routing_options_overridden(self): + set_module_args( + dict( + config=dict( + autonomous_system=dict( + as_number="1", + loops=4, + asdot_notation=True, + ), + ), + state="overridden", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + "<nc:autonomous-system>1<nc:loops>4</nc:loops><nc:asdot-notation/>", + str(result["commands"]), + ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py new file mode 100644 index 000000000..de66f103d --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_rpc.py @@ -0,0 +1,137 @@ +# (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 + +try: + from lxml.etree import fromstring +except ImportError: + from xml.etree.ElementTree import fromstring + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_rpc +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +RPC_CLI_MAP = { + "get-software-information": "show version", + "get-interface-information": "show interfaces details", + "get-system-memory-information": "show system memory", + "get-chassis-inventory": "show chassis hardware", + "get-system-storage": "show system storage", + "load-configuration": "load configuration", +} + + +class TestJunosCommandModule(TestJunosModule): + + module = junos_rpc + + def setUp(self): + super(TestJunosCommandModule, self).setUp() + self.mock_conn = patch("ansible.module_utils.connection.Connection") + self.conn = self.mock_conn.start() + + self.mock_netconf = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.NetconfConnection", + ) + self.netconf_conn = self.mock_netconf.start() + + self.mock_netconf_rpc = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.netconf.NetconfConnection", + ) + self.netconf_rpc = self.mock_netconf_rpc.start() + + self.mock_exec_rpc = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_rpc.exec_rpc", + ) + self.exec_rpc = self.mock_exec_rpc.start() + + def tearDown(self): + super(TestJunosCommandModule, self).tearDown() + self.mock_conn.stop() + self.mock_netconf.stop() + self.mock_netconf_rpc.stop() + self.mock_exec_rpc.stop() + + def load_fixtures(self, commands=None, format="text", changed=False): + def load_from_file(*args, **kwargs): + element = fromstring(args[1]) + if element.text: + path = str(element.text) + else: + tag = str(element.tag) + if tag.startswith("{"): + tag = tag.split("}", 1)[1] + path = RPC_CLI_MAP[tag] + + filename = path.replace(" ", "_") + filename = "%s_%s.txt" % (filename, format) + + return load_fixture(filename) + + self.exec_rpc.side_effect = load_from_file + + def test_junos_rpc_xml(self): + set_module_args(dict(rpc="get-chassis-inventory")) + result = self.execute_module(format="xml") + self.assertTrue(result["xml"].find("<chassis-inventory>\n")) + + def test_junos_rpc_text(self): + set_module_args(dict(rpc="get-software-information", output="text")) + result = self.execute_module(format="text") + self.assertTrue( + result["output_lines"][0].startswith("Hostname: vsrx01"), + ) + + def test_junos_rpc_json(self): + set_module_args(dict(rpc="get-software-information", output="json")) + result = self.execute_module(format="json") + self.assertTrue("software-information" in result["output"]) + + def test_junos_rpc_args(self): + set_module_args( + dict( + rpc="get-software-information", + args={"interface": "em0", "media": True}, + ), + ) + self.execute_module(format="xml") + args, kwargs = self.exec_rpc.call_args + reply = args[1] + self.assertTrue( + reply.find( + "<interface>em0</interface><media /></get-software-information>", + ), + ) + + def test_junos_rpc_attrs(self): + set_module_args( + dict( + rpc="load-configuration", + output="xml", + attrs={"url": "/var/tmp/config.conf"}, + ), + ) + result = self.execute_module(format="xml") + self.assertTrue(result["xml"].find("<load-success/>")) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py new file mode 100644 index 000000000..6286d57de --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_scp.py @@ -0,0 +1,121 @@ +# (c) 2018 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +import os + +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import MagicMock, patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule + + +jnpr_mock = MagicMock() +modules = { + "jnpr": jnpr_mock, + "jnpr.junos": jnpr_mock.junos, + "jnpr.junos.utils": jnpr_mock.junos.utils, + "jnpr.junos.utils.scp": jnpr_mock.junos.utils.scp, +} +module_patcher = patch.dict("sys.modules", modules) +module_patcher.start() + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_scp + + +class TestJunosScpModule(TestJunosModule): + + module = junos_scp + + def setUp(self): + super(TestJunosScpModule, self).setUp() + self.mock_get_device = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_scp.get_device", + ) + self.get_device = self.mock_get_device.start() + + self.mock_scp = patch( + "ansible_collections.junipernetworks.junos.plugins.modules.junos_scp.SCP", + ) + self.scp = self.mock_scp.start() + + self.scp_mock = MagicMock() + self.scp().__enter__.return_value = self.scp_mock + + def tearDown(self): + super(TestJunosScpModule, self).tearDown() + self.mock_get_device.stop() + self.mock_scp.stop() + + def test_junos_scp_src(self): + set_module_args(dict(src="test.txt")) + self.execute_module(changed=True) + + self.scp_mock.put.assert_called_once_with( + "test.txt", + remote_path=".", + recursive=False, + ) + + def test_junos_scp_src_expand_tilde(self): + set_module_args(dict(src="~/test.txt")) + self.execute_module(changed=True) + + self.scp_mock.put.assert_called_once_with( + os.path.expanduser("~/test.txt"), + remote_path=".", + recursive=False, + ) + + def test_junos_scp_src_fail(self): + self.scp_mock.put.side_effect = OSError( + "[Errno 2] No such file or directory: 'text.txt'", + ) + set_module_args(dict(src="test.txt")) + result = self.execute_module(changed=True, failed=True) + + self.assertEqual( + result["msg"], + "[Errno 2] No such file or directory: 'text.txt'", + ) + + def test_junos_scp_remote_src(self): + set_module_args(dict(src="test.txt", remote_src=True)) + self.execute_module(changed=True) + + self.scp_mock.get.assert_called_once_with( + "test.txt", + local_path=".", + recursive=False, + ) + + def test_junos_scp_all(self): + set_module_args( + dict(src="test", remote_src=True, dest="tmp", recursive=True), + ) + self.execute_module(changed=True) + + self.scp_mock.get.assert_called_once_with( + "test", + local_path="tmp", + recursive=True, + ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py new file mode 100644 index 000000000..bdb94ed6c --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies.py @@ -0,0 +1,1090 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_security_policies +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosSecurity_policiesModule(TestJunosModule): + module = junos_security_policies + + def setUp(self): + super(TestJunosSecurity_policiesModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_policies.security_policies.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_policies.security_policies.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.security_policies.security_policies" + ".Security_policiesFacts._get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosSecurity_policiesModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_security_policies_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def sorted_xml(self, xml_string): + temp = [] + index = 0 + while index < len(xml_string): + temp_line = "" + if xml_string[index] == "<": + while index < len(xml_string) and xml_string[index] != ">": + temp_line += xml_string[index] + index += 1 + temp_line += ">" + index += 1 + temp.append(temp_line) + else: + while index < len(xml_string) and xml_string[index] != "<": + temp_line += xml_string[index] + index += 1 + temp.append(temp_line) + return sorted(temp) + + def test_junos_security_policies_merged_01(self): + set_module_args( + dict( + config={ + "from_zones": [ + { + "name": "one", + "to_zones": [ + { + "name": "two", + "policies": [ + { + "match": { + "application": { + "names": [ + "junos-dhcp-relay", + "junos-finger", + ], + }, + "destination_address": { + "addresses": ["a2", "a4"], + }, + "destination_address_excluded": True, + "dynamic_application": { + "any": True, + }, + "source_address": { + "addresses": ["a1", "a3"], + }, + "source_address_excluded": True, + "source_end_user_profile": "test_end_user_profile", + "source_identity": { + "unknown_user": True, + }, + "url_category": { + "names": [ + "Enhanced_Web_Chat", + "Enhanced_Web_Collaboration", + ], + }, + }, + "name": "test_policy_1", + "then": { + "count": True, + "deny": True, + "log": {"session_close": True}, + }, + }, + { + "match": { + "application": { + "names": [ + "junos-dhcp-relay", + ], + }, + "destination_address": { + "addresses": ["a2"], + }, + "source_address": { + "addresses": ["a1"], + }, + }, + "name": "test_policy_2", + "then": { + "reject": { + "enable": True, + "profile": "test_dyn_app", + "ssl_proxy": { + "enable": True, + "profile_name": "SECURITY-SSL-PROXY", + }, + }, + }, + }, + ], + }, + { + "name": "three", + "policies": [ + { + "match": { + "application": { + "names": [ + "junos-dhcp-relay", + ], + }, + "destination_address": { + "addresses": ["a2"], + }, + "source_address": { + "addresses": ["a1"], + }, + }, + "name": "test_policy_3", + "then": { + "permit": { + "destination_address": "drop-translated", + "application_services": { + "advanced_anti_malware_policy": "test_anti_malware", + "application_traffic_control_rule_set": "test_traffic_control", + "gprs_gtp_profile": "gtp1", + "gprs_sctp_profile": "sctp1", + "icap_redirect": "test_icap", + "idp_policy": "test_idp", + "reverse_redirect_wx": True, + "ssl_proxy": { + "enable": True, + "profile_name": "SECURITY-SSL-PROXY", + }, + "uac_policy": { + "enable": True, + }, + "utm_policy": "test_utm", + }, + "firewall_authentication": { + "pass_through": { + "access_profile": "WEBAUTH", + "auth_only_browser": True, + "auth_user_agent": "Opera1", + "client_match": "test-client", + "ssl_termination_profile": "test_ssl_term", + "web_redirect": True, + "web_redirect_to_https": True, + }, + "push_to_identity_management": True, + "user_firewall": { + "access_profile": "WEBAUTH", + "auth_only_browser": True, + "auth_user_agent": "Opera1", + "ssl_termination_profile": "test_ssl_term", + "web_redirect": True, + "web_redirect_to_https": True, + }, + "web_authentication": [ + "FWClient1", + "FWClient2", + ], + }, + "tcp_options": { + "initial_tcp_mss": 64, + "reverse_tcp_mss": 64, + "window_scale": True, + }, + }, + }, + }, + ], + }, + ], + }, + ], + "global": { + "policies": [ + { + "match": { + "application": { + "names": ["junos-dhcp-relay"], + }, + "destination_address": { + "addresses": ["a2"], + }, + "source_address": {"addresses": ["a1"]}, + }, + "name": "test_glob_1", + "then": {"deny": True}, + }, + { + "match": { + "application": { + "names": ["junos-dhcp-relay"], + }, + "destination_address": { + "addresses": ["a2"], + }, + "source_address": {"addresses": ["a1"]}, + }, + "name": "test_glob_2", + "then": {"deny": True}, + }, + ], + }, + }, + state="merged", + ), + ) + + result = self.execute_module(changed=True) + + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies><nc:policy>' + "<nc:from-zone-name>one</nc:from-zone-name><nc:to-zone-name>two</nc:to-zone-name><nc:policy>" + "<nc:name>test_policy_1</nc:name><nc:match><nc:source-address>a1</nc:source-address>" + "<nc:source-address>a3</nc:source-address><nc:source-address-excluded/><nc:destination-address>" + "a2</nc:destination-address><nc:destination-address>a4</nc:destination-address>" + "<nc:destination-address-excluded/><nc:application>junos-dhcp-relay</nc:application>" + "<nc:application>junos-finger</nc:application><nc:source-end-user-profile>test_end_user_profile" + "</nc:source-end-user-profile><nc:source-identity>unknown-user</nc:source-identity>" + "<nc:url-category>Enhanced_Web_Chat</nc:url-category><nc:url-category>Enhanced_Web_Collaboration" + "</nc:url-category><nc:dynamic-application>any</nc:dynamic-application></nc:match><nc:then>" + "<nc:deny/><nc:count> </nc:count><nc:log><nc:session-close/></nc:log></nc:then></nc:policy>" + "<nc:policy><nc:name>test_policy_2</nc:name><nc:match><nc:source-address>a1</nc:source-address>" + "<nc:destination-address>a2</nc:destination-address><nc:application>junos-dhcp-relay" + "</nc:application></nc:match><nc:then><nc:reject> <nc:profile>test_dyn_app</nc:profile>" + "<nc:ssl-proxy> <nc:profile-name>SECURITY-SSL-PROXY</nc:profile-name></nc:ssl-proxy>" + "</nc:reject></nc:then></nc:policy></nc:policy><nc:policy><nc:from-zone-name>one" + "</nc:from-zone-name><nc:to-zone-name>three</nc:to-zone-name><nc:policy><nc:name>test_policy_3" + "</nc:name><nc:match><nc:source-address>a1</nc:source-address><nc:destination-address>a2" + "</nc:destination-address><nc:application>junos-dhcp-relay</nc:application></nc:match><nc:then>" + "<nc:permit><nc:application-services><nc:advanced-anti-malware-policy>test_anti_malware" + "</nc:advanced-anti-malware-policy><nc:application-traffic-control><nc:rule-set>" + "test_traffic_control</nc:rule-set></nc:application-traffic-control><nc:gprs-gtp-profile>gtp1" + "</nc:gprs-gtp-profile><nc:gprs-sctp-profile>sctp1</nc:gprs-sctp-profile><nc:icap-redirect>" + "test_icap</nc:icap-redirect><nc:idp-policy>test_idp</nc:idp-policy><nc:reverse-redirect-wx/>" + "<nc:ssl-proxy> <nc:profile-name>SECURITY-SSL-PROXY</nc:profile-name></nc:ssl-proxy>" + "<nc:uac-policy> </nc:uac-policy><nc:utm-policy>test_utm</nc:utm-policy>" + "</nc:application-services><nc:destination-address><nc:drop-translated/></nc:destination-address>" + "<nc:firewall-authentication><nc:pass-through> <nc:access-profile>WEBAUTH</nc:access-profile>" + "<nc:auth-only-browser> </nc:auth-only-browser><nc:auth-user-agent>Opera1</nc:auth-user-agent>" + "<nc:client-match>test-client</nc:client-match><nc:ssl-termination-profile>test_ssl_term" + "</nc:ssl-termination-profile><nc:web-redirect/><nc:web-redirect-to-https/><nc:auth-user-agent>" + "Opera1</nc:auth-user-agent></nc:pass-through><nc:push-to-identity-management/>" + "<nc:user-firewall> <nc:access-profile>WEBAUTH</nc:access-profile><nc:ssl-termination-profile>" + "test_ssl_term</nc:ssl-termination-profile><nc:web-redirect> </nc:web-redirect>" + "<nc:web-redirect-to-https> </nc:web-redirect-to-https></nc:user-firewall>" + "<nc:web-authentication> <nc:client-match>FWClient1</nc:client-match><nc:client-match>FWClient2" + "</nc:client-match></nc:web-authentication></nc:firewall-authentication><nc:tcp-options>" + " <nc:initial-tcp-mss>64</nc:initial-tcp-mss><nc:reverse-tcp-mss>64</nc:reverse-tcp-mss>" + "<nc:window-scale/></nc:tcp-options></nc:permit></nc:then></nc:policy></nc:policy><nc:global>" + "<nc:policy><nc:name>test_glob_1</nc:name><nc:match><nc:source-address>a1</nc:source-address>" + "<nc:destination-address>a2</nc:destination-address><nc:application>junos-dhcp-relay" + "</nc:application></nc:match><nc:then><nc:deny/></nc:then></nc:policy><nc:policy><nc:name>" + "test_glob_2</nc:name><nc:match><nc:source-address>a1</nc:source-address><nc:destination-address>" + "a2</nc:destination-address><nc:application>junos-dhcp-relay</nc:application></nc:match><nc:then>" + "<nc:deny/></nc:then></nc:policy></nc:global></nc:policies></nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_policies_merged_02(self): + + set_module_args( + dict( + config={ + "from_zones": [ + { + "name": "one", + "to_zones": [ + { + "name": "two", + "policies": [ + { + "match": { + "application": {"any": True}, + "destination_address": { + "any_ipv4": True, + "any_ipv6": True, + "any": True, + }, + "dynamic_application": { + "names": [ + "test1", + "test2", + ], + "none": True, + }, + "source_address": { + "any_ipv4": True, + "any_ipv6": True, + "any": True, + }, + "source_identity": { + "unknown_user": True, + "unauthenticated_user": True, + "authenticated_user": True, + "names": ["test1"], + }, + "url_category": { + "any": True, + "none": True, + }, + }, + "name": "test_policy_1", + "then": { + "count": True, + "deny": True, + "log": {"session_init": True}, + }, + }, + ], + }, + { + "name": "three", + "policies": [ + { + "match": { + "application": { + "names": [ + "junos-dhcp-relay", + ], + }, + "destination_address": { + "any": True, + }, + "source_address": { + "any": True, + }, + }, + "name": "test_policy_3", + "then": { + "permit": { + "application_services": { + "idp": True, + "redirect_wx": True, + "uac_policy": { + "captive_portal": "test", + }, + }, + "firewall_authentication": { + "user_firewall": { + "domain": "test", + }, + }, + "destination_address": "drop-untranslated", + "tunnel": { + "ipsec_vpn": "test_vpn", + "pair_policy": "test_policy", + }, + }, + }, + }, + ], + }, + ], + }, + ], + }, + state="merged", + ), + ) + + result = self.execute_module(changed=True) + + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies><nc:policy>' + "<nc:from-zone-name>one</nc:from-zone-name><nc:to-zone-name>two</nc:to-zone-name><nc:policy>" + "<nc:name>test_policy_1</nc:name><nc:match><nc:source-address>any-ipv4</nc:source-address>" + "<nc:source-address>any-ipv6</nc:source-address><nc:source-address>any</nc:source-address>" + "<nc:destination-address>any-ipv4</nc:destination-address><nc:destination-address>any-ipv6" + "</nc:destination-address><nc:destination-address>any</nc:destination-address><nc:application>" + "any</nc:application><nc:source-identity>unknown-user</nc:source-identity><nc:source-identity>" + "unauthenticated-user</nc:source-identity><nc:source-identity>authenticated-user" + "</nc:source-identity><nc:source-identity>test1</nc:source-identity><nc:url-category>any" + "</nc:url-category><nc:url-category>none</nc:url-category><nc:dynamic-application>test1" + "</nc:dynamic-application><nc:dynamic-application>test2</nc:dynamic-application>" + "<nc:dynamic-application>none</nc:dynamic-application></nc:match><nc:then><nc:deny/><nc:count>" + " </nc:count><nc:log><nc:session-init/></nc:log></nc:then></nc:policy></nc:policy><nc:policy>" + "<nc:from-zone-name>one</nc:from-zone-name><nc:to-zone-name>three</nc:to-zone-name><nc:policy>" + "<nc:name>test_policy_3</nc:name><nc:match><nc:source-address>any</nc:source-address>" + "<nc:destination-address>any</nc:destination-address><nc:application>junos-dhcp-relay" + "</nc:application></nc:match><nc:then><nc:permit><nc:application-services><nc:idp/>" + "<nc:redirect-wx/><nc:uac-policy> <nc:captive-portal>test</nc:captive-portal></nc:uac-policy>" + "</nc:application-services><nc:destination-address><nc:drop-untranslated/>" + "</nc:destination-address><nc:firewall-authentication><nc:user-firewall> <nc:domain>test" + "</nc:domain></nc:user-firewall></nc:firewall-authentication><nc:tunnel> <nc:ipsec-vpn/>" + "<nc:pair-policy/></nc:tunnel></nc:permit></nc:then></nc:policy></nc:policy></nc:policies>" + "</nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_policies_parsed_01(self): + parsed_str = """ + <rpc-reply> + <configuration> + <security> + <policies> + <policy> + <from-zone-name>one</from-zone-name> + <to-zone-name>two</to-zone-name> + <policy> + <name>test_policy_1</name> + <match> + <source-address>a1</source-address> + <source-address>a3</source-address> + <destination-address>a2</destination-address> + <destination-address>a4</destination-address> + <source-address-excluded /> + <destination-address-excluded /> + <application>junos-dhcp-relay</application> + <application>junos-finger</application> + <source-identity>authenticated-user</source-identity> + <source-identity>unknown-user</source-identity> + <source-end-user-profile> + <source-end-user-profile-name>test_end_user_profile</source-end-user-profile-name> + </source-end-user-profile> + <dynamic-application>any</dynamic-application> + <url-category>Enhanced_Web_Chat</url-category> + <url-category>Enhanced_Web_Collaboration</url-category> + </match> + <then> + <deny /> + <log> + <session-close /> + </log> + <count></count> + </then> + </policy> + <policy> + <name>test_policy_2</name> + <match> + <source-address>a1</source-address> + <destination-address>a2</destination-address> + <application>junos-dhcp-relay</application> + </match> + <then> + <reject> + <profile>test_dyn_app</profile> + <ssl-proxy> + <profile-name>SECURITY-SSL-PROXY</profile-name> + </ssl-proxy> + </reject> + </then> + </policy> + </policy> + <policy> + <from-zone-name>one</from-zone-name> + <to-zone-name>three</to-zone-name> + <policy> + <name>test_policy_3</name> + <match> + <source-address>a1</source-address> + <destination-address>a2</destination-address> + <application>junos-dhcp-relay</application> + </match> + <then> + <permit> + <firewall-authentication> + <web-authentication> + <client-match>FWClient1</client-match> + <client-match>FWClient2</client-match> + </web-authentication> + <pass-through> + <access-profile>WEBAUTH</access-profile> + <auth-only-browser /> + <auth-user-agent>Opera1</auth-user-agent> + <client-match>test-client</client-match> + <ssl-termination-profile>test_ssl_term</ssl-termination-profile> + <web-redirect /> + <web-redirect-to-https /> + </pass-through> + <user-firewall> + <access-profile>WEBAUTH</access-profile> + <auth-only-browser /> + <auth-user-agent>Opera1</auth-user-agent> + <client-match>test-client</client-match> + <ssl-termination-profile>test_ssl_term</ssl-termination-profile> + <web-redirect /> + <web-redirect-to-https /> + </user-firewall> + <push-to-identity-management /> + </firewall-authentication> + <destination-address> + <drop-untranslated /> + </destination-address> + <application-services> + <gprs-gtp-profile>gtp1</gprs-gtp-profile> + <gprs-sctp-profile>sctp1</gprs-sctp-profile> + <idp-policy>test_idp</idp-policy> + <ssl-proxy> + <profile-name>SECURITY-SSL-PROXY</profile-name> + </ssl-proxy> + <uac-policy></uac-policy> + <utm-policy>test_utm</utm-policy> + <icap-redirect>test_icap</icap-redirect> + <application-traffic-control> + <rule-set>test_traffic_control</rule-set> + </application-traffic-control> + <reverse-redirect-wx /> + <advanced-anti-malware-policy>test_anti_malware</advanced-anti-malware-policy> + </application-services> + <tcp-options> + <initial-tcp-mss>64</initial-tcp-mss> + <reverse-tcp-mss>64</reverse-tcp-mss> + <window-scale /> + </tcp-options> + </permit> + </then> + </policy> + </policy> + <global> + <policy> + <name>test_glob_1</name> + <match> + <source-address>a1</source-address> + <destination-address>a2</destination-address> + <application>junos-dhcp-relay</application> + </match> + <then> + <deny /> + </then> + </policy> + <policy> + <name>test_glob_2</name> + <match> + <source-address>a1</source-address> + <destination-address>a2</destination-address> + <application>junos-dhcp-relay</application> + </match> + <then> + <deny /> + </then> + </policy> + </global> + </policies> + </security> + </configuration> + <database-status-information></database-status-information> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "from_zones": [ + { + "name": "one", + "to_zones": [ + { + "name": "two", + "policies": [ + { + "match": { + "application": { + "names": [ + "junos-dhcp-relay", + "junos-finger", + ], + }, + "destination_address": { + "addresses": ["a2", "a4"], + }, + "destination_address_excluded": True, + "dynamic_application": {"any": True}, + "source_address": { + "addresses": ["a1", "a3"], + }, + "source_address_excluded": True, + "source_end_user_profile": "test_end_user_profile", + "source_identity": { + "unknown_user": True, + }, + "url_category": { + "names": [ + "Enhanced_Web_Chat", + "Enhanced_Web_Collaboration", + ], + }, + }, + "name": "test_policy_1", + "then": { + "count": True, + "deny": True, + "log": {"session_close": True}, + }, + }, + { + "match": { + "application": { + "names": ["junos-dhcp-relay"], + }, + "destination_address": { + "addresses": ["a2"], + }, + "source_address": { + "addresses": ["a1"], + }, + }, + "name": "test_policy_2", + "then": { + "reject": { + "enable": True, + "profile": "test_dyn_app", + "ssl_proxy": { + "enable": True, + "profile_name": "SECURITY-SSL-PROXY", + }, + }, + }, + }, + ], + }, + { + "name": "three", + "policies": [ + { + "match": { + "application": { + "names": ["junos-dhcp-relay"], + }, + "destination_address": { + "addresses": ["a2"], + }, + "source_address": { + "addresses": ["a1"], + }, + }, + "name": "test_policy_3", + "then": { + "permit": { + "application_services": { + "advanced_anti_malware_policy": "test_anti_malware", + "application_traffic_control_rule_set": "test_traffic_control", + "gprs_gtp_profile": "gtp1", + "gprs_sctp_profile": "sctp1", + "icap_redirect": "test_icap", + "idp_policy": "test_idp", + "reverse_redirect_wx": True, + "ssl_proxy": { + "enable": True, + "profile_name": "SECURITY-SSL-PROXY", + }, + "uac_policy": {"enable": True}, + "utm_policy": "test_utm", + }, + "firewall_authentication": { + "pass_through": { + "access_profile": "WEBAUTH", + "auth_only_browser": True, + "auth_user_agent": "Opera1", + "client_match": "test-client", + "ssl_termination_profile": "test_ssl_term", + "web_redirect": True, + "web_redirect_to_https": True, + }, + "push_to_identity_management": True, + "user_firewall": { + "access_profile": "WEBAUTH", + "auth_only_browser": True, + "auth_user_agent": "Opera1", + "ssl_termination_profile": "test_ssl_term", + "web_redirect": True, + "web_redirect_to_https": True, + }, + "web_authentication": [ + "FWClient1", + "FWClient2", + ], + }, + "tcp_options": { + "initial_tcp_mss": 64, + "reverse_tcp_mss": 64, + "window_scale": True, + }, + }, + }, + }, + ], + }, + ], + }, + ], + "global": { + "policies": [ + { + "match": { + "application": {"names": ["junos-dhcp-relay"]}, + "destination_address": {"addresses": ["a2"]}, + "source_address": {"addresses": ["a1"]}, + }, + "name": "test_glob_1", + "then": {"deny": True}, + }, + { + "match": { + "application": {"names": ["junos-dhcp-relay"]}, + "destination_address": {"addresses": ["a2"]}, + "source_address": {"addresses": ["a1"]}, + }, + "name": "test_glob_2", + "then": {"deny": True}, + }, + ], + }, + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_security_policies_overridden_01(self): + set_module_args( + dict( + config={ + "global": { + "policies": [ + { + "description": "test update", + "match": { + "application": {"any": True}, + "destination_address": {"any_ipv6": True}, + "source_address": {"any": True}, + }, + "name": "test_glob_3", + "then": {"deny": True}, + }, + ], + }, + }, + state="overridden", + ), + ) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies delete="delete"/><nc:policies><nc:global><nc:policy>' + "<nc:name>test_glob_3</nc:name><nc:description>test update</nc:description><nc:match><nc:source-address>any</nc:source-address>" + "<nc:destination-address>any-ipv6</nc:destination-address><nc:application>any</nc:application></nc:match><nc:then><nc:deny/>" + "</nc:then></nc:policy></nc:global></nc:policies></nc:security>" + ) + result = self.execute_module(changed=True) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_policies_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = { + "from_zones": [ + { + "name": "one", + "to_zones": [ + { + "name": "two", + "policies": [ + { + "match": { + "application": { + "names": [ + "junos-dhcp-relay", + "junos-finger", + ], + }, + "destination_address": { + "addresses": ["a2", "a4"], + }, + "destination_address_excluded": True, + "dynamic_application": { + "any": True, + "none": True, + "names": ["test"], + }, + "source_address": { + "addresses": ["a1", "a3"], + }, + "source_address_excluded": True, + "source_end_user_profile": "test_end_user_profile", + "source_identity": { + "unknown_user": True, + "unauthenticated_user": True, + "authenticated_user": True, + "any": True, + "names": ["test"], + }, + "url_category": { + "any": True, + "none": True, + "names": [ + "Enhanced_Web_Chat", + "Enhanced_Web_Collaboration", + ], + }, + }, + "name": "test_policy_1", + "then": { + "count": True, + "deny": True, + "log": {"session_close": True}, + }, + }, + { + "match": { + "application": { + "names": ["junos-dhcp-relay"], + }, + "destination_address": { + "addresses": ["a2"], + }, + "source_address": { + "addresses": ["a1"], + }, + }, + "name": "test_policy_2", + "then": { + "reject": { + "enable": True, + "profile": "test_dyn_app", + "ssl_proxy": { + "enable": True, + "profile_name": "SECURITY-SSL-PROXY", + }, + }, + }, + }, + ], + }, + { + "name": "three", + "policies": [ + { + "match": { + "application": {"any": True}, + "destination_address": { + "any": True, + "any_ipv4": True, + "any_ipv6": True, + }, + "source_address": { + "any": True, + "any_ipv4": True, + "any_ipv6": True, + }, + }, + "name": "test_policy_3", + "then": { + "permit": { + "application_services": { + "advanced_anti_malware_policy": "test_anti_malware", + "application_traffic_control_rule_set": "test_traffic_control", + "gprs_gtp_profile": "gtp1", + "gprs_sctp_profile": "sctp1", + "icap_redirect": "test_icap", + "idp": True, + "idp_policy": "test_idp", + "reverse_redirect_wx": True, + "redirect_wx": True, + "ssl_proxy": { + "enable": True, + "profile_name": "SECURITY-SSL-PROXY", + }, + "security_intelligence_policy": "test", + "uac_policy": { + "enable": True, + "captive_portal": "test", + }, + "utm_policy": "test_utm", + }, + "firewall_authentication": { + "pass_through": { + "access_profile": "WEBAUTH", + "auth_only_browser": True, + "auth_user_agent": "Opera1", + "client_match": "test-client", + "ssl_termination_profile": "test_ssl_term", + "web_redirect": True, + "web_redirect_to_https": True, + }, + "push_to_identity_management": True, + "user_firewall": { + "access_profile": "WEBAUTH", + "auth_only_browser": True, + "auth_user_agent": "Opera1", + "ssl_termination_profile": "test_ssl_term", + "web_redirect": True, + "web_redirect_to_https": True, + "domain": "test", + }, + "web_authentication": [ + "FWClient1", + "FWClient2", + ], + }, + "tcp_options": { + "initial_tcp_mss": 64, + "reverse_tcp_mss": 64, + "window_scale": True, + "sequence_check_required": True, + "syn_check_required": True, + }, + "tunnel": { + "ipsec_vpn": "test", + "pair_policy": "test", + }, + }, + }, + }, + ], + }, + ], + }, + ], + "global": { + "policies": [ + { + "match": { + "application": {"names": ["junos-dhcp-relay"]}, + "destination_address": {"addresses": ["a2"]}, + "source_address": {"addresses": ["a1"]}, + }, + "name": "test_glob_1", + "then": {"deny": True, "log": {"session_init": True}}, + }, + { + "match": { + "application": {"names": ["junos-dhcp-relay"]}, + "destination_address": {"addresses": ["a2"]}, + "source_address": {"addresses": ["a1"]}, + }, + "name": "test_glob_2", + "then": {"deny": True}, + }, + ], + }, + } + self.assertEqual(gather_list, result["gathered"]) + + def test_junos_security_policies_rendered(self): + set_module_args( + dict( + config={ + "global": { + "policies": [ + { + "description": "test update", + "match": { + "application": {"any": True}, + "destination_address": {"any_ipv6": True}, + "source_address": {"any": True}, + }, + "name": "test_glob_3", + "then": {"deny": True}, + }, + ], + }, + }, + state="rendered", + ), + ) + rendered = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies><nc:global>' + "<nc:policy><nc:name>test_glob_3</nc:name><nc:description>test update</nc:description><nc:match>" + "<nc:source-address>any</nc:source-address><nc:destination-address>any-ipv6</nc:destination-address>" + "<nc:application>any</nc:application></nc:match><nc:then><nc:deny/></nc:then></nc:policy></nc:global>" + "</nc:policies></nc:security>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_security_policies_replaced_01(self): + set_module_args( + dict( + config={ + "global": { + "policies": [ + { + "description": "test update", + "match": { + "application": {"any": True}, + "destination_address": {"any_ipv6": True}, + "source_address": {"any": True}, + }, + "name": "test_glob_3", + "then": {"deny": True}, + }, + ], + }, + }, + state="replaced", + ), + ) + result = self.execute_module(changed=True) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies delete="delete"/><nc:policies><nc:global><nc:policy>' + "<nc:name>test_glob_3</nc:name><nc:description>test update</nc:description><nc:match><nc:source-address>any</nc:source-address>" + "<nc:destination-address>any-ipv6</nc:destination-address><nc:application>any</nc:application></nc:match><nc:then><nc:deny/>" + "</nc:then></nc:policy></nc:global></nc:policies></nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py new file mode 100644 index 000000000..1dd375233 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_policies_global.py @@ -0,0 +1,637 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_security_policies_global +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosSecurity_policies_globalModule(TestJunosModule): + module = junos_security_policies_global + + def setUp(self): + super(TestJunosSecurity_policies_globalModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_policies_global.security_policies_global.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_policies_global." + "security_policies_global.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.security_policies_global.security_policies_global." + "Security_policies_globalFacts._get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + self.maxDiff = None + + def tearDown(self): + super(TestJunosSecurity_policies_globalModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_security_policies_global_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def sorted_xml(self, xml_string): + temp = [] + index = 0 + while index < len(xml_string): + temp_line = "" + if xml_string[index] == "<": + while index < len(xml_string) and xml_string[index] != ">": + temp_line += xml_string[index] + index += 1 + temp_line += ">" + index += 1 + temp.append(temp_line) + else: + while index < len(xml_string) and xml_string[index] != "<": + temp_line += xml_string[index] + index += 1 + temp.append(temp_line) + return sorted(temp) + + def test_junos_security_policies_global_merged_01(self): + set_module_args( + dict( + config={ + "default_policy": "permit-all", + "policy_rematch": {"enable": True, "extensive": True}, + "policy_stats": {"enable": True, "system_wide": True}, + "pre_id_default_policy_action": { + "log": {"session_init": True, "session_close": True}, + "session_timeout": {"icmp": 10, "others": 10}, + }, + "traceoptions": { + "file": { + "files": 3, + "match": "/[A-Z]*/gm", + "no_world_readable": True, + "size": "10k", + }, + "flag": "all", + "no_remote_trace": True, + }, + }, + state="merged", + ), + ) + result = self.execute_module(changed=True) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies>' + "<nc:default-policy><nc:permit-all/></nc:default-policy><nc:policy-rematch> <nc:extensive/>" + "</nc:policy-rematch><nc:policy-stats> <nc:system-wide>enable</nc:system-wide></nc:policy-stats>" + "<nc:pre-id-default-policy><nc:then><nc:log><nc:session-init/><nc:session-close/></nc:log><nc:session-timeout>" + "<nc:icmp>10</nc:icmp><nc:others>10</nc:others></nc:session-timeout></nc:then>" + "</nc:pre-id-default-policy><nc:traceoptions><nc:file><nc:files>3</nc:files><nc:match>" + "/[A-Z]*/gm</nc:match><nc:size>10k</nc:size><nc:no-world-readable/></nc:file><nc:flag>" + "<nc:name>all</nc:name></nc:flag><nc:no-remote-trace/></nc:traceoptions></nc:policies>" + "</nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_policies_global_merged_02(self): + set_module_args( + dict( + config={ + "default_policy": "deny-all", + "policy_rematch": {"enable": True, "extensive": True}, + "policy_stats": {"enable": True, "system_wide": False}, + "pre_id_default_policy_action": { + "log": {"session_init": True}, + "session_timeout": { + "icmp": 10, + "others": 10, + "icmp6": 10, + "ospf": 10, + "tcp": 10, + "udp": 10, + }, + }, + "traceoptions": { + "file": { + "files": 3, + "match": "/[A-Z]*/gm", + "world_readable": True, + "size": "10k", + }, + "flag": "configuration", + "no_remote_trace": True, + }, + }, + state="merged", + ), + ) + result = self.execute_module(changed=True) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies>' + "<nc:default-policy><nc:deny-all/></nc:default-policy><nc:policy-rematch> <nc:extensive/>" + "</nc:policy-rematch><nc:policy-stats> <nc:system-wide>disable</nc:system-wide></nc:policy-stats>" + "<nc:pre-id-default-policy><nc:then><nc:log><nc:session-init/></nc:log><nc:session-timeout>" + "<nc:icmp>10</nc:icmp><nc:others>10</nc:others><nc:icmp6>10</nc:icmp6><nc:ospf>10</nc:ospf>" + "<nc:tcp>10</nc:tcp><nc:udp>10</nc:udp></nc:session-timeout></nc:then></nc:pre-id-default-policy>" + "<nc:traceoptions><nc:file><nc:files>3</nc:files><nc:match>/[A-Z]*/gm</nc:match><nc:size>10k</nc:size>" + "<nc:world-readable/></nc:file><nc:flag><nc:name>configuration</nc:name></nc:flag><nc:no-remote-trace/>" + "</nc:traceoptions></nc:policies></nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_policies_global_merged_03(self): + set_module_args( + dict( + config={"traceoptions": {"flag": "compilation"}}, + state="merged", + ), + ) + result = self.execute_module(changed=True) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies>' + "<nc:traceoptions><nc:flag><nc:name>compilation</nc:name></nc:flag>" + "</nc:traceoptions></nc:policies></nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_policies_global_merged_04(self): + set_module_args( + dict(config={"traceoptions": {"flag": "lookup"}}, state="merged"), + ) + result = self.execute_module(changed=True) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies>' + "<nc:traceoptions><nc:flag><nc:name>lookup</nc:name></nc:flag>" + "</nc:traceoptions></nc:policies></nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_policies_global_parsed_01(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <policies> + <traceoptions> + <no-remote-trace /> + <file> + <size>10k</size> + <files>3</files> + <no-world-readable /> + <match>/[A-Z]*/gm</match> + </file> + <flag> + <name>all</name> + </flag> + </traceoptions> + <default-policy> + <permit-all /> + </default-policy> + <policy-rematch> + <extensive /> + </policy-rematch> + <policy-stats> + <system-wide>enable</system-wide> + </policy-stats> + <pre-id-default-policy> + <then> + <log> + <session-init /> + </log> + <session-timeout> + <icmp>10</icmp> + <others>10</others> + </session-timeout> + </then> + </pre-id-default-policy> + </policies> + </security> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "default_policy": "permit-all", + "policy_rematch": {"enable": True, "extensive": True}, + "policy_stats": {"enable": True, "system_wide": True}, + "pre_id_default_policy_action": { + "log": {"session_init": True}, + "session_timeout": {"icmp": 10, "others": 10}, + }, + "traceoptions": { + "file": { + "files": 3, + "match": "/[A-Z]*/gm", + "no_world_readable": True, + "size": "10k", + }, + "flag": "compilation", + "no_remote_trace": True, + }, + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_security_policies_global_parsed_02(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <policies> + <traceoptions> + <file> + <size>10k</size> + <files>3</files> + <world-readable /> + <match>/[A-Z]*/gm</match> + </file> + <flag> + <name>compilation</name> + </flag> + </traceoptions> + <default-policy> + <deny-all /> + </default-policy> + <policy-stats> + <system-wide>disable</system-wide> + </policy-stats> + <pre-id-default-policy> + <then> + <log> + <session-close /> + </log> + <session-timeout> + <icmp>10</icmp> + <others>10</others> + <icmp6>10</icmp6> + <ospf>10</ospf> + <tcp>10</tcp> + <udp>10</udp> + </session-timeout> + </then> + </pre-id-default-policy> + </policies> + </security> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "default_policy": "deny-all", + "policy_stats": {"enable": True, "system_wide": False}, + "pre_id_default_policy_action": { + "log": {"session_close": True}, + "session_timeout": { + "icmp": 10, + "others": 10, + "ospf": 10, + "icmp6": 10, + "tcp": 10, + "udp": 10, + }, + }, + "traceoptions": { + "file": { + "files": 3, + "match": "/[A-Z]*/gm", + "world_readable": True, + "size": "10k", + }, + "flag": "compilation", + }, + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_security_policies_global_parsed_03(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <policies> + <traceoptions> + <flag> + <name>configuration</name> + </flag> + </traceoptions> + </policies> + </security> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = {"traceoptions": {"flag": "configuration"}} + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_security_policies_global_parsed_04(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <policies> + <traceoptions> + <flag> + <name>ipc</name> + </flag> + </traceoptions> + </policies> + </security> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = {"traceoptions": {"flag": "ipc"}} + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_security_policies_global_parsed_05(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <policies> + <traceoptions> + <flag> + <name>lookup</name> + </flag> + </traceoptions> + </policies> + </security> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = {"traceoptions": {"flag": "lookup"}} + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_security_policies_global_parsed_06(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <policies> + <traceoptions> + <flag> + <name>routing-socket</name> + </flag> + </traceoptions> + </policies> + </security> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = {"traceoptions": {"flag": "routing-socket"}} + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_security_policies_global_parsed_07(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <policies> + <traceoptions> + <flag> + <name>rules</name> + </flag> + </traceoptions> + </policies> + </security> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = {"traceoptions": {"flag": "rules"}} + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_security_policies_global_overridden_01(self): + set_module_args( + dict( + config={ + "default_policy": "permit-all", + "policy_rematch": {"enable": True, "extensive": True}, + "policy_stats": {"enable": True, "system_wide": True}, + "pre_id_default_policy_action": { + "log": {"session_init": True}, + "session_timeout": {"icmp": 10, "others": 10}, + }, + "traceoptions": { + "file": { + "files": 3, + "match": "/[A-Z]*/gm", + "no_world_readable": True, + "size": "10k", + }, + "flag": "ipc", + "no_remote_trace": True, + }, + }, + state="overridden", + ), + ) + result = self.execute_module(changed=True) + print(result["commands"]) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies>' + "<nc:default-policy><nc:permit-all/></nc:default-policy><nc:policy-rematch> <nc:extensive/>" + "</nc:policy-rematch><nc:policy-stats> <nc:system-wide>enable</nc:system-wide></nc:policy-stats>" + "<nc:pre-id-default-policy><nc:then><nc:log><nc:session-init/></nc:log><nc:session-timeout>" + "<nc:icmp>10</nc:icmp><nc:others>10</nc:others></nc:session-timeout></nc:then>" + "</nc:pre-id-default-policy><nc:traceoptions><nc:file><nc:files>3</nc:files><nc:match>" + "/[A-Z]*/gm</nc:match><nc:size>10k</nc:size><nc:no-world-readable/></nc:file><nc:flag>" + "<nc:name>ipc</nc:name></nc:flag><nc:no-remote-trace/></nc:traceoptions></nc:policies>" + '</nc:security><nc:policies delete="delete"/>' + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_policies_global_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = { + "default_policy": "permit-all", + "policy_rematch": {"enable": True, "extensive": True}, + "policy_stats": {"enable": True, "system_wide": True}, + "pre_id_default_policy_action": { + "log": {"session_init": True}, + "session_timeout": {"icmp": 10, "others": 10}, + }, + "traceoptions": { + "file": { + "files": 3, + "match": "/[A-Z]*/gm", + "no_world_readable": True, + "size": "10k", + }, + "flag": "lookup", + "no_remote_trace": True, + }, + } + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + def test_junos_security_policies_global_rendered(self): + set_module_args( + dict( + config={ + "default_policy": "permit-all", + "policy_rematch": {"enable": True, "extensive": True}, + "policy_stats": {"enable": True, "system_wide": True}, + "pre_id_default_policy_action": { + "log": {"session_init": True}, + "session_timeout": {"icmp": 10, "others": 10}, + }, + "traceoptions": { + "file": { + "files": 3, + "match": "/[A-Z]*/gm", + "no_world_readable": True, + "size": "10k", + }, + "flag": "routing-socket", + "no_remote_trace": True, + }, + }, + state="rendered", + ), + ) + rendered = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies>' + "<nc:default-policy><nc:permit-all/></nc:default-policy><nc:policy-rematch> <nc:extensive/>" + "</nc:policy-rematch><nc:policy-stats> <nc:system-wide>enable</nc:system-wide></nc:policy-stats>" + "<nc:pre-id-default-policy><nc:then><nc:log><nc:session-init/></nc:log><nc:session-timeout>" + "<nc:icmp>10</nc:icmp><nc:others>10</nc:others></nc:session-timeout></nc:then>" + "</nc:pre-id-default-policy><nc:traceoptions><nc:file><nc:files>3</nc:files><nc:match>" + "/[A-Z]*/gm</nc:match><nc:size>10k</nc:size><nc:no-world-readable/></nc:file><nc:flag>" + "<nc:name>routing-socket</nc:name></nc:flag><nc:no-remote-trace/></nc:traceoptions></nc:policies>" + "</nc:security>" + ) + result = self.execute_module(changed=False) + print(self.sorted_xml(result["rendered"])) + print(self.sorted_xml(rendered)) + self.assertEqual( + self.sorted_xml(result["rendered"]), + self.sorted_xml(rendered), + ) + + def test_junos_security_policies_global_replaced_01(self): + set_module_args( + dict( + config={ + "default_policy": "permit-all", + "policy_rematch": {"enable": True, "extensive": True}, + "policy_stats": {"enable": True, "system_wide": True}, + "pre_id_default_policy_action": { + "log": {"session_init": True}, + "session_timeout": {"icmp": 10, "others": 10}, + }, + "traceoptions": { + "file": { + "files": 3, + "match": "/[A-Z]*/gm", + "no_world_readable": True, + "size": "10k", + }, + "flag": "rules", + "no_remote_trace": True, + }, + }, + state="replaced", + ), + ) + result = self.execute_module(changed=True) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:policies>' + "<nc:default-policy><nc:permit-all/></nc:default-policy><nc:policy-rematch> <nc:extensive/>" + "</nc:policy-rematch><nc:policy-stats> <nc:system-wide>enable</nc:system-wide></nc:policy-stats>" + "<nc:pre-id-default-policy><nc:then><nc:log><nc:session-init/></nc:log><nc:session-timeout>" + "<nc:icmp>10</nc:icmp><nc:others>10</nc:others></nc:session-timeout></nc:then>" + "</nc:pre-id-default-policy><nc:traceoptions><nc:file><nc:files>3</nc:files><nc:match>" + "/[A-Z]*/gm</nc:match><nc:size>10k</nc:size><nc:no-world-readable/></nc:file><nc:flag>" + "<nc:name>rules</nc:name></nc:flag><nc:no-remote-trace/></nc:traceoptions></nc:policies>" + '</nc:security><nc:policies delete="delete"/>' + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py new file mode 100644 index 000000000..e593037dc --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_security_zones.py @@ -0,0 +1,994 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_security_zones +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosSecurity_zonesModule(TestJunosModule): + module = junos_security_zones + + def setUp(self): + super(TestJunosSecurity_zonesModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_zones.security_zones.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.security_zones.security_zones.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.security_zones.security_zones." + "Security_zonesFacts._get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosSecurity_zonesModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_security_zones_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def sorted_xml(self, xml_string): + temp = [] + index = 0 + while index < len(xml_string): + temp_line = "" + if xml_string[index] == "<": + while index < len(xml_string) and xml_string[index] != ">": + temp_line += xml_string[index] + index += 1 + temp_line += ">" + index += 1 + temp.append(temp_line) + else: + while index < len(xml_string) and xml_string[index] != "<": + temp_line += xml_string[index] + index += 1 + temp.append(temp_line) + return sorted(temp) + + def test_junos_security_zones_merged_01(self): + set_module_args( + dict( + config={ + "functional_zone_management": { + "description": "test description", + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + ], + }, + "interfaces": ["ge-0/0/1.0", "ge-0/0/2.0"], + "screen": "test_screen", + }, + "zones": [ + { + "address_book": { + "address_sets": [ + { + "addresses": [ + "test_adr1", + "test_adr2", + ], + "name": "test_adrset1", + }, + { + "addresses": [ + "test_adr3", + "test_adr4", + ], + "name": "test_adrset2", + }, + { + "address_sets": [ + "test_adrset1", + "test_adrset2", + ], + "addresses": ["test_adr5"], + "description": "test description", + "name": "test_adrset3", + }, + ], + "addresses": [ + { + "description": "test desc", + "ip_prefix": "10.0.0.0/24", + "name": "test_adr1", + }, + { + "dns_name": { + "ipv6_only": True, + "name": "1.1.1.1", + }, + "name": "test_adr2", + }, + { + "name": "test_adr3", + "range_address": { + "from": "10.2.0.1", + "to": "10.2.0.2", + }, + }, + { + "name": "test_adr4", + "wildcard_address": "10.3.0.1/24", + }, + { + "description": "test desc", + "ip_prefix": "10.1.0.0/24", + "name": "test_adr5", + }, + ], + }, + "advance_policy_based_routing_profile": "test_profile", + "advanced_connection_tracking": { + "mode": "allow-any-host", + "timeout": "20", + "track_all_policies_to_this_zone": True, + }, + "application_tracking": True, + "description": "test description", + "enable_reverse_reroute": True, + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + ], + }, + "interfaces": ["ge-0/0/3.0", "ge-0/0/4.0"], + "name": "test_sec_zone1", + "screen": "test_screen", + "source_identity_log": True, + "tcp_rst": True, + "unidirectional_session_refreshing": True, + }, + ], + }, + state="merged", + ), + ) + result = self.execute_module(changed=True) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:zones><nc:functional-zone><nc:management><nc:description>t' + "est description</nc:description><nc:host-inbound-traffic><nc:protocols><nc:name>all</nc:name></nc:protocols><nc:protocols><nc:na" + "me>bgp</nc:name><nc:except/></nc:protocols><nc:system-services><nc:name>all</nc:name></nc:system-services><nc:system-services><n" + "c:name>dhcp</nc:name><nc:except/></nc:system-services></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0/0/1.0</nc:name></nc" + ":interfaces><nc:interfaces><nc:name>ge-0/0/2.0</nc:name></nc:interfaces><nc:screen>test_screen</nc:screen></nc:management></nc:f" + "unctional-zone><nc:security-zone><nc:name>test_sec_zone1</nc:name><nc:address-book><nc:address><nc:name>test_adr1</nc:name><nc:i" + "p-prefix>10.0.0.0/24</nc:ip-prefix><nc:description>test desc</nc:description></nc:address><nc:address><nc:name>test_adr2</nc:nam" + "e><nc:dns-name><nc:name>1.1.1.1</nc:name><nc:ipv6-only/></nc:dns-name></nc:address><nc:address><nc:name>test_adr3</nc:name><nc:r" + "ange-address><nc:name>10.2.0.1</nc:name><nc:to><nc:range-high>10.2.0.2</nc:range-high></nc:to></nc:range-address></nc:address><n" + "c:address><nc:name>test_adr4</nc:name><nc:wildcard-address><nc:name>10.3.0.1/24</nc:name></nc:wildcard-address></nc:address><nc:" + "address><nc:name>test_adr5</nc:name><nc:ip-prefix>10.1.0.0/24</nc:ip-prefix><nc:description>test desc</nc:description></nc:addre" + "ss><nc:address-set><nc:name>test_adrset1</nc:name><nc:address><nc:name>test_adr1</nc:name></nc:address><nc:address><nc:name>test" + "_adr2</nc:name></nc:address></nc:address-set><nc:address-set><nc:name>test_adrset2</nc:name><nc:address><nc:name>test_adr3</nc:n" + "ame></nc:address><nc:address><nc:name>test_adr4</nc:name></nc:address></nc:address-set><nc:address-set><nc:name>test_adrset3</nc" + ":name><nc:address><nc:name>test_adr5</nc:name></nc:address><nc:address-set><nc:name>test_adrset1</nc:name></nc:address-set><nc:a" + "ddress-set><nc:name>test_adrset2</nc:name></nc:address-set><nc:description>test description</nc:description></nc:address-set></n" + "c:address-book><nc:advance-policy-based-routing-profile><nc:profile>test_profile</nc:profile></nc:advance-policy-based-routing-p" + "rofile><nc:advanced-connection-tracking><nc:mode>allow-any-host</nc:mode><nc:timeout>20</nc:timeout><nc:track-all-policies-to-th" + "is-zone/></nc:advanced-connection-tracking><nc:application-tracking/><nc:description>test description</nc:description><nc:enable" + "-reverse-reroute/><nc:host-inbound-traffic><nc:protocols><nc:name>all</nc:name></nc:protocols><nc:protocols><nc:name>bgp</nc:nam" + "e><nc:except/></nc:protocols><nc:system-services><nc:name>all</nc:name></nc:system-services><nc:system-services><nc:name>dhcp</n" + "c:name><nc:except/></nc:system-services></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0/0/3.0</nc:name></nc:interfaces><n" + "c:interfaces><nc:name>ge-0/0/4.0</nc:name></nc:interfaces><nc:screen>test_screen</nc:screen><nc:source-identity-log/><nc:tcp-rst" + "/><nc:unidirectional-session-refreshing/></nc:security-zone></nc:zones></nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_zones_parsed_01(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <security> + <zones> + <functional-zone> + <management> + <description>test description</description> + <host-inbound-traffic> + <protocols> + <name>all</name> + </protocols> + <protocols> + <name>bgp</name> + <except /> + </protocols> + <system-services> + <name>all</name> + </system-services> + <system-services> + <name>dhcp</name> + <except /> + </system-services> + </host-inbound-traffic> + <interfaces> + <name>ge-0/0/1.0</name> + </interfaces> + <interfaces> + <name>ge-0/0/2.0</name> + </interfaces> + <screen>test_screen</screen> + </management> + </functional-zone> + <security-zone> + <name>test_sec_zone1</name> + <address-book> + <address> + <name>test_adr1</name> + <ip-prefix>10.0.0.0/24</ip-prefix> + <description>test desc</description> + </address> + <address> + <name>test_adr2</name> + <dns-name> + <name>1.1.1.1</name> + <ipv6-only /> + </dns-name> + </address> + <address> + <name>test_adr3</name> + <range-address> + <name>10.2.0.1</name> + <to> + <range-high>10.2.0.2</range-high> + </to> + </range-address> + </address> + <address> + <name>test_adr4</name> + <wildcard-address> + <name>10.3.0.1/24</name> + </wildcard-address> + </address> + <address> + <name>test_adr5</name> + <ip-prefix>10.1.0.0/24</ip-prefix> + <description>test desc</description> + </address> + <address-set> + <name>test_adrset1</name> + <address> + <name>test_adr1</name> + </address> + <address> + <name>test_adr2</name> + </address> + </address-set> + <address-set> + <name>test_adrset2</name> + <address> + <name>test_adr3</name> + </address> + <address> + <name>test_adr4</name> + </address> + </address-set> + <address-set> + <name>test_adrset3</name> + <address> + <name>test_adr5</name> + </address> + <address-set> + <name>test_adrset1</name> + </address-set> + <address-set> + <name>test_adrset2</name> + </address-set> + <description>test description</description> + </address-set> + </address-book> + <advance-policy-based-routing-profile> + <profile>test_profile</profile> + </advance-policy-based-routing-profile> + <advanced-connection-tracking> + <mode>allow-any-host</mode> + <timeout>20</timeout> + <track-all-policies-to-this-zone/> + </advanced-connection-tracking> + <application-tracking /> + <description>test description</description> + <enable-reverse-reroute /> + <host-inbound-traffic> + <protocols> + <name>all</name> + </protocols> + <protocols> + <name>bgp</name> + <except /> + </protocols> + <system-services> + <name>all</name> + </system-services> + <system-services> + <name>dhcp</name> + <except /> + </system-services> + </host-inbound-traffic> + <interfaces> + <name>ge-0/0/3.0</name> + </interfaces> + <interfaces> + <name>ge-0/0/4.0</name> + </interfaces> + <screen>test_screen</screen> + <source-identity-log /> + <tcp-rst /> + <unidirectional-session-refreshing /> + </security-zone> + </zones> + </security> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "functional_zone_management": { + "description": "test description 2", + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + {"except": True, "name": "bfd"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + {"except": True, "name": "dhcpv6"}, + ], + }, + "interfaces": ["ge-0/0/1.0", "ge-0/0/2.0"], + "screen": "test_screen", + }, + "zones": [ + { + "address_book": { + "address_sets": [ + { + "addresses": ["test_adr1", "test_adr2"], + "name": "test_adrset1", + }, + { + "addresses": ["test_adr3", "test_adr4"], + "name": "test_adrset2", + }, + { + "address_sets": [ + "test_adrset1", + "test_adrset2", + ], + "addresses": ["test_adr5"], + "description": "test description", + "name": "test_adrset3", + }, + ], + "addresses": [ + { + "description": "test desc", + "ip_prefix": "10.0.0.0/24", + "name": "test_adr1", + }, + { + "dns_name": { + "ipv6_only": True, + "name": "1.1.1.1", + }, + "name": "test_adr2", + }, + { + "name": "test_adr3", + "range_address": { + "from": "10.2.0.1", + "to": "10.2.0.2", + }, + }, + { + "name": "test_adr4", + "wildcard_address": "10.3.0.1/24", + }, + { + "description": "test desc", + "ip_prefix": "10.1.0.0/24", + "name": "test_adr5", + }, + ], + }, + "advance_policy_based_routing_profile": "test_profile", + "advanced_connection_tracking": { + "mode": "allow-any-host", + "timeout": "20", + "track_all_policies_to_this_zone": True, + }, + "application_tracking": True, + "description": "test description", + "enable_reverse_reroute": True, + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + ], + }, + "interfaces": ["ge-0/0/3.0", "ge-0/0/4.0"], + "name": "test_sec_zone1", + "screen": "test_screen", + "source_identity_log": True, + "tcp_rst": True, + "unidirectional_session_refreshing": True, + }, + { + "name": "test_sec_zone2", + "source_identity_log": True, + "tcp_rst": True, + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_security_zones_overridden_01(self): + set_module_args( + dict( + config={ + "functional_zone_management": { + "description": "test description 2", + "host_inbound_traffic": { + "protocols": [{"name": "all"}], + "system_services": [{"name": "all"}], + }, + "interfaces": ["ge-0/0/1.0", "ge-0/0/2.0"], + "screen": "test_screen", + }, + "zones": [ + { + "address_book": { + "address_sets": [ + { + "addresses": [ + "test_adr1", + "test_adr2", + ], + "name": "test_adrset1", + }, + { + "addresses": [ + "test_adr3", + "test_adr4", + ], + "name": "test_adrset2", + }, + { + "address_sets": [ + "test_adrset1", + "test_adrset2", + ], + "addresses": ["test_adr5"], + "description": "test description", + "name": "test_adrset3", + }, + ], + "addresses": [ + { + "description": "test desc", + "ip_prefix": "10.0.0.0/24", + "name": "test_adr1", + }, + { + "dns_name": { + "ipv6_only": True, + "name": "1.1.1.1", + }, + "name": "test_adr2", + }, + { + "name": "test_adr3", + "range_address": { + "from": "10.2.0.1", + "to": "10.2.0.2", + }, + }, + { + "name": "test_adr4", + "wildcard_address": "10.3.0.1/24", + }, + { + "description": "test desc", + "ip_prefix": "10.1.0.0/24", + "name": "test_adr5", + }, + ], + }, + "advance_policy_based_routing_profile": "test_profile", + "application_tracking": True, + "description": "test description", + "enable_reverse_reroute": True, + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + ], + }, + "interfaces": ["ge-0/0/3.0", "ge-0/0/4.0"], + "name": "test_sec_zone1", + "screen": "test_screen", + "source_identity_log": True, + "tcp_rst": True, + }, + ], + }, + state="overridden", + ), + ) + result = self.execute_module(changed=True) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:zones delete="delete"/><nc:zones><nc:functional-zone><nc' + ":management><nc:description>test description 2</nc:description><nc:host-inbound-traffic><nc:protocols><nc:name>all</nc:name></nc" + ":protocols><nc:system-services><nc:name>all</nc:name></nc:system-services></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0" + "/0/1.0</nc:name></nc:interfaces><nc:interfaces><nc:name>ge-0/0/2.0</nc:name></nc:interfaces><nc:screen>test_screen</nc:screen></" + "nc:management></nc:functional-zone><nc:security-zone><nc:name>test_sec_zone1</nc:name><nc:address-book><nc:address><nc:name>test" + "_adr1</nc:name><nc:ip-prefix>10.0.0.0/24</nc:ip-prefix><nc:description>test desc</nc:description></nc:address><nc:address><nc:na" + "me>test_adr2</nc:name><nc:dns-name><nc:name>1.1.1.1</nc:name><nc:ipv6-only/></nc:dns-name></nc:address><nc:address><nc:name>test" + "_adr3</nc:name><nc:range-address><nc:name>10.2.0.1</nc:name><nc:to><nc:range-high>10.2.0.2</nc:range-high></nc:to></nc:range-add" + "ress></nc:address><nc:address><nc:name>test_adr4</nc:name><nc:wildcard-address><nc:name>10.3.0.1/24</nc:name></nc:wildcard-addre" + "ss></nc:address><nc:address><nc:name>test_adr5</nc:name><nc:ip-prefix>10.1.0.0/24</nc:ip-prefix><nc:description>test desc</nc:de" + "scription></nc:address><nc:address-set><nc:name>test_adrset1</nc:name><nc:address><nc:name>test_adr1</nc:name></nc:address><nc:a" + "ddress><nc:name>test_adr2</nc:name></nc:address></nc:address-set><nc:address-set><nc:name>test_adrset2</nc:name><nc:address><nc:" + "name>test_adr3</nc:name></nc:address><nc:address><nc:name>test_adr4</nc:name></nc:address></nc:address-set><nc:address-set><nc:n" + "ame>test_adrset3</nc:name><nc:address><nc:name>test_adr5</nc:name></nc:address><nc:address-set><nc:name>test_adrset1</nc:name></" + "nc:address-set><nc:address-set><nc:name>test_adrset2</nc:name></nc:address-set><nc:description>test description</nc:description>" + "</nc:address-set></nc:address-book><nc:advance-policy-based-routing-profile><nc:profile>test_profile</nc:profile></nc:advance-po" + "licy-based-routing-profile><nc:application-tracking/><nc:description>test description</nc:description><nc:enable-reverse-reroute" + "/><nc:host-inbound-traffic><nc:protocols><nc:name>all</nc:name></nc:protocols><nc:protocols><nc:name>bgp</nc:name><nc:except/></" + "nc:protocols><nc:system-services><nc:name>all</nc:name></nc:system-services><nc:system-services><nc:name>dhcp</nc:name><nc:excep" + "t/></nc:system-services></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0/0/3.0</nc:name></nc:interfaces><nc:interfaces><nc" + ":name>ge-0/0/4.0</nc:name></nc:interfaces><nc:screen>test_screen</nc:screen><nc:source-identity-log/><nc:tcp-rst/></nc:security-" + "zone></nc:zones></nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) + + def test_junos_security_zones_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = { + "functional_zone_management": { + "description": "test description 2", + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + {"except": True, "name": "bfd"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + {"except": True, "name": "dhcpv6"}, + ], + }, + "interfaces": ["ge-0/0/1.0", "ge-0/0/2.0"], + "screen": "test_screen", + }, + "zones": [ + { + "address_book": { + "address_sets": [ + { + "addresses": ["test_adr1", "test_adr2"], + "name": "test_adrset1", + }, + { + "addresses": ["test_adr3", "test_adr4"], + "name": "test_adrset2", + }, + { + "address_sets": [ + "test_adrset1", + "test_adrset2", + ], + "addresses": ["test_adr5"], + "description": "test description", + "name": "test_adrset3", + }, + ], + "addresses": [ + { + "description": "test desc", + "ip_prefix": "10.0.0.0/24", + "name": "test_adr1", + }, + { + "dns_name": { + "ipv6_only": True, + "name": "1.1.1.1", + }, + "name": "test_adr2", + }, + { + "name": "test_adr3", + "range_address": { + "from": "10.2.0.1", + "to": "10.2.0.2", + }, + }, + { + "name": "test_adr4", + "wildcard_address": "10.3.0.1/24", + }, + { + "description": "test desc", + "ip_prefix": "10.1.0.0/24", + "name": "test_adr5", + }, + ], + }, + "advance_policy_based_routing_profile": "test_profile", + "application_tracking": True, + "description": "test description", + "enable_reverse_reroute": True, + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + ], + }, + "interfaces": ["ge-0/0/3.0", "ge-0/0/4.0"], + "name": "test_sec_zone1", + "screen": "test_screen", + "source_identity_log": True, + "tcp_rst": True, + }, + { + "name": "test_sec_zone2", + "source_identity_log": True, + "tcp_rst": True, + }, + ], + } + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + def test_junos_security_zones_rendered(self): + set_module_args( + dict( + config={ + "functional_zone_management": { + "description": "test description", + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + ], + }, + "interfaces": ["ge-0/0/1.0", "ge-0/0/2.0"], + "screen": "test_screen", + }, + "zones": [ + { + "address_book": { + "address_sets": [ + { + "addresses": [ + "test_adr1", + "test_adr2", + ], + "name": "test_adrset1", + }, + { + "addresses": [ + "test_adr3", + "test_adr4", + ], + "name": "test_adrset2", + }, + { + "address_sets": [ + "test_adrset1", + "test_adrset2", + ], + "addresses": ["test_adr5"], + "description": "test description", + "name": "test_adrset3", + }, + ], + "addresses": [ + { + "description": "test desc", + "ip_prefix": "10.0.0.0/24", + "name": "test_adr1", + }, + { + "dns_name": { + "ipv6_only": True, + "name": "1.1.1.1", + }, + "name": "test_adr2", + }, + { + "name": "test_adr3", + "range_address": { + "from": "10.2.0.1", + "to": "10.2.0.2", + }, + }, + { + "name": "test_adr4", + "wildcard_address": "10.3.0.1/24", + }, + { + "description": "test desc", + "ip_prefix": "10.1.0.0/24", + "name": "test_adr5", + }, + ], + }, + "advance_policy_based_routing_profile": "test_profile", + "application_tracking": True, + "description": "test description", + "enable_reverse_reroute": True, + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + ], + }, + "interfaces": ["ge-0/0/3.0", "ge-0/0/4.0"], + "name": "test_sec_zone1", + "screen": "test_screen", + "source_identity_log": True, + "tcp_rst": True, + }, + ], + }, + state="rendered", + ), + ) + rendered = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:zones><nc:functional-zone><nc:management><nc:description>t' + "est description</nc:description><nc:host-inbound-traffic><nc:protocols><nc:name>all</nc:name></nc:protocols><nc:protocols><nc:na" + "me>bgp</nc:name><nc:except/></nc:protocols><nc:system-services><nc:name>all</nc:name></nc:system-services><nc:system-services><n" + "c:name>dhcp</nc:name><nc:except/></nc:system-services></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0/0/1.0</nc:name></nc" + ":interfaces><nc:interfaces><nc:name>ge-0/0/2.0</nc:name></nc:interfaces><nc:screen>test_screen</nc:screen></nc:management></nc:f" + "unctional-zone><nc:security-zone><nc:name>test_sec_zone1</nc:name><nc:address-book><nc:address><nc:name>test_adr1</nc:name><nc:i" + "p-prefix>10.0.0.0/24</nc:ip-prefix><nc:description>test desc</nc:description></nc:address><nc:address><nc:name>test_adr2</nc:nam" + "e><nc:dns-name><nc:name>1.1.1.1</nc:name><nc:ipv6-only/></nc:dns-name></nc:address><nc:address><nc:name>test_adr3</nc:name><nc:r" + "ange-address><nc:name>10.2.0.1</nc:name><nc:to><nc:range-high>10.2.0.2</nc:range-high></nc:to></nc:range-address></nc:address><n" + "c:address><nc:name>test_adr4</nc:name><nc:wildcard-address><nc:name>10.3.0.1/24</nc:name></nc:wildcard-address></nc:address><nc:" + "address><nc:name>test_adr5</nc:name><nc:ip-prefix>10.1.0.0/24</nc:ip-prefix><nc:description>test desc</nc:description></nc:addre" + "ss><nc:address-set><nc:name>test_adrset1</nc:name><nc:address><nc:name>test_adr1</nc:name></nc:address><nc:address><nc:name>test" + "_adr2</nc:name></nc:address></nc:address-set><nc:address-set><nc:name>test_adrset2</nc:name><nc:address><nc:name>test_adr3</nc:n" + "ame></nc:address><nc:address><nc:name>test_adr4</nc:name></nc:address></nc:address-set><nc:address-set><nc:name>test_adrset3</nc" + ":name><nc:address><nc:name>test_adr5</nc:name></nc:address><nc:address-set><nc:name>test_adrset1</nc:name></nc:address-set><nc:a" + "ddress-set><nc:name>test_adrset2</nc:name></nc:address-set><nc:description>test description</nc:description></nc:address-set></n" + "c:address-book><nc:advance-policy-based-routing-profile><nc:profile>test_profile</nc:profile></nc:advance-policy-based-routing-p" + "rofile><nc:application-tracking/><nc:description>test description</nc:description><nc:enable-reverse-reroute/><nc:host-inbound-t" + "raffic><nc:protocols><nc:name>all</nc:name></nc:protocols><nc:protocols><nc:name>bgp</nc:name><nc:except/></nc:protocols><nc:sys" + "tem-services><nc:name>all</nc:name></nc:system-services><nc:system-services><nc:name>dhcp</nc:name><nc:except/></nc:system-servi" + "ces></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0/0/3.0</nc:name></nc:interfaces><nc:interfaces><nc:name>ge-0/0/4.0</nc" + ":name></nc:interfaces><nc:screen>test_screen</nc:screen><nc:source-identity-log/><nc:tcp-rst/></nc:security-zone></nc:zones></nc" + ":security>" + ) + result = self.execute_module(changed=False) + self.assertEqual( + self.sorted_xml(result["rendered"]), + self.sorted_xml(rendered), + ) + + def test_junos_security_zones_replaced_01(self): + set_module_args( + dict( + config={ + "functional_zone_management": { + "description": "test description 2", + "host_inbound_traffic": { + "protocols": [{"name": "all"}], + "system_services": [{"name": "all"}], + }, + "interfaces": ["ge-0/0/1.0", "ge-0/0/2.0"], + "screen": "test_screen", + }, + "zones": [ + { + "address_book": { + "address_sets": [ + { + "addresses": [ + "test_adr1", + "test_adr2", + ], + "name": "test_adrset1", + }, + { + "addresses": [ + "test_adr3", + "test_adr4", + ], + "name": "test_adrset2", + }, + { + "address_sets": [ + "test_adrset1", + "test_adrset2", + ], + "addresses": ["test_adr5"], + "description": "test description", + "name": "test_adrset3", + }, + ], + "addresses": [ + { + "description": "test desc", + "ip_prefix": "10.0.0.0/24", + "name": "test_adr1", + }, + { + "dns_name": { + "ipv6_only": True, + "name": "1.1.1.1", + }, + "name": "test_adr2", + }, + { + "name": "test_adr3", + "range_address": { + "from": "10.2.0.1", + "to": "10.2.0.2", + }, + }, + { + "name": "test_adr4", + "wildcard_address": "10.3.0.1/24", + }, + { + "description": "test desc", + "ip_prefix": "10.1.0.0/24", + "name": "test_adr5", + }, + ], + }, + "advance_policy_based_routing_profile": "test_profile", + "application_tracking": True, + "description": "test description", + "enable_reverse_reroute": True, + "host_inbound_traffic": { + "protocols": [ + {"name": "all"}, + {"except": True, "name": "bgp"}, + ], + "system_services": [ + {"name": "all"}, + {"except": True, "name": "dhcp"}, + ], + }, + "interfaces": ["ge-0/0/3.0", "ge-0/0/4.0"], + "name": "test_sec_zone1", + "screen": "test_screen", + "source_identity_log": True, + "tcp_rst": True, + }, + ], + }, + state="replaced", + ), + ) + result = self.execute_module(changed=True) + commands = ( + '<nc:security xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:zones delete="delete"/><nc:zones><nc:functional-zone><nc' + ":management><nc:description>test description 2</nc:description><nc:host-inbound-traffic><nc:protocols><nc:name>all</nc:name></nc" + ":protocols><nc:system-services><nc:name>all</nc:name></nc:system-services></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0" + "/0/1.0</nc:name></nc:interfaces><nc:interfaces><nc:name>ge-0/0/2.0</nc:name></nc:interfaces><nc:screen>test_screen</nc:screen></" + "nc:management></nc:functional-zone><nc:security-zone><nc:name>test_sec_zone1</nc:name><nc:address-book><nc:address><nc:name>test" + "_adr1</nc:name><nc:ip-prefix>10.0.0.0/24</nc:ip-prefix><nc:description>test desc</nc:description></nc:address><nc:address><nc:na" + "me>test_adr2</nc:name><nc:dns-name><nc:name>1.1.1.1</nc:name><nc:ipv6-only/></nc:dns-name></nc:address><nc:address><nc:name>test" + "_adr3</nc:name><nc:range-address><nc:name>10.2.0.1</nc:name><nc:to><nc:range-high>10.2.0.2</nc:range-high></nc:to></nc:range-add" + "ress></nc:address><nc:address><nc:name>test_adr4</nc:name><nc:wildcard-address><nc:name>10.3.0.1/24</nc:name></nc:wildcard-addre" + "ss></nc:address><nc:address><nc:name>test_adr5</nc:name><nc:ip-prefix>10.1.0.0/24</nc:ip-prefix><nc:description>test desc</nc:de" + "scription></nc:address><nc:address-set><nc:name>test_adrset1</nc:name><nc:address><nc:name>test_adr1</nc:name></nc:address><nc:a" + "ddress><nc:name>test_adr2</nc:name></nc:address></nc:address-set><nc:address-set><nc:name>test_adrset2</nc:name><nc:address><nc:" + "name>test_adr3</nc:name></nc:address><nc:address><nc:name>test_adr4</nc:name></nc:address></nc:address-set><nc:address-set><nc:n" + "ame>test_adrset3</nc:name><nc:address><nc:name>test_adr5</nc:name></nc:address><nc:address-set><nc:name>test_adrset1</nc:name></" + "nc:address-set><nc:address-set><nc:name>test_adrset2</nc:name></nc:address-set><nc:description>test description</nc:description>" + "</nc:address-set></nc:address-book><nc:advance-policy-based-routing-profile><nc:profile>test_profile</nc:profile></nc:advance-po" + "licy-based-routing-profile><nc:application-tracking/><nc:description>test description</nc:description><nc:enable-reverse-reroute" + "/><nc:host-inbound-traffic><nc:protocols><nc:name>all</nc:name></nc:protocols><nc:protocols><nc:name>bgp</nc:name><nc:except/></" + "nc:protocols><nc:system-services><nc:name>all</nc:name></nc:system-services><nc:system-services><nc:name>dhcp</nc:name><nc:excep" + "t/></nc:system-services></nc:host-inbound-traffic><nc:interfaces><nc:name>ge-0/0/3.0</nc:name></nc:interfaces><nc:interfaces><nc" + ":name>ge-0/0/4.0</nc:name></nc:interfaces><nc:screen>test_screen</nc:screen><nc:source-identity-log/><nc:tcp-rst/></nc:security-" + "zone></nc:zones></nc:security>" + ) + self.assertEqual( + self.sorted_xml(commands), + self.sorted_xml(str(result["commands"])), + ) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py new file mode 100644 index 000000000..db31904e8 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_snmp_server.py @@ -0,0 +1,889 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_snmp_server +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosSnmp_serverModule(TestJunosModule): + module = junos_snmp_server + + def setUp(self): + super(TestJunosSnmp_serverModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.snmp_server.snmp_server.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.snmp_server.snmp_server.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.snmp_server.snmp_server." + "Snmp_serverFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosSnmp_serverModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_snmp_server_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def test_junos_snmp_server_merged_arp_01(self): + set_module_args( + dict( + config=dict(arp=dict(set=True, host_name_resolution=True)), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + "<nc:arp><nc:host-name-resolution/></nc:arp></nc:snmp>", + str(result["commands"]), + ) + + def test_junos_snmp_server_merged_client_02(self): + set_module_args( + dict( + config=dict( + client_lists=[ + dict( + name="cl2", + addresses=[dict(address="192.16.4.0/24")], + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + self.assertIn( + '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + str(result["commands"]), + ) + self.assertIn( + "<nc:client-list><nc:name>cl2</nc:name><nc:client-address-list>", + str(result["commands"]), + ) + self.assertIn( + "<nc:name>192.16.4.0/24</nc:name>", + str(result["commands"]), + ) + self.assertIn( + "</nc:client-address-list></nc:client-list></nc:snmp>", + str(result["commands"]), + ) + + def test_junos_snmp_server_merged_clients_03(self): + set_module_args( + dict( + config=dict( + client_lists=[ + dict( + name="cl3", + addresses=[ + dict(address="172.16.1.0/24"), + dict(address="10.11.11.11", restrict=True), + ], + ), + dict( + name="cl4", + addresses=[dict(address="172.16.4.0/24")], + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + commands = [ + '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + "<nc:client-list><nc:name>cl3</nc:name>", + "<nc:client-address-list><nc:name>172.16.1.0/24</nc:name>", + "</nc:client-address-list><nc:client-address-list>", + "<nc:name>10.11.11.11</nc:name><nc:restrict/></nc:client-address-list>", + "</nc:client-list><nc:client-list><nc:name>cl4</nc:name>", + "<nc:client-address-list><nc:name>172.16.4.0/24</nc:name>", + "</nc:client-address-list></nc:client-list></nc:snmp>", + ] + for command in commands: + self.assertIn(command, str(result["commands"])) + + def test_junos_snmp_server_merged_routing_access_04(self): + set_module_args( + dict( + config=dict( + routing_instance_access=dict( + set=True, + access_lists=["clv1"], + ), + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + commands = [ + '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + "<nc:routing-instance-access><nc:access-list><nc:name>clv1</nc:name>", + "</nc:access-list></nc:routing-instance-access></nc:snmp>", + ] + for command in commands: + self.assertIn(command, str(result["commands"])) + + def test_junos_snmp_server_merged_communities_05(self): + set_module_args( + dict( + config=dict( + communities=[ + dict( + name="comm1", + clients=[ + dict(address="24.0.0.0/32", restrict=True), + ], + routing_instances=[ + dict( + name="clv1", + clients=[ + dict( + address="13.13.13.13/24", + restrict=True, + ), + ], + ), + ], + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + commands = [ + '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:community><nc:name>comm1</nc:name><nc:clients>", + "<nc:name>24.0.0.0/32</nc:name><nc:restrict/></nc:clients>", + "<nc:routing-instance><nc:name>clv1</nc:name><nc:clients>", + "<nc:name>13.13.13.13/24</nc:name><nc:restrict/></nc:clients>", + "</nc:routing-instance></nc:community></nc:snmp>", + ] + for command in commands: + self.assertIn(command, str(result["commands"])) + + def test_junos_snmp_server_merged_06(self): + set_module_args( + dict( + config=dict( + communities=[ + dict( + name="comm1", + clients=[ + dict(address="24.0.0.0/32", restrict=True), + dict(address="30.0.0.0/32", restrict=True), + ], + routing_instances=[ + dict( + name="clv1", + clients=[ + dict( + address="13.13.13.13/24", + restrict=True, + ), + dict(address="24.0.0.0/32"), + dict(address="30.0.0.0/32"), + ], + ), + dict( + name="clv2", + clients=[dict(address="15.15.15.15/24")], + ), + ], + ), + dict(name="comm2"), + ], + contact="rohitthakur2590", + customization=dict(ether_stats_ifd_only=True), + description="Local SNMP Server", + engine_id=dict( + local="local1", + use_default_ip_address=True, + use_mac_address=True, + ), + filter_duplicates=True, + filter_interfaces=dict( + all_internal_interfaces=True, + interfaces=["eth1", "eth2"], + ), + health_monitor=dict( + falling_threshold=50, + idp=True, + interval=100, + rising_threshold=60, + ), + if_count_with_filter_interfaces=True, + interfaces=["eth1", "eth2", "eth3"], + location="inter_lab", + logical_system_trap_filter=True, + name="SNMP_LAB_SERVER", + nonvolatile=dict(commit_delay=30), + rmon=dict( + alarms=[ + dict( + id=4, + variable="1.x.y.z", + sample_type="absolute-value", + rising_threshold=1020, + ), + dict( + id=5, + variable="1.x.y.z", + sample_type="absolute-value", + rising_threshold=1020, + ), + ], + events=[ + dict(id=100, type="log"), + dict(id=200, type="log"), + ], + ), + routing_instance_access=dict( + access_lists=["clv1", "clv2"], + ), + subagent=dict(tcp=dict(routing_instances_default=True)), + snmp_v3=dict( + notify=[dict(name="not1", type="inform", tag="tag2")], + notify_filter=[ + dict( + name="not_fil_01", + oids=[dict(include=True, oid="1.a.s.b.d")], + ), + dict( + name="not_fil_02", + oids=[ + dict(include=True, oid="1.x.b.b.d"), + dict(include=True, oid="1.a.c.b.d"), + ], + ), + ], + snmp_community=[ + dict( + community_index="v3_comm1", + community_name="mycommu", + security_name="sec101", + context="cont1", + tag="109", + ), + dict( + community_index="v3_comm2", + community_name="mycomm", + security_name="sec102", + context="cont1", + tag="109", + ), + ], + target_addresses=[ + dict( + name="tar201", + address="162.12.10.2", + port=23122, + timeout=300, + retry_count=200, + tag_list="tag101", + address_mask="24", + routing_instance="clv2", + target_parameters="tarparam2", + ), + dict( + name="tar202", + address="162.12.10.2", + port=23122, + timeout=300, + retry_count=200, + tag_list="tag101", + address_mask="24", + routing_instance="clv2", + target_parameters="tarparam2", + ), + ], + target_parameters=[ + dict( + name="param111", + notify_filter="not121", + parameters=dict( + message_processing_model="v1", + security_model="v1", + security_level="none", + security_name="secure111", + ), + ), + ], + ), + traceoptions=dict( + file=dict( + files=20, + match="snmp_cfg", + no_world_readable=True, + size=20000, + ), + flag=dict( + all=True, + general=True, + interface_stats=True, + nonvolatile_sets=True, + pdu=True, + protocol_timeouts=True, + routing_socket=True, + subagent=True, + timer=True, + varbind_error=True, + ), + memory_trace=dict(size=1350), + ), + trap_groups=[ + dict( + name="trgrp_01", + destination_port=2346, + categories=dict( + authentication=True, + chassis=True, + otn_alarms=dict( + oc_lof=True, + otu_uas_threshold=True, + ), + ), + targets=["11.11.11.11", "12.12.12.12"], + routing_instance="clv1", + ), + ], + ), + state="merged", + ), + ) + result = self.execute_module(changed=True) + commands = [ + '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', + "<nc:routing-instance-access><nc:access-list><nc:name>clv1</nc:name>", + "</nc:access-list><nc:access-list><nc:name>clv2</nc:name></nc:access-list>", + "</nc:routing-instance-access><nc:community><nc:name>comm1</nc:name><nc:clients>", + "<nc:name>24.0.0.0/32</nc:name><nc:restrict/></nc:clients><nc:clients><nc:name>30.0.0.0/32</nc:name>", + "<nc:restrict/></nc:clients><nc:routing-instance><nc:name>clv1</nc:name><nc:clients>", + "<nc:name>13.13.13.13/24</nc:name><nc:restrict/></nc:clients><nc:clients><nc:name>24.0.0.0/32</nc:name>", + "</nc:clients><nc:clients><nc:name>30.0.0.0/32</nc:name></nc:clients></nc:routing-instance>", + "<nc:routing-instance><nc:name>clv2</nc:name><nc:clients><nc:name>15.15.15.15/24</nc:name>", + "</nc:clients></nc:routing-instance></nc:community><nc:community><nc:name>comm2</nc:name>", + "</nc:community><nc:contact>rohitthakur2590</nc:contact><nc:customization><nc:ether-stats-ifd-only/>", + "</nc:customization><nc:description>Local SNMP Server</nc:description><nc:engine-id>", + "<nc:local>local1</nc:local><nc:use-default-ip-address/><nc:use-mac-address/></nc:engine-id>", + ] + for command in commands: + self.assertIn(command, str(result["commands"])) + + def test_junos_snmp_server_parsed_07(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <snmp> + <system-name>SNMP_LAB_SERVER</system-name> + <description>Local SNMP Server</description> + <location>inter_lab</location> + <contact>rohitthakur2590</contact> + <interface>eth1.0</interface> + <interface>eth2.0</interface> + <interface>eth3.0</interface> + <filter-interfaces> + <interfaces> + <name>eth1</name> + </interfaces> + <interfaces> + <name>eth2</name> + </interfaces> + <all-internal-interfaces/> + </filter-interfaces> + <if-count-with-filter-interfaces/> + <filter-duplicates/> + <nonvolatile> + <commit-delay>30</commit-delay> + </nonvolatile> + <v3> + <target-address> + <name>tar201</name> + <address>162.12.10.2</address> + <port>23122</port> + <timeout>300</timeout> + <retry-count>200</retry-count> + <tag-list>tag101</tag-list> + <address-mask>24.0.0.0</address-mask> + <routing-instance>clv2</routing-instance> + <target-parameters>tarparam2</target-parameters> + </target-address> + <target-address> + <name>tar202</name> + <address>162.12.10.2</address> + <port>23122</port> + <timeout>300</timeout> + <retry-count>200</retry-count> + <tag-list>tag101</tag-list> + <address-mask>24.0.0.0</address-mask> + <routing-instance>clv2</routing-instance> + <target-parameters>tarparam2</target-parameters> + </target-address> + <target-parameters> + <name>param111</name> + <parameters> + <message-processing-model>v1</message-processing-model> + <security-model>v1</security-model> + <security-level>none</security-level> + <security-name>secure111</security-name> + </parameters> + <notify-filter> + <filter>not121</filter> + </notify-filter> + </target-parameters> + <notify> + <name>not1</name> + <type>inform</type> + <tag>tag2</tag> + </notify> + <notify-filter> + <name>not_fil_01</name> + <oid> + <name>1.a.s.b.d</name> + <include/> + </oid> + </notify-filter> + <notify-filter> + <name>not_fil_02</name> + <oid> + <name>1.x.b.b.d</name> + <include/> + </oid> + <oid> + <name>1.a.c.b.d</name> + <include/> + </oid> + </notify-filter> + <snmp-community> + <name>v3_comm1</name> + <community-name>$9$gUoGiQF/tpB5QORhr8LjHq</community-name> + <security-name>sec101</security-name> + <context>cont1</context> + <tag>109</tag> + </snmp-community> + <snmp-community> + <name>v3_comm2</name> + <community-name>$9$9te0A0IKMX-dslKwgoGq.</community-name> + <security-name>sec102</security-name> + <context>cont1</context> + <tag>109</tag> + </snmp-community> + </v3> + <subagent> + <tcp> + <routing-instance> + <default/> + </routing-instance> + </tcp> + </subagent> + <engine-id> + <use-mac-address/> + </engine-id> + <community> + <name>comm1</name> + <clients> + <name>24.0.0.0/32</name> + <restrict/> + </clients> + <clients> + <name>30.0.0.0/32</name> + <restrict/> + </clients> + <routing-instance> + <name>clv1</name> + <clients> + <name>13.13.13.13/24</name> + <restrict/> + </clients> + <clients> + <name>24.0.0.0/32</name> + </clients> + <clients> + <name>30.0.0.0/32</name> + </clients> + </routing-instance> + <routing-instance> + <name>clv2</name> + <clients> + <name>15.15.15.15/24</name> + </clients> + </routing-instance> + </community> + <community> + <name>comm2</name> + </community> + <trap-group> + <name>trgrp_01</name> + <destination-port>2346</destination-port> + <categories> + <authentication/> + <chassis/> + <otn-alarms> + <oc-lof/> + <otu-uas-threshold/> + </otn-alarms> + </categories> + <targets> + <name>11.11.11.11</name> + </targets> + <targets> + <name>12.12.12.12</name> + </targets> + <routing-instance>clv1</routing-instance> + </trap-group> + <routing-instance-access> + <access-list> + <name>clv1</name> + </access-list> + <access-list> + <name>clv2</name> + </access-list> + </routing-instance-access> + <logical-system-trap-filter/> + <traceoptions> + <memory-trace> + <size>1350</size> + </memory-trace> + <file> + <size>20000</size> + <files>20</files> + <no-world-readable/> + <match>snmp_cfg</match> + </file> + <flag> + <name>all</name> + </flag> + <flag> + <name>general</name> + </flag> + <flag> + <name>interface-stats</name> + </flag> + <flag> + <name>nonvolatile-sets</name> + </flag> + <flag> + <name>pdu</name> + </flag> + <flag> + <name>protocol-timeouts</name> + </flag> + <flag> + <name>routing-socket</name> + </flag> + <flag> + <name>subagent</name> + </flag> + <flag> + <name>timer</name> + </flag> + <flag> + <name>varbind-error</name> + </flag> + </traceoptions> + <rmon> + <alarm> + <name>4</name> + <variable>1.x.y.z</variable> + <sample-type>absolute-value</sample-type> + <rising-threshold>1020</rising-threshold> + </alarm> + <alarm> + <name>5</name> + <variable>1.x.y.z</variable> + <sample-type>absolute-value</sample-type> + <rising-threshold>1020</rising-threshold> + </alarm> + <event> + <name>100</name> + <type>log</type> + </event> + <event> + <name>200</name> + <type>log</type> + </event> + </rmon> + <health-monitor> + <interval>100</interval> + <rising-threshold>60</rising-threshold> + <falling-threshold>50</falling-threshold> + <idp> + </idp> + </health-monitor> + <customization> + <ether-stats-ifd-only/> + </customization> + </snmp> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_dict = { + "communities": [ + { + "clients": [ + {"address": "24.0.0.0/32", "restrict": True}, + {"address": "30.0.0.0/32", "restrict": True}, + ], + "name": "comm1", + "routing_instances": [ + { + "clients": [ + { + "address": "13.13.13.13/24", + "restrict": True, + }, + {"address": "24.0.0.0/32"}, + {"address": "30.0.0.0/32"}, + ], + "name": "clv1", + }, + { + "clients": [{"address": "15.15.15.15/24"}], + "name": "clv2", + }, + ], + }, + {"name": "comm2"}, + ], + "contact": "rohitthakur2590", + "customization": {"ether_stats_ifd_only": True}, + "description": "Local SNMP Server", + "engine_id": {"use_mac_address": True}, + "filter_duplicates": True, + "filter_interfaces": { + "all_internal_interfaces": True, + "interfaces": ["eth1", "eth2"], + }, + "health_monitor": { + "falling_threshold": 50, + "idp": True, + "interval": 100, + "rising_threshold": 60, + }, + "if_count_with_filter_interfaces": True, + "location": "inter_lab", + "logical_system_trap_filter": True, + "name": "SNMP_LAB_SERVER", + "nonvolatile": {"commit_delay": 30}, + "rmon": { + "alarms": [ + { + "id": "4", + "rising_threshold": 1020, + "sample_type": "absolute-value", + "variable": "1.x.y.z", + }, + { + "id": "5", + "rising_threshold": 1020, + "sample_type": "absolute-value", + "variable": "1.x.y.z", + }, + ], + "events": [ + {"id": 100, "type": "log"}, + {"id": 200, "type": "log"}, + ], + }, + "routing_instance_access": {"access_lists": ["clv1", "clv2"]}, + "snmp_v3": { + "notify": [{"name": "not1", "tag": "tag2", "type": "inform"}], + "notify_filter": [ + { + "name": "not_fil_01", + "oids": [{"include": True, "oid": "1.a.s.b.d"}], + }, + { + "name": "not_fil_02", + "oids": [ + {"include": True, "oid": "1.x.b.b.d"}, + {"include": True, "oid": "1.a.c.b.d"}, + ], + }, + ], + "snmp_community": [ + { + "community_index": "v3_comm1", + "community_name": "$9$gUoGiQF/tpB5QORhr8LjHq", + "context": "cont1", + "security_name": "sec101", + "tag": "109", + }, + { + "community_index": "v3_comm2", + "community_name": "$9$9te0A0IKMX-dslKwgoGq.", + "context": "cont1", + "security_name": "sec102", + "tag": "109", + }, + ], + "target_addresses": [ + { + "address": "162.12.10.2", + "address_mask": "24.0.0.0", + "name": "tar201", + "port": 23122, + "retry_count": 200, + "routing_instance": "clv2", + "tag_list": "tag101", + "target_parameters": "tarparam2", + "timeout": 300, + }, + { + "address": "162.12.10.2", + "address_mask": "24.0.0.0", + "name": "tar202", + "port": 23122, + "retry_count": 200, + "routing_instance": "clv2", + "tag_list": "tag101", + "target_parameters": "tarparam2", + "timeout": 300, + }, + ], + "target_parameters": [ + { + "name": "param111", + "notify_filter": "{'filter': 'not121'}", + "parameters": { + "message_processing_model": "v1", + "security_level": "none", + "security_model": "v1", + "security_name": "secure111", + }, + }, + ], + }, + "subagent": {"tcp": {"routing_instances_default": True}}, + "traceoptions": { + "file": { + "files": 20, + "match": "snmp_cfg", + "no_world_readable": True, + "size": 20000, + }, + "flag": { + "all": True, + "general": True, + "interface_stats": True, + "nonvolatile_sets": True, + "pdu": True, + "protocol_timeouts": True, + "routing_socket": True, + "subagent": True, + "timer": True, + "varbind_error": True, + }, + "memory_trace": {"size": 1350}, + }, + "trap_groups": [ + { + "categories": { + "authentication": True, + "chassis": True, + "otn_alarms": { + "oc_lof": True, + "otu_uas_threshold": True, + }, + }, + "destination_port": 2346, + "name": "trgrp_01", + "routing_instance": "clv1", + "targets": ["11.11.11.11", "12.12.12.12"], + }, + ], + } + self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) + + def test_junos_ntp_global_rendered(self): + set_module_args( + dict( + config=dict( + client_lists=[ + dict( + name="cl2", + addresses=[dict(address="192.16.4.0/24")], + ), + ], + ), + state="rendered", + ), + ) + rendered = ( + '<nc:snmp xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><nc:client-list><nc:name>cl2</nc:name>' + "<nc:client-address-list><nc:name>192.16.4.0/24</nc:name></nc:client-address-list>" + "</nc:client-list></nc:snmp>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py new file mode 100644 index 000000000..c6f33fc12 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/network/junos/test_junos_vlans.py @@ -0,0 +1,257 @@ +# -*- coding: utf-8 -*- +# Copyright 2020 Red Hat +# GNU General Public License v3.0+ +# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +############################################# +# WARNING # +############################################# +# +# This file is auto generated by the resource +# module builder playbook. +# +# Do not edit this file manually. +# +# Changes to this file will be over written +# by the resource module builder. +# +# Changes should be made in the model used to +# generate this file or in the resource module +# builder template. +# +############################################# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from ansible_collections.junipernetworks.junos.plugins.modules import junos_vlans +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch +from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import set_module_args + +from .junos_module import TestJunosModule, load_fixture + + +class TestJunosVlansModule(TestJunosModule): + module = junos_vlans + + def setUp(self): + super(TestJunosVlansModule, self).setUp() + + self.mock_lock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration", + ) + self.lock_configuration = self.mock_lock_configuration.start() + + self.mock_unlock_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration", + ) + self.unlock_configuration = self.mock_unlock_configuration.start() + + self.mock_load_config = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.vlans.vlans.load_config", + ) + self.load_config = self.mock_load_config.start() + + self.mock_commit_configuration = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.vlans.vlans.commit_configuration", + ) + self.mock_commit_configuration = self.mock_commit_configuration.start() + + self.mock_execute_show_command = patch( + "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.vlans.vlans." + "VlansFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestJunosVlansModule, self).tearDown() + self.mock_load_config.stop() + self.mock_lock_configuration.stop() + self.mock_unlock_configuration.stop() + self.mock_commit_configuration.stop() + self.mock_execute_show_command.stop() + + def load_fixtures( + self, + commands=None, + format="text", + changed=False, + filename=None, + ): + def load_from_file(*args, **kwargs): + output = load_fixture("junos_vlans_config.cfg") + return output + + self.execute_show_command.side_effect = load_from_file + + def sort_vlans(self, entry_list): + entry_list.sort(key=lambda i: i.get("name")) + + def test_junos_vlans_merged(self): + set_module_args( + dict( + config=[dict(name="vlan2", vlan_id=2, l3_interface="irb.12")], + state="merged", + ), + ) + commands = [ + '<nc:vlans xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:vlan><nc:name>vlan2</nc:name><nc:vlan-id>2</nc:vlan-id>" + "<nc:l3-interface>irb.12</nc:l3-interface></nc:vlan></nc:vlans>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_vlans_merged_idempotent(self): + set_module_args( + dict(config=[dict(name="vlan1", vlan_id=1)], state="merged"), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_vlans_replaced(self): + """ + :return: + """ + set_module_args( + dict( + config=[ + dict(name="vlan1", vlan_id=1, l3_interface="irb.10"), + dict(name="vlan2", vlan_id=2), + ], + state="replaced", + ), + ) + + commands = [ + '<nc:vlans xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:vlan delete="delete"><nc:name>vlan1</nc:name></nc:vlan>' + '<nc:vlan delete="delete"><nc:name>vlan2</nc:name></nc:vlan>' + "<nc:vlan><nc:name>vlan1</nc:name><nc:vlan-id>1</nc:vlan-id>" + "<nc:l3-interface>irb.10</nc:l3-interface></nc:vlan><nc:vlan>" + "<nc:name>vlan2</nc:name><nc:vlan-id>2</nc:vlan-id></nc:vlan></nc:vlans>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_vlans_replaced_idempotent(self): + set_module_args( + dict(config=[dict(name="vlan1", vlan_id=1)], state="replaced"), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_vlans_overridden(self): + """ + :return: + """ + set_module_args( + dict( + config=[dict(name="vlan3", vlan_id=3, l3_interface="irb.13")], + state="overridden", + ), + ) + + commands = [ + '<nc:vlans xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:vlan delete="delete"><nc:name>vlan1</nc:name></nc:vlan>' + "<nc:vlan><nc:name>vlan3</nc:name><nc:vlan-id>3</nc:vlan-id>" + "<nc:l3-interface>irb.13</nc:l3-interface></nc:vlan></nc:vlans>", + ] + result = self.execute_module(changed=True, commands=commands) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_vlans_overridden_idempotent(self): + set_module_args( + dict(config=[dict(name="vlan1", vlan_id=1)], state="overridden"), + ) + result = self.execute_module(changed=True) + self.assertEqual(result["before"], result["after"]) + + def test_junos_vlans_gathered(self): + """ + :return: + """ + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = [{"name": "vlan1", "vlan_id": 1}] + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + def test_junos_vlans_deleted(self): + """ + :return: + """ + set_module_args(dict(config=[dict(name="vlan1")], state="deleted")) + + commands = [ + '<nc:vlans xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:vlan delete="delete"><nc:name>vlan1</nc:name></nc:vlan></nc:vlans>', + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_vlans_deleted_01(self): + """ + :return: + """ + set_module_args(dict(config=[], state="deleted")) + + commands = [ + '<nc:vlans xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + '<nc:vlan delete="delete"><nc:name>vlan1</nc:name></nc:vlan></nc:vlans>', + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_junos_vlans_rendered(self): + """ + :return: + """ + set_module_args( + dict( + config=[ + dict(name="vlan1", vlan_id=1), + dict(name="vlan2", vlan_id=2, l3_interface="irb.12"), + ], + state="rendered", + ), + ) + rendered = ( + '<nc:vlans xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' + "<nc:vlan><nc:name>vlan1</nc:name><nc:vlan-id>1</nc:vlan-id></nc:vlan>" + "<nc:vlan><nc:name>vlan2</nc:name><nc:vlan-id>2</nc:vlan-id>" + "<nc:l3-interface>irb.12</nc:l3-interface></nc:vlan></nc:vlans>" + ) + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["rendered"]), sorted(rendered)) + + def test_junos_vlans_parsed(self): + parsed_str = """ + <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> + <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> + <version>18.4R1-S2.4</version> + <vlans> + <vlan> + <name>vlan1</name> + <vlan-id>1</vlan-id> + </vlan> + <vlan> + <name>vlan2</name> + <vlan-id>2</vlan-id> + <l3-interface>irb.12</l3-interface> + </vlan> + </vlans> + </configuration> + </rpc-reply> + """ + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = [ + {"name": "vlan1", "vlan_id": 1}, + {"l3_interface": "irb.12", "name": "vlan2", "vlan_id": 2}, + ] + self.sort_vlans(result["parsed"]) + self.sort_vlans(parsed_list) + self.assertEqual(result["parsed"], parsed_list) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py new file mode 100644 index 000000000..d1cc4ec53 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/modules/utils.py @@ -0,0 +1,55 @@ +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type +import json + +from ansible.module_utils import basic +from ansible.module_utils._text import to_bytes + +from ansible_collections.junipernetworks.junos.tests.unit.compat import unittest +from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import patch + + +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/ansible_collections/junipernetworks/junos/tests/unit/plugins/__init__.py b/ansible_collections/junipernetworks/junos/tests/unit/plugins/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/plugins/__init__.py diff --git a/ansible_collections/junipernetworks/junos/tests/unit/plugins/terminal/__init__.py b/ansible_collections/junipernetworks/junos/tests/unit/plugins/terminal/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/plugins/terminal/__init__.py diff --git a/ansible_collections/junipernetworks/junos/tests/unit/plugins/terminal/test_junos.py b/ansible_collections/junipernetworks/junos/tests/unit/plugins/terminal/test_junos.py new file mode 100644 index 000000000..a61e645e7 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/tests/unit/plugins/terminal/test_junos.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright: (c) 2018, Fran Fitzpatrick <francis.x.fitzpatrick@gmail.com> fxfitz +# 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 pytest + +from ansible.errors import AnsibleConnectionFailure +from mock import MagicMock, call + +from ansible_collections.junipernetworks.junos.plugins.terminal import junos + + +@pytest.fixture +def junos_terminal(): + mock_connection = MagicMock() + return junos.TerminalModule(mock_connection) + + +def test_on_open_shell_sets_terminal_parameters(junos_terminal): + expected_calls = [ + call(b"set cli timestamp disable"), + call(b"set cli screen-length 0"), + call(b"set cli screen-width 1024"), + ] + junos_terminal._exec_cli_command = MagicMock() + junos_terminal._get_prompt = MagicMock() + + junos_terminal._get_prompt.return_value = b"user@localhost >" + junos_terminal.on_open_shell() + junos_terminal._exec_cli_command.assert_has_calls(expected_calls) + + +def test_on_open_shell_enters_cli_if_root_prompt(junos_terminal): + expected_calls = [ + call(b"cli"), + call(b"set cli timestamp disable"), + call(b"set cli screen-length 0"), + call(b"set cli screen-width 1024"), + ] + junos_terminal._exec_cli_command = MagicMock() + junos_terminal._get_prompt = MagicMock() + + junos_terminal._connection.get_prompt.return_value = b"root@localhost%" + junos_terminal.on_open_shell() + junos_terminal._exec_cli_command.assert_has_calls(expected_calls) + + +def test_on_open_shell_raises_problem_setting_terminal_config(junos_terminal): + junos_terminal._connection.exec_command.side_effect = AnsibleConnectionFailure + with pytest.raises(AnsibleConnectionFailure) as exc: + junos_terminal.on_open_shell() + + assert "unable to set terminal parameters" in str(exc.value) diff --git a/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt b/ansible_collections/junipernetworks/junos/tests/unit/requirements.txt new file mode 100644 index 000000000..a9772bea1 --- /dev/null +++ b/ansible_collections/junipernetworks/junos/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' |