diff --git a/lib/ansible/modules/network/vyos/vyos_lldp.py b/lib/ansible/modules/network/vyos/vyos_lldp.py new file mode 100644 index 0000000000..8292633f55 --- /dev/null +++ b/lib/ansible/modules/network/vyos/vyos_lldp.py @@ -0,0 +1,119 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2017, Ansible by Red Hat, inc +# +# This file is part of Ansible by Red Hat +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +# + +ANSIBLE_METADATA = {'metadata_version': '1.0', + 'status': ['preview'], + 'supported_by': 'core'} + + +DOCUMENTATION = """ +--- +module: vyos_lldp +version_added: "2.4" +author: "Ricardo Carrillo Cruz (@rcarrillocruz)" +short_description: Manage LLDP configuration on VyOS network devices +description: + - This module provides declarative management of LLDP service + on VyOS network devices. +options: + state: + description: + - State of the LLDP configuration. + default: present + choices: ['present', 'absent'] +""" + +EXAMPLES = """ +- name: Enable LLDP service + vyos_lldp: + state: present + +- name: Disable LLDP service + vyos_lldp: + state: absent +""" + +RETURN = """ +commands: + description: The list of configuration mode commands to send to the device + returned: always, except for the platforms that use Netconf transport to manage the device. + type: list + sample: + - set service lldp +""" +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vyos import get_config, load_config +from ansible.module_utils.vyos import vyos_argument_spec, check_args + + +def has_lldp(module): + config = get_config(module).splitlines() + + if "set service 'lldp'" in config or 'set service lldp' in config: + return True + else: + return False + + +def main(): + """ main entry point for module execution + """ + argument_spec = dict( + interfaces=dict(type='list'), + purge=dict(default=False, type='bool'), + state=dict(default='present', + choices=['present', 'absent', + 'enabled', 'disabled']) + ) + + argument_spec.update(vyos_argument_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + warnings = list() + check_args(module, warnings) + + result = {'changed': False} + + if warnings: + result['warnings'] = warnings + + HAS_LLDP = has_lldp(module) + + commands = [] + + if module.params['state'] == 'absent' and HAS_LLDP: + commands.append('delete service lldp') + elif module.params['state'] == 'present' and not HAS_LLDP: + commands.append('set service lldp') + + result['commands'] = commands + + if commands: + commit = not module.check_mode + load_config(module, commands, commit=commit) + result['changed'] = True + + module.exit_json(**result) + +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/network/vyos/vyos_lldp_interface.py b/lib/ansible/modules/network/vyos/vyos_lldp_interface.py new file mode 100644 index 0000000000..bab7d75fff --- /dev/null +++ b/lib/ansible/modules/network/vyos/vyos_lldp_interface.py @@ -0,0 +1,202 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2017, Ansible by Red Hat, inc +# +# This file is part of Ansible by Red Hat +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +# + +ANSIBLE_METADATA = {'metadata_version': '1.0', + 'status': ['preview'], + 'supported_by': 'core'} + + +DOCUMENTATION = """ +--- +module: vyos_lldp_interface +version_added: "2.4" +author: "Ricardo Carrillo Cruz (@rcarrillocruz)" +short_description: Manage LLDP interfaces configuration on VyOS network devices +description: + - This module provides declarative management of LLDP interfaces + configuration on VyOS network devices. +options: + name: + description: + - Name of the interface LLDP should be configured on. + aggregate: + description: List of interfaces LLDP should be configured on. + purge: + description: + - Purge interfaces not defined in the aggregate parameter. + default: no + state: + description: + - State of the LLDP configuration. + default: present + choices: ['present', 'absent', 'enabled', 'disabled'] +""" + +EXAMPLES = """ +- name: Enable LLDP on eth1 + net_lldp_interface: + state: present + +- name: Enable LLDP on specific interfaces + net_lldp_interface: + interfaces: + - eth1 + - eth2 + state: present + +- name: Disable LLDP globally + net_lldp_interface: + state: lldp +""" + +RETURN = """ +commands: + description: The list of configuration mode commands to send to the device + returned: always, except for the platforms that use Netconf transport to manage the device. + type: list + sample: + - set service lldp eth1 + - set service lldp eth2 disable +""" +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vyos import get_config, load_config +from ansible.module_utils.vyos import vyos_argument_spec, check_args + + +def search_obj_in_list(name, lst): + for o in lst: + if o['name'] == name: + return o + + return None + + +def map_obj_to_commands(updates, module): + commands = list() + want, have = updates + + for w in want: + name = w['name'] + state = w['state'] + + obj_in_have = search_obj_in_list(name, have) + + if state == 'absent' and obj_in_have: + commands.append('delete service lldp interface ' + name) + elif state in ('present', 'enabled'): + if not obj_in_have: + commands.append('set service lldp interface ' + name) + elif obj_in_have and obj_in_have['state'] == 'disabled' and state == 'enabled': + commands.append('delete service lldp interface ' + name + ' disable') + elif state == 'disabled': + if not obj_in_have: + commands.append('set service lldp interface ' + name) + commands.append('set service lldp interface ' + name + ' disable') + elif obj_in_have and obj_in_have['state'] != 'disabled': + commands.append('set service lldp interface ' + name + ' disable') + + return commands + + +def map_config_to_obj(module): + obj = [] + config = get_config(module).splitlines() + + output = [c for c in config if c.startswith("set service lldp interface")] + + for i in output: + splitted_line = i.split() + + if len(splitted_line) > 5: + new_obj = {'name': splitted_line[4]} + + if splitted_line[5] == "'disable'": + new_obj['state'] = 'disabled' + else: + new_obj = {'name': splitted_line[4][1:-1]} + new_obj['state'] = 'present' + + obj.append(new_obj) + + return obj + + +def map_params_to_obj(module): + obj = [] + + if module.params['aggregate']: + for i in module.params['aggregate']: + d = i.copy() + + if 'state' not in d: + d['state'] = module.params['state'] + + obj.append(d) + else: + obj.append({'name': module.params['name'], 'state': module.params['state']}) + + return obj + + +def main(): + """ main entry point for module execution + """ + argument_spec = dict( + name=dict(), + aggregate=dict(type='list'), + purge=dict(default=False, type='bool'), + state=dict(default='present', + choices=['present', 'absent', + 'enabled', 'disabled']) + ) + + argument_spec.update(vyos_argument_spec) + required_one_of = [['name', 'aggregate']] + mutually_exclusive = [['name', 'aggregate']] + + module = AnsibleModule(argument_spec=argument_spec, + required_one_of=required_one_of, + mutually_exclusive=mutually_exclusive, + supports_check_mode=True) + + warnings = list() + check_args(module, warnings) + + result = {'changed': False} + + if warnings: + result['warnings'] = warnings + + want = map_params_to_obj(module) + have = map_config_to_obj(module) + + commands = map_obj_to_commands((want, have), module) + result['commands'] = commands + + if commands: + commit = not module.check_mode + load_config(module, commands, commit=commit) + result['changed'] = True + + module.exit_json(**result) + +if __name__ == '__main__': + main() diff --git a/test/integration/platform_agnostic.yaml b/test/integration/platform_agnostic.yaml index b364d83db2..bbb5cbb751 100644 --- a/test/integration/platform_agnostic.yaml +++ b/test/integration/platform_agnostic.yaml @@ -85,6 +85,20 @@ rescue: - set_fact: test_failed=true + - block: + - include_role: + name: net_lldp + when: "limit_to in ['*', 'net_lldp']" + rescue: + - set_fact: test_failed=true + + - block: + - include_role: + name: net_lldp_interface + when: "limit_to in ['*', 'net_lldp_interface']" + rescue: + - set_fact: test_failed=true + ########### - name: Has any previous test failed? fail: diff --git a/test/integration/targets/net_lldp/aliases b/test/integration/targets/net_lldp/aliases new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integration/targets/net_lldp/defaults/main.yaml b/test/integration/targets/net_lldp/defaults/main.yaml new file mode 100644 index 0000000000..9ef5ba5165 --- /dev/null +++ b/test/integration/targets/net_lldp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/test/integration/targets/net_lldp/tasks/cli.yaml b/test/integration/targets/net_lldp/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/net_lldp/tasks/cli.yaml @@ -0,0 +1,15 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/net_lldp/tasks/main.yaml b/test/integration/targets/net_lldp/tasks/main.yaml new file mode 100644 index 0000000000..af08869c92 --- /dev/null +++ b/test/integration/targets/net_lldp/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: netconf.yaml, tags: ['netconf'] } diff --git a/test/integration/targets/net_lldp/tasks/netconf.yaml b/test/integration/targets/net_lldp/tasks/netconf.yaml new file mode 100644 index 0000000000..1286b35422 --- /dev/null +++ b/test/integration/targets/net_lldp/tasks/netconf.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all netconf test cases + find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + 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 + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/net_lldp/tests/cli/basic.yaml b/test/integration/targets/net_lldp/tests/cli/basic.yaml new file mode 100644 index 0000000000..29e7b06be1 --- /dev/null +++ b/test/integration/targets/net_lldp/tests/cli/basic.yaml @@ -0,0 +1,4 @@ +--- + +- include: "{{ role_path }}/tests/vyos/basic.yaml" + when: hostvars[inventory_hostname]['ansible_network_os'] == 'vyos' diff --git a/test/integration/targets/net_lldp/tests/vyos/basic.yaml b/test/integration/targets/net_lldp/tests/vyos/basic.yaml new file mode 100644 index 0000000000..874a5287ed --- /dev/null +++ b/test/integration/targets/net_lldp/tests/vyos/basic.yaml @@ -0,0 +1,42 @@ +--- +- name: Make sure LLDP is not running before tests + vyos_config: + lines: delete service lldp + +- name: Enable LLDP service + net_lldp: + state: present + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp" in result.commands' + +- name: Enable LLDP service again (idempotent) + net_lldp: + state: present + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Disable LLDP service + net_lldp: + state: absent + register: result + +- assert: + that: + - 'result.changed == true' + - '"delete service lldp" in result.commands' + +- name: + net_lldp: + state: absent + register: result + +- assert: + that: + - 'result.changed == false' diff --git a/test/integration/targets/net_lldp_interface/aliases b/test/integration/targets/net_lldp_interface/aliases new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integration/targets/net_lldp_interface/defaults/main.yaml b/test/integration/targets/net_lldp_interface/defaults/main.yaml new file mode 100644 index 0000000000..9ef5ba5165 --- /dev/null +++ b/test/integration/targets/net_lldp_interface/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/test/integration/targets/net_lldp_interface/tasks/cli.yaml b/test/integration/targets/net_lldp_interface/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/net_lldp_interface/tasks/cli.yaml @@ -0,0 +1,15 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/net_lldp_interface/tasks/main.yaml b/test/integration/targets/net_lldp_interface/tasks/main.yaml new file mode 100644 index 0000000000..af08869c92 --- /dev/null +++ b/test/integration/targets/net_lldp_interface/tasks/main.yaml @@ -0,0 +1,3 @@ +--- +- { include: cli.yaml, tags: ['cli'] } +- { include: netconf.yaml, tags: ['netconf'] } diff --git a/test/integration/targets/net_lldp_interface/tasks/netconf.yaml b/test/integration/targets/net_lldp_interface/tasks/netconf.yaml new file mode 100644 index 0000000000..1286b35422 --- /dev/null +++ b/test/integration/targets/net_lldp_interface/tasks/netconf.yaml @@ -0,0 +1,16 @@ +--- +- name: collect all netconf test cases + find: + paths: "{{ role_path }}/tests/netconf" + patterns: "{{ testcase }}.yaml" + 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 + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/net_lldp_interface/tests/cli/basic.yaml b/test/integration/targets/net_lldp_interface/tests/cli/basic.yaml new file mode 100644 index 0000000000..29e7b06be1 --- /dev/null +++ b/test/integration/targets/net_lldp_interface/tests/cli/basic.yaml @@ -0,0 +1,4 @@ +--- + +- include: "{{ role_path }}/tests/vyos/basic.yaml" + when: hostvars[inventory_hostname]['ansible_network_os'] == 'vyos' diff --git a/test/integration/targets/net_lldp_interface/tests/vyos/basic.yaml b/test/integration/targets/net_lldp_interface/tests/vyos/basic.yaml new file mode 100644 index 0000000000..d9f8f4a156 --- /dev/null +++ b/test/integration/targets/net_lldp_interface/tests/vyos/basic.yaml @@ -0,0 +1,165 @@ +--- +- name: Make sure LLDP is not running before tests + vyos_config: + lines: delete service lldp + +- name: Create LLDP configuration + net_lldp_interface: + name: eth1 + state: present + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp interface eth1" in result.commands' + +- name: Create LLDP configuration again (idempotent) + net_lldp_interface: + name: eth1 + state: present + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Disable LLDP configuration + net_lldp_interface: + name: eth1 + state: disabled + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp interface eth1 disable" in result.commands' + +- name: Disable LLDP configuration again (idempotent) + net_lldp_interface: + name: eth1 + state: disabled + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Enable LLDP configuration + net_lldp_interface: + name: eth1 + state: enabled + register: result + +- assert: + that: + - 'result.changed == true' + - '"delete service lldp interface eth1 disable" in result.commands' + +- name: Enable LLDP configuration again (idempotent) + net_lldp_interface: + name: eth1 + state: enabled + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Delete LLDP configuration + net_lldp_interface: + name: eth1 + state: absent + register: result + +- assert: + that: + - 'result.changed == true' + - '"delete service lldp interface eth1" in result.commands' + +- name: Delete LLDP configuration again (idempotent) + net_lldp_interface: + name: eth1 + state: absent + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Create aggregate of LLDP interface configurations + net_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2 } + state: present + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp interface eth1" in result.commands' + - '"set service lldp interface eth2" in result.commands' + +- name: Create aggregate of LLDP interface configurations again (idempotent) + net_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2 } + state: present + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Override LLDP interface configuration on aggregate + net_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2, state: disabled } + state: present + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp interface eth2 disable" in result.commands' + +- name: Override LLDP interface configuration on aggregate again (idempotent) + net_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2, state: disabled } + state: present + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Delete aggregate of LLDP interface configurations + net_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2 } + state: absent + register: result + +- assert: + that: + - 'result.changed == true' + - '"delete service lldp interface eth1" in result.commands' + - '"delete service lldp interface eth2" in result.commands' + +- name: Delete aggregate of LLDP interface configurations (idempotent) + net_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2 } + state: absent + register: result + +- assert: + that: + - 'result.changed == false' diff --git a/test/integration/targets/vyos_lldp/defaults/main.yaml b/test/integration/targets/vyos_lldp/defaults/main.yaml new file mode 100644 index 0000000000..9ef5ba5165 --- /dev/null +++ b/test/integration/targets/vyos_lldp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/test/integration/targets/vyos_lldp/tasks/cli.yaml b/test/integration/targets/vyos_lldp/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/vyos_lldp/tasks/cli.yaml @@ -0,0 +1,15 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_lldp/tasks/main.yaml b/test/integration/targets/vyos_lldp/tasks/main.yaml new file mode 100644 index 0000000000..415c99d8b1 --- /dev/null +++ b/test/integration/targets/vyos_lldp/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/test/integration/targets/vyos_lldp/tests/cli/basic.yaml b/test/integration/targets/vyos_lldp/tests/cli/basic.yaml new file mode 100644 index 0000000000..ec2dfb42ff --- /dev/null +++ b/test/integration/targets/vyos_lldp/tests/cli/basic.yaml @@ -0,0 +1,42 @@ +--- +- name: Make sure LLDP is not running before tests + vyos_config: + lines: delete service lldp + +- name: Enable LLDP service + vyos_lldp: + state: present + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp" in result.commands' + +- name: Enable LLDP service again (idempotent) + vyos_lldp: + state: present + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Disable LLDP service + vyos_lldp: + state: absent + register: result + +- assert: + that: + - 'result.changed == true' + - '"delete service lldp" in result.commands' + +- name: + vyos_lldp: + state: absent + register: result + +- assert: + that: + - 'result.changed == false' diff --git a/test/integration/targets/vyos_lldp_interface/defaults/main.yaml b/test/integration/targets/vyos_lldp_interface/defaults/main.yaml new file mode 100644 index 0000000000..9ef5ba5165 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interface/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/test/integration/targets/vyos_lldp_interface/tasks/cli.yaml b/test/integration/targets/vyos_lldp_interface/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interface/tasks/cli.yaml @@ -0,0 +1,15 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_lldp_interface/tasks/main.yaml b/test/integration/targets/vyos_lldp_interface/tasks/main.yaml new file mode 100644 index 0000000000..415c99d8b1 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interface/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/test/integration/targets/vyos_lldp_interface/tests/cli/basic.yaml b/test/integration/targets/vyos_lldp_interface/tests/cli/basic.yaml new file mode 100644 index 0000000000..53c8f4c47a --- /dev/null +++ b/test/integration/targets/vyos_lldp_interface/tests/cli/basic.yaml @@ -0,0 +1,165 @@ +--- +- name: Make sure LLDP is not running before tests + vyos_config: + lines: delete service lldp + +- name: Create LLDP configuration + vyos_lldp_interface: + name: eth1 + state: present + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp interface eth1" in result.commands' + +- name: Create LLDP configuration again (idempotent) + vyos_lldp_interface: + name: eth1 + state: present + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Disable LLDP configuration + vyos_lldp_interface: + name: eth1 + state: disabled + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp interface eth1 disable" in result.commands' + +- name: Disable LLDP configuration again (idempotent) + vyos_lldp_interface: + name: eth1 + state: disabled + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Enable LLDP configuration + vyos_lldp_interface: + name: eth1 + state: enabled + register: result + +- assert: + that: + - 'result.changed == true' + - '"delete service lldp interface eth1 disable" in result.commands' + +- name: Enable LLDP configuration again (idempotent) + vyos_lldp_interface: + name: eth1 + state: enabled + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Delete LLDP configuration + vyos_lldp_interface: + name: eth1 + state: absent + register: result + +- assert: + that: + - 'result.changed == true' + - '"delete service lldp interface eth1" in result.commands' + +- name: Delete LLDP configuration again (idempotent) + vyos_lldp_interface: + name: eth1 + state: absent + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Create aggregate of LLDP interface configurations + vyos_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2 } + state: present + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp interface eth1" in result.commands' + - '"set service lldp interface eth2" in result.commands' + +- name: Create aggregate of LLDP interface configurations again (idempotent) + vyos_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2 } + state: present + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Override LLDP interface configuration on aggregate + vyos_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2, state: disabled } + state: present + register: result + +- assert: + that: + - 'result.changed == true' + - '"set service lldp interface eth2 disable" in result.commands' + +- name: Override LLDP interface configuration on aggregate again (idempotent) + vyos_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2, state: disabled } + state: present + register: result + +- assert: + that: + - 'result.changed == false' + +- name: Delete aggregate of LLDP interface configurations + vyos_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2 } + state: absent + register: result + +- assert: + that: + - 'result.changed == true' + - '"delete service lldp interface eth1" in result.commands' + - '"delete service lldp interface eth2" in result.commands' + +- name: Delete aggregate of LLDP interface configurations (idempotent) + vyos_lldp_interface: + aggregate: + - { name: eth1 } + - { name: eth2 } + state: absent + register: result + +- assert: + that: + - 'result.changed == false' diff --git a/test/integration/vyos.yaml b/test/integration/vyos.yaml index 41319c527a..157e138c85 100644 --- a/test/integration/vyos.yaml +++ b/test/integration/vyos.yaml @@ -70,6 +70,20 @@ rescue: - set_fact: test_failed=true + - block: + - include_role: + name: vyos_lldp + when: "limit_to in ['*', 'vyos_lldp']" + rescue: + - set_fact: test_failed=true + + - block: + - include_role: + name: vyos_lldp_interface + when: "limit_to in ['*', 'vyos_lldp_interface']" + rescue: + - set_fact: test_failed=true + ########### - name: Has any previous test failed?