diff options
Diffstat (limited to 'tests')
21 files changed, 1815 insertions, 1 deletions
diff --git a/tests/integration/targets/vyos_ospfv2/defaults/main.yaml b/tests/integration/targets/vyos_ospfv2/defaults/main.yaml new file mode 100644 index 0000000..852a6be --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/tests/integration/targets/vyos_ospfv2/meta/main.yaml b/tests/integration/targets/vyos_ospfv2/meta/main.yaml new file mode 100644 index 0000000..7413320 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/meta/main.yaml @@ -0,0 +1,3 @@ +--- +dependencies: + - prepare_vyos_tests diff --git a/tests/integration/targets/vyos_ospfv2/tasks/cli.yaml b/tests/integration/targets/vyos_ospfv2/tasks/cli.yaml new file mode 100644 index 0000000..93eb2fe --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/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_ospfv2/tasks/main.yaml b/tests/integration/targets/vyos_ospfv2/tasks/main.yaml new file mode 100644 index 0000000..a3db933 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - cli diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg new file mode 100644 index 0000000..9cc720b --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_parsed_config.cfg @@ -0,0 +1,29 @@ +set protocols ospf area 2 area-type 'normal' +set protocols ospf area 2 authentication 'plaintext-password' +set protocols ospf area 2 shortcut 'enable' +set protocols ospf area 3 area-type 'nssa' +set protocols ospf area 4 area-type stub default-cost '20' +set protocols ospf area 4 network '192.0.2.0/24' +set protocols ospf area 4 range 192.0.3.0/24 cost '10' +set protocols ospf area 4 range 192.0.4.0/24 cost '12' +set protocols ospf auto-cost reference-bandwidth '2' +set protocols ospf default-information originate 'always' +set protocols ospf default-information originate metric '10' +set protocols ospf default-information originate metric-type '2' +set protocols ospf default-information originate route-map 'ingress' +set protocols ospf log-adjacency-changes 'detail' +set protocols ospf max-metric router-lsa 'administrative' +set protocols ospf max-metric router-lsa on-shutdown '10' +set protocols ospf max-metric router-lsa on-startup '10' +set protocols ospf mpls-te 'enable' +set protocols ospf mpls-te router-address '192.0.11.11' +set protocols ospf neighbor 192.0.11.12 poll-interval '10' +set protocols ospf neighbor 192.0.11.12 priority '2' +set protocols ospf parameters abr-type 'cisco' +set protocols ospf parameters 'opaque-lsa' +set protocols ospf parameters 'rfc1583-compatibility' +set protocols ospf parameters router-id '192.0.1.1' +set protocols ospf passive-interface 'eth1' +set protocols ospf passive-interface 'eth2' +set protocols ospf redistribute bgp metric '10' +set protocols ospf redistribute bgp metric-type '2' diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml new file mode 100644 index 0000000..9f358d5 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_populate.yaml @@ -0,0 +1,35 @@ +--- +- name: Setup + vars: + lines: "set protocols ospf mpls-te 'enable' \n + set protocols ospf mpls-te router-address '192.0.11.11' \n + set protocols ospf redistribute bgp metric-type '2' \n + set protocols ospf redistribute bgp metric '10'\n + set protocols ospf default-information originate metric-type '2' \n + set protocols ospf default-information originate 'always' \n + set protocols ospf default-information originate metric '10' \n + set protocols ospf default-information originate route-map 'ingress' \n + set protocols ospf auto-cost reference-bandwidth '2' \n + set protocols ospf parameters router-id '192.0.1.1' \n + set protocols ospf parameters 'opaque-lsa' \n + set protocols ospf parameters abr-type 'cisco' \n + set protocols ospf parameters 'rfc1583-compatibility' \n + set protocols ospf passive-interface 'eth1' \n + set protocols ospf passive-interface 'eth2' \n + set protocols ospf max-metric router-lsa on-shutdown '10' \n + set protocols ospf max-metric router-lsa 'administrative' \n + set protocols ospf max-metric router-lsa on-startup '10' \n + set protocols ospf log-adjacency-changes 'detail' \n + set protocols ospf neighbor 192.0.11.12 priority '2' \n + set protocols ospf neighbor 192.0.11.12 poll-interval '10' \n + set protocols ospf area 2 authentication 'plaintext-password' \n + set protocols ospf area 2 shortcut 'enable' \n + set protocols ospf area 2 area-type 'normal' \n + set protocols ospf area 3 area-type 'nssa' \n + set protocols ospf area 4 range 192.0.3.0/24 cost '10' \n + set protocols ospf area 4 range 192.0.4.0/24 cost '12' \n + set protocols ospf area 4 area-type stub default-cost '20' \n + set protocols ospf area 4 network '192.0.2.0/24'" + + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml new file mode 100644 index 0000000..7360870 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/_remove_config.yaml @@ -0,0 +1,6 @@ +--- +- name: Remove Config + vars: + lines: "delete protocols ospf\n" + ansible.netcommon.cli_config: + config: '{{ lines }}' diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/delete_single.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/delete_single.yaml new file mode 100644 index 0000000..150242a --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/delete_single.yaml @@ -0,0 +1,57 @@ +--- +- debug: + msg: Start vyos_ospfv2 deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _populate.yaml + +- block: + + - name: Delete attributes of ospfv2. + register: result + vyos.vyos.vyos_ospfv2: &id001 + config: + log_adjacency_changes: 'detail' + max_metric: + default_information: + mpls_te: + neighbor: + redistribute: + parameters: + passive_interface: + areas: + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ populate == result['before'] }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted_single['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted_single['after'] == result['after'] }}" + + - name: Delete attributes of given interfaces (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospfv2: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + - result.commands|length == 0 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted_single['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml new file mode 100644 index 0000000..a61f5a7 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/deleted.yaml @@ -0,0 +1,48 @@ +--- +- debug: + msg: Start vyos_ospfv2 deleted integration tests ansible_connection={{ + ansible_connection }} + +- include_tasks: _populate.yaml + +- block: + + - name: Delete attributes of ospfv2. + register: result + vyos.vyos.vyos_ospfv2: &id001 + config: + state: deleted + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ populate == result['before'] }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['after'] }}" + + - name: Delete attributes of given interfaces (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospfv2: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result.changed == false + - result.commands|length == 0 + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/empty_config.yaml new file mode 100644 index 0000000..4566bf4 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/empty_config.yaml @@ -0,0 +1,49 @@ +--- +- debug: + msg: START vyos_ospfv2 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_ospfv2: + config: + state: merged + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_ospfv2: + config: + state: replaced + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Parsed with empty running_config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_ospfv2: + 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_ospfv2: + 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_ospfv2/tests/cli/gathered.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/gathered.yaml new file mode 100644 index 0000000..22c378b --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/gathered.yaml @@ -0,0 +1,33 @@ +--- +- debug: + msg: START vyos_ospfv2 gathered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.vyos_ospfv2: &id001 + config: + state: gathered + + - name: Assert that gathered dicts was correctly generated + assert: + that: + - "{{ populate == result['gathered'] }}" + + - name: Gather the existing running configuration (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospfv2: *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_ospfv2/tests/cli/merged.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/merged.yaml new file mode 100644 index 0000000..6a58bb5 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/merged.yaml @@ -0,0 +1,101 @@ +--- +- debug: + msg: START vyos_ospfv2 merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.vyos_ospfv2: &id001 + config: + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + mpls_te: + enabled: true + router_address: '192.0.11.11' + auto_cost: + reference_bandwidth: 2 + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + redistribute: + - route_type: 'bgp' + metric: 10 + metric_type: 2 + passive_interface: + - 'eth1' + - 'eth2' + parameters: + router_id: '192.0.1.1' + opaque_lsa: true + rfc1583_compatibility: true + abr_type: 'cisco' + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '3' + area_type: + nssa: + set: true + - area_id: '4' + area_type: + stub: + default_cost: 20 + network: + - address: '192.0.2.0/24' + range: + - address: '192.0.3.0/24' + cost: 10 + - address: '192.0.4.0/24' + cost: 12 + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospfv2: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/merged_update.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/merged_update.yaml new file mode 100644 index 0000000..453dbb0 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/merged_update.yaml @@ -0,0 +1,70 @@ +--- +- debug: + msg: START vyos_ospfv2 merged integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Merge the provided configuration with the exisiting running configuration + register: result + vyos.vyos.vyos_ospfv2: &id001 + config: + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + passive_interface: + - 'eth1' + areas: + - area_id: '3' + area_type: + nssa: + set: true + - area_id: '4' + area_type: + stub: + set: false + network: + - address: '192.0.2.0/24' + - address: '192.0.22.0/24' + - address: '192.0.32.0/24' + state: merged + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged_update['before'] == result['before'] }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged_update['commands'] | symmetric_difference(result['commands']) |length\ + \ == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged_update['after'] == result['after'] }}" + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospfv2: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ merged_update['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml
\ No newline at end of file diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml new file mode 100644 index 0000000..6fbe2f9 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/parsed.yaml @@ -0,0 +1,41 @@ +--- +- debug: + msg: START vyos_ospfv2 parsed integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Gather ospfv2 facts + register: ospfv2_facts + vyos.vyos.vyos_facts: + gather_subset: + - default + gather_network_resources: + - ospfv2 + + - name: Provide the running configuration for parsing (config to be parsed) + register: result + vyos.vyos.vyos_ospfv2: &id001 + running_config: "{{ lookup('file', '_parsed_config.cfg') }}" + state: parsed + + - name: Assert that correct parsing done + assert: + that: "{{ ansible_facts['network_resources']['ospfv2'] == result['parsed']\ + \ }}" + + - name: Gather the existing running configuration (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospfv2: *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_ospfv2/tests/cli/rendered.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml new file mode 100644 index 0000000..86c07cf --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/rendered.yaml @@ -0,0 +1,88 @@ +--- +- debug: + msg: START vyos_ospfv2 rendered integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Structure provided configuration into device specific commands + register: result + vyos.vyos.vyos_ospfv2: &id001 + config: + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + mpls_te: + enabled: true + router_address: '192.0.11.11' + auto_cost: + reference_bandwidth: 2 + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + redistribute: + - route_type: 'bgp' + metric: 10 + metric_type: 2 + passive_interface: + - 'eth1' + - 'eth2' + parameters: + router_id: '192.0.1.1' + opaque_lsa: true + rfc1583_compatibility: true + abr_type: 'cisco' + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '3' + area_type: + nssa: + set: true + - area_id: '4' + area_type: + stub: + default_cost: 20 + network: + - address: '192.0.2.0/24' + range: + - address: '192.0.3.0/24' + cost: 10 + - address: '192.0.4.0/24' + cost: 12 + state: rendered + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\ + \ |length == 0 }}" + + - name: Structure provided configuration into device specific commands (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospfv2: *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_ospfv2/tests/cli/replaced.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml new file mode 100644 index 0000000..07606f9 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/replaced.yaml @@ -0,0 +1,100 @@ +--- +- debug: + msg: START vyos_ospfv2 replaced integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Replace device configurations of listed ospfv2 routes with provided configurations + register: result + vyos.vyos.vyos_ospfv2: &id001 + config: + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + mpls_te: + enabled: true + router_address: '192.0.22.22' + auto_cost: + reference_bandwidth: 2 + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + redistribute: + - route_type: 'bgp' + metric: 10 + metric_type: 2 + passive_interface: + - 'eth1' + parameters: + router_id: '192.0.1.1' + opaque_lsa: true + rfc1583_compatibility: true + abr_type: 'cisco' + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '4' + area_type: + stub: + default_cost: 20 + network: + - address: '192.0.2.0/24' + - address: '192.0.12.0/24' + - address: '192.0.22.0/24' + - address: '192.0.32.0/24' + range: + - address: '1.1.2.0/24' + cost: 10 + state: replaced + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands'])\ + \ |length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ populate == result['before'] }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] == result['after'] }}" + + - name: Replace device configurations of listed ospfv2 routes with provided configurarions + (IDEMPOTENT) + register: result + vyos.vyos.vyos_ospfv2: *id001 + + - name: Assert that task was idempotent + assert: + that: + - result['changed'] == false + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] == result['before'] }}" + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml b/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml new file mode 100644 index 0000000..7efc2a7 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/tests/cli/rtt.yaml @@ -0,0 +1,149 @@ +--- +- debug: + msg: START vyos_ospfv2 round trip integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- block: + + - name: Apply the provided configuration (base config) + register: base_config + vyos.vyos.vyos_ospfv2: + config: + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + mpls_te: + enabled: true + router_address: '192.0.11.11' + auto_cost: + reference_bandwidth: 2 + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + redistribute: + - route_type: 'bgp' + metric: 10 + metric_type: 2 + passive_interface: + - 'eth1' + - 'eth2' + parameters: + router_id: '192.0.1.1' + opaque_lsa: true + rfc1583_compatibility: true + abr_type: 'cisco' + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '3' + area_type: + nssa: + set: true + - area_id: '4' + area_type: + stub: + default_cost: 20 + network: + - address: '192.0.2.0/24' + range: + - address: '192.0.3.0/24' + cost: 10 + - address: '192.0.4.0/24' + cost: 12 + state: merged + + - name: Gather ospfv2 facts + vyos.vyos.vyos_facts: + gather_subset: + - default + gather_network_resources: + - ospfv2 + + - name: Apply the provided configuration (config to be reverted) + register: result + vyos.vyos.vyos_ospfv2: + config: + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '4' + area_type: + stub: + default_cost: 20 + set: true + network: + - address: '192.0.12.0/24' + - address: '192.0.2.0/24' + - address: '192.0.22.0/24' + - address: '192.0.32.0/24' + range: + - address: '1.1.2.0/24' + cost: 10 + auto_cost: + reference_bandwidth: 2 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + mpls_te: + enabled: true + router_address: '192.0.22.22' + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + parameters: + abr_type: 'cisco' + opaque_lsa: true + rfc1583_compatibility: true + router_id: '192.0.1.1' + passive_interface: + - 'eth1' + redistribute: + - metric: 10 + metric_type: 2 + route_type: 'bgp' + state: replaced + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] == result['after'] }}" + + - name: Revert back to base config using facts round trip + register: revert + vyos.vyos.vyos_ospfv2: + config: "{{ ansible_facts['network_resources']['ospfv2'] }}" + state: replaced + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] == revert['after']}}" + always: + + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_ospfv2/vars/main.yaml b/tests/integration/targets/vyos_ospfv2/vars/main.yaml new file mode 100644 index 0000000..76a54e3 --- /dev/null +++ b/tests/integration/targets/vyos_ospfv2/vars/main.yaml @@ -0,0 +1,444 @@ +--- +merged: + before: [] + commands: + - set protocols ospf mpls-te enable + - set protocols ospf mpls-te router-address '192.0.11.11' + - set protocols ospf redistribute bgp + - set protocols ospf redistribute bgp metric-type 2 + - set protocols ospf redistribute bgp metric 10 + - set protocols ospf default-information originate metric-type 2 + - set protocols ospf default-information originate always + - set protocols ospf default-information originate metric 10 + - set protocols ospf default-information originate route-map ingress + - set protocols ospf auto-cost reference-bandwidth '2' + - set protocols ospf parameters router-id '192.0.1.1' + - set protocols ospf parameters opaque-lsa + - set protocols ospf parameters abr-type 'cisco' + - set protocols ospf parameters rfc1583-compatibility + - set protocols ospf passive-interface eth1 + - set protocols ospf passive-interface eth2 + - set protocols ospf max-metric router-lsa on-shutdown 10 + - set protocols ospf max-metric router-lsa administrative + - set protocols ospf max-metric router-lsa on-startup 10 + - set protocols ospf log-adjacency-changes 'detail' + - set protocols ospf neighbor 192.0.11.12 priority 2 + - set protocols ospf neighbor 192.0.11.12 poll-interval 10 + - set protocols ospf neighbor 192.0.11.12 + - set protocols ospf area '2' + - set protocols ospf area 2 authentication plaintext-password + - set protocols ospf area 2 shortcut enable + - set protocols ospf area 2 area-type normal + - set protocols ospf area '3' + - set protocols ospf area 3 area-type nssa + - set protocols ospf area 4 range 192.0.3.0/24 cost 10 + - set protocols ospf area 4 range 192.0.3.0/24 + - set protocols ospf area 4 range 192.0.4.0/24 cost 12 + - set protocols ospf area 4 range 192.0.4.0/24 + - set protocols ospf area 4 area-type stub default-cost 20 + - set protocols ospf area '4' + - set protocols ospf area 4 network 192.0.2.0/24 + after: + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '3' + area_type: + nssa: + set: true + - area_id: '4' + area_type: + stub: + default_cost: 20 + set: true + network: + - address: '192.0.2.0/24' + range: + - address: '192.0.3.0/24' + cost: 10 + - address: '192.0.4.0/24' + cost: 12 + auto_cost: + reference_bandwidth: 2 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + mpls_te: + enabled: true + router_address: '192.0.11.11' + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + parameters: + abr_type: 'cisco' + opaque_lsa: true + rfc1583_compatibility: true + router_id: '192.0.1.1' + passive_interface: + - 'eth2' + - 'eth1' + redistribute: + - metric: 10 + metric_type: 2 + route_type: 'bgp' +merged_update: + before: + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '3' + area_type: + nssa: + set: true + - area_id: '4' + area_type: + stub: + default_cost: 20 + set: true + network: + - address: '192.0.2.0/24' + range: + - address: '192.0.3.0/24' + cost: 10 + - address: '192.0.4.0/24' + cost: 12 + auto_cost: + reference_bandwidth: 2 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + mpls_te: + enabled: true + router_address: '192.0.11.11' + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + parameters: + abr_type: 'cisco' + opaque_lsa: true + rfc1583_compatibility: true + router_id: '192.0.1.1' + passive_interface: + - 'eth2' + - 'eth1' + redistribute: + - metric: 10 + metric_type: 2 + route_type: 'bgp' + after: + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '3' + area_type: + nssa: + set: true + - area_id: '4' + network: + - address: '192.0.2.0/24' + - address: '192.0.22.0/24' + - address: '192.0.32.0/24' + range: + - address: '192.0.3.0/24' + cost: 10 + - address: '192.0.4.0/24' + cost: 12 + auto_cost: + reference_bandwidth: 2 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + mpls_te: + enabled: true + router_address: '192.0.11.11' + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + parameters: + abr_type: 'cisco' + opaque_lsa: true + rfc1583_compatibility: true + router_id: '192.0.1.1' + passive_interface: + - 'eth2' + - 'eth1' + redistribute: + - metric: 10 + metric_type: 2 + route_type: 'bgp' + commands: + - delete protocols ospf area 4 area-type stub + - set protocols ospf area 4 network 192.0.22.0/24 + - set protocols ospf area 4 network 192.0.32.0/24 +populate: + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '3' + area_type: + nssa: + set: true + - area_id: '4' + area_type: + stub: + default_cost: 20 + set: true + network: + - address: '192.0.2.0/24' + range: + - address: '192.0.3.0/24' + cost: 10 + - address: '192.0.4.0/24' + cost: 12 + auto_cost: + reference_bandwidth: 2 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + mpls_te: + enabled: true + router_address: '192.0.11.11' + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + parameters: + abr_type: 'cisco' + opaque_lsa: true + rfc1583_compatibility: true + router_id: '192.0.1.1' + passive_interface: + - 'eth2' + - 'eth1' + redistribute: + - metric: 10 + metric_type: 2 + route_type: 'bgp' +replaced: + commands: + - delete protocols ospf passive-interface eth2 + - delete protocols ospf area 3 + - delete protocols ospf area 4 range 192.0.3.0/24 cost + - delete protocols ospf area 4 range 192.0.3.0/24 + - delete protocols ospf area 4 range 192.0.4.0/24 cost + - delete protocols ospf area 4 range 192.0.4.0/24 + - set protocols ospf mpls-te router-address '192.0.22.22' + - set protocols ospf area 4 range 1.1.2.0/24 cost 10 + - set protocols ospf area 4 range 1.1.2.0/24 + - set protocols ospf area 4 network 192.0.12.0/24 + - set protocols ospf area 4 network 192.0.22.0/24 + - set protocols ospf area 4 network 192.0.32.0/24 + after: + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '4' + area_type: + stub: + default_cost: 20 + set: true + network: + - address: '192.0.12.0/24' + - address: '192.0.2.0/24' + - address: '192.0.22.0/24' + - address: '192.0.32.0/24' + range: + - address: '1.1.2.0/24' + cost: 10 + auto_cost: + reference_bandwidth: 2 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + mpls_te: + enabled: true + router_address: '192.0.22.22' + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + parameters: + abr_type: 'cisco' + opaque_lsa: true + rfc1583_compatibility: true + router_id: '192.0.1.1' + passive_interface: + - 'eth1' + redistribute: + - metric: 10 + metric_type: 2 + route_type: 'bgp' +rendered: + commands: + - set protocols ospf mpls-te enable + - set protocols ospf mpls-te router-address '192.0.11.11' + - set protocols ospf redistribute bgp + - set protocols ospf redistribute bgp metric-type 2 + - set protocols ospf redistribute bgp metric 10 + - set protocols ospf default-information originate metric-type 2 + - set protocols ospf default-information originate always + - set protocols ospf default-information originate metric 10 + - set protocols ospf default-information originate route-map ingress + - set protocols ospf auto-cost reference-bandwidth '2' + - set protocols ospf parameters router-id '192.0.1.1' + - set protocols ospf parameters opaque-lsa + - set protocols ospf parameters abr-type 'cisco' + - set protocols ospf parameters rfc1583-compatibility + - set protocols ospf passive-interface eth1 + - set protocols ospf passive-interface eth2 + - set protocols ospf max-metric router-lsa on-shutdown 10 + - set protocols ospf max-metric router-lsa administrative + - set protocols ospf max-metric router-lsa on-startup 10 + - set protocols ospf log-adjacency-changes 'detail' + - set protocols ospf neighbor 192.0.11.12 priority 2 + - set protocols ospf neighbor 192.0.11.12 poll-interval 10 + - set protocols ospf neighbor 192.0.11.12 + - set protocols ospf area '2' + - set protocols ospf area 2 authentication plaintext-password + - set protocols ospf area 2 shortcut enable + - set protocols ospf area 2 area-type normal + - set protocols ospf area '3' + - set protocols ospf area 3 area-type nssa + - set protocols ospf area 4 range 192.0.3.0/24 cost 10 + - set protocols ospf area 4 range 192.0.3.0/24 + - set protocols ospf area 4 range 192.0.4.0/24 cost 12 + - set protocols ospf area 4 range 192.0.4.0/24 + - set protocols ospf area 4 area-type stub default-cost 20 + - set protocols ospf area '4' + - set protocols ospf area 4 network 192.0.2.0/24 +deleted_single: + commands: + - delete protocols ospf mpls-te + - delete protocols ospf redistribute + - delete protocols ospf auto-cost + - delete protocols ospf passive-interface + - delete protocols ospf parameters + - delete protocols ospf default-information + - delete protocols ospf max-metric + - delete protocols ospf log-adjacency-changes + - delete protocols ospf neighbor + - delete protocols ospf area 2 + - delete protocols ospf area 3 + - delete protocols ospf area 4 + - delete protocols ospf area + after: [] +deleted: + commands: + - 'delete protocols ospf' + after: [] +round_trip: + after: + areas: + - area_id: '2' + area_type: + normal: true + authentication: "plaintext-password" + shortcut: 'enable' + - area_id: '4' + area_type: + stub: + default_cost: 20 + set: true + network: + - address: '192.0.12.0/24' + - address: '192.0.2.0/24' + - address: '192.0.22.0/24' + - address: '192.0.32.0/24' + range: + - address: '1.1.2.0/24' + cost: 10 + auto_cost: + reference_bandwidth: 2 + default_information: + originate: + always: true + metric: 10 + metric_type: 2 + route_map: 'ingress' + log_adjacency_changes: 'detail' + max_metric: + router_lsa: + administrative: true + on_shutdown: 10 + on_startup: 10 + mpls_te: + enabled: true + router_address: '192.0.22.22' + neighbor: + - neighbor_id: '192.0.11.12' + poll_interval: 10 + priority: 2 + parameters: + abr_type: 'cisco' + opaque_lsa: true + rfc1583_compatibility: true + router_id: '192.0.1.1' + passive_interface: + - 'eth1' + redistribute: + - metric: 10 + metric_type: 2 + route_type: 'bgp' diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_ospfv2_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_ospfv2_config.cfg new file mode 100644 index 0000000..297671b --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_ospfv2_config.cfg @@ -0,0 +1,9 @@ +set protocols ospf area 12 area-type normal +set protocols ospf area 12 authentication plaintext-password +set protocols ospf area 12 shortcut enable +set protocols ospf area 14 range 192.0.13.0/24 cost 10 +set protocols ospf area 14 range 192.0.13.0/24 +set protocols ospf area 14 range 192.0.14.0/24 cost 12 +set protocols ospf area 14 range 192.0.14.0/24 +set protocols ospf area 14 area-type stub default-cost 20 +set protocols ospf area 14 network 192.0.12.0/24 diff --git a/tests/unit/modules/network/vyos/test_vyos_ospfv2.py b/tests/unit/modules/network/vyos/test_vyos_ospfv2.py new file mode 100644 index 0000000..8e6b095 --- /dev/null +++ b/tests/unit/modules/network/vyos/test_vyos_ospfv2.py @@ -0,0 +1,526 @@ +# (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_ospfv2 +from ansible_collections.vyos.vyos.tests.unit.modules.utils import ( + set_module_args, +) +from .vyos_module import TestVyosModule, load_fixture + + +class TestVyosFirewallRulesModule(TestVyosModule): + + module = vyos_ospfv2 + + def setUp(self): + super(TestVyosFirewallRulesModule, self).setUp() + self.mock_get_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config" + ) + self.get_config = self.mock_get_config.start() + + self.mock_load_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config" + ) + self.load_config = self.mock_load_config.start() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection" + ) + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection" + ) + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.ospfv2.ospfv2.Ospfv2Facts.get_device_data" + ) + + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestVyosFirewallRulesModule, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_get_config.stop() + self.mock_load_config.stop() + self.mock_execute_show_command.stop() + + def load_fixtures(self, commands=None, transport="cli", filename=None): + if filename is None: + filename = "vyos_ospfv2_config.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + + def test_vyos_ospfv2_merged_new_config(self): + set_module_args( + dict( + config=dict( + log_adjacency_changes="detail", + mpls_te=dict(enabled=True, router_address='192.0.11.11'), + auto_cost=dict(reference_bandwidth=2), + areas=[ + dict( + area_id="2", + area_type=dict(normal=True), + authentication="plaintext-password", + shortcut='enable', + ), + dict( + area_id="4", + area_type=dict( + stub=dict(default_cost=10) + ), + network=[ + dict(address="192.0.2.0/24"), + ], + range=[ + dict(address="192.0.3.0/24", cost=10), + dict(address="192.0.4.0/24", cost=12) + ] + ), + ], + ), + state="merged", + ) + ) + commands = [ + "set protocols ospf mpls-te enable", + "set protocols ospf mpls-te router-address '192.0.11.11'", + "set protocols ospf auto-cost reference-bandwidth '2'", + "set protocols ospf log-adjacency-changes 'detail'", + "set protocols ospf area '2'", + "set protocols ospf area 2 authentication plaintext-password", + "set protocols ospf area 2 shortcut enable", + "set protocols ospf area 2 area-type normal", + "set protocols ospf area 4 range 192.0.3.0/24 cost 10", + "set protocols ospf area 4 range 192.0.3.0/24", + "set protocols ospf area 4 range 192.0.4.0/24 cost 12", + "set protocols ospf area 4 range 192.0.4.0/24", + "set protocols ospf area 4 area-type stub default-cost 10", + "set protocols ospf area '4'", + "set protocols ospf area 4 network 192.0.2.0/24" + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospfv2_merged_idem(self): + set_module_args( + dict( + config=dict( + areas=[ + dict( + area_id="12", + area_type=dict(normal=True), + authentication="plaintext-password", + shortcut='enable', + ), + dict( + area_id="14", + area_type=dict( + stub=dict(default_cost=20) + ), + network=[ + dict(address="192.0.12.0/24"), + ], + range=[ + dict(address="192.0.13.0/24", cost=10), + dict(address="192.0.14.0/24", cost=12) + ] + ), + ], + ), + state="merged", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_ospfv2_merged_update_existing(self): + set_module_args( + dict( + config=dict( + areas=[ + dict( + area_id="12", + area_type=dict(normal=True), + authentication="plaintext-password", + shortcut='enable', + ), + dict( + area_id="14", + area_type=dict( + stub=dict(set=False) + ), + network=[ + dict(address="192.0.12.0/24"), + dict(address="192.0.22.0/24"), + ], + range=[ + dict(address="192.0.13.0/24", cost=10), + dict(address="192.0.14.0/24", cost=12) + ] + ), + ], + ), + state="merged", + ) + ) + commands = [ + "delete protocols ospf area 14 area-type stub", + "set protocols ospf area 14 network 192.0.22.0/24" + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospfv2_replaced(self): + set_module_args( + dict( + config=dict( + log_adjacency_changes="detail", + mpls_te=dict(enabled=True, router_address='192.0.11.11'), + auto_cost=dict(reference_bandwidth=2), + areas=[ + dict( + area_id="12", + area_type=dict(normal=True), + authentication="plaintext-password", + shortcut='enable', + ), + dict( + area_id="15", + area_type=dict( + stub=dict(default_cost=10) + ), + network=[ + dict(address="192.0.12.0/24"), + ], + range=[ + dict(address="192.0.13.0/24", cost=10), + dict(address="192.0.14.0/24", cost=12), + dict(address="192.0.15.0/24", cost=14) + ] + ), + ], + ), + state="replaced", + ) + ) + commands = [ + "set protocols ospf mpls-te enable", + "set protocols ospf mpls-te router-address '192.0.11.11'", + "set protocols ospf auto-cost reference-bandwidth '2'", + "set protocols ospf log-adjacency-changes 'detail'", + "delete protocols ospf area 14", + "set protocols ospf area 15 range 192.0.13.0/24 cost 10", + "set protocols ospf area 15 range 192.0.13.0/24", + "set protocols ospf area 15 range 192.0.14.0/24 cost 12", + "set protocols ospf area 15 range 192.0.14.0/24", + "set protocols ospf area 15 range 192.0.15.0/24 cost 14", + "set protocols ospf area 15 range 192.0.15.0/24", + "set protocols ospf area 15 area-type stub default-cost 10", + "set protocols ospf area '15'", + "set protocols ospf area 15 network 192.0.12.0/24" + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospfv2_replaced_idem(self): + set_module_args( + dict( + config=dict( + areas=[ + dict( + area_id="12", + area_type=dict(normal=True), + authentication="plaintext-password", + shortcut='enable', + ), + dict( + area_id="14", + area_type=dict( + stub=dict(default_cost=20) + ), + network=[ + dict(address="192.0.12.0/24"), + ], + range=[ + dict(address="192.0.13.0/24", cost=10), + dict(address="192.0.14.0/24", cost=12) + ] + ), + ], + ), + state="replaced", + ) + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_ospfv2_deleted_no_config(self): + set_module_args(dict(config=None, state="deleted")) + commands = ["delete protocols ospf"] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospfv2_set_01_deleted_single_attributes(self): + set_module_args( + dict( + config=dict( + mpls_te=dict(), + auto_cost=dict(), + areas=[] + ), + state="deleted", + ) + ) + commands = ["delete protocols ospf area 12", + "delete protocols ospf area 14", + "delete protocols ospf area"] + self.execute_module(changed=True, commands=commands) + + def test_vyos_ospfv2_gathered(self): + set_module_args(dict(state="gathered")) + result = self.execute_module( + changed=False, filename="vyos_ospfv2_config.cfg" + ) + gather_dict = { + "areas": [ + { + "area_id": "2", + "area_type": { + "normal": True + }, + "authentication": "plaintext-password", + "shortcut": "enable" + }, + { + "area_id": "14", + "area_type": { + "stub": { + "default_cost": 20, + "set": True + } + }, + "network": [ + { + "address": "192.0.12.0/24" + } + ], + "range": [ + { + "address": "192.0.13.0/24", + "cost": 10 + }, + { + "address": "192.0.14.0/24", + "cost": 12 + } + ] + } + ], + } + self.assertEqual(sorted(gather_dict), sorted(result["gathered"])) + + def test_vyos_ospfv2_parsed(self): + parsed_str = """set protocols ospf area 2 area-type 'normal' + set protocols ospf area 2 authentication 'plaintext-password' + set protocols ospf area 2 shortcut 'enable' + set protocols ospf area 3 area-type 'nssa' + set protocols ospf area 4 area-type stub default-cost '20' + set protocols ospf area 4 network '192.0.2.0/24' + set protocols ospf area 4 range 192.0.3.0/24 cost '10' + set protocols ospf area 4 range 192.0.4.0/24 cost '12' + set protocols ospf default-information originate 'always' + set protocols ospf default-information originate metric '10' + set protocols ospf default-information originate metric-type '2' +set protocols ospf auto-cost reference-bandwidth '2' +set protocols ospf default-information originate route-map 'ingress' +set protocols ospf log-adjacency-changes 'detail' +set protocols ospf max-metric router-lsa 'administrative' +set protocols ospf max-metric router-lsa on-shutdown '10' +set protocols ospf max-metric router-lsa on-startup '10' +set protocols ospf mpls-te 'enable' +set protocols ospf mpls-te router-address '192.0.11.11' +set protocols ospf neighbor 192.0.11.12 poll-interval '10' +set protocols ospf neighbor 192.0.11.12 priority '2' +set protocols ospf parameters abr-type 'cisco' +set protocols ospf parameters 'opaque-lsa' +set protocols ospf parameters 'rfc1583-compatibility' +set protocols ospf parameters router-id '192.0.1.1' +set protocols ospf passive-interface 'eth1' +set protocols ospf passive-interface 'eth2' +set protocols ospf redistribute bgp metric '10' +set protocols ospf redistribute bgp metric-type '2'""" + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = { + "areas": [ + { + "area_id": "2", + "area_type": { + "normal": True + }, + "authentication": "plaintext-password", + "shortcut": "enable" + }, + { + "area_id": "3", + "area_type": { + "nssa": { + "set": True + } + } + }, + { + "area_id": "4", + "area_type": { + "stub": { + "default_cost": 20, + "set": True + } + }, + "network": [ + { + "address": "192.0.2.0/24" + } + ], + "range": [ + { + "address": "192.0.3.0/24", + "cost": 10 + }, + { + "address": "192.0.4.0/24", + "cost": 12 + } + ] + } + ], + "auto_cost": { + "reference_bandwidth": 2 + }, + "default_information": { + "originate": { + "always": True, + "metric": 10, + "metric_type": 2, + "route_map": "ingress" + } + }, + "log_adjacency_changes": "detail", + "max_metric": { + "router_lsa": { + "administrative": True, + "on_shutdown": 10, + "on_startup": 10 + } + }, + "mpls_te": { + "enabled": True, + "router_address": "192.0.11.11" + }, + "neighbor": [ + { + "neighbor_id": "192.0.11.12", + "poll_interval": 10, + "priority": 2 + } + ], + "parameters": { + "abr_type": "cisco", + "opaque_lsa": True, + "rfc1583_compatibility": True, + "router_id": "192.0.1.1" + }, + "passive_interface": [ + "eth2", + "eth1" + ], + "redistribute": [ + { + "metric": 10, + "metric_type": 2, + "route_type": "bgp" + } + ] + } + self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) + + def test_vyos_ospfv2_rendered(self): + set_module_args( + dict( + config=dict( + log_adjacency_changes="detail", + mpls_te=dict(enabled=True, router_address='192.0.11.11'), + auto_cost=dict(reference_bandwidth=2), + areas=[ + dict( + area_id="2", + area_type=dict(normal=True), + authentication="plaintext-password", + shortcut='enable', + ), + dict( + area_id="4", + area_type=dict( + stub=dict(default_cost=10) + ), + network=[ + dict(address="192.0.2.0/24"), + ], + range=[ + dict(address="192.0.3.0/24", cost=10), + dict(address="192.0.4.0/24", cost=12) + ] + ), + ], + ), + state="rendered", + ) + ) + commands = [ + "set protocols ospf mpls-te enable", + "set protocols ospf mpls-te router-address '192.0.11.11'", + "set protocols ospf auto-cost reference-bandwidth '2'", + "set protocols ospf log-adjacency-changes 'detail'", + "set protocols ospf area '2'", + "set protocols ospf area 2 authentication plaintext-password", + "set protocols ospf area 2 shortcut enable", + "set protocols ospf area 2 area-type normal", + "set protocols ospf area 4 range 192.0.3.0/24 cost 10", + "set protocols ospf area 4 range 192.0.3.0/24", + "set protocols ospf area 4 range 192.0.4.0/24 cost 12", + "set protocols ospf area 4 range 192.0.4.0/24", + "set protocols ospf area 4 area-type stub default-cost 10", + "set protocols ospf area '4'", + "set protocols ospf area 4 network 192.0.2.0/24" + ] + result = self.execute_module(changed=False) + self.assertEqual( + sorted(result["rendered"]), sorted(commands), result["rendered"] + ) diff --git a/tests/unit/modules/network/vyos/vyos_module.py b/tests/unit/modules/network/vyos/vyos_module.py index 49d4652..e0ab699 100644 --- a/tests/unit/modules/network/vyos/vyos_module.py +++ b/tests/unit/modules/network/vyos/vyos_module.py @@ -60,7 +60,7 @@ class TestVyosModule(ModuleTestCase): commands=None, sort=True, defaults=False, - filename=None, + filename=None ): self.load_fixtures(commands) |