diff options
Diffstat (limited to 'tests/integration/targets/vyos_l3_interfaces')
11 files changed, 375 insertions, 0 deletions
diff --git a/tests/integration/targets/vyos_l3_interfaces/defaults/main.yaml b/tests/integration/targets/vyos_l3_interfaces/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/tests/integration/targets/vyos_l3_interfaces/meta/main.yml b/tests/integration/targets/vyos_l3_interfaces/meta/main.yml new file mode 100644 index 0000000..e380a13 --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_vyos_tests
\ No newline at end of file diff --git a/tests/integration/targets/vyos_l3_interfaces/tasks/cli.yaml b/tests/integration/targets/vyos_l3_interfaces/tasks/cli.yaml new file mode 100644 index 0000000..337e341 --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tasks/cli.yaml @@ -0,0 +1,20 @@ +--- +- name: Collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + delegate_to: localhost + +- name: Run test case (connection=network_cli) + include: "{{ test_case_to_run }}" + vars: + ansible_connection: network_cli + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/tests/integration/targets/vyos_l3_interfaces/tasks/main.yaml b/tests/integration/targets/vyos_l3_interfaces/tasks/main.yaml new file mode 100644 index 0000000..415c99d --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml new file mode 100644 index 0000000..fc0bbb2 --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml @@ -0,0 +1,11 @@ +--- +- name: Setup + network.cli.cli_config: + config: "{{ lines }}" + vars: + lines: | + set interfaces ethernet eth1 address '192.0.2.14/24' + set interfaces ethernet eth2 address '192.0.2.10/24' + set interfaces ethernet eth2 address '192.0.2.11/24' + set interfaces ethernet eth2 address '2001:db8::10/32' + set interfaces ethernet eth2 address '2001:db8::12/32'
\ No newline at end of file diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 0000000..95b2b8c --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,13 @@ +--- +- name: Remove Config + network.cli.cli_config: + config: "{{ lines }}" + vars: + lines: | + delete interfaces ethernet "{{ intf }}" address + delete interfaces ethernet "{{ intf }}" vif + loop: + - eth1 + - eth2 + loop_control: + loop_var: intf diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml new file mode 100644 index 0000000..a40901c --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,48 @@ +--- +- debug: + msg: "Start vyos_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- block: + - include_tasks: _populate.yaml + + - name: Delete attributes of given interfaces + vyos.vyos.vyos_l3_interfaces: &deleted + config: + - name: eth1 + - name: eth2 + state: deleted + register: result + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" + + - name: Assert that the correct set of commands were generated + assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + + - name: Assert that the after dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) |length == 0 }}" + + - name: Delete attributes of given interfaces (IDEMPOTENT) + vyos.vyos.vyos_l3_interfaces: *deleted + register: result + + - name: Assert that the previous task was idempotent + assert: + that: + - "result.changed == false" + + - name: Assert that the before dicts were correctly generated + assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['before']) |length == 0 }}" + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/merged.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/merged.yaml new file mode 100644 index 0000000..64724ef --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/merged.yaml @@ -0,0 +1,58 @@ +--- +- debug: + msg: "START vyos_l3_interfaces merged integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- block: + - name: Merge the provided configuration with the exisiting running configuration + vyos.vyos.vyos_l3_interfaces: &merged + config: + - name: eth1 + ipv4: + - address: 192.0.2.10/24 + ipv6: + - address: 2001:db8::10/32 + + - name: eth2 + ipv4: + - address: 198.51.100.10/24 + vifs: + - vlan_id: 101 + ipv4: + - address: 198.51.100.130/25 + ipv6: + - address: 2001:db8::20/32 + state: merged + register: result + + - name: Assert that before dicts were correctly generated + assert: + that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + + - name: Assert that after dicts was correctly generated + assert: + that: + - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" + + - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) + vyos.vyos.vyos_l3_interfaces: *merged + register: result + + - 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'] | symmetric_difference(result['before']) |length == 0 }}" + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml new file mode 100644 index 0000000..6a9b013 --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,52 @@ +--- +- debug: + msg: "START vyos_l3_interfaces merged integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- block: + - include_tasks: _populate.yaml + + - name: Overrides all device configuration with provided configuration + vyos.vyos.vyos_l3_interfaces: &overridden + config: + - name: eth0 + ipv4: + - address: dhcp + - name: eth1 + ipv4: + - address: "192.0.2.15/24" + state: overridden + register: result + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" + + - name: Assert that correct commands were generated + assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + + - name: Assert that after dicts were correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" + + - name: Overrides all device configuration with provided configurations (IDEMPOTENT) + vyos.vyos.vyos_l3_interfaces: *overridden + register: result + + - name: Assert that the previous task was idempotent + assert: + that: + - "result['changed'] == false" + + - name: Assert that before dicts were correctly generated + assert: + that: + - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml new file mode 100644 index 0000000..4d44983 --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,52 @@ +--- +- debug: + msg: "START vyos_l3_interfaces replaced integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- block: + - include_tasks: _populate.yaml + + - name: Replace device configurations of listed interfaces with provided configurations + vyos.vyos.vyos_l3_interfaces: &replaced + config: + - name: eth1 + ipv4: + - address: 192.0.2.19/24 + - name: eth2 + ipv6: + - address: 2001:db8::11/32 + state: replaced + register: result + + - name: Assert that correct set of commands were generated + assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + + - name: Assert that before dicts are correctly generated + assert: + that: + - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" + + - name: Assert that after dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" + + - name: Replace device configurations of listed interfaces with provided configurarions (IDEMPOTENT) + vyos.vyos.vyos_l3_interfaces: *replaced + register: result + + - name: Assert that task was idempotent + assert: + that: + - "result['changed'] == false" + + - name: Assert that before dict is correctly generated + assert: + that: + - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" + + always: + - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_l3_interfaces/vars/main.yaml b/tests/integration/targets/vyos_l3_interfaces/vars/main.yaml new file mode 100644 index 0000000..f908d2c --- /dev/null +++ b/tests/integration/targets/vyos_l3_interfaces/vars/main.yaml @@ -0,0 +1,114 @@ +--- +merged: + before: + - name: "eth0" + ipv4: + - address: "dhcp" + + - name: "eth1" + + - name: "eth2" + + commands: + - "set interfaces ethernet eth1 address '192.0.2.10/24'" + - "set interfaces ethernet eth1 address '2001:db8::10/32'" + - "set interfaces ethernet eth2 address '198.51.100.10/24'" + - "set interfaces ethernet eth2 vif 101 address '198.51.100.130/25'" + - "set interfaces ethernet eth2 vif 101 address '2001:db8::20/32'" + + after: + - name: "eth0" + ipv4: + - address: "dhcp" + + - name: "eth1" + ipv4: + - address: "192.0.2.10/24" + ipv6: + - address: "2001:db8::10/32" + + - name: "eth2" + ipv4: + - address: "198.51.100.10/24" + vifs: + - vlan_id: 101 + ipv4: + - address: "198.51.100.130/25" + ipv6: + - address: "2001:db8::20/32" + +populate: + - name: "eth1" + ipv4: + - address: "192.0.2.14/24" + + - name: "eth2" + ipv4: + - address: "192.0.2.10/24" + - address: "192.0.2.11/24" + ipv6: + - address: "2001:db8::10/32" + - address: "2001:db8::12/32" + + - name: "eth0" + ipv4: + - address: "dhcp" + +replaced: + commands: + - "delete interfaces ethernet eth2 address '192.0.2.10/24'" + - "delete interfaces ethernet eth2 address '192.0.2.11/24'" + - "delete interfaces ethernet eth2 address '2001:db8::10/32'" + - "delete interfaces ethernet eth2 address '2001:db8::12/32'" + - "set interfaces ethernet eth2 address '2001:db8::11/32'" + - "delete interfaces ethernet eth1 address '192.0.2.14/24'" + - "set interfaces ethernet eth1 address '192.0.2.19/24'" + + after: + - name: "eth2" + ipv6: + - address: "2001:db8::11/32" + + - name: "eth1" + ipv4: + - address: "192.0.2.19/24" + + - name: "eth0" + ipv4: + - address: "dhcp" + +overridden: + commands: + - delete interfaces ethernet eth1 address '192.0.2.14/24' + - set interfaces ethernet eth1 address '192.0.2.15/24' + - delete interfaces ethernet eth2 address '192.0.2.10/24' + - delete interfaces ethernet eth2 address '192.0.2.11/24' + - delete interfaces ethernet eth2 address '2001:db8::10/32' + - delete interfaces ethernet eth2 address '2001:db8::12/32' + + after: + - name: "eth0" + ipv4: + - address: "dhcp" + + - name: "eth1" + ipv4: + - address: "192.0.2.15/24" + + - name: "eth2" + +deleted: + commands: + - delete interfaces ethernet eth1 address '192.0.2.14/24' + - delete interfaces ethernet eth2 address '192.0.2.10/24' + - delete interfaces ethernet eth2 address '192.0.2.11/24' + - delete interfaces ethernet eth2 address '2001:db8::10/32' + - delete interfaces ethernet eth2 address '2001:db8::12/32' + after: + - name: "eth0" + ipv4: + - address: "dhcp" + + - name: "eth1" + + - name: "eth2" |