diff options
author | GomathiselviS <gomathiselvi@gmail.com> | 2020-10-30 20:21:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-31 00:21:45 +0000 |
commit | de18ed01ddd7ac1db3bbde83a156624a972a43ae (patch) | |
tree | 6cf49ffa7c500d0ec0ff147326c5e079a7e570ab /tests | |
parent | f5e6f4e2111890012b4bce4ce5096912e2eb3094 (diff) | |
download | vyos.vyos-de18ed01ddd7ac1db3bbde83a156624a972a43ae.tar.gz vyos.vyos-de18ed01ddd7ac1db3bbde83a156624a972a43ae.zip |
Add ospf_interfaces resource module (#96)
Add ospf_interfaces resource module
Reviewed-by: https://github.com/apps/ansible-zuul
Diffstat (limited to 'tests')
20 files changed, 1078 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_ospf_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_ospf_interfaces/defaults/main.yaml new file mode 100644 index 0000000..852a6be --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/tests/integration/targets/vyos_ospf_interfaces/meta/main.yaml b/tests/integration/targets/vyos_ospf_interfaces/meta/main.yaml new file mode 100644 index 0000000..7413320 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_vyos_tests diff --git a/tests/integration/targets/vyos_ospf_interfaces/tasks/cli.yaml b/tests/integration/targets/vyos_ospf_interfaces/tasks/cli.yaml new file mode 100644 index 0000000..93eb2fe --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tasks/cli.yaml @@ -0,0 +1,19 @@ +--- +- name: Collect all cli test cases + find: + paths: '{{ role_path }}/tests/cli' + patterns: '{{ testcase }}.yaml' + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=ansible.netcommon.network_cli) + include: '{{ test_case_to_run }}' + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: '{{ test_items }}' + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_ospf_interfaces/tasks/main.yaml b/tests/integration/targets/vyos_ospf_interfaces/tasks/main.yaml new file mode 100644 index 0000000..b957d2f --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed.cfg new file mode 100644 index 0000000..aa57677 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed.cfg @@ -0,0 +1,6 @@ +set interfaces ethernet eth0 ip ospf cost '50' +set interfaces ethernet eth0 ip ospf priority '26' +set interfaces ethernet eth0 ipv6 ospfv3 'mtu-ignore' +set interfaces ethernet eth0 ipv6 ospfv3 instance-id '33' +set interfaces bonding bond2 ip ospf transmit-delay '45' +set interfaces bonding bond2 ipv6 ospfv3 'passive' diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config.cfg new file mode 100644 index 0000000..54696e8 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_parsed_config.cfg @@ -0,0 +1,10 @@ +set interfaces ethernet eth1 firewall in name 'INBOUND' +set interfaces ethernet eth1 firewall out name 'OUTBOUND' +set interfaces ethernet eth1 firewall local name 'LOCAL' +set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' +set interfaces ethernet eth2 firewall in name 'INBOUND' +set interfaces ethernet eth2 firewall out name 'OUTBOUND' +set interfaces ethernet eth2 firewall local name 'LOCAL' +set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' +set interfaces ethernet eth0 + diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_populate.yaml new file mode 100644 index 0000000..c4749d3 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_populate.yaml @@ -0,0 +1,13 @@ +--- +- name: setup + vyos.vyos.vyos_config: + lines: + - set interfaces ethernet eth0 ip ospf cost 50 + - set interfaces ethernet eth0 ip ospf priority 26 + - set interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore + - set interfaces ethernet eth0 ipv6 ospfv3 instance-id 33 + - set interfaces bonding bond2 ip ospf transmit-delay 45 + - set interfaces bonding bond2 ipv6 ospfv3 passive + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 0000000..9a2e699 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,15 @@ +--- +- name: Remove pre-existing OSPF processes + vyos.vyos.vyos_config: + lines: + - delete interfaces ethernet eth0 ip ospf + - delete interfaces ethernet eth0 ipv6 ospfv3 + - delete interfaces ethernet eth1 ip ospf + - delete interfaces ethernet eth1 ipv6 ospfv3 + - delete interfaces bonding bond1 ip ospf + - delete interfaces bonding bond1 ipv6 ospfv3 + - delete interfaces bonding bond2 ip ospf + - delete interfaces bonding bond2 ipv6 ospfv3 + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml new file mode 100644 index 0000000..573e611 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,42 @@ +--- +- debug: + msg: START vyos_ospf_interfaces deleted integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Delete the provided configuration + register: result + vyos.vyos.vyos_ospf_interfaces: &id001 + config: + - name: "bond2" + state: deleted + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: ospf_interfaces + + - assert: + that: + - result.commands|length == 2 + - result.changed == true + - result.commands|symmetric_difference(deleted.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] + + - name: Delete the existing configuration with the provided running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospf_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 0000000..aff0f66 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START vyos_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 + vyos.vyos.vyos_ospf_interfaces: + config: + state: merged + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_ospf_interfaces: + config: + state: replaced + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_ospf_interfaces: + config: + state: overridden + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Parsed with empty running_config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_ospf_interfaces: + running_config: + state: parsed + +- 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 + vyos.vyos.vyos_ospf_interfaces: + config: + state: rendered + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/gathered.yaml new file mode 100644 index 0000000..ec320c3 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START vyos_ospf_interfaces gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Gather config from the device in structured format. + register: result + vyos.vyos.vyos_ospf_interfaces: + state: gathered + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: ospf_interfaces + + - assert: + that: + - result.changed == false + - result.gathered|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml new file mode 100644 index 0000000..294b6f1 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/merged.yaml @@ -0,0 +1,53 @@ +--- +- debug: + msg: START vyos_ospf_interfaces merged integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.vyos_ospf_interfaces: &id001 + config: + - name: "eth0" + address_family: + - afi: "ipv4" + cost: 50 + priority: 26 + - afi: "ipv6" + mtu_ignore: true + instance: 33 + - name: "bond2" + address_family: + - afi: "ipv4" + transmit_delay: 45 + - afi: "ipv6" + passive: true + state: merged + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: ospf_interfaces + + - assert: + that: + - result.commands|length == 6 + - result.changed == true + - result.commands|symmetric_difference(merged.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospf_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml new file mode 100644 index 0000000..67bbca1 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,49 @@ +--- +- debug: + msg: START vyos_ospf_interfaces overridden integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Override the existing configuration with the provided running configuration + register: result + vyos.vyos.vyos_ospf_interfaces: &id001 + config: + - name: "eth0" + address_family: + - afi: "ipv4" + transmit_delay: 50 + priority: 26 + network: "point-to-point" + - afi: "ipv6" + dead_interval: 39 + state: overridden + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: ospf_interfaces + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] + + - name: Override the existing configuration with the provided running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospf_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml new file mode 100644 index 0000000..a065a00 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START vyos_ospfv3_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- name: Provide the running configuration for parsing (config to be parsed) + become: true + register: result + vyos.vyos.vyos_ospf_interfaces: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + +- assert: + that: + - result.changed == false + - result.parsed|symmetric_difference(merged.after) == [] diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml new file mode 100644 index 0000000..328406b --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: START vyos_ospf_interfaces rendered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Structure provided configuration into device specific commands + register: result + vyos.vyos.vyos_ospf_interfaces: + config: + - name: "eth0" + address_family: + - afi: "ipv4" + cost: 50 + priority: 26 + - afi: "ipv6" + mtu_ignore: true + instance: 33 + - name: "bond2" + address_family: + - afi: "ipv4" + transmit_delay: 45 + - afi: "ipv6" + passive: true + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml new file mode 100644 index 0000000..ff32012 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START vyos_ospf_interfaces replaced integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Replace the existing configuration with the provided running configuration + register: result + vyos.vyos.vyos_ospf_interfaces: &id001 + config: + - name: "eth0" + address_family: + - afi: "ipv4" + transmit_delay: 50 + priority: 26 + network: "point-to-point" + - afi: "ipv6" + dead_interval: 39 + - name: "bond2" + address_family: + - afi: "ipv4" + transmit_delay: 45 + bandwidth: 70 + authentication: + md5_key: + key_id: 10 + key: "1111111111232345" + - afi: "ipv6" + passive: true + state: replaced + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: ospf_interfaces + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(replaced.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] + + - name: Replace the existing configuration with the provided running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospf_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml new file mode 100644 index 0000000..46eb79d --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,70 @@ +--- +- debug: + msg: START vyos_ospf_interfaces rtt integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: baseconfig + vyos.vyos.vyos_ospf_interfaces: &id001 + config: + - name: "eth0" + address_family: + - afi: "ipv4" + cost: 50 + priority: 26 + - afi: "ipv6" + mtu_ignore: true + instance: 33 + - name: "bond2" + address_family: + - afi: "ipv4" + transmit_delay: 45 + - afi: "ipv6" + passive: true + state: merged + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: ospf_interfaces + + - assert: + that: + - baseconfig.commands|length == 6 + - baseconfig.changed == true + - baseconfig.commands|symmetric_difference(merged.commands) == [] + - baseconfig.after|symmetric_difference(ansible_facts['network_resources']['ospf_interfaces']) == [] + + - name: Apply the provided configuration (config to be reverted) + become: true + register: result + vyos.vyos.vyos_ospf_interfaces: + config: + - name: "eth0" + address_family: + - afi: "ipv4" + transmit_delay: 50 + priority: 26 + network: "point-to-point" + - afi: "ipv6" + dead_interval: 39 + + + - name: Revert back to base config using facts round trip + become: true + register: revert + vyos.vyos.vyos_ospf_interfaces: + config: "{{ ansible_facts['network_resources']['ospf_interfaces'] }}" + state: overridden + + - name: Assert that config was reverted + assert: + that: baseconfig.after == revert.after + + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospf_interfaces/vars/main.yaml b/tests/integration/targets/vyos_ospf_interfaces/vars/main.yaml new file mode 100644 index 0000000..a98d351 --- /dev/null +++ b/tests/integration/targets/vyos_ospf_interfaces/vars/main.yaml @@ -0,0 +1,133 @@ +--- +merged: + commands: + - set interfaces ethernet eth0 ip ospf cost 50 + - set interfaces ethernet eth0 ip ospf priority 26 + - set interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore + - set interfaces ethernet eth0 ipv6 ospfv3 instance-id 33 + - set interfaces bonding bond2 ip ospf transmit-delay 45 + - set interfaces bonding bond2 ipv6 ospfv3 passive + after: + - address_family: + - afi: "ipv4" + transmit_delay: 45 + - afi: "ipv6" + passive: true + name: "bond2" + - address_family: + - afi: "ipv4" + cost: 50 + priority: 26 + - afi: "ipv6" + instance: "33" + mtu_ignore: true + name: "eth0" + +replaced: + commands: + - set interfaces ethernet eth0 ip ospf transmit-delay 50 + - set interfaces ethernet eth0 ip ospf network point-to-point + - set interfaces ethernet eth0 ipv6 ospfv3 dead-interval 39 + - delete interfaces ethernet eth0 ip ospf cost 50 + - delete interfaces ethernet eth0 ipv6 ospfv3 instance-id 33 + - delete interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore + - set interfaces bonding bond2 ip ospf bandwidth 70 + - set interfaces bonding bond2 ip ospf authentication md5 key-id 10 md5-key 1111111111232345 + + after: + - address_family: + - afi: "ipv4" + authentication: + md5_key: + key: "1111111111232345" + key_id: 10 + bandwidth: 70 + transmit_delay: 45 + - afi: "ipv6" + passive: true + name: "bond2" + - address_family: + - afi: "ipv4" + network: "point-to-point" + priority: 26 + transmit_delay: 50 + - afi: "ipv6" + dead_interval: 39 + name: "eth0" + +overridden: + commands: + - delete interfaces bonding bond2 ip ospf + - delete interfaces bonding bond2 ipv6 ospfv3 + - set interfaces ethernet eth0 ip ospf transmit-delay 50 + - set interfaces ethernet eth0 ip ospf network point-to-point + - set interfaces ethernet eth0 ipv6 ospfv3 dead-interval 39 + - delete interfaces ethernet eth0 ip ospf cost 50 + - delete interfaces ethernet eth0 ipv6 ospfv3 instance-id 33 + - delete interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore + + after: + - address_family: + - afi: "ipv4" + network: "point-to-point" + priority: 26 + transmit_delay: 50 + - afi: "ipv6" + dead_interval: 39 + name: "eth0" + +deleted: + commands: + - delete interfaces bonding bond2 ip ospf + - delete interfaces bonding bond2 ipv6 ospfv3 + after: + - address_family: + - afi: "ipv4" + cost: 50 + priority: 26 + - afi: "ipv6" + instance: "33" + mtu_ignore: true + name: "eth0" + +rendered: + commands: + - set interfaces ethernet eth1 firewall in name 'INBOUND' + - set interfaces ethernet eth1 firewall out name 'OUTBOUND' + - set interfaces ethernet eth1 firewall local name 'LOCAL' + - set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' + - set interfaces ethernet eth2 firewall in name 'INBOUND' + - set interfaces ethernet eth2 firewall out name 'OUTBOUND' + - set interfaces ethernet eth2 firewall local name 'LOCAL' + - set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' +round_trip: + after: + - name: eth0 + - access_rules: + - afi: ipv4 + rules: + - direction: in + name: INBOUND + - direction: local + name: LOCAL + - direction: out + name: OUTBOUND + - afi: ipv6 + rules: + - direction: local + name: V6-LOCAL + name: eth1 + - name: eth2 + access_rules: + - afi: ipv4 + rules: + - direction: in + name: INBOUND + - direction: local + name: LOCAL + - direction: out + name: OUTBOUND + - afi: ipv6 + rules: + - direction: local + name: V6-LOCAL diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config.cfg new file mode 100644 index 0000000..1fab55e --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_ospf_interfaces_config.cfg @@ -0,0 +1,4 @@ +set interfaces ethernet eth0 ipv6 ospfv3 instance-id '33' +set interfaces ethernet eth0 ipv6 ospfv3 'mtu-ignore' +set interfaces ethernet eth1 ip ospf cost '100' +set interfaces ethernet eth1 ipv6 ospfv3 ifmtu '33' diff --git a/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py b/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py new file mode 100644 index 0000000..3250d11 --- /dev/null +++ b/tests/unit/modules/network/vyos/test_vyos_ospf_interfaces.py @@ -0,0 +1,461 @@ +# (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.vyos.vyos.tests.unit.compat.mock import patch +from ansible_collections.vyos.vyos.plugins.modules import vyos_ospf_interfaces +from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( + set_module_args, +) +from .vyos_module import TestVyosModule, load_fixture + + +class TestVyosOspfInterfacesModule(TestVyosModule): + + module = vyos_ospf_interfaces + + def setUp(self): + super(TestVyosOspfInterfacesModule, self).setUp() + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module.get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospf_interfaces.ospf_interfaces.Ospf_interfacesFacts.get_device_data" + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestVyosOspfInterfacesModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None, transport="cli", filename=None): + if filename is None: + filename = "vyos_ospf_interfaces_config.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + + def sort_address_family(self, entry_list): + for entry in entry_list: + if entry.get("address_family"): + entry["address_family"].sort(key=lambda i: i.get("afi")) + + def test_vyos_ospf_interfaces_merged_new_config(self): + set_module_args( + dict( + config=[ + dict( + name="eth0", + address_family=[ + dict( + afi="ipv4", + cost=100, + authentication=dict( + plaintext_password="abcdefg!" + ), + priority=55, + ), + dict(afi="ipv6", mtu_ignore=True, instance=20), + ], + ), + dict( + name="bond2", + address_family=[ + dict( + afi="ipv4", + transmit_delay=9, + ), + dict(afi="ipv6", passive=True), + ], + ), + ], + state="merged", + ) + ) + commands = [ + "set interfaces bonding bond2 ip ospf transmit-delay 9", + "set interfaces bonding bond2 ipv6 ospfv3 passive", + "set interfaces ethernet eth0 ip ospf cost 100", + "set interfaces ethernet eth0 ip ospf priority 55", + "set interfaces ethernet eth0 ip ospf authentication plaintext-password abcdefg!", + "set interfaces ethernet eth0 ipv6 ospfv3 instance-id 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospf_interfaces_merged_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="eth0", + address_family=[ + dict(afi="ipv6", mtu_ignore=True, instance=33), + ], + ), + dict( + name="eth1", + address_family=[ + dict( + afi="ipv4", + cost=100, + ), + dict(afi="ipv6", ifmtu=33), + ], + ), + ], + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_ospf_interfaces_existing_config_merged(self): + set_module_args( + dict( + config=[ + dict( + name="eth0", + address_family=[ + dict(afi="ipv6", cost=500), + ], + ), + dict( + name="eth1", + address_family=[ + dict( + afi="ipv4", + priority=100, + ), + dict(afi="ipv6", ifmtu=25), + ], + ), + ], + ) + ) + commands = [ + "set interfaces ethernet eth0 ipv6 ospfv3 cost 500", + "set interfaces ethernet eth1 ip ospf priority 100", + "set interfaces ethernet eth1 ipv6 ospfv3 ifmtu 25", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospf_interfaces_replaced(self): + set_module_args( + dict( + config=[ + dict( + name="eth0", + address_family=[ + dict( + afi="ipv4", + cost=100, + authentication=dict( + plaintext_password="abcdefg!" + ), + priority=55, + ), + ], + ), + dict( + name="bond2", + address_family=[ + dict( + afi="ipv4", + transmit_delay=9, + ), + dict(afi="ipv6", passive=True), + ], + ), + ], + state="replaced", + ) + ) + commands = [ + "set interfaces bonding bond2 ip ospf transmit-delay 9", + "set interfaces bonding bond2 ipv6 ospfv3 passive", + "set interfaces ethernet eth0 ip ospf cost 100", + "set interfaces ethernet eth0 ip ospf priority 55", + "set interfaces ethernet eth0 ip ospf authentication plaintext-password abcdefg!", + "delete interfaces ethernet eth0 ipv6 ospfv3 instance-id 33", + "delete interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospf_interfaces_replaced_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="eth0", + address_family=[ + dict(afi="ipv6", mtu_ignore=True, instance=33), + ], + ), + dict( + name="eth1", + address_family=[ + dict( + afi="ipv4", + cost=100, + ), + dict(afi="ipv6", ifmtu=33), + ], + ), + ], + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_ospf_interfaces_overridden(self): + set_module_args( + dict( + config=[ + dict( + name="eth0", + address_family=[ + dict( + afi="ipv4", + cost=100, + authentication=dict( + plaintext_password="abcdefg!" + ), + priority=55, + ), + ], + ), + dict( + name="bond2", + address_family=[ + dict( + afi="ipv4", + transmit_delay=9, + ), + dict(afi="ipv6", passive=True), + ], + ), + ], + state="overridden", + ) + ) + commands = [ + "set interfaces bonding bond2 ip ospf transmit-delay 9", + "set interfaces bonding bond2 ipv6 ospfv3 passive", + "set interfaces ethernet eth0 ip ospf cost 100", + "set interfaces ethernet eth0 ip ospf priority 55", + "set interfaces ethernet eth0 ip ospf authentication plaintext-password abcdefg!", + "delete interfaces ethernet eth1 ip ospf", + "delete interfaces ethernet eth1 ipv6 ospfv3", + "delete interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore", + "delete interfaces ethernet eth0 ipv6 ospfv3 instance-id 33", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospf_interfaces_overridden_idempotent(self): + set_module_args( + dict( + config=[ + dict( + name="eth0", + address_family=[ + dict(afi="ipv6", mtu_ignore=True, instance=33), + ], + ), + dict( + name="eth1", + address_family=[ + dict( + afi="ipv4", + cost=100, + ), + dict(afi="ipv6", ifmtu=33), + ], + ), + ], + state="overridden", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_ospf_interfaces_deleted(self): + set_module_args( + dict( + config=[ + dict( + name="eth0", + ), + ], + state="deleted", + ) + ) + commands = ["delete interfaces ethernet eth0 ipv6 ospfv3"] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospf_interfaces_notpresent_deleted(self): + set_module_args( + dict( + config=[ + dict( + name="eth3", + ), + ], + state="deleted", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_ospf_interfaces_rendered(self): + set_module_args( + dict( + config=[ + dict( + name="eth0", + address_family=[ + dict( + afi="ipv4", + cost=100, + authentication=dict( + plaintext_password="abcdefg!" + ), + priority=55, + ), + dict(afi="ipv6", mtu_ignore=True, instance=20), + ], + ), + dict( + name="bond2", + address_family=[ + dict( + afi="ipv4", + transmit_delay=9, + ), + dict(afi="ipv6", passive=True), + ], + ), + ], + state="rendered", + ) + ) + commands = [ + "set interfaces ethernet eth0 ip ospf cost 100", + "set interfaces ethernet eth0 ip ospf authentication plaintext-password abcdefg!", + "set interfaces ethernet eth0 ip ospf priority 55", + "set interfaces ethernet eth0 ipv6 ospfv3 mtu-ignore", + "set interfaces ethernet eth0 ipv6 ospfv3 instance-id 20", + "set interfaces bonding bond2 ip ospf transmit-delay 9", + "set interfaces bonding bond2 ipv6 ospfv3 passive", + ] + result = self.execute_module(changed=False) + self.assertEqual( + sorted(result["rendered"]), sorted(commands), result["rendered"] + ) + + def test_vyos_ospf_interfaces_parsed(self): + commands = [ + "set interfaces bonding bond2 ip ospf authentication md5 key-id 10 md5-key '1111111111232345'", + "set interfaces bonding bond2 ip ospf bandwidth '70'", + "set interfaces bonding bond2 ip ospf transmit-delay '45'", + "set interfaces bonding bond2 ipv6 ospfv3 'passive'", + "set interfaces ethernet eth0 ip ospf cost '50'", + "set interfaces ethernet eth0 ip ospf priority '26'", + "set interfaces ethernet eth0 ipv6 ospfv3 instance-id '33'", + "set interfaces ethernet eth0 ipv6 ospfv3 'mtu-ignore'", + "set interfaces ethernet eth1 ip ospf network 'point-to-point'", + "set interfaces ethernet eth1 ip ospf priority '26'", + "set interfaces ethernet eth1 ip ospf transmit-delay '50'", + "set interfaces ethernet eth1 ipv6 ospfv3 dead-interval '39'", + ] + + parsed_str = "\n".join(commands) + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = [ + { + "address_family": [ + { + "afi": "ipv4", + "authentication": { + "md5_key": { + "key": "1111111111232345", + "key_id": 10, + } + }, + "bandwidth": 70, + "transmit_delay": 45, + }, + {"afi": "ipv6", "passive": True}, + ], + "name": "bond2", + }, + { + "address_family": [ + {"afi": "ipv4", "cost": 50, "priority": 26}, + {"afi": "ipv6", "instance": "33", "mtu_ignore": True}, + ], + "name": "eth0", + }, + { + "address_family": [ + { + "afi": "ipv4", + "network": "point-to-point", + "priority": 26, + "transmit_delay": 50, + }, + {"afi": "ipv6", "dead_interval": 39}, + ], + "name": "eth1", + }, + ] + result_list = self.sort_address_family(result["parsed"]) + given_list = self.sort_address_family(parsed_list) + self.assertEqual(result_list, given_list) + + def test_vyos_ospf_interfaces_gathered(self): + set_module_args(dict(state="gathered")) + result = self.execute_module( + changed=False, filename="vyos_ospf_interfaces_config.cfg" + ) + gathered_list = [ + { + "address_family": [ + {"afi": "ipv6", "instance": "33", "mtu_ignore": True} + ], + "name": "eth0", + }, + { + "address_family": [ + {"afi": "ipv4", "cost": 100}, + {"afi": "ipv6", "ifmtu": 33}, + ], + "name": "eth1", + }, + ] + + result_list = self.sort_address_family(result["gathered"]) + given_list = self.sort_address_family(gathered_list) + self.assertEqual(result_list, given_list) |