diff options
author | Rohit Thakur <rohitthakur2590@outlook.com> | 2020-04-29 16:45:39 +0530 |
---|---|---|
committer | Rohit Thakur <rohitthakur2590@outlook.com> | 2020-04-29 16:45:39 +0530 |
commit | 7344ffc5dc646bbb362c5cd157a1828c3d1537ec (patch) | |
tree | 33b5cd79bb26f04bbc3f628ef3dec4abe056f73e /tests/integration/targets | |
parent | 77e8b041b2983415ac36eb6264f6e385ac87b074 (diff) | |
download | vyos-ansible-old-7344ffc5dc646bbb362c5cd157a1828c3d1537ec.tar.gz vyos-ansible-old-7344ffc5dc646bbb362c5cd157a1828c3d1537ec.zip |
new states added
Signed-off-by: Rohit Thakur <rohitthakur2590@outlook.com>
Diffstat (limited to 'tests/integration/targets')
6 files changed, 189 insertions, 2 deletions
diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_interfaces/tests/cli/_parsed_config.cfg new file mode 100644 index 0000000..f3f24c5 --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/cli/_parsed_config.cfg @@ -0,0 +1,15 @@ +set interfaces ethernet eth0 address 'dhcp' +set interfaces ethernet eth0 duplex 'auto' +set interfaces ethernet eth0 hw-id '08:00:27:50:5e:19' +set interfaces ethernet eth0 smp_affinity 'auto' +set interfaces ethernet eth0 speed 'auto' +set interfaces ethernet eth1 description 'Configured by Ansible' +set interfaces ethernet eth1 duplex 'auto' +set interfaces ethernet eth1 mtu '1500' +set interfaces ethernet eth1 speed 'auto' +set interfaces ethernet eth1 vif 200 description 'VIF - 200' +set interfaces ethernet eth2 description 'Configured by Ansible' +set interfaces ethernet eth2 duplex 'auto' +set interfaces ethernet eth2 mtu '1500' +set interfaces ethernet eth2 speed 'auto' +set interfaces ethernet eth2 vif 200 description 'VIF - 200'
\ No newline at end of file diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml index e1e154d..652f158 100644 --- a/tests/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml @@ -1,7 +1,7 @@ --- - debug: - msg: START vyos_interfaces empty_config integration tests on connection={{ ansible_connection - }} + msg: START vyos_interfaces empty_config integration tests on connection={{ + ansible_connection }} - name: Merged with empty config should give appropriate error message register: result @@ -35,3 +35,26 @@ - 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_interfaces: + running_config: + state: parsed + +- assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state + parsed' + +- name: Rendered with empty config should give appropriate error message + register: result + ignore_errors: true + vyos.vyos.vyos_interfaces: + config: + state: rendered + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/gathered.yaml new file mode 100644 index 0000000..be63030 --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,34 @@ +--- +- debug: + msg: START vyos_interfaces 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_interfaces: &id001 + config: + state: gathered + + - name: Assert that gathered dicts was correctly generated + assert: + that: + - "{{ populate | symmetric_difference(result['gathered']) |length == 0\ + \ }}" + + - name: Gather the existing running configuration (IDEMPOTENT) + register: result + vyos.vyos.vyos_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml
\ No newline at end of file diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml new file mode 100644 index 0000000..32af476 --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,42 @@ +--- +- debug: + msg: START vyos_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Gather interfaces facts + register: interfaces_facts + vyos.vyos.vyos_facts: + gather_subset: + - default + gather_network_resources: + - interfaces + + - name: Provide the running configuration for parsing (config to be parsed) + register: result + vyos.vyos.vyos_interfaces: &id001 + running_config: "{{ lookup('file', '_parsed_config.cfg') }}" + state: parsed + - debug: + msg: "{{ ansible_facts['network_resources']['interfaces'] }}" + - name: Assert that correct parsing done + assert: + that: "{{ ansible_facts['network_resources']['interfaces'] | symmetric_difference(result['parsed'])\ + \ |length == 0 }}" + + - name: Gather the existing running configuration (IDEMPOTENT) + register: result + vyos.vyos.vyos_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml
\ No newline at end of file diff --git a/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml new file mode 100644 index 0000000..1d2e108 --- /dev/null +++ b/tests/integration/targets/vyos_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,56 @@ +--- +- debug: + msg: START vyos_interfaces 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_interfaces: &id001 + config: + - 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 + 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_interfaces: *id001 + + - name: Assert that the previous task was idempotent + assert: + that: + - result['changed'] == false + always: + + - include_tasks: _remove_config.yaml
\ No newline at end of file diff --git a/tests/integration/targets/vyos_interfaces/vars/main.yaml b/tests/integration/targets/vyos_interfaces/vars/main.yaml index b730080..4c8307e 100644 --- a/tests/integration/targets/vyos_interfaces/vars/main.yaml +++ b/tests/integration/targets/vyos_interfaces/vars/main.yaml @@ -133,6 +133,23 @@ overridden: vifs: - vlan_id: 200 enabled: true +rendered: + commands: + - set interfaces ethernet eth0 duplex 'auto' + - set interfaces ethernet eth0 speed 'auto' + - delete interfaces ethernet eth0 disable + - set interfaces ethernet eth1 duplex 'auto' + - delete interfaces ethernet eth1 disable + - set interfaces ethernet eth1 speed 'auto' + - set interfaces ethernet eth1 description 'Configured by Ansible - Interface 1' + - set interfaces ethernet eth1 mtu '1500' + - 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 disable + - set interfaces ethernet eth2 description 'Configured by Ansible - Interface 2 (ADMIN DOWN)' + - set interfaces ethernet eth2 mtu '600' + deleted: commands: - delete interfaces ethernet eth1 description |