Add [junos_lldp_global] model (#59712)
* Add [junos_lldp_global] model * Add new resource module junos_lldp_global * Targets model https://github.com/ansible/network/pull/30 * Deprecate junos_lldp module * Run lldp integration test only if protocol supported
This commit is contained in:
parent
0acf7be56a
commit
9efa00e762
21 changed files with 832 additions and 7 deletions
|
@ -14,6 +14,7 @@ CHOICES = [
|
|||
'lag_interfaces',
|
||||
'l2_interfaces',
|
||||
'l3_interfaces',
|
||||
'lldp_global',
|
||||
'lldp_interfaces',
|
||||
'vlans',
|
||||
]
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#
|
||||
# -*- 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 junos_lldp module
|
||||
"""
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class Lldp_globalArgs(object):
|
||||
"""The arg spec for the junos_lldp module
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
pass
|
||||
|
||||
argument_spec = {'config': {'options': {'address': {'type': 'str'},
|
||||
'enable': {'type': 'bool'},
|
||||
'hold_multiplier': {'type': 'int'},
|
||||
'interval': {'type': 'int'},
|
||||
'transmit_delay': {'type': 'int'}},
|
||||
'type': 'dict'},
|
||||
'state': {'choices': ['merged', 'replaced', 'deleted'],
|
||||
'default': 'merged',
|
||||
'type': 'str'}}
|
|
@ -0,0 +1,177 @@
|
|||
#
|
||||
# -*- 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 junos_lldp 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.junos.junos import locked_config, load_config, commit_configuration, discard_changes, tostring
|
||||
from ansible.module_utils.network.common.utils import to_list
|
||||
from ansible.module_utils.network.junos.facts.facts import Facts
|
||||
from ansible.module_utils.network.common.netconf import build_root_xml_node, build_child_xml_node, build_subtree
|
||||
|
||||
|
||||
class Lldp_global(ConfigBase):
|
||||
"""
|
||||
The junos_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}
|
||||
|
||||
existing_lldp_global_facts = self.get_lldp_global_facts()
|
||||
config_xmls = self.set_config(existing_lldp_global_facts)
|
||||
|
||||
with locked_config(self._module):
|
||||
for config_xml in to_list(config_xmls):
|
||||
diff = load_config(self._module, config_xml, [])
|
||||
|
||||
commit = not self._module.check_mode
|
||||
if diff:
|
||||
if commit:
|
||||
commit_configuration(self._module)
|
||||
else:
|
||||
discard_changes(self._module)
|
||||
result['changed'] = True
|
||||
|
||||
if self._module._diff:
|
||||
result['diff'] = {'prepared': diff}
|
||||
|
||||
result['xml'] = config_xmls
|
||||
|
||||
changed_lldp_global_facts = self.get_lldp_global_facts()
|
||||
|
||||
result['before'] = existing_lldp_global_facts
|
||||
if result['changed']:
|
||||
result['after'] = changed_lldp_global_facts
|
||||
|
||||
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']
|
||||
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 list xml configuration necessary to migrate the current configuration
|
||||
to the desired configuration
|
||||
"""
|
||||
root = build_root_xml_node('protocols')
|
||||
state = self._module.params['state']
|
||||
if state == 'deleted':
|
||||
config_xmls = self._state_deleted(want, have)
|
||||
elif state == 'merged':
|
||||
config_xmls = self._state_merged(want, have)
|
||||
elif state == 'replaced':
|
||||
config_xmls = self._state_replaced(want, have)
|
||||
|
||||
for xml in config_xmls:
|
||||
root.append(xml)
|
||||
return tostring(root)
|
||||
|
||||
def _state_replaced(self, want, have):
|
||||
""" The xml configuration generator when state is merged
|
||||
:rtype: A list
|
||||
:returns: the xml configuration necessary to merge the provided into
|
||||
the current configuration
|
||||
"""
|
||||
lldp_xml = []
|
||||
lldp_xml.extend(self._state_deleted(want, have))
|
||||
lldp_xml.extend(self._state_merged(want, have))
|
||||
|
||||
return lldp_xml
|
||||
|
||||
def _state_merged(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 list xml configuration necessary to migrate the current configuration
|
||||
to the desired configuration
|
||||
"""
|
||||
lldp_xml = []
|
||||
|
||||
lldp_root = build_root_xml_node('lldp')
|
||||
if want.get('address'):
|
||||
build_child_xml_node(lldp_root, 'management-address', want['address'])
|
||||
if want.get('interval'):
|
||||
build_child_xml_node(lldp_root, 'advertisement-interval', want['interval'])
|
||||
if want.get('transmit_delay'):
|
||||
build_child_xml_node(lldp_root, 'transmit-delay', want['transmit_delay'])
|
||||
if want.get('hold_multiplier'):
|
||||
build_child_xml_node(lldp_root, 'hold-multiplier', want['hold_multiplier'])
|
||||
enable = want.get('enable')
|
||||
if enable is not None:
|
||||
if enable is False:
|
||||
build_child_xml_node(lldp_root, 'disable')
|
||||
else:
|
||||
build_child_xml_node(lldp_root, 'disable', None, {'delete': 'delete'})
|
||||
else:
|
||||
build_child_xml_node(lldp_root, 'disable', None, {'delete': 'delete'})
|
||||
lldp_xml.append(lldp_root)
|
||||
|
||||
return lldp_xml
|
||||
|
||||
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
|
||||
"""
|
||||
lldp_xml = []
|
||||
|
||||
lldp_root = build_root_xml_node('lldp')
|
||||
build_child_xml_node(lldp_root, 'management-address', None, {'delete': 'delete'})
|
||||
build_child_xml_node(lldp_root, 'advertisement-interval', None, {'delete': 'delete'})
|
||||
build_child_xml_node(lldp_root, 'transmit-delay', None, {'delete': 'delete'})
|
||||
build_child_xml_node(lldp_root, 'hold-multiplier', None, {'delete': 'delete'})
|
||||
build_child_xml_node(lldp_root, 'disable', None, {'delete': 'delete'})
|
||||
lldp_xml.append(lldp_root)
|
||||
return lldp_xml
|
|
@ -17,6 +17,7 @@ from ansible.module_utils.network.junos.facts.lacp.lacp import LacpFacts
|
|||
from ansible.module_utils.network.junos.facts.lacp_interfaces.lacp_interfaces import Lacp_interfacesFacts
|
||||
from ansible.module_utils.network.junos.facts.lag_interfaces.lag_interfaces import Lag_interfacesFacts
|
||||
from ansible.module_utils.network.junos.facts.l3_interfaces.l3_interfaces import L3_interfacesFacts
|
||||
from ansible.module_utils.network.junos.facts.lldp_global.lldp_global import Lldp_globalFacts
|
||||
from ansible.module_utils.network.junos.facts.lldp_interfaces.lldp_interfaces import Lldp_interfacesFacts
|
||||
from ansible.module_utils.network.junos.facts.vlans.vlans import VlansFacts
|
||||
from ansible.module_utils.network.junos.facts.l2_interfaces.l2_interfaces import L2_interfacesFacts
|
||||
|
@ -34,6 +35,7 @@ FACT_RESOURCE_SUBSETS = dict(
|
|||
lag_interfaces=Lag_interfacesFacts,
|
||||
l2_interfaces=L2_interfacesFacts,
|
||||
l3_interfaces=L3_interfacesFacts,
|
||||
lldp_global=Lldp_globalFacts,
|
||||
lldp_interfaces=Lldp_interfacesFacts,
|
||||
vlans=VlansFacts,
|
||||
)
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
#
|
||||
# -*- 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 junos 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
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.module_utils.network.common import utils
|
||||
from ansible.module_utils.network.junos.argspec.lldp_global.lldp_global import Lldp_globalArgs
|
||||
from ansible.module_utils.six import string_types
|
||||
try:
|
||||
from lxml import etree
|
||||
HAS_LXML = True
|
||||
except ImportError:
|
||||
HAS_LXML = False
|
||||
|
||||
|
||||
class Lldp_globalFacts(object):
|
||||
""" The junos 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 interfaces
|
||||
:param connection: the device connection
|
||||
:param data: previously collected configuration as lxml ElementTree root instance
|
||||
or valid xml sting
|
||||
:rtype: dictionary
|
||||
:returns: facts
|
||||
"""
|
||||
if not HAS_LXML:
|
||||
self._module.fail_json(msg='lxml is not installed.')
|
||||
|
||||
if not data:
|
||||
config_filter = """
|
||||
<configuration>
|
||||
<protocols>
|
||||
<lldp>
|
||||
</lldp>
|
||||
</protocols>
|
||||
</configuration>
|
||||
"""
|
||||
data = connection.get_configuration(filter=config_filter)
|
||||
|
||||
if isinstance(data, string_types):
|
||||
data = etree.fromstring(to_bytes(data, errors='surrogate_then_replace'))
|
||||
|
||||
facts = {}
|
||||
config = deepcopy(self.generated_spec)
|
||||
resources = data.xpath('configuration/protocols/lldp')
|
||||
if resources:
|
||||
lldp_root = resources[0]
|
||||
config['address'] = utils.get_xml_conf_arg(lldp_root, 'management-address')
|
||||
config['interval'] = utils.get_xml_conf_arg(lldp_root, 'advertisement-interval')
|
||||
config['transmit_delay'] = utils.get_xml_conf_arg(lldp_root, 'transmit-delay')
|
||||
config['hold_multiplier'] = utils.get_xml_conf_arg(lldp_root, 'hold-multiplier')
|
||||
if utils.get_xml_conf_arg(lldp_root, 'disable', data='tag'):
|
||||
config['enable'] = False
|
||||
|
||||
params = utils.validate_config(self.argument_spec, {'config': utils.remove_empties(config)})
|
||||
|
||||
facts['lldp_global'] = utils.remove_empties(params['config'])
|
||||
ansible_facts['ansible_network_resources'].update(facts)
|
||||
|
||||
return ansible_facts
|
|
@ -9,7 +9,7 @@ __metaclass__ = type
|
|||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'status': ['deprecated'],
|
||||
'supported_by': 'network'}
|
||||
|
||||
|
||||
|
@ -22,6 +22,10 @@ short_description: Manage LLDP configuration on Juniper JUNOS network devices
|
|||
description:
|
||||
- This module provides declarative management of LLDP service
|
||||
on Juniper JUNOS network devices.
|
||||
deprecated:
|
||||
removed_in: "2.13"
|
||||
why: Updated modules released with more functionality
|
||||
alternative: Use M(junos_lldp_global) instead.
|
||||
options:
|
||||
interval:
|
||||
description:
|
|
@ -63,7 +63,7 @@ options:
|
|||
to a given subset. Possible values for this argument include
|
||||
all and the resources like interfaces, vlans etc.
|
||||
Can specify a list of values to include a larger subset.
|
||||
choices: ['all', 'interfaces', 'lacp', 'lacp_interfaces', 'lag_interfaces', 'l2_interfaces', 'l3_interfaces', 'lldp_interfaces', 'vlans']
|
||||
choices: ['all', 'interfaces', 'lacp', 'lacp_interfaces', 'lag_interfaces', 'l2_interfaces', 'l3_interfaces', 'lldp_global', 'lldp_interfaces', 'vlans']
|
||||
required: false
|
||||
version_added: "2.9"
|
||||
requirements:
|
||||
|
|
196
lib/ansible/modules/network/junos/junos_lldp_global.py
Normal file
196
lib/ansible/modules/network/junos/junos_lldp_global.py
Normal file
|
@ -0,0 +1,196 @@
|
|||
#!/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 junos_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: junos_lldp_global
|
||||
version_added: 2.9
|
||||
short_description: Manage link layer discovery protocol (LLDP) attributes on Juniper JUNOS devices.
|
||||
description:
|
||||
- This module manages link layer discovery protocol (LLDP) attributes on Juniper JUNOS devices.
|
||||
author: Ganesh Nalawade (@ganeshrn)
|
||||
options:
|
||||
config:
|
||||
description: The list of link layer discovery protocol attribute configurations
|
||||
type: dict
|
||||
suboptions:
|
||||
enable:
|
||||
description:
|
||||
- This argument is a boolean value to enable or disable LLDP.
|
||||
type: bool
|
||||
interval:
|
||||
description:
|
||||
- Frequency at which LLDP advertisements are sent (in seconds).
|
||||
type: int
|
||||
address:
|
||||
description:
|
||||
- This argument sets the management address from LLDP.
|
||||
type: str
|
||||
transmit_delay:
|
||||
description:
|
||||
- Specify the number of seconds the device waits before sending
|
||||
advertisements to neighbors after a change is made in local system.
|
||||
type: int
|
||||
hold_multiplier:
|
||||
description:
|
||||
- Specify the number of seconds that LLDP information is held before it is
|
||||
discarded. The multiplier value is used in combination with the
|
||||
C(interval) value.
|
||||
type: int
|
||||
state:
|
||||
description:
|
||||
- The state the configuration should be left in.
|
||||
type: str
|
||||
choices:
|
||||
- merged
|
||||
- replaced
|
||||
- deleted
|
||||
default: merged
|
||||
requirements:
|
||||
- ncclient (>=v0.6.4)
|
||||
notes:
|
||||
- This module requires the netconf system service be enabled on
|
||||
the remote device being managed.
|
||||
- Tested against vSRX JUNOS version 18.4R1.
|
||||
- This module works with connection C(netconf). See L(the Junos OS Platform Options,../network/user_guide/platform_junos.html).
|
||||
|
||||
"""
|
||||
EXAMPLES = """
|
||||
# Using merged
|
||||
# Before state:
|
||||
# -------------
|
||||
# user@junos01# # show protocols lldp
|
||||
#
|
||||
- name: Merge provided configuration with device configuration
|
||||
junos_lldp_global:
|
||||
config:
|
||||
interval: 10000
|
||||
address: 10.1.1.1
|
||||
transmit_delay: 400
|
||||
hold_multiplier: 10
|
||||
state: merged
|
||||
|
||||
# After state:
|
||||
# -------------
|
||||
# user@junos01# show protocols lldp
|
||||
# management-address 10.1.1.1;
|
||||
# advertisement-interval 10000;
|
||||
# transmit-delay 400;
|
||||
# hold-multiplier 10;
|
||||
|
||||
# Using replaced
|
||||
# Before state:
|
||||
# -------------
|
||||
# user@junos01# show protocols lldp
|
||||
# management-address 10.1.1.1;
|
||||
# advertisement-interval 10000;
|
||||
# transmit-delay 400;
|
||||
# hold-multiplier 10;
|
||||
|
||||
- name: Replace provided configuration with device configuration
|
||||
junos_lldp_global:
|
||||
config:
|
||||
address: 20.2.2.2
|
||||
hold_multiplier: 30
|
||||
enable: False
|
||||
state: replaced
|
||||
|
||||
# After state:
|
||||
# -------------
|
||||
# user@junos01# show protocols lldp
|
||||
# disable;
|
||||
# management-address 20.2.2.2;
|
||||
# hold-multiplier 30;
|
||||
|
||||
# Using deleted
|
||||
# Before state:
|
||||
# -------------
|
||||
# user@junos01# show protocols lldp
|
||||
# management-address 20.2.2.2;
|
||||
# hold-multiplier 30;
|
||||
|
||||
- name: Delete lldp configuration (this will by default remove all lldp configuration)
|
||||
junos_lldp_global:
|
||||
state: deleted
|
||||
|
||||
# After state:
|
||||
# -------------
|
||||
# user@junos01# # show protocols 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: ['xml 1', 'xml 2', 'xml 3']
|
||||
"""
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.junos.argspec.lldp_global.lldp_global import Lldp_globalArgs
|
||||
from ansible.module_utils.network.junos.config.lldp_global.lldp_global import Lldp_global
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main entry point for module execution
|
||||
:returns: the result form module invocation
|
||||
"""
|
||||
module = AnsibleModule(argument_spec=Lldp_globalArgs.argument_spec,
|
||||
supports_check_mode=True)
|
||||
|
||||
result = Lldp_global(module).execute_module()
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testcase: "[^_].*"
|
||||
test_items: []
|
2
test/integration/targets/junos_lldp_global/meta/main.yml
Normal file
2
test/integration/targets/junos_lldp_global/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_junos_tests
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: netconf.yaml, tags: ['netconf'] }
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
- name: collect all netconf test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/netconf"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
use_regex: true
|
||||
connection: local
|
||||
register: test_cases
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case (connection=netconf)
|
||||
include: "{{ test_case_to_run }} ansible_connection=netconf"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "Start junos_lldp_global deleted remove interface config ansible_connection={{ ansible_connection }}"
|
||||
|
||||
- name: "Setup - remove lldp global config"
|
||||
junos_config:
|
||||
lines:
|
||||
- delete protocols lldp
|
||||
|
||||
- debug:
|
||||
msg: "End junos_lldp_global deleted remove interface config ansible_connection={{ ansible_connection }}"
|
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START junos_lldp_global deleted integration tests on connection={{ ansible_connection }}"
|
||||
|
||||
- name: get supported protocols
|
||||
junos_command:
|
||||
commands: show lldp
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- name: lldp supported
|
||||
set_fact:
|
||||
lldp_supported: True
|
||||
when: not result.failed
|
||||
|
||||
- name: lldp not supported
|
||||
set_fact:
|
||||
lldp_supported: False
|
||||
when: result.failed
|
||||
|
||||
- block:
|
||||
|
||||
- include_tasks: _remove_config.yaml
|
||||
|
||||
- set_fact:
|
||||
expected_deleted_output: []
|
||||
|
||||
- name: Configure initial state for lldp global
|
||||
junos_lldp_global:
|
||||
config:
|
||||
interval: 10000
|
||||
address: 10.1.1.1
|
||||
transmit_delay: 400
|
||||
hold_multiplier: 10
|
||||
state: merged
|
||||
register: result
|
||||
|
||||
- name: Delete the provided configuration from running configuration
|
||||
junos_lldp_global: &deleted
|
||||
config:
|
||||
state: deleted
|
||||
register: result
|
||||
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "{{ result['after'] == {} }}"
|
||||
|
||||
- name: Delete the provided configuration from running configuration (IDEMPOTENT)
|
||||
junos_lldp_global: *deleted
|
||||
register: result
|
||||
|
||||
- name: Assert that the previous task was idempotent
|
||||
assert:
|
||||
that:
|
||||
- "result['changed'] == false"
|
||||
|
||||
always:
|
||||
- include_tasks: _remove_config.yaml
|
||||
when: lldp_supported
|
||||
|
||||
- debug:
|
||||
msg: "END junos_lldp_global deleted integration tests on connection={{ ansible_connection }}"
|
|
@ -0,0 +1,61 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START junos_lldp_global merged integration tests on connection={{ ansible_connection }}"
|
||||
|
||||
- name: get supported protocols
|
||||
junos_command:
|
||||
commands: show lldp
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- name: lldp supported
|
||||
set_fact:
|
||||
lldp_supported: True
|
||||
when: not result.failed
|
||||
|
||||
- name: lldp not supported
|
||||
set_fact:
|
||||
lldp_supported: False
|
||||
when: result.failed
|
||||
|
||||
- block:
|
||||
|
||||
- include_tasks: _remove_config.yaml
|
||||
|
||||
- set_fact:
|
||||
expected_merged_output:
|
||||
- interval: 10000
|
||||
address: 10.1.1.1
|
||||
transmit_delay: 400
|
||||
hold_multiplier: 10
|
||||
|
||||
- name: Merge the provided configuration with the exisiting running configuration
|
||||
junos_lldp_global: &merged
|
||||
config:
|
||||
interval: 10000
|
||||
address: 10.1.1.1
|
||||
transmit_delay: 400
|
||||
hold_multiplier: 10
|
||||
state: merged
|
||||
register: result
|
||||
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "{{ expected_merged_output | symmetric_difference([result['after']]) |length == 0 }}"
|
||||
|
||||
- name: Merge the provided configuration with the existing running configuration (IDEMPOTENT)
|
||||
junos_lldp_global: *merged
|
||||
register: result
|
||||
|
||||
- name: Assert that the previous task was idempotent
|
||||
assert:
|
||||
that:
|
||||
- "result['changed'] == false"
|
||||
|
||||
always:
|
||||
- include_tasks: _remove_config.yaml
|
||||
when: lldp_supported
|
||||
|
||||
- debug:
|
||||
msg: "END junos_lldp_global merged integration tests on connection={{ ansible_connection }}"
|
|
@ -0,0 +1,72 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START junos_lldp_global replaced integration tests on connection={{ ansible_connection }}"
|
||||
|
||||
- name: get supported protocols
|
||||
junos_command:
|
||||
commands: show lldp
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- name: lldp supported
|
||||
set_fact:
|
||||
lldp_supported: True
|
||||
when: not result.failed
|
||||
|
||||
- name: lldp not supported
|
||||
set_fact:
|
||||
lldp_supported: False
|
||||
when: result.failed
|
||||
|
||||
- block:
|
||||
- include_tasks: _remove_config.yaml
|
||||
|
||||
- set_fact:
|
||||
expected_replaced_output:
|
||||
- interval: 20000
|
||||
address: 10.1.1.2
|
||||
transmit_delay: 500
|
||||
hold_multiplier: 5
|
||||
enable: False
|
||||
|
||||
- name: Configure initial state for lldp global
|
||||
junos_lldp_global:
|
||||
config:
|
||||
interval: 10000
|
||||
address: 10.1.1.1
|
||||
transmit_delay: 400
|
||||
hold_multiplier: 10
|
||||
state: merged
|
||||
register: result
|
||||
|
||||
- name: Replace the provided configuration with the exisiting running configuration
|
||||
junos_lldp_global: &replaced
|
||||
config:
|
||||
interval: 20000
|
||||
address: 10.1.1.2
|
||||
transmit_delay: 500
|
||||
hold_multiplier: 5
|
||||
enable: False
|
||||
state: replaced
|
||||
register: result
|
||||
|
||||
- name: Assert the configuration is reflected on host
|
||||
assert:
|
||||
that:
|
||||
- "{{ expected_replaced_output | symmetric_difference([result['after']]) |length == 0 }}"
|
||||
|
||||
- name: Replace the provided configuration with the existing running configuration (IDEMPOTENT)
|
||||
junos_lldp_global: *replaced
|
||||
register: result
|
||||
|
||||
- name: Assert that the previous task was idempotent
|
||||
assert:
|
||||
that:
|
||||
- "result['changed'] == false"
|
||||
|
||||
always:
|
||||
- include_tasks: _remove_config.yaml
|
||||
when: lldp_supported
|
||||
|
||||
- debug:
|
||||
msg: "END junos_lldp_global replaced integration tests on connection={{ ansible_connection }}"
|
|
@ -0,0 +1,79 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START junos_lldp_global round trip integration tests on connection={{ ansible_connection }}"
|
||||
|
||||
- name: get supported protocols
|
||||
junos_command:
|
||||
commands: show lldp
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- name: lldp supported
|
||||
set_fact:
|
||||
lldp_supported: True
|
||||
when: not result.failed
|
||||
|
||||
- name: lldp not supported
|
||||
set_fact:
|
||||
lldp_supported: False
|
||||
when: result.failed
|
||||
|
||||
- block:
|
||||
|
||||
- include_tasks: _remove_config.yaml
|
||||
|
||||
- set_fact:
|
||||
expected_revert_output:
|
||||
- interval: 10000
|
||||
address: 10.1.1.1
|
||||
transmit_delay: 400
|
||||
hold_multiplier: 10
|
||||
|
||||
- name: Apply the provided configuration (base config)
|
||||
junos_lldp_global: &merged
|
||||
config:
|
||||
interval: 10000
|
||||
address: 10.1.1.1
|
||||
transmit_delay: 400
|
||||
hold_multiplier: 10
|
||||
state: merged
|
||||
register: base_config
|
||||
|
||||
- name: Gather interfaces facts
|
||||
junos_facts:
|
||||
gather_subset:
|
||||
- default
|
||||
gather_network_resources:
|
||||
- lldp_global
|
||||
|
||||
- name: Apply the provided configuration (config to be reverted)
|
||||
junos_lldp_global:
|
||||
config:
|
||||
interval: 20000
|
||||
address: 10.1.1.2
|
||||
transmit_delay: 500
|
||||
hold_multiplier: 5
|
||||
enable: False
|
||||
state: replaced
|
||||
register: result
|
||||
|
||||
- name: Assert that changes were applied
|
||||
assert:
|
||||
that: "result['changed'] == true"
|
||||
|
||||
- name: Revert back to base config using facts round trip
|
||||
junos_lldp_global:
|
||||
config: "{{ ansible_facts['network_resources']['lldp_global'] }}"
|
||||
state: replaced
|
||||
register: revert
|
||||
|
||||
- name: Assert that config was reverted
|
||||
assert:
|
||||
that: "{{ expected_revert_output | symmetric_difference([revert['after']]) |length == 0 }}"
|
||||
|
||||
always:
|
||||
- include_tasks: _remove_config.yaml
|
||||
when: lldp_supported
|
||||
|
||||
- debug:
|
||||
msg: "END junos_lldp_global round trip integration tests on connection={{ ansible_connection }}"
|
|
@ -4364,6 +4364,11 @@ lib/ansible/modules/network/junos/_junos_l3_interface.py validate-modules:E326
|
|||
lib/ansible/modules/network/junos/_junos_l3_interface.py validate-modules:E337
|
||||
lib/ansible/modules/network/junos/_junos_l3_interface.py validate-modules:E338
|
||||
lib/ansible/modules/network/junos/_junos_l3_interface.py validate-modules:E340
|
||||
lib/ansible/modules/network/junos/_junos_lldp.py validate-modules:E322
|
||||
lib/ansible/modules/network/junos/_junos_lldp.py validate-modules:E324
|
||||
lib/ansible/modules/network/junos/_junos_lldp.py validate-modules:E326
|
||||
lib/ansible/modules/network/junos/_junos_lldp.py validate-modules:E337
|
||||
lib/ansible/modules/network/junos/_junos_lldp.py validate-modules:E338
|
||||
lib/ansible/modules/network/junos/_junos_lldp_interface.py validate-modules:E322
|
||||
lib/ansible/modules/network/junos/_junos_lldp_interface.py validate-modules:E324
|
||||
lib/ansible/modules/network/junos/_junos_lldp_interface.py validate-modules:E326
|
||||
|
@ -4389,11 +4394,6 @@ lib/ansible/modules/network/junos/junos_facts.py validate-modules:E337
|
|||
lib/ansible/modules/network/junos/junos_facts.py validate-modules:E338
|
||||
lib/ansible/modules/network/junos/junos_interfaces.py validate-modules:E325
|
||||
lib/ansible/modules/network/junos/junos_lag_interfaces.py validate-modules:E338
|
||||
lib/ansible/modules/network/junos/junos_lldp.py validate-modules:E322
|
||||
lib/ansible/modules/network/junos/junos_lldp.py validate-modules:E324
|
||||
lib/ansible/modules/network/junos/junos_lldp.py validate-modules:E326
|
||||
lib/ansible/modules/network/junos/junos_lldp.py validate-modules:E337
|
||||
lib/ansible/modules/network/junos/junos_lldp.py validate-modules:E338
|
||||
lib/ansible/modules/network/junos/junos_logging.py validate-modules:E322
|
||||
lib/ansible/modules/network/junos/junos_logging.py validate-modules:E324
|
||||
lib/ansible/modules/network/junos/junos_logging.py validate-modules:E326
|
||||
|
|
Loading…
Reference in a new issue