From c7039afea05ea49cd010e98359d7989cc1bd574e Mon Sep 17 00:00:00 2001 From: Rohit Thakur Date: Thu, 30 Apr 2020 14:34:01 +0530 Subject: new states added Signed-off-by: Rohit Thakur --- .../tests/cli/_parsed_config.cfg | 6 +++ .../tests/cli/empty_config.yaml | 23 +++++++++++ .../vyos_lldp_interfaces/tests/cli/gathered.yaml | 34 +++++++++++++++ .../vyos_lldp_interfaces/tests/cli/parsed.yaml | 41 ++++++++++++++++++ .../vyos_lldp_interfaces/tests/cli/rendered.yaml | 48 ++++++++++++++++++++++ .../targets/vyos_lldp_interfaces/vars/main.yaml | 14 +++++-- 6 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg create mode 100644 tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml create mode 100644 tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml create mode 100644 tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml (limited to 'tests') diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg new file mode 100644 index 00000000..40c96c40 --- /dev/null +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg @@ -0,0 +1,6 @@ +set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' +set service lldp interface eth1 location civic-based country-code 'US' +set service lldp interface eth2 location coordinate-based altitude '2200' +set service lldp interface eth2 location coordinate-based datum 'WGS84' +set service lldp interface eth2 location coordinate-based latitude '33.524449N' +set service lldp interface eth2 location coordinate-based longitude '222.267255W' \ No newline at end of file diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml index a5ff0a8e..4ef40c9e 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/empty_config.yaml @@ -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_lldp_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_lldp_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_lldp_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml new file mode 100644 index 00000000..d440b534 --- /dev/null +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml @@ -0,0 +1,34 @@ +--- +- debug: + msg: START vyos_lldp_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_lldp_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_lldp_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_lldp_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml new file mode 100644 index 00000000..7842152f --- /dev/null +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml @@ -0,0 +1,41 @@ +--- +- debug: + msg: START vyos_lldp_interfaces parsed integration tests on connection={{ ansible_connection + }} + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: + + - name: Gather lldp_interfaces facts + register: lldp_interfaces_facts + vyos.vyos.vyos_facts: + gather_subset: + - default + gather_network_resources: + - lldp_interfaces + + - name: Provide the running configuration for parsing (config to be parsed) + register: result + vyos.vyos.vyos_lldp_interfaces: &id001 + running_config: "{{ lookup('file', '_parsed_config.cfg') }}" + state: parsed + + - name: Assert that correct parsing done + assert: + that: "{{ ansible_facts['network_resources']['lldp_interfaces'] | symmetric_difference(result['parsed'])\ + \ |length == 0 }}" + + - name: Gather the existing running configuration (IDEMPOTENT) + register: result + vyos.vyos.vyos_lldp_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_lldp_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml new file mode 100644 index 00000000..6bb9f5a0 --- /dev/null +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml @@ -0,0 +1,48 @@ +--- +- debug: + msg: START vyos_lldp_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_lldp_interfaces: &id001 + config: + - name: eth1 + location: + civic_based: + country_code: US + ca_info: + - ca_type: 0 + ca_value: ENGLISH + - name: eth2 + location: + coordinate_based: + altitude: 2200 + datum: WGS84 + longitude: 222.267255W + latitude: 33.524449N + 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_lldp_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_lldp_interfaces/vars/main.yaml b/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml index 3cb684ea..506bdf70 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml @@ -9,10 +9,6 @@ merged: - set service lldp interface eth2 location coordinate-based altitude '2200' - set service lldp interface eth2 location coordinate-based datum 'WGS84' - set service lldp interface eth2 location coordinate-based longitude '222.267255W' - - set service lldp interface eth2 location coordinate-based latitude '33.524449N' - - set service lldp interface eth2 location coordinate-based altitude '2200' - - set service lldp interface eth2 location coordinate-based datum 'WGS84' - - set service lldp interface eth2 location coordinate-based longitude '222.267255W' - set service lldp interface eth2 after: - name: eth1 @@ -44,6 +40,16 @@ populate: datum: WGS84 longitude: 222.267255W latitude: 33.524449N +rendered: + commands: + - set service lldp interface eth1 location civic-based country-code 'US' + - set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH' + - set service lldp interface eth1 + - set service lldp interface eth2 location coordinate-based latitude '33.524449N' + - set service lldp interface eth2 location coordinate-based altitude '2200' + - set service lldp interface eth2 location coordinate-based datum 'WGS84' + - set service lldp interface eth2 location coordinate-based longitude '222.267255W' + - set service lldp interface eth2 replaced: commands: - delete service lldp interface eth2 location -- cgit v1.2.3 From df5f503a3603164cc4ba74723aa39e7f33be6605 Mon Sep 17 00:00:00 2001 From: Rohit Thakur Date: Wed, 6 May 2020 17:32:09 +0530 Subject: common comments incorporated Signed-off-by: Rohit Thakur --- plugins/modules/vyos_lldp_interfaces.py | 8 ++------ .../targets/vyos_lldp_interfaces/tests/cli/gathered.yaml | 11 +---------- .../targets/vyos_lldp_interfaces/tests/cli/parsed.yaml | 10 +--------- .../targets/vyos_lldp_interfaces/tests/cli/rendered.yaml | 11 +---------- 4 files changed, 5 insertions(+), 35 deletions(-) (limited to 'tests') diff --git a/plugins/modules/vyos_lldp_interfaces.py b/plugins/modules/vyos_lldp_interfaces.py index 95675112..b26da49e 100644 --- a/plugins/modules/vyos_lldp_interfaces.py +++ b/plugins/modules/vyos_lldp_interfaces.py @@ -30,11 +30,7 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -ANSIBLE_METADATA = { - "metadata_version": "1.1", - "status": ["preview"], - "supported_by": "network", -} +ANSIBLE_METADATA = {"metadata_version": "1.1", "supported_by": "Ansible"} DOCUMENTATION = """module: vyos_lldp_interfaces short_description: LLDP interfaces resource module @@ -42,6 +38,7 @@ description: This module manages attributes of lldp interfaces on VyOS network d notes: - Tested against VyOS 1.1.8 (helium). - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). +version_added: "1.0.0" author: - Rohit Thakur (@rohitthakur2590) options: @@ -120,7 +117,6 @@ options: it into Ansible structured data as per the resource module's argspec and the value is then returned in the I(parsed) key within the result. type: str - version_added: "1.0.0" state: description: - The state of the configuration after module completion. diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml index d440b534..30b804a5 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml @@ -9,7 +9,7 @@ - block: - - name: Merge the provided configuration with the exisiting running configuration + - name: Gather the provided configuration with the exisiting running configuration register: result vyos.vyos.vyos_lldp_interfaces: &id001 config: @@ -20,15 +20,6 @@ that: - "{{ populate | symmetric_difference(result['gathered']) |length == 0\ \ }}" - - - name: Gather the existing running configuration (IDEMPOTENT) - register: result - vyos.vyos.vyos_lldp_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_lldp_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml index 7842152f..c549ce7d 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml @@ -19,7 +19,7 @@ - name: Provide the running configuration for parsing (config to be parsed) register: result - vyos.vyos.vyos_lldp_interfaces: &id001 + vyos.vyos.vyos_lldp_interfaces: running_config: "{{ lookup('file', '_parsed_config.cfg') }}" state: parsed @@ -28,14 +28,6 @@ that: "{{ ansible_facts['network_resources']['lldp_interfaces'] | symmetric_difference(result['parsed'])\ \ |length == 0 }}" - - name: Gather the existing running configuration (IDEMPOTENT) - register: result - vyos.vyos.vyos_lldp_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_lldp_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml index 6bb9f5a0..d69e1c55 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml @@ -11,7 +11,7 @@ - name: Structure provided configuration into device specific commands register: result - vyos.vyos.vyos_lldp_interfaces: &id001 + vyos.vyos.vyos_lldp_interfaces: config: - name: eth1 location: @@ -34,15 +34,6 @@ that: - "{{ rendered['commands'] | symmetric_difference(result['rendered'])\ \ |length == 0 }}" - - - name: Structure provided configuration into device specific commands (IDEMPOTENT) - register: result - vyos.vyos.vyos_lldp_interfaces: *id001 - - - name: Assert that the previous task was idempotent - assert: - that: - - result['changed'] == false always: - include_tasks: _remove_config.yaml -- cgit v1.2.3 From bd128df488162da0691596560ce9b395d707a503 Mon Sep 17 00:00:00 2001 From: Rohit Thakur Date: Fri, 8 May 2020 12:35:18 +0530 Subject: parsed test updated Signed-off-by: Rohit Thakur --- .../vyos_lldp_interfaces/tests/cli/gathered.yaml | 2 +- .../vyos_lldp_interfaces/tests/cli/parsed.yaml | 41 +++++++--------------- .../vyos_lldp_interfaces/tests/cli/rendered.yaml | 2 -- .../targets/vyos_lldp_interfaces/vars/main.yaml | 16 +++++++++ 4 files changed, 29 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml index 30b804a5..180b62f8 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml @@ -11,7 +11,7 @@ - name: Gather the provided configuration with the exisiting running configuration register: result - vyos.vyos.vyos_lldp_interfaces: &id001 + vyos.vyos.vyos_lldp_interfaces: config: state: gathered diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml index c549ce7d..0ca52bed 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml @@ -1,33 +1,16 @@ --- - debug: - msg: START vyos_lldp_interfaces parsed integration tests on connection={{ ansible_connection + msg: START vyos_lldp_nterfaces parsed integration tests on connection={{ ansible_connection }} -- include_tasks: _remove_config.yaml - -- include_tasks: _populate.yaml - -- block: - - - name: Gather lldp_interfaces facts - register: lldp_interfaces_facts - vyos.vyos.vyos_facts: - gather_subset: - - default - gather_network_resources: - - lldp_interfaces - - - name: Provide the running configuration for parsing (config to be parsed) - register: result - vyos.vyos.vyos_lldp_interfaces: - running_config: "{{ lookup('file', '_parsed_config.cfg') }}" - state: parsed - - - name: Assert that correct parsing done - assert: - that: "{{ ansible_facts['network_resources']['lldp_interfaces'] | symmetric_difference(result['parsed'])\ - \ |length == 0 }}" - - always: - - - include_tasks: _remove_config.yaml +- name: Parse externally provided interfaces config to agnostic model + register: result + vyos.vyos.vyos_lldp_interfaces: + running_config: "{{ lookup('file', '_parsed_config.cfg') }}" + state: parsed + +- name: Assert that config was correctly parsed + assert: + that: + - "{{ parsed['after'] | symmetric_difference(result['parsed']) |length ==\ + \ 0 }}" diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml index d69e1c55..342e64b9 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml @@ -5,8 +5,6 @@ - include_tasks: _remove_config.yaml -- include_tasks: _populate.yaml - - block: - name: Structure provided configuration into device specific commands diff --git a/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml b/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml index 506bdf70..092f653c 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml @@ -97,6 +97,22 @@ overridden: - name: eth2 location: elin: 0000000911 +parsed: + after: + - name: eth1 + location: + civic_based: + country_code: US + ca_info: + - ca_type: 0 + ca_value: ENGLISH + - name: eth2 + location: + coordinate_based: + altitude: 2200 + datum: WGS84 + longitude: 222.267255W + latitude: 33.524449N deleted: commands: - delete service lldp interface eth1 -- cgit v1.2.3