diff options
Diffstat (limited to 'test/integration/targets')
23 files changed, 955 insertions, 0 deletions
diff --git a/test/integration/targets/vyos_interfaces/defaults/main.yaml b/test/integration/targets/vyos_interfaces/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/test/integration/targets/vyos_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/test/integration/targets/vyos_interfaces/meta/main.yaml b/test/integration/targets/vyos_interfaces/meta/main.yaml new file mode 100644 index 0000000..e380a13 --- /dev/null +++ b/test/integration/targets/vyos_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_vyos_tests
\ No newline at end of file diff --git a/test/integration/targets/vyos_interfaces/tasks/cli.yaml b/test/integration/targets/vyos_interfaces/tasks/cli.yaml new file mode 100644 index 0000000..655e51e --- /dev/null +++ b/test/integration/targets/vyos_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=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/test/integration/targets/vyos_interfaces/tasks/main.yaml b/test/integration/targets/vyos_interfaces/tasks/main.yaml new file mode 100644 index 0000000..415c99d --- /dev/null +++ b/test/integration/targets/vyos_interfaces/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/test/integration/targets/vyos_interfaces/tests/cli/_populate.yaml b/test/integration/targets/vyos_interfaces/tests/cli/_populate.yaml new file mode 100644 index 0000000..b798bae --- /dev/null +++ b/test/integration/targets/vyos_interfaces/tests/cli/_populate.yaml @@ -0,0 +1,17 @@ +--- +- name: Setup + cli_config: + config: "{{ lines }}" + vars: + lines: | + set interfaces ethernet "{{ intf }}" description 'Configured by Ansible' + set interfaces ethernet "{{ intf }}" speed 'auto' + set interfaces ethernet "{{ intf }}" duplex 'auto' + set interfaces ethernet "{{ intf }}" mtu '1500' + set interfaces ethernet "{{ intf }}" vif 200 + set interfaces ethernet "{{ intf }}" vif 200 description 'VIF - 200' + loop: + - eth1 + - eth2 + loop_control: + loop_var: intf
\ No newline at end of file diff --git a/test/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 0000000..6d559c1 --- /dev/null +++ b/test/integration/targets/vyos_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,17 @@ +--- +- name: Remove Config + cli_config: + config: "{{ lines }}" + vars: + lines: | + delete interfaces ethernet "{{ intf }}" description + delete interfaces ethernet "{{ intf }}" speed + delete interfaces ethernet "{{ intf }}" duplex + delete interfaces ethernet "{{ intf }}" mtu + delete interfaces ethernet "{{ intf }}" disable + delete interfaces ethernet "{{ intf }}" vif + loop: + - eth1 + - eth2 + loop_control: + loop_var: intf
\ No newline at end of file diff --git a/test/integration/targets/vyos_interfaces/tests/cli/deleted.yaml b/test/integration/targets/vyos_interfaces/tests/cli/deleted.yaml new file mode 100644 index 0000000..b48f916 --- /dev/null +++ b/test/integration/targets/vyos_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,46 @@ +--- +- debug: + msg: "Start vyos_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" + +- include_tasks: _populate.yaml + +- block: + - name: Delete attributes of given interfaces + vyos.vyos.vyos_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_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/test/integration/targets/vyos_interfaces/tests/cli/merged.yaml b/test/integration/targets/vyos_interfaces/tests/cli/merged.yaml new file mode 100644 index 0000000..89ed893 --- /dev/null +++ b/test/integration/targets/vyos_interfaces/tests/cli/merged.yaml @@ -0,0 +1,59 @@ +--- +- debug: + msg: "START vyos_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_interfaces: &merged + config: + - name: eth1 + description: "Configured by Ansible - Interface 1" + mtu: 1500 + speed: auto + duplex: auto + vifs: + - vlan_id: 100 + description: "Eth1 - VIF 100" + mtu: 400 + + - vlan_id: 101 + description: "Eth1 - VIF 101" + + - name: eth2 + description: "Configured by Ansible - Interface 2 (ADMIN DOWN)" + mtu: 600 + enabled: false + 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_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/test/integration/targets/vyos_interfaces/tests/cli/overridden.yaml b/test/integration/targets/vyos_interfaces/tests/cli/overridden.yaml new file mode 100644 index 0000000..c9eb1b7 --- /dev/null +++ b/test/integration/targets/vyos_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,52 @@ +--- +- debug: + msg: "START vyos_interfaces overridden integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + - name: Overrides all device configuration with provided configuration + vyos.vyos.vyos_interfaces: &overridden + config: + - name: eth0 + speed: "auto" + duplex: "auto" + - name: eth2 + description: "Overridden by Ansible" + mtu: 1200 + 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_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/test/integration/targets/vyos_interfaces/tests/cli/replaced.yaml b/test/integration/targets/vyos_interfaces/tests/cli/replaced.yaml new file mode 100644 index 0000000..1211f63 --- /dev/null +++ b/test/integration/targets/vyos_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,55 @@ +--- +- debug: + msg: "START vyos_interfaces replaced integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + - name: Replace device configurations of listed interfaces with provided configurations + vyos.vyos.vyos_interfaces: &replaced + config: + - name: eth1 + description: "Replaced by Ansible" + vifs: + - vlan_id: 100 + description: "VIF 100 - Replaced by Ansible" + + - name: eth2 + mtu: 1400 + description: "Replaced by Ansible" + 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_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
\ No newline at end of file diff --git a/test/integration/targets/vyos_interfaces/tests/cli/rtt.yaml b/test/integration/targets/vyos_interfaces/tests/cli/rtt.yaml new file mode 100644 index 0000000..3ec4d3d --- /dev/null +++ b/test/integration/targets/vyos_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,78 @@ +--- +- debug: + msg: "START vyos_interfaces round trip integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- block: + - name: Apply the provided configuration (base config) + vyos.vyos.vyos_interfaces: + config: + - name: eth0 + enabled: true + duplex: "auto" + speed: "auto" + + - name: eth1 + description: "Interface - 1" + mtu: 1500 + vifs: + - vlan_id: 100 + description: "Eth1 - VIF 100" + mtu: 200 + + - vlan_id: 101 + enabled: false + + - name: eth2 + description: "Interface - 2" + enabled: true + mtu: 900 + state: merged + register: base_config + + - name: Gather interfaces facts + vyos.vyos.vyos_facts: + gather_subset: + - default + gather_network_resources: + - interfaces + + - name: Apply the provided configuration (config to be reverted) + vyos.vyos.vyos_interfaces: + config: + - name: eth1 + description: "Interface 1 - Description (WILL BE REVERTED)" + mtu: 1200 + vifs: + - vlan_id: 100 + description: "Eth1 - VIF 100 (WILL BE REVERTED)" + mtu: 400 + + - vlan_id: 101 + description: "Eth1 - VIF 101 (WILL BE REMOVED)" + enabled: true + + - name: eth2 + description: "Interface 2 (ADMIN DOWN) (WILL BE REVERTED)" + mtu: 600 + enabled: false + state: merged + register: result + + - name: Assert that changes were applied + assert: + that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" + + - name: Revert back to base config using facts round trip + vyos.vyos.vyos_interfaces: + config: "{{ ansible_facts['network_resources']['interfaces'] }}" + state: replaced + register: revert + + - name: Assert that config was reverted + assert: + that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" + + always: + - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_interfaces/vars/main.yaml b/test/integration/targets/vyos_interfaces/vars/main.yaml new file mode 100644 index 0000000..e3bd818 --- /dev/null +++ b/test/integration/targets/vyos_interfaces/vars/main.yaml @@ -0,0 +1,230 @@ +--- +merged: + before: + - name: "eth0" + enabled: true + speed: "auto" + duplex: "auto" + + - name: "eth1" + enabled: true + + - name: "eth2" + enabled: true + + - name: "lo" + enabled: true + + commands: + - "set interfaces ethernet eth1 description 'Configured by Ansible - Interface 1'" + - "set interfaces ethernet eth1 mtu '1500'" + - "set interfaces ethernet eth1 duplex 'auto'" + - "set interfaces ethernet eth1 speed 'auto'" + - "set interfaces ethernet eth1 vif 100 description 'Eth1 - VIF 100'" + - "set interfaces ethernet eth1 vif 100 mtu '400'" + - "set interfaces ethernet eth1 vif 101 description 'Eth1 - VIF 101'" + - "set interfaces ethernet eth2 description 'Configured by Ansible - Interface 2 (ADMIN DOWN)'" + - "set interfaces ethernet eth2 mtu '600'" + - "set interfaces ethernet eth2 disable" + + after: + - name: "lo" + enabled: true + + - name: "eth0" + enabled: true + duplex: "auto" + speed: "auto" + + - name: "eth1" + description: "Configured by Ansible - Interface 1" + mtu: 1500 + speed: "auto" + duplex: "auto" + enabled: true + vifs: + - vlan_id: 100 + description: "Eth1 - VIF 100" + mtu: 400 + enabled: true + + - vlan_id: 101 + description: "Eth1 - VIF 101" + enabled: true + + - name: "eth2" + description: "Configured by Ansible - Interface 2 (ADMIN DOWN)" + mtu: 600 + enabled: false + +populate: + - name: "eth1" + enabled: true + speed: "auto" + duplex: "auto" + description: "Configured by Ansible" + mtu: 1500 + vifs: + - vlan_id: 200 + enabled: true + description: "VIF - 200" + + - name: "eth2" + enabled: true + speed: "auto" + duplex: "auto" + description: "Configured by Ansible" + mtu: 1500 + vifs: + - vlan_id: 200 + enabled: true + description: "VIF - 200" + + - name: "eth0" + enabled: true + duplex: "auto" + speed: "auto" + + - name: "lo" + enabled: true + +replaced: + commands: + - "delete interfaces ethernet eth1 mtu" + - "delete interfaces ethernet eth1 speed" + - "delete interfaces ethernet eth1 duplex" + - "delete interfaces ethernet eth1 vif 200 description" + - "set interfaces ethernet eth1 description 'Replaced by Ansible'" + - "set interfaces ethernet eth1 vif 100 description 'VIF 100 - Replaced by Ansible'" + - "delete interfaces ethernet eth2 speed" + - "delete interfaces ethernet eth2 duplex" + - "delete interfaces ethernet eth2 vif 200 description" + - "set interfaces ethernet eth2 description 'Replaced by Ansible'" + - "set interfaces ethernet eth2 mtu '1400'" + + after: + - name: "lo" + enabled: true + + - name: "eth1" + description: "Replaced by Ansible" + enabled: true + vifs: + - vlan_id: 100 + enabled: true + description: "VIF 100 - Replaced by Ansible" + + - vlan_id: 200 + enabled: true + + - name: "eth2" + mtu: 1400 + description: "Replaced by Ansible" + enabled: true + vifs: + - vlan_id: 200 + enabled: true + + - name: "eth0" + enabled: true + duplex: "auto" + speed: "auto" + +overridden: + commands: + - "delete interfaces ethernet eth1 description" + - "delete interfaces ethernet eth1 speed" + - "delete interfaces ethernet eth1 duplex" + - "delete interfaces ethernet eth1 mtu" + - "delete interfaces ethernet eth1 vif 200 description" + - "delete interfaces ethernet eth2 speed" + - "delete interfaces ethernet eth2 duplex" + - "delete interfaces ethernet eth2 vif 200 description" + - "set interfaces ethernet eth2 description 'Overridden by Ansible'" + - "set interfaces ethernet eth2 mtu '1200'" + + after: + - name: "lo" + enabled: true + + - name: "eth0" + enabled: true + speed: "auto" + duplex: "auto" + + - name: "eth1" + enabled: true + vifs: + - vlan_id: 200 + enabled: true + + - name: "eth2" + enabled: true + description: "Overridden by Ansible" + mtu: 1200 + vifs: + - vlan_id: 200 + enabled: true + +deleted: + commands: + - "delete interfaces ethernet eth1 description" + - "delete interfaces ethernet eth1 speed" + - "delete interfaces ethernet eth1 duplex" + - "delete interfaces ethernet eth1 mtu" + - "delete interfaces ethernet eth1 vif 200 description" + - "delete interfaces ethernet eth2 description" + - "delete interfaces ethernet eth2 speed" + - "delete interfaces ethernet eth2 duplex" + - "delete interfaces ethernet eth2 mtu" + - "delete interfaces ethernet eth2 vif 200 description" + + after: + - name: "lo" + enabled: true + + - name: "eth0" + enabled: true + speed: "auto" + duplex: "auto" + + - name: "eth1" + enabled: true + vifs: + - vlan_id: 200 + enabled: true + + - name: "eth2" + enabled: true + vifs: + - vlan_id: 200 + enabled: true + +round_trip: + after: + - name: "lo" + enabled: true + + - name: "eth0" + enabled: true + speed: "auto" + duplex: "auto" + + - name: "eth1" + description: "Interface 1 - Description (WILL BE REVERTED)" + enabled: true + mtu: 1200 + vifs: + - vlan_id: 100 + description: "Eth1 - VIF 100 (WILL BE REVERTED)" + mtu: 400 + enabled: true + + - vlan_id: 101 + description: "Eth1 - VIF 101 (WILL BE REMOVED)" + enabled: true + + - name: "eth2" + description: "Interface 2 (ADMIN DOWN) (WILL BE REVERTED)" + mtu: 600 + enabled: false diff --git a/test/integration/targets/vyos_l3_interfaces/defaults/main.yaml b/test/integration/targets/vyos_l3_interfaces/defaults/main.yaml new file mode 100644 index 0000000..164afea --- /dev/null +++ b/test/integration/targets/vyos_l3_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/test/integration/targets/vyos_l3_interfaces/meta/main.yml b/test/integration/targets/vyos_l3_interfaces/meta/main.yml new file mode 100644 index 0000000..e380a13 --- /dev/null +++ b/test/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/test/integration/targets/vyos_l3_interfaces/tasks/cli.yaml b/test/integration/targets/vyos_l3_interfaces/tasks/cli.yaml new file mode 100644 index 0000000..337e341 --- /dev/null +++ b/test/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/test/integration/targets/vyos_l3_interfaces/tasks/main.yaml b/test/integration/targets/vyos_l3_interfaces/tasks/main.yaml new file mode 100644 index 0000000..415c99d --- /dev/null +++ b/test/integration/targets/vyos_l3_interfaces/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/test/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml new file mode 100644 index 0000000..248a9bb --- /dev/null +++ b/test/integration/targets/vyos_l3_interfaces/tests/cli/_populate.yaml @@ -0,0 +1,11 @@ +--- +- name: Setup + 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/test/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 0000000..31af5ba --- /dev/null +++ b/test/integration/targets/vyos_l3_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,13 @@ +--- +- name: Remove Config + 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/test/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/deleted.yaml new file mode 100644 index 0000000..a40901c --- /dev/null +++ b/test/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/test/integration/targets/vyos_l3_interfaces/tests/cli/merged.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/merged.yaml new file mode 100644 index 0000000..64724ef --- /dev/null +++ b/test/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/test/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/overridden.yaml new file mode 100644 index 0000000..6a9b013 --- /dev/null +++ b/test/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/test/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/replaced.yaml new file mode 100644 index 0000000..4d44983 --- /dev/null +++ b/test/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/test/integration/targets/vyos_l3_interfaces/vars/main.yaml b/test/integration/targets/vyos_l3_interfaces/vars/main.yaml new file mode 100644 index 0000000..f908d2c --- /dev/null +++ b/test/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" |