Add iosxr_lldp_global resource module (#60074)

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>
This commit is contained in:
Nilashish Chakraborty 2019-08-12 18:03:23 +05:30 committed by GitHub
parent 3929dc00a1
commit 09f712c7f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 1051 additions and 9 deletions

View file

@ -23,7 +23,9 @@ class FactsArgs(object): # pylint: disable=R0903
'lacp', 'lacp',
'!lacp', '!lacp',
'lacp_interfaces', 'lacp_interfaces',
'!lacp_interfaces' '!lacp_interfaces',
'lldp_global',
'!lldp_global'
] ]
argument_spec = { argument_spec = {

View file

@ -0,0 +1,82 @@
#
# -*- coding: utf-8 -*-
# Copyright 2019 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#############################################
# WARNING #
#############################################
#
# This file is auto generated by the resource
# module builder playbook.
#
# Do not edit this file manually.
#
# Changes to this file will be over written
# by the resource module builder.
#
# Changes should be made in the model used to
# generate this file or in the resource module
# builder template.
#
#############################################
"""
The arg spec for the iosxr_lldp_global module
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
class Lldp_globalArgs(object): # pylint: disable=R0903
"""The arg spec for the iosxr_lldp module
"""
def __init__(self, **kwargs):
pass
argument_spec = {
'config': {
'options': {
'holdtime': {
'type': 'int'
},
'reinit': {
'type': 'int'
},
'subinterfaces': {
'type': 'bool'
},
'timer': {
'type': 'int'
},
'tlv_select': {
'options': {
'management_address': {
'type': 'bool'
},
'port_description': {
'type': 'bool'
},
'system_capabilities': {
'type': 'bool'
},
'system_description': {
'type': 'bool'
},
'system_name': {
'type': 'bool'
}
},
'type': 'dict'
}
},
'type': 'dict'
},
'state': {
'choices': ['merged', 'replaced', 'deleted'],
'default': 'merged',
'type': 'str'
}
} # pylint: disable=C0301

View file

@ -0,0 +1,186 @@
#
# -*- coding: utf-8 -*-
# Copyright 2019 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""
The iosxr_lldp_global class
It is in this file where the current configuration (as dict)
is compared to the provided configuration (as dict) and the command set
necessary to bring the current configuration to it's desired end-state is
created
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
from ansible.module_utils.network.common.cfg.base import ConfigBase
from ansible.module_utils.network.common.utils import to_list, dict_diff, remove_empties
from ansible.module_utils.network.iosxr.facts.facts import Facts
from ansible.module_utils.six import iteritems
from ansible.module_utils.network.iosxr. \
utils.utils import flatten_dict, dict_delete
class Lldp_global(ConfigBase):
"""
The iosxr_lldp class
"""
gather_subset = [
'!all',
'!min',
]
gather_network_resources = [
'lldp_global',
]
def __init__(self, module):
super(Lldp_global, self).__init__(module)
def get_lldp_global_facts(self):
""" Get the 'facts' (the current configuration)
:rtype: A dictionary
:returns: The current configuration as a dictionary
"""
facts, _warnings = Facts(self._module).get_facts(self.gather_subset, self.gather_network_resources)
lldp_facts = facts['ansible_network_resources'].get('lldp_global')
if not lldp_facts:
return {}
return lldp_facts
def execute_module(self):
""" Execute the module
:rtype: A dictionary
:returns: The result from module execution
"""
result = {'changed': False}
warnings = list()
commands = list()
existing_lldp_global_facts = self.get_lldp_global_facts()
commands.extend(self.set_config(existing_lldp_global_facts))
if commands:
if not self._module.check_mode:
self._connection.edit_config(commands)
result['changed'] = True
result['commands'] = commands
changed_lldp_global_facts = self.get_lldp_global_facts()
result['before'] = existing_lldp_global_facts
if result['changed']:
result['after'] = changed_lldp_global_facts
result['warnings'] = warnings
return result
def set_config(self, existing_lldp_global_facts):
""" Collect the configuration from the args passed to the module,
collect the current configuration (as a dict from facts)
:rtype: A list
:returns: the commands necessary to migrate the current configuration
to the desired configuration
"""
want = self._module.params['config']
if not want and self._module.params['state'] == 'deleted':
want = {}
have = existing_lldp_global_facts
resp = self.set_state(want, have)
return to_list(resp)
def set_state(self, want, have):
""" Select the appropriate function based on the state provided
:param want: the desired configuration as a dictionary
:param have: the current configuration as a dictionary
:rtype: A list
:returns: the commands necessary to migrate the current configuration
to the desired configuration
"""
state = self._module.params['state']
if state == 'deleted':
commands = self._state_deleted(want, have)
elif state == 'merged':
commands = self._state_merged(want, have)
elif state == 'replaced':
commands = self._state_replaced(want, have)
return commands
def _state_replaced(self, want, have):
""" The command generator when state is replaced
:rtype: A list
:returns: the commands necessary to migrate the current configuration
to the desired configuration
"""
commands = []
commands.extend(
self._state_deleted(want, have)
)
commands.extend(
self._state_merged(want, have)
)
return commands
def _state_merged(self, want, have):
""" The command generator when state is merged
:rtype: A list
:returns: the commands necessary to merge the provided into
the current configuration
"""
commands = []
updates = dict_diff(have, want)
if updates:
for key, value in iteritems(flatten_dict(remove_empties(updates))):
commands.append(self._compute_commands(key, value))
return commands
def _state_deleted(self, want, have):
""" The command generator when state is deleted
:rtype: A list
:returns: the commands necessary to remove the current configuration
of the provided objects
"""
commands = []
for key, value in iteritems(flatten_dict(dict_delete(have, remove_empties(want)))):
cmd = self._compute_commands(key, value, remove=True)
if cmd:
commands.append(cmd)
return commands
def _compute_commands(self, key, value=None, remove=False):
if key in ['holdtime', 'reinit', 'timer']:
cmd = 'lldp {0} {1}'.format(key, value)
if remove:
return 'no {0}'.format(cmd)
else:
return cmd
elif key == 'subinterfaces':
cmd = 'lldp subinterfaces enable'
if (value and not remove):
return cmd
elif (not value and not remove) or (value and remove):
return 'no {0}'.format(cmd)
else:
cmd = 'lldp tlv-select {0} disable'.format(key.replace('_', '-'))
if (not value and not remove):
return cmd
elif (value and not remove) or (not value and remove):
return 'no {0}'.format(cmd)

View file

@ -17,6 +17,7 @@ from ansible.module_utils.network.iosxr.argspec.facts.facts import FactsArgs
from ansible.module_utils.network.common.facts.facts import FactsBase from ansible.module_utils.network.common.facts.facts import FactsBase
from ansible.module_utils.network.iosxr.facts.lacp.lacp import LacpFacts from ansible.module_utils.network.iosxr.facts.lacp.lacp import LacpFacts
from ansible.module_utils.network.iosxr.facts.lacp_interfaces.lacp_interfaces import Lacp_interfacesFacts from ansible.module_utils.network.iosxr.facts.lacp_interfaces.lacp_interfaces import Lacp_interfacesFacts
from ansible.module_utils.network.iosxr.facts.lldp_global.lldp_global import Lldp_globalFacts
from ansible.module_utils.network.iosxr.facts.legacy.\ from ansible.module_utils.network.iosxr.facts.legacy.\
base import Default, Hardware, Interfaces, Config base import Default, Hardware, Interfaces, Config
@ -29,7 +30,8 @@ FACT_LEGACY_SUBSETS = dict(
) )
FACT_RESOURCE_SUBSETS = dict( FACT_RESOURCE_SUBSETS = dict(
lacp=LacpFacts, lacp=LacpFacts,
lacp_interfaces=Lacp_interfacesFacts lacp_interfaces=Lacp_interfacesFacts,
lldp_global=Lldp_globalFacts
) )

View file

@ -56,9 +56,9 @@ class LacpFacts(object):
ansible_facts['ansible_network_resources'].pop('lacp', None) ansible_facts['ansible_network_resources'].pop('lacp', None)
facts = {} facts = {}
if obj:
params = utils.validate_config(self.argument_spec, {'config': obj}) params = utils.validate_config(self.argument_spec, {'config': obj})
facts['lacp'] = utils.remove_empties(params['config']) facts['lacp'] = utils.remove_empties(params['config'])
ansible_facts['ansible_network_resources'].update(facts) ansible_facts['ansible_network_resources'].update(facts)
return ansible_facts return ansible_facts

View file

@ -0,0 +1,93 @@
#
# -*- coding: utf-8 -*-
# Copyright 2019 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""
The iosxr lldp fact class
It is in this file the configuration is collected from the device
for a given resource, parsed, and the facts tree is populated
based on the configuration.
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import re
from copy import deepcopy
from ansible.module_utils.network.common import utils
from ansible.module_utils.network.iosxr.argspec.lldp_global.lldp_global import Lldp_globalArgs
from ansible.module_utils.network.iosxr.utils.utils import flatten_dict
class Lldp_globalFacts(object):
""" The iosxr lldp fact class
"""
def __init__(self, module, subspec='config', options='options'):
self._module = module
self.argument_spec = Lldp_globalArgs.argument_spec
spec = deepcopy(self.argument_spec)
if subspec:
if options:
facts_argument_spec = spec[subspec][options]
else:
facts_argument_spec = spec[subspec]
else:
facts_argument_spec = spec
self.generated_spec = utils.generate_dict(facts_argument_spec)
def populate_facts(self, connection, ansible_facts, data=None):
""" Populate the facts for lldp
:param connection: the device connection
:param ansible_facts: Facts dictionary
:param data: previously collected conf
:rtype: dictionary
:returns: facts
"""
if not data:
data = connection.get_config(flags='lldp')
obj = {}
if data:
lldp_obj = self.render_config(self.generated_spec, data)
if lldp_obj:
obj = lldp_obj
ansible_facts['ansible_network_resources'].pop('lldp_global', None)
facts = {}
params = utils.validate_config(self.argument_spec, {'config': obj})
facts['lldp_global'] = utils.remove_empties(params['config'])
ansible_facts['ansible_network_resources'].update(facts)
return ansible_facts
def render_config(self, spec, conf):
"""
Render config as dictionary structure and delete keys
from spec for null values
:param spec: The facts tree, generated from the argspec
:param conf: The configuration
:rtype: dictionary
:returns: The generated config
"""
config = deepcopy(spec)
for key in spec.keys():
if key == 'subinterfaces':
config[key] = True if 'subinterfaces enable' in conf else None
elif key == 'tlv_select':
for item in ['system_name', 'port_description', 'management_address', 'system_description', 'system_capabilities']:
config[key][item] = False if ('{0} disable'.format(item.replace('_', '-'))) in conf else None
else:
value = utils.parse_conf_arg(conf, key)
config[key] = int(value) if value else value
return config

View file

@ -42,6 +42,9 @@ version_added: 2.9
short_description: Manage Global Link Aggregation Control Protocol (LACP) on IOS-XR devices. short_description: Manage Global Link Aggregation Control Protocol (LACP) on IOS-XR devices.
description: description:
- This module manages Global Link Aggregation Control Protocol (LACP) on IOS-XR devices. - This module manages Global Link Aggregation Control Protocol (LACP) on IOS-XR devices.
notes:
- Tested against IOS-XR 6.1.3.
- This module works with connection C(network_cli).
author: Nilashish Chakraborty (@nilashishc) author: Nilashish Chakraborty (@nilashishc)
options: options:
config: config:
@ -254,14 +257,14 @@ RETURN = """
before: before:
description: The configuration prior to the model invocation. description: The configuration prior to the model invocation.
returned: always returned: always
type: list type: dict
sample: > sample: >
The configuration returned will always be in the same format The configuration returned will always be in the same format
of the parameters above. of the parameters above.
after: after:
description: The resulting configuration model invocation. description: The resulting configuration model invocation.
returned: when changed returned: when changed
type: list type: dict
sample: > sample: >
The configuration returned will always be in the same format The configuration returned will always be in the same format
of the parameters above. of the parameters above.
@ -284,7 +287,9 @@ def main():
:returns: the result form module invocation :returns: the result form module invocation
""" """
module = AnsibleModule(argument_spec=LacpArgs.argument_spec, required_if = [('state', 'merged', ('config',)),
('state', 'replaced', ('config',))]
module = AnsibleModule(argument_spec=LacpArgs.argument_spec, required_if=required_if,
supports_check_mode=True) supports_check_mode=True)
result = Lacp(module).execute_module() result = Lacp(module).execute_module()

View file

@ -42,6 +42,9 @@ version_added: 2.9
short_description: Manage Link Aggregation Control Protocol (LACP) attributes of interfaces on IOS-XR devices. short_description: Manage Link Aggregation Control Protocol (LACP) attributes of interfaces on IOS-XR devices.
description: description:
- This module manages Link Aggregation Control Protocol (LACP) attributes of interfaces on IOS-XR devices. - This module manages Link Aggregation Control Protocol (LACP) attributes of interfaces on IOS-XR devices.
notes:
- Tested against IOS-XR 6.1.3.
- This module works with connection C(network_cli).
author: Nilashish Chakraborty (@nilashishc) author: Nilashish Chakraborty (@nilashishc)
options: options:
config: config:
@ -522,7 +525,9 @@ def main():
:returns: the result form module invocation :returns: the result form module invocation
""" """
module = AnsibleModule(argument_spec=Lacp_interfacesArgs.argument_spec, required_if = [('state', 'merged', ('config',)),
('state', 'replaced', ('config',))]
module = AnsibleModule(argument_spec=Lacp_interfacesArgs.argument_spec, required_if=required_if,
supports_check_mode=True) supports_check_mode=True)
result = Lacp_interfaces(module).execute_module() result = Lacp_interfaces(module).execute_module()

View file

@ -0,0 +1,376 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2019 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#############################################
# WARNING #
#############################################
#
# This file is auto generated by the resource
# module builder playbook.
#
# Do not edit this file manually.
#
# Changes to this file will be over written
# by the resource module builder.
#
# Changes should be made in the model used to
# generate this file or in the resource module
# builder template.
#
#############################################
"""
The module file for iosxr_lldp_global
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'network'
}
DOCUMENTATION = """
---
module: iosxr_lldp_global
version_added: 2.9
short_description: Manage Global Link Layer Discovery Protocol (LLDP) settings on IOS-XR devices.
description:
- This module manages Global Link Layer Discovery Protocol (LLDP) settings on IOS-XR devices.
notes:
- Tested against IOS-XR 6.1.3.
- This module works with connection C(network_cli).
author: Nilashish Chakraborty (@NilashishC)
options:
config:
description: The provided global LLDP configuration.
type: dict
suboptions:
holdtime:
description:
- Specifies the holdtime (in sec) to be sent in packets.
type: int
reinit:
description:
- Specifies the delay (in sec) for LLDP initialization on any interface.
type: int
subinterfaces:
description:
- Enable or disable LLDP over sub-interfaces.
type: bool
timer:
description:
- Specifies the rate at which LLDP packets are sent (in sec).
type: int
tlv_select:
description:
- Specifies the LLDP TLVs to enable or disable.
type: dict
suboptions:
management_address:
description:
- Enable or disable management address TLV.
type: bool
port_description:
description:
- Enable or disable port description TLV.
type: bool
system_capabilities:
description:
- Enable or disable system capabilities TLV.
type: bool
system_description:
description:
- Enable or disable system description TLV.
type: bool
system_name:
description:
- Enable or disable system name TLV.
type: bool
state:
description:
- The state the configuration should be left in.
type: str
choices:
- merged
- replaced
- deleted
default: merged
"""
EXAMPLES = """
# Using merged
#
#
# -------------
# Before State
# -------------
#
#
# RP/0/0/CPU0:an-iosxr#sh run lldp
# Tue Aug 6 19:27:54.933 UTC
# % No such configuration item(s)
#
#
- name: Merge provided LLDP configuration with the existing configuration
iosxr_lldp_global:
config:
holdtime: 100
reinit: 2
timer: 3000
subinterfaces: True
tlv_select:
management_address: False
system_description: False
state: merged
#
#
# ------------------------
# Module Execution Result
# ------------------------
#
# "before": {}
#
# "commands": [
# "lldp subinterfaces enable",
# "lldp holdtime 100",
# "lldp reinit 2",
# "lldp tlv-select system-description disable",
# "lldp tlv-select management-address disable",
# "lldp timer 3000"
# ]
#
# "after": {
# "holdtime": 100,
# "reinit": 2,
# "subinterfaces": true,
# "timer": 3000,
# "tlv_select": {
# "management_address": false,
# "system_description": false
# }
# }
#
#
# ------------
# After state
# ------------
#
#
# RP/0/0/CPU0:an-iosxr#sh run lldp
# Tue Aug 6 21:31:10.587 UTC
# lldp
# timer 3000
# reinit 2
# subinterfaces enable
# holdtime 100
# tlv-select
# management-address disable
# system-description disable
# !
# !
#
#
# Using replaced
#
#
# -------------
# Before State
# -------------
#
# RP/0/0/CPU0:an-iosxr#sh run lldp
# Tue Aug 6 21:31:10.587 UTC
# lldp
# timer 3000
# reinit 2
# subinterfaces enable
# holdtime 100
# tlv-select
# management-address disable
# system-description disable
# !
# !
#
#
- name: Replace existing LLDP device configuration with provided configuration
iosxr_lldp_global:
config:
holdtime: 100
tlv_select:
port_description: False
system_description: True
management_description: True
state: replaced
#
#
# ------------------------
# Module Execution Result
# ------------------------
#
# "before": {
# "holdtime": 100,
# "reinit": 2,
# "subinterfaces": true,
# "timer": 3000,
# "tlv_select": {
# "management_address": false,
# "system_description": false
# }
# }
#
# "commands": [
# "no lldp reinit 2",
# "no lldp subinterfaces enable",
# "no lldp timer 3000",
# "no lldp tlv-select management-address disable",
# "no lldp tlv-select system-description disable",
# "lldp tlv-select port-description disable"
# ]
#
# "after": {
# "holdtime": 100,
# "tlv_select": {
# "port_description": false
# }
# }
#
#
# ------------
# After state
# ------------
#
# RP/0/0/CPU0:an-iosxr#sh run lldp
# Tue Aug 6 21:53:08.407 UTC
# lldp
# holdtime 100
# tlv-select
# port-description disable
# !
# !
#
#
# Using deleted
#
# ------------
# Before state
# ------------
#
#
# RP/0/0/CPU0:an-iosxr#sh run lldp
# Tue Aug 6 21:31:10.587 UTC
# lldp
# timer 3000
# reinit 2
# subinterfaces enable
# holdtime 100
# tlv-select
# management-address disable
# system-description disable
# !
# !
#
#
- name: Deleted existing LLDP configurations from the device
iosxr_lldp_global:
state: deleted
#
#
# ------------------------
# Module Execution Result
# ------------------------
#
# "before": {
# "holdtime": 100,
# "reinit": 2,
# "subinterfaces": true,
# "timer": 3000,
# "tlv_select": {
# "management_address": false,
# "system_description": false
# }
# },
#
# "commands": [
# "no lldp holdtime 100",
# "no lldp reinit 2",
# "no lldp subinterfaces enable",
# "no lldp timer 3000",
# "no lldp tlv-select management-address disable",
# "no lldp tlv-select system-description disable"
# ]
#
# "after": {}
#
#
# -----------
# After state
# -----------
#
# RP/0/0/CPU0:an-iosxr#sh run lldp
# Tue Aug 6 21:38:31.187 UTC
# lldp
# !
#
#
"""
RETURN = """
before:
description: The configuration prior to the model invocation.
returned: always
type: dict
sample: >
The configuration returned will always be in the same format
of the parameters above.
after:
description: The resulting configuration model invocation.
returned: when changed
type: dict
sample: >
The configuration returned will always be in the same format
of the parameters above.
commands:
description: The set of commands pushed to the remote device.
returned: always
type: list
sample: ['lldp subinterfaces enable', 'lldp holdtime 100', 'no lldp tlv-select management-address disable']
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.iosxr.argspec.lldp_global.lldp_global import Lldp_globalArgs
from ansible.module_utils.network.iosxr.config.lldp_global.lldp_global import Lldp_global
def main():
"""
Main entry point for module execution
:returns: the result form module invocation
"""
required_if = [('state', 'merged', ('config',)),
('state', 'replaced', ('config',))]
module = AnsibleModule(argument_spec=Lldp_globalArgs.argument_spec, required_if=required_if,
supports_check_mode=True)
result = Lldp_global(module).execute_module()
module.exit_json(**result)
if __name__ == '__main__':
main()

View file

@ -0,0 +1,3 @@
---
testcase: "[^_].*"
test_items: []

View file

@ -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

View file

@ -0,0 +1,2 @@
---
- { include: cli.yaml, tags: ['cli'] }

View file

@ -0,0 +1,13 @@
---
- name: Setup
cli_config:
config: "{{ lines }}"
vars:
lines: |
lldp reinit 2
lldp holdtime 100
lldp timer 3000
lldp subinterfaces enable
lldp tlv-select system-description disable
lldp tlv-select management-address disable

View file

@ -0,0 +1,7 @@
---
- name: Remove Config
cli_config:
config: "{{ lines }}"
vars:
lines: |
no lldp

View file

@ -0,0 +1,45 @@
---
- debug:
msg: "Start iosxr_lldp_global deleted integration tests ansible_connection={{ ansible_connection }}"
- include_tasks: _remove_config.yaml
- include_tasks: _populate.yaml
- block:
- name: Delete global LLDP attributes
iosxr_lldp_global: &deleted
state: deleted
register: result
- name: Assert that the before dicts were correctly generated
assert:
that:
- "{{ merged['after'] == result['before'] }}"
- 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'] == result['after'] }}"
- name: Delete attributes of given interfaces (IDEMPOTENT)
iosxr_lldp_global: *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'] == result['before'] }}"
always:
- include_tasks: _remove_config.yaml

View file

@ -0,0 +1,49 @@
---
- debug:
msg: "START iosxr_lldp_global merged integration tests on connection={{ ansible_connection }}"
- include_tasks: _remove_config.yaml
- block:
- name: Merge the provided configuration with the exisiting running configuration
iosxr_lldp_global: &merged
config:
holdtime: 100
reinit: 2
timer: 3000
subinterfaces: True
tlv_select:
management_address: False
system_description: False
state: merged
register: result
- name: Assert that before dicts were correctly generated
assert:
that: "{{ merged['before'] == result['before'] }}"
- 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'] == result['after'] }}"
- name: Merge the provided configuration with the existing running configuration (IDEMPOTENT)
iosxr_lldp_global: *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'] == result['before']}}"
always:
- include_tasks: _remove_config.yaml

View file

@ -0,0 +1,51 @@
---
- debug:
msg: "START iosxr_lldp_global replaced integration tests on connection={{ ansible_connection }}"
- include_tasks: _remove_config.yaml
- include_tasks: _populate.yaml
- block:
- name: Replace global LLDP configuration with provided configurations
iosxr_lldp_global: &replaced
config:
holdtime: 100
tlv_select:
port_description: False
system_description: False
management_address: False
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:
- "{{ merged['after'] == result['before'] }}"
- name: Assert that after dict is correctly generated
assert:
that:
- "{{ replaced['after'] == result['after'] }}"
- name: Replace device global LLDP configurations with provided configurarions (IDEMPOTENT)
iosxr_lldp_global: *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'] == result['before'] }}"
always:
- include_tasks: _remove_config.yaml

View file

@ -0,0 +1,49 @@
---
- debug:
msg: "START isoxr_lldp_global round trip integration tests on connection={{ ansible_connection }}"
- block:
- include_tasks: _remove_config.yaml
- name: Apply the provided configuration (base config)
iosxr_lldp_global:
config:
holdtime: 200
timer: 500
state: merged
register: base_config
- name: Gather interfaces facts
iosxr_facts:
gather_subset:
- "!all"
- "!min"
gather_network_resources:
- lldp_global
- name: Apply the provided configuration (config to be reverted)
iosxr_lldp_global:
config:
holdtime: 200
reinit: 4
subinterfaces: True
timer: 3000
state: merged
register: result
- name: Assert that changes were applied
assert:
that: "{{ round_trip['after'] == result['after'] }}"
- name: Revert back to base config using facts round trip
iosxr_lldp_global:
config: "{{ ansible_facts['network_resources']['lldp_global'] }}"
state: replaced
register: revert
- name: Assert that config was reverted
assert:
that: "{{ base_config['after'] == revert['after'] }}"
always:
- include_tasks: _remove_config.yaml

View file

@ -0,0 +1,52 @@
---
merged:
before: {}
commands:
- "lldp reinit 2"
- "lldp holdtime 100"
- "lldp timer 3000"
- "lldp subinterfaces enable"
- "lldp tlv-select system-description disable"
- "lldp tlv-select management-address disable"
after:
holdtime: 100
reinit: 2
subinterfaces: True
timer: 3000
tlv_select:
management_address: False
system_description: False
replaced:
commands:
- "no lldp reinit 2"
- "no lldp subinterfaces enable"
- "no lldp timer 3000"
- "lldp tlv-select port-description disable"
after:
holdtime: 100
tlv_select:
management_address: False
port_description: False
system_description: False
deleted:
commands:
- "no lldp holdtime 100"
- "no lldp reinit 2"
- "no lldp subinterfaces enable"
- "no lldp timer 3000"
- "no lldp tlv-select management-address disable"
- "no lldp tlv-select system-description disable"
after: {}
round_trip:
after:
holdtime: 200
reinit: 4
subinterfaces: True
timer: 3000