diff options
Diffstat (limited to 'tests/integration/targets')
16 files changed, 610 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_route_maps/defaults/main.yaml b/tests/integration/targets/vyos_route_maps/defaults/main.yaml new file mode 100644 index 0000000..852a6be --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: '[^_].*' +test_items: [] diff --git a/tests/integration/targets/vyos_route_maps/tasks/cli.yaml b/tests/integration/targets/vyos_route_maps/tasks/cli.yaml new file mode 100644 index 0000000..93eb2fe --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/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_route_maps/tasks/main.yaml b/tests/integration/targets/vyos_route_maps/tasks/main.yaml new file mode 100644 index 0000000..b957d2f --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tasks/main.yaml @@ -0,0 +1,4 @@ +--- +- include: cli.yaml + tags: + - network_cli diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg new file mode 100644 index 0000000..a4aa4d3 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_parsed.cfg @@ -0,0 +1,13 @@ +set policy route-map test1 rule 1 description test +set policy route-map test1 rule 1 action permit +set policy route-map test1 rule 1 continue 2 +set policy route-map test3 rule 1 action permit +set policy route-map test3 rule 1 set local-preference 4 +set policy route-map test3 rule 1 set metric 5 +set policy route-map test3 rule 1 set metric-type type-1 +set policy route-map test3 rule 1 set origin egp +set policy route-map test3 rule 1 set originator-id 192.0.2.34 +set policy route-map test3 rule 1 set tag 5 +set policy route-map test3 rule 1 set weight 4 +set policy route-map test3 rule 1 match metric 1 +set policy route-map test3 rule 1 match peer 192.0.2.32
\ No newline at end of file diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml new file mode 100644 index 0000000..9ef975f --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_populate.yaml @@ -0,0 +1,23 @@ +--- +- name: setup + vyos.vyos.vyos_config: + lines: + - set policy route-map test2 rule 1 action 'permit' + - set policy route-map test2 rule 1 description 'test' + - set policy route-map test2 rule 2 action 'permit' + - set policy route-map test2 rule 2 on-match goto '4' + - set policy route-map test3 rule 1 action 'permit' + - set policy route-map test3 rule 1 match metric '1' + - set policy route-map test3 rule 1 match peer '192.0.2.32' + - set policy route-map test3 rule 1 set community 'internet' + - set policy route-map test3 rule 1 set ip-next-hop '192.0.2.33' + - set policy route-map test3 rule 1 set local-preference '4' + - set policy route-map test3 rule 1 set metric '5' + - set policy route-map test3 rule 1 set metric-type 'type-1' + - set policy route-map test3 rule 1 set origin 'egp' + - set policy route-map test3 rule 1 set originator-id '192.0.2.34' + - set policy route-map test3 rule 1 set tag '5' + - set policy route-map test3 rule 1 set weight '4' + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml new file mode 100644 index 0000000..70e9889 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/_remove_config.yaml @@ -0,0 +1,10 @@ +--- +- name: Remove pre-existing route-maps + vyos.vyos.vyos_config: + lines: + - delete policy route-map test1 + - delete policy route-map test2 + - delete policy route-map test3 + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml new file mode 100644 index 0000000..efcb88b --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/deleted.yaml @@ -0,0 +1,36 @@ +--- +- debug: + msg: START vyos_route_maps 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_route_maps: &id001 + config: + state: deleted + + - assert: + that: + - result.commands|length == 2 + - result.changed == true + - result.commands|symmetric_difference(deleted.commands) == [] + + - 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_route_maps/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/empty_config.yaml new file mode 100644 index 0000000..6d992b8 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/empty_config.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START vyos_route_maps 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_route_maps: + 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_route_maps: + 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_route_maps: + 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_route_maps: + 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_route_maps: + 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_route_maps/tests/cli/gathered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml new file mode 100644 index 0000000..b73fe23 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/gathered.yaml @@ -0,0 +1,24 @@ +--- +- debug: + msg: START vyos_route_maps 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_route_maps: + state: gathered + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - result.changed == false + - result.gathered|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml new file mode 100644 index 0000000..2b86969 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/merged.yaml @@ -0,0 +1,60 @@ +--- +- debug: + msg: START vyos_route_maps 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_route_maps: &id001 + config: + - route_map: test1 + entries: + - sequence: 1 + description: "test" + action: permit + continue_sequence: 2 + - route_map: test3 + entries: + - sequence: 1 + action: permit + match: + metric: 1 + peer: 192.0.2.32 + set: + local_preference: 4 + metric: 5 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 5 + weight: 4 + state: merged + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - result.commands|length == 13 + - result.changed == true + - result.commands|symmetric_difference(merged.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] + + - name: Merge the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_route_maps: *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_route_maps/tests/cli/overridden.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml new file mode 100644 index 0000000..f014cf1 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/overridden.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: START vyos_route_maps 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_route_maps: &id001 + config: + - route_map: test3 + entries: + - sequence: 1 + action: permit + match: + metric: 3 + peer: 192.0.2.35 + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + state: overridden + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - result.commands|length == 8 + - result.changed == true + - result.commands|symmetric_difference(overridden.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] + + - name: Override the existing configuration with the provided running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_route_maps: *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_route_maps/tests/cli/parsed.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml new file mode 100644 index 0000000..47cb4cc --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/parsed.yaml @@ -0,0 +1,16 @@ +--- +- debug: + msg: START vyos_route_maps 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_route_maps: + 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_route_maps/tests/cli/rendered.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml new file mode 100644 index 0000000..7d194d9 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/rendered.yaml @@ -0,0 +1,40 @@ +--- +- debug: + msg: START vyos_route_maps 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_route_maps: &id001 + config: + - route_map: test1 + entries: + - sequence: 1 + description: "test" + action: permit + continue_sequence: 2 + - route_map: test3 + entries: + - sequence: 1 + action: permit + match: + metric: 1 + peer: 192.0.2.32 + set: + local_preference: 4 + metric: 5 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 5 + weight: 4 + state: rendered + + - assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml new file mode 100644 index 0000000..1675ec5 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/replaced.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: START vyos_route_maps replaced integration tests on connection={{ + ansible_connection }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Replace the provided configuration with the exisiting running configuration + register: result + vyos.vyos.vyos_route_maps: &id001 + config: + - route_map: test3 + entries: + - sequence: 1 + action: permit + match: + metric: 3 + peer: 192.0.2.35 + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + state: replaced + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - result.commands|length == 7 + - result.changed == true + - result.commands|symmetric_difference(replaced.commands) == [] + - result.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] + + - name: Replace the provided configuration with the existing running configuration + (IDEMPOTENT) + register: result + vyos.vyos.vyos_route_maps: *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_route_maps/tests/cli/rtt.yaml b/tests/integration/targets/vyos_route_maps/tests/cli/rtt.yaml new file mode 100644 index 0000000..2a95f1f --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/tests/cli/rtt.yaml @@ -0,0 +1,81 @@ +--- +- debug: + msg: START vyos_route_maps merged 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_route_maps: + config: + - route_map: test1 + entries: + - sequence: 1 + description: "test" + action: permit + continue_sequence: 2 + - route_map: test3 + entries: + - sequence: 1 + action: permit + match: + metric: 1 + peer: 192.0.2.32 + set: + local_preference: 4 + metric: 5 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 5 + weight: 4 + state: merged + + - become: true + vyos.vyos.vyos_facts: + gather_network_resources: route_maps + + - assert: + that: + - baseconfig.commands|length == 13 + - baseconfig.changed == true + - baseconfig.commands|symmetric_difference(merged.commands) == [] + - baseconfig.after|symmetric_difference(ansible_facts['network_resources']['route_maps']) == [] + + - name: Merge the existing configuration with the provided running configuration + register: result + vyos.vyos.vyos_route_maps: + config: + - route_map: test2 + entries: + - sequence: 1 + action: permit + match: + metric: 3 + peer: 192.0.2.35 + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + + - name: Revert back to base config using facts round trip + become: true + register: revert + vyos.vyos.vyos_route_maps: + config: "{{ ansible_facts['network_resources']['route_maps'] }}" + 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_route_maps/vars/main.yaml b/tests/integration/targets/vyos_route_maps/vars/main.yaml new file mode 100644 index 0000000..5a0d027 --- /dev/null +++ b/tests/integration/targets/vyos_route_maps/vars/main.yaml @@ -0,0 +1,109 @@ +--- +merged: + commands: + - set policy route-map test1 rule 1 description test + - set policy route-map test1 rule 1 action permit + - set policy route-map test1 rule 1 continue 2 + - set policy route-map test3 rule 1 action permit + - set policy route-map test3 rule 1 set local-preference 4 + - set policy route-map test3 rule 1 set metric 5 + - set policy route-map test3 rule 1 set metric-type type-1 + - set policy route-map test3 rule 1 set origin egp + - set policy route-map test3 rule 1 set originator-id 192.0.2.34 + - set policy route-map test3 rule 1 set tag 5 + - set policy route-map test3 rule 1 set weight 4 + - set policy route-map test3 rule 1 match metric 1 + - set policy route-map test3 rule 1 match peer 192.0.2.32 + + after: + - route_map: "test3" + entries: + - sequence: 1 + action: "permit" + match: + metric: 1 + peer: "192.0.2.32" + set: + local_preference: "4" + metric: "5" + metric_type: "type-1" + origin: egp + originator_id: "192.0.2.34" + tag: "5" + weight: "4" + - route_map: "test1" + entries: + - sequence: 1 + description: "test" + action: "permit" + continue_sequence: 2 + +replaced: + commands: + - delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33 + - set policy route-map test3 rule 1 set local-preference 6 + - set policy route-map test3 rule 1 set metric 4 + - set policy route-map test3 rule 1 set tag 4 + - delete policy route-map test3 rule 1 set community internet + - set policy route-map test3 rule 1 match metric 3 + - set policy route-map test3 rule 1 match peer 192.0.2.35 + + after: + - route_map: test2 + entries: + - sequence: 1 + description: "test" + action: permit + - sequence: 1 + action: permit + on_match: + goto: 4 + - route_map: test3 + entries: + - sequence: 1 + action: permit + match: + metric: 3 + peer: 192.0.2.35 + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + +overridden: + commands: + - delete policy route-map test2 + - delete policy route-map test3 rule 1 set ip-next-hop 192.0.2.33 + - set policy route-map test3 rule 1 set local-preference 6 + - set policy route-map test3 rule 1 set metric 4 + - set policy route-map test3 rule 1 set tag 4 + - delete policy route-map test3 rule 1 set community internet + - set policy route-map test3 rule 1 match metric 3 + - set policy route-map test3 rule 1 match peer 192.0.2.35 + + after: + - route_map: test3 + entries: + - sequence: 1 + action: permit + match: + metric: 3 + peer: 192.0.2.35 + set: + local_preference: 6 + metric: 4 + metric_type: "type-1" + origin: egp + originator_id: 192.0.2.34 + tag: 4 + weight: 4 + +deleted: + commands: + - delete policy route-map test2 + - delete policy route-map test3 + after: [] |