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 0000000..40c96c4 --- /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 a5ff0a8..4ef40c9 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 0000000..d440b53 --- /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 0000000..7842152 --- /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 0000000..6bb9f5a --- /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 3cb684e..506bdf7 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