diff options
30 files changed, 429 insertions, 581 deletions
diff --git a/changelogs/fragments/T7011-lldp-integration-tests.yaml b/changelogs/fragments/T7011-lldp-integration-tests.yaml new file mode 100644 index 0000000..8913866 --- /dev/null +++ b/changelogs/fragments/T7011-lldp-integration-tests.yaml @@ -0,0 +1,9 @@ +--- +breaking_changes: + - if "address" is available, merge will cause it to be added, in contrast to + the previous behavior where it was replaced. When used in replace mode, it + will remove any existing addresses and replace them with the new one. + - civic_address is no longer a valid key (removed prior to 1.3) + +minor_changes: + - lldp_global address is now addresses, with appropriate coercion diff --git a/docs/vyos.vyos.vyos_lldp_global_module.rst b/docs/vyos.vyos.vyos_lldp_global_module.rst index d9e002a..9e8758c 100644 --- a/docs/vyos.vyos.vyos_lldp_global_module.rst +++ b/docs/vyos.vyos.vyos_lldp_global_module.rst @@ -61,7 +61,24 @@ Parameters <td> </td> <td> - <div>This argument defines management-address.</div> + <div>Exactly one management address (exclusive with addresses). Deprecated in favor of addresses. To be removed in 7.0.0.</div> + </td> + </tr> + <tr> + <td class="elbow-placeholder"></td> + <td colspan="1"> + <div class="ansibleOptionAnchor" id="parameter-"></div> + <b>addresses</b> + <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> + <div style="font-size: small"> + <span style="color: purple">list</span> + / <span style="color: purple">elements=string</span> + </div> + </td> + <td> + </td> + <td> + <div>One or more management addresses. The management address is used to identify the management interface of the system. Only addresses connected to the system will be transmitted.</div> </td> </tr> <tr> @@ -196,7 +213,8 @@ Examples - fdp - cdp snmp: enable - address: 192.0.2.11 + addresses: + - 192.0.2.11 state: merged # # @@ -215,7 +233,9 @@ Examples # # after": { # "snmp": "enable" - # "address": "192.0.2.11" + # "addresses": [ + # "192.0.2.11" + # ] # "legacy_protocols": [ # "cdp", # "fdp" @@ -250,7 +270,8 @@ Examples - edp - sonmp - cdp - address: 192.0.2.14 + addresses: + - 192.0.2.14 state: replaced # # @@ -261,7 +282,9 @@ Examples # # "before": { # "snmp": "enable" - # "address": "192.0.2.11" + # "addresses": [ + # "192.0.2.11" + # ] # "legacy_protocols": [ # "cdp", # "fdp" @@ -272,13 +295,16 @@ Examples # "commands": [ # "delete service lldp snmp", # "delete service lldp legacy-protocols fdp", + # "delete service lldp management-address '192.0.2.11'", # "set service lldp management-address '192.0.2.14'", # "set service lldp legacy-protocols edp", # "set service lldp legacy-protocols sonmp" # ] # # "after": { - # "address": "192.0.2.14" + # "addresses": [ + # "192.0.2.14" + # ] # "legacy_protocols": [ # "cdp", # "edp", @@ -319,7 +345,9 @@ Examples # ------------------------ # # "before": { - # "address": "192.0.2.14" + # "addresses": [ + # "192.0.2.14" + # ] # "legacy_protocols": [ # "cdp", # "edp", @@ -451,7 +479,8 @@ Examples - name: Render the commands for provided configuration vyos.vyos.vyos_lldp_global: config: - address: 192.0.2.17 + addresses: + - 192.0.2.17 enable: true legacy_protocols: - cdp @@ -489,7 +518,9 @@ Examples # # # "parsed": { - # "address": "192.0.2.11", + # "addresses": [ + # "192.0.2.11" + # ] # "enable": true, # "legacy_protocols": [ # "cdp", diff --git a/docs/vyos.vyos.vyos_lldp_interfaces_module.rst b/docs/vyos.vyos.vyos_lldp_interfaces_module.rst index 78b0a73..8ace265 100644 --- a/docs/vyos.vyos.vyos_lldp_interfaces_module.rst +++ b/docs/vyos.vyos.vyos_lldp_interfaces_module.rst @@ -29,12 +29,12 @@ Parameters <table border=0 cellpadding=0 class="documentation-table"> <tr> - <th colspan="5">Parameter</th> + <th colspan="4">Parameter</th> <th>Choices/<font color="blue">Defaults</font></th> <th width="100%">Comments</th> </tr> <tr> - <td colspan="5"> + <td colspan="4"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>config</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -51,7 +51,7 @@ Parameters </tr> <tr> <td class="elbow-placeholder"></td> - <td colspan="4"> + <td colspan="3"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>enable</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -71,7 +71,7 @@ Parameters </tr> <tr> <td class="elbow-placeholder"></td> - <td colspan="4"> + <td colspan="3"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>location</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -88,105 +88,8 @@ Parameters <tr> <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> - <td colspan="3"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>civic_based</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">dictionary</span> - </div> - </td> - <td> - </td> - <td> - <div>Civic-based location data.</div> - </td> - </tr> - <tr> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> <td colspan="2"> <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>ca_info</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">list</span> - / <span style="color: purple">elements=dictionary</span> - </div> - </td> - <td> - </td> - <td> - <div>LLDP-MED address info</div> - </td> - </tr> - <tr> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>ca_type</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">integer</span> - / <span style="color: red">required</span> - </div> - </td> - <td> - </td> - <td> - <div>LLDP-MED Civic Address type.</div> - </td> - </tr> - <tr> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td colspan="1"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>ca_value</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - / <span style="color: red">required</span> - </div> - </td> - <td> - </td> - <td> - <div>LLDP-MED Civic Address value.</div> - </td> - </tr> - - <tr> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td colspan="2"> - <div class="ansibleOptionAnchor" id="parameter-"></div> - <b>country_code</b> - <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> - <div style="font-size: small"> - <span style="color: purple">string</span> - / <span style="color: red">required</span> - </div> - </td> - <td> - </td> - <td> - <div>Country Code</div> - </td> - </tr> - - <tr> - <td class="elbow-placeholder"></td> - <td class="elbow-placeholder"></td> - <td colspan="3"> - <div class="ansibleOptionAnchor" id="parameter-"></div> <b>coordinate_based</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> <div style="font-size: small"> @@ -203,7 +106,7 @@ Parameters <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> - <td colspan="2"> + <td colspan="1"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>altitude</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -221,7 +124,7 @@ Parameters <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> - <td colspan="2"> + <td colspan="1"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>datum</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -244,7 +147,7 @@ Parameters <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> - <td colspan="2"> + <td colspan="1"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>latitude</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -263,7 +166,7 @@ Parameters <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> - <td colspan="2"> + <td colspan="1"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>longitude</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -282,7 +185,7 @@ Parameters <tr> <td class="elbow-placeholder"></td> <td class="elbow-placeholder"></td> - <td colspan="3"> + <td colspan="2"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>elin</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -299,7 +202,7 @@ Parameters <tr> <td class="elbow-placeholder"></td> - <td colspan="4"> + <td colspan="3"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>name</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -316,7 +219,7 @@ Parameters </tr> <tr> - <td colspan="5"> + <td colspan="4"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>running_config</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -333,7 +236,7 @@ Parameters </td> </tr> <tr> - <td colspan="5"> + <td colspan="4"> <div class="ansibleOptionAnchor" id="parameter-"></div> <b>state</b> <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> @@ -386,11 +289,7 @@ Examples config: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: coordinate_based: @@ -408,10 +307,7 @@ Examples # before": {} # # "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 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 location elin '0000000911'", # "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'", @@ -437,14 +333,7 @@ Examples # }, # { # "location": { - # "civic_based": { - # "ca_info": [ - # { - # "ca_type": 0, - # "ca_value": "ENGLISH" - # } - # ], - # "country_code": "US" + # "elin": "0000000911" # } # }, # "name": "eth1" @@ -454,8 +343,7 @@ Examples # ------------- # # vyos@vyos:~$ show configuration commands | grep lldp - # 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 eth1 location elin '0000000911' # 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' @@ -468,8 +356,7 @@ Examples # ------------- # # vyos@vyos:~$ show configuration commands | grep lldp - # 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 eth1 location elin '0000000911' # 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' @@ -482,11 +369,7 @@ Examples config: - name: eth2 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth1 location: coordinate_based: @@ -515,15 +398,7 @@ Examples # }, # { # "location": { - # "civic_based": { - # "ca_info": [ - # { - # "ca_type": 0, - # "ca_value": "ENGLISH" - # } - # ], - # "country_code": "US" - # } + # "elin": "0000000911" # }, # "name": "eth1" # } @@ -532,8 +407,7 @@ Examples # "commands": [ # "delete service lldp interface eth2 location", # "set service lldp interface eth2 'disable'", - # "set service lldp interface eth2 location civic-based country-code 'US'", - # "set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH'", + # "set service lldp interface eth2 location elin '0000000911'", # "delete service lldp interface eth1 location", # "set service lldp interface eth1 'disable'", # "set service lldp interface eth1 location coordinate-based latitude '33.524449N'", @@ -544,15 +418,7 @@ Examples # # "after": { # "location": { - # "civic_based": { - # "ca_info": [ - # { - # "ca_type": 0, - # "ca_value": "ENGLISH" - # } - # ], - # "country_code": "US" - # } + # "elin": "0000000911" # }, # "name": "eth2" # }, @@ -578,8 +444,7 @@ Examples # set service lldp interface eth1 location coordinate-based latitude '33.524449N' # set service lldp interface eth1 location coordinate-based longitude '222.267255W' # set service lldp interface eth2 'disable' - # set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH' - # set service lldp interface eth2 location civic-based country-code 'US' + # set service lldp interface eth2 location elin '0000000911' # Using overridden @@ -594,8 +459,7 @@ Examples # set service lldp interface eth1 location coordinate-based latitude '33.524449N' # set service lldp interface eth1 location coordinate-based longitude '222.267255W' # set service lldp interface eth2 'disable' - # set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH' - # set service lldp interface eth2 location civic-based country-code 'US' + # set service lldp interface eth2 location elin '0000000911' # - name: Overrides all device configuration with provided configuration vyos.vyos.vyos_lldp_interfaces: @@ -614,17 +478,7 @@ Examples # "before": [ # { # "enable": false, - # "location": { - # "civic_based": { - # "ca_info": [ - # { - # "ca_type": 0, - # "ca_value": "ENGLISH" - # } - # ], - # "country_code": "US" - # } - # }, + # "elin": "0000000911", # "name": "eth2" # }, # { @@ -708,8 +562,7 @@ Examples # ------------- # # vyos@192# run show configuration commands | grep lldp - # 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 eth1 location elin '0000000911' # 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' @@ -739,15 +592,7 @@ Examples # }, # { # "location": { - # "civic_based": { - # "ca_info": [ - # { - # "ca_type": 0, - # "ca_value": "ENGLISH" - # } - # ], - # "country_code": "US" - # } + # "elin": "0000000911" # }, # "name": "eth1" # } @@ -758,8 +603,7 @@ Examples # ------------- # # vyos@192# run show configuration commands | grep lldp - # 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 eth1 location elin '0000000911' # 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' @@ -774,11 +618,7 @@ Examples config: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: coordinate_based: @@ -796,8 +636,7 @@ Examples # # # "rendered": [ - # "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 location elin '0000000911'", # "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'", @@ -813,8 +652,7 @@ Examples - name: Parsed the commands to provide structured configuration. vyos.vyos.vyos_lldp_interfaces: running_config: - "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 eth1 location elin '0000000911' 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' @@ -841,15 +679,7 @@ Examples # }, # { # "location": { - # "civic_based": { - # "ca_info": [ - # { - # "ca_type": 0, - # "ca_value": "ENGLISH" - # } - # ], - # "country_code": "US" - # } + # "elin": "0000000911" # }, # "name": "eth1" # } diff --git a/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py index 5c33d67..d79de61 100644 --- a/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py +++ b/plugins/module_utils/network/vyos/argspec/lldp_global/lldp_global.py @@ -42,6 +42,10 @@ class Lldp_globalArgs(object): # pylint: disable=R0903 "config": { "options": { "address": {"type": "str"}, + "addresses": { + "elements": "str", + "type": "list", + }, "enable": {"type": "bool"}, "legacy_protocols": { "choices": [ @@ -56,6 +60,7 @@ class Lldp_globalArgs(object): # pylint: disable=R0903 "snmp": {"type": "str"}, }, "type": "dict", + "mutually_exclusive": [["addresses", "address"]], }, "running_config": {"type": "str"}, "state": { diff --git a/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py index 37a6afb..fd6c627 100644 --- a/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py +++ b/plugins/module_utils/network/vyos/argspec/lldp_interfaces/lldp_interfaces.py @@ -45,29 +45,6 @@ class Lldp_interfacesArgs(object): # pylint: disable=R0903 "enable": {"default": True, "type": "bool"}, "location": { "options": { - "civic_based": { - "options": { - "ca_info": { - "elements": "dict", - "options": { - "ca_type": { - "required": True, - "type": "int", - }, - "ca_value": { - "required": True, - "type": "str", - }, - }, - "type": "list", - }, - "country_code": { - "required": True, - "type": "str", - }, - }, - "type": "dict", - }, "coordinate_based": { "options": { "altitude": {"type": "int"}, diff --git a/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py index 1afda78..1dfd25e 100644 --- a/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py +++ b/plugins/module_utils/network/vyos/config/lldp_global/lldp_global.py @@ -42,7 +42,8 @@ class Lldp_global(ConfigBase): "lldp_global", ] - params = ["enable", "address", "snmp", "legacy_protocols"] + # address intentionally omitted since it's coerced to addresses + params = ["enable", "addresses", "snmp", "legacy_protocols"] def __init__(self, module): super(Lldp_global, self).__init__(module) @@ -73,6 +74,12 @@ class Lldp_global(ConfigBase): warnings = list() commands = list() + # fix for new name/type + if self._module.params["config"]: + temp_have_address = self._module.params["config"].pop("address", None) + if temp_have_address: + self._module.params["config"]["addresses"] = [temp_have_address] + if self.state in self.ACTION_STATES: existing_lldp_global_facts = self.get_lldp_global_facts() else: @@ -184,14 +191,19 @@ class Lldp_global(ConfigBase): for item in Lldp_global.params: if item == "legacy_protocols": commands.extend(self._update_lldp_protocols(want, have)) + if item == "addresses": + commands.extend(self._update_management_addresses(want, have)) elif have.get(item) and not want.get(item) and item != "enable": commands.append(Lldp_global.del_cmd + item) elif have: + if have.get("enable"): + commands.append(self._compute_command(remove=True)) + return commands for item in Lldp_global.params: if have.get(item): if item == "legacy_protocols": commands.append(self._compute_command("legacy-protocols", remove=True)) - elif item == "address": + elif item == "addresses": commands.append(self._compute_command("management-address", remove=True)) elif item == "snmp": commands.append(self._compute_command(item, remove=True)) @@ -202,9 +214,17 @@ class Lldp_global(ConfigBase): commands = [] if have: temp_have_legacy_protos = have.pop("legacy_protocols", None) + temp_have_addreses = have.pop("addresses", None) + temp_have_address = have.pop("address", None) + if temp_have_address: + temp_have_addresses = [temp_have_address] else: have = {} temp_want_legacy_protos = want.pop("legacy_protocols", None) + temp_want_addreses = want.pop("addresses", None) + temp_want_address = want.pop("address", None) + if temp_want_address: + temp_want_addresses = [temp_want_address] updates = dict_diff(have, want) @@ -212,16 +232,23 @@ class Lldp_global(ConfigBase): have["legacy_protocols"] = temp_have_legacy_protos if not have and temp_want_legacy_protos: want["legacy_protocols"] = temp_want_legacy_protos + if have and temp_have_addreses: + have["addresses"] = temp_have_addreses + if not have and temp_want_addreses: + want["addresses"] = temp_want_addreses commands.extend(self._add_lldp_protocols(want, have)) + commands.extend(self._add_management_addresses(want, have)) if updates: for key, value in iteritems(updates): - if value: + if value is not None: if key == "enable": - commands.append(self._compute_command()) - elif key == "address": - commands.append(self._compute_command("management-address", str(value))) + if value is False: + commands.append(self._compute_command(remove=True)) + return commands + else: + commands.append(self._compute_command()) elif key == "snmp": if value == "disable": commands.append(self._compute_command(key, remove=True)) @@ -232,8 +259,17 @@ class Lldp_global(ConfigBase): def _add_lldp_protocols(self, want, have): commands = [] diff_members = get_lst_diff_for_dicts(want, have, "legacy_protocols") - for key in diff_members: - commands.append(self._compute_command("legacy-protocols", key)) + if diff_members: + for key in diff_members: + commands.append(self._compute_command("legacy-protocols", key)) + return commands + + def _add_management_addresses(self, want, have): + commands = [] + diff_members = get_lst_diff_for_dicts(want, have, "addresses") + if diff_members: + for key in diff_members: + commands.append(self._compute_command("management-address", key)) return commands def _update_lldp_protocols(self, want_item, have_item): @@ -247,6 +283,17 @@ class Lldp_global(ConfigBase): commands.append(self._compute_command("legacy-protocols", member, remove=True)) return commands + def _update_management_addresses(self, want_item, have_item): + commands = [] + want_addresses = want_item.get("addresses") or [] + have_addresses = have_item.get("addresses") or [] + + members_diff = list_diff_have_only(want_addresses, have_addresses) + if members_diff: + for member in members_diff: + commands.append(self._compute_command("management-address", member, remove=True)) + return commands + def _compute_command(self, key=None, value=None, remove=False): if remove: cmd = "delete service lldp" diff --git a/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py index 53e9aed..2fd6a54 100644 --- a/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py +++ b/plugins/module_utils/network/vyos/config/lldp_interfaces/lldp_interfaces.py @@ -29,7 +29,6 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils import ( is_dict_element_present, key_value_in_dict, - search_dict_tv_in_list, search_obj_in_list, ) @@ -290,31 +289,6 @@ class Lldp_interfaces(ConfigBase): if value: commands.append(self._compute_command(set_cmd + location_type, key, str(value))) - elif want_location_type["civic_based"]: - location_type = "civic-based" - want_dict = want_location_type.get("civic_based") or {} - want_ca = want_dict.get("ca_info") or [] - if is_dict_element_present(have_location_type, "civic_based"): - have_dict = have_location_type.get("civic_based") or {} - have_ca = have_dict.get("ca_info") or [] - if want_dict["country_code"] != have_dict["country_code"]: - commands.append( - self._compute_command( - set_cmd + location_type, - "country-code", - str(want_dict["country_code"]), - ), - ) - else: - commands.append( - self._compute_command( - set_cmd + location_type, - "country-code", - str(want_dict["country_code"]), - ), - ) - commands.extend(self._add_civic_address(name, want_ca, have_ca)) - elif want_location_type["elin"]: location_type = "elin" if is_dict_element_present(have_location_type, "elin"): @@ -354,16 +328,6 @@ class Lldp_interfaces(ConfigBase): else: commands.append(self._compute_command(del_cmd, remove=True)) - elif want_location_type["civic_based"]: - want_dict = want_location_type.get("civic_based") or {} - want_ca = want_dict.get("ca_info") or [] - if is_dict_element_present(have_location_type, "civic_based"): - have_dict = have_location_type.get("civic_based") or {} - have_ca = have_dict.get("ca_info") - commands.extend(self._update_civic_address(name, want_ca, have_ca)) - else: - commands.append(self._compute_command(del_cmd, remove=True)) - else: if is_dict_element_present(have_location_type, "elin"): if want_location_type.get("elin") != have_location_type.get("elin"): @@ -372,39 +336,6 @@ class Lldp_interfaces(ConfigBase): commands.append(self._compute_command(del_cmd, remove=True)) return commands - def _add_civic_address(self, name, want, have): - commands = [] - for item in want: - ca_type = item["ca_type"] - ca_value = item["ca_value"] - obj_in_have = search_dict_tv_in_list(ca_type, ca_value, have, "ca_type", "ca_value") - if not obj_in_have: - commands.append( - self._compute_command( - key=name + " location civic-based ca-type", - attrib=str(ca_type) + " ca-value", - value=ca_value, - ), - ) - return commands - - def _update_civic_address(self, name, want, have): - commands = [] - for item in have: - ca_type = item["ca_type"] - ca_value = item["ca_value"] - in_want = search_dict_tv_in_list(ca_type, ca_value, want, "ca_type", "ca_value") - if not in_want: - commands.append( - self._compute_command( - name, - "location civic-based ca-type", - str(ca_type), - remove=True, - ), - ) - return commands - def _compute_command(self, key, attrib=None, value=None, remove=False): if remove: cmd = "delete service lldp interface " diff --git a/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py b/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py index b2afe59..7a6e9b8 100644 --- a/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py +++ b/plugins/module_utils/network/vyos/facts/lldp_global/lldp_global.py @@ -41,6 +41,9 @@ class Lldp_globalFacts(object): self.generated_spec = utils.generate_dict(facts_argument_spec) + def get_config(self, connection): + return connection.get("show configuration commands | grep lldp") + def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for lldp_global :param connection: the device connection @@ -50,7 +53,7 @@ class Lldp_globalFacts(object): :returns: facts """ if not data: - data = connection.get_config() + data = self.get_config(connection) objs = {} lldp_output = findall(r"^set service lldp (\S+)", data, M) @@ -85,9 +88,11 @@ class Lldp_globalFacts(object): :returns: The generated config """ protocol_conf = "\n".join(filter(lambda x: ("legacy-protocols" in x), conf)) - att_conf = "\n".join(filter(lambda x: ("legacy-protocols" not in x), conf)) - config = self.parse_attribs(["snmp", "address"], att_conf) + att_conf = "\n".join(filter(lambda x: ("snmp" in x), conf)) + addr_conf = "\n".join(filter(lambda x: ("management-address" in x), conf)) + config = self.parse_attribs(["snmp"], att_conf) config["legacy_protocols"] = self.parse_protocols(protocol_conf) + config["addresses"] = self.parse_addresses(addr_conf) return utils.remove_empties(config) def parse_protocols(self, conf): @@ -100,6 +105,16 @@ class Lldp_globalFacts(object): protocol_support.append(protocol.strip("'")) return protocol_support + def parse_addresses(self, conf): + management_addresses = None + if conf: + addresses = findall(r"^.*management-address (.+)", conf, M) + if addresses: + management_addresses = [] + for protocol in addresses: + management_addresses.append(protocol.strip("'")) + return management_addresses + def parse_attribs(self, attribs, conf): config = {} for item in attribs: diff --git a/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py b/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py index 5f439e7..e029b47 100644 --- a/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py +++ b/plugins/module_utils/network/vyos/facts/lldp_interfaces/lldp_interfaces.py @@ -85,7 +85,6 @@ class Lldp_interfacesFacts(object): config = {} location = {} - civic_conf = "\n".join(filter(lambda x: ("civic-based" in x), conf)) elin_conf = "\n".join(filter(lambda x: ("elin" in x), conf)) coordinate_conf = "\n".join(filter(lambda x: ("coordinate-based" in x), conf)) disable = "\n".join(filter(lambda x: ("disable" in x), conf)) @@ -95,15 +94,11 @@ class Lldp_interfacesFacts(object): coordinate_conf, ) elin_based_conf = self.parse_lldp_elin_based(elin_conf) - civic_based_conf = self.parse_lldp_civic_based(civic_conf) if disable: config["enable"] = False if coordinate_conf: location["coordinate_based"] = coordinate_based_conf config["location"] = location - elif civic_based_conf: - location["civic_based"] = civic_based_conf - config["location"] = location elif elin_conf: location["elin"] = elin_based_conf config["location"] = location @@ -123,25 +118,6 @@ class Lldp_interfacesFacts(object): config[item] = None return utils.remove_empties(config) - def parse_lldp_civic_based(self, conf): - civic_based = None - if conf: - civic_info_list = [] - civic_add_list = findall(r"^.*civic-based ca-type (.+)", conf, M) - if civic_add_list: - for civic_add in civic_add_list: - ca = civic_add.split(" ") - c_add = {} - c_add["ca_type"] = int(ca[0].strip("'")) - c_add["ca_value"] = ca[2].strip("'") - civic_info_list.append(c_add) - - country_code = search(r"^.*civic-based country-code (.+)", conf, M) - civic_based = {} - civic_based["ca_info"] = civic_info_list - civic_based["country_code"] = country_code.group(1).strip("'") - return civic_based - def parse_lldp_elin_based(self, conf): elin_based = None if conf: diff --git a/plugins/modules/vyos_lldp_global.py b/plugins/modules/vyos_lldp_global.py index e2f7914..190f451 100644 --- a/plugins/modules/vyos_lldp_global.py +++ b/plugins/modules/vyos_lldp_global.py @@ -60,8 +60,16 @@ options: type: bool address: description: - - This argument defines management-address. + - Exactly one management address (exclusive with addresses). + Deprecated in favor of addresses. To be removed in 7.0.0. type: str + addresses: + description: + - One or more management addresses. The management address is used to identify + the management interface of the system. Only addresses connected to the + system will be transmitted. + type: list + elements: str snmp: description: - This argument enable the SNMP queries to LLDP database. @@ -113,7 +121,8 @@ EXAMPLES = """ - fdp - cdp snmp: enable - address: 192.0.2.11 + addresses: + - 192.0.2.11 state: merged # # @@ -132,7 +141,9 @@ EXAMPLES = """ # # after": { # "snmp": "enable" -# "address": "192.0.2.11" +# "addresses": [ +# "192.0.2.11" +# ] # "legacy_protocols": [ # "cdp", # "fdp" @@ -167,7 +178,8 @@ EXAMPLES = """ - edp - sonmp - cdp - address: 192.0.2.14 + addresses: + - 192.0.2.14 state: replaced # # @@ -178,7 +190,9 @@ EXAMPLES = """ # # "before": { # "snmp": "enable" -# "address": "192.0.2.11" +# "addresses": [ +# "192.0.2.11" +# ] # "legacy_protocols": [ # "cdp", # "fdp" @@ -189,13 +203,16 @@ EXAMPLES = """ # "commands": [ # "delete service lldp snmp", # "delete service lldp legacy-protocols fdp", +# "delete service lldp management-address '192.0.2.11'", # "set service lldp management-address '192.0.2.14'", # "set service lldp legacy-protocols edp", # "set service lldp legacy-protocols sonmp" # ] # # "after": { -# "address": "192.0.2.14" +# "addresses": [ +# "192.0.2.14" +# ] # "legacy_protocols": [ # "cdp", # "edp", @@ -236,7 +253,9 @@ EXAMPLES = """ # ------------------------ # # "before": { -# "address": "192.0.2.14" +# "addresses": [ +# "192.0.2.14" +# ] # "legacy_protocols": [ # "cdp", # "edp", @@ -368,7 +387,8 @@ EXAMPLES = """ - name: Render the commands for provided configuration vyos.vyos.vyos_lldp_global: config: - address: 192.0.2.17 + addresses: + - 192.0.2.17 enable: true legacy_protocols: - cdp @@ -406,7 +426,9 @@ EXAMPLES = """ # # # "parsed": { -# "address": "192.0.2.11", +# "addresses": [ +# "192.0.2.11" +# ] # "enable": true, # "legacy_protocols": [ # "cdp", diff --git a/plugins/modules/vyos_lldp_interfaces.py b/plugins/modules/vyos_lldp_interfaces.py index 14160c7..0a8f892 100644 --- a/plugins/modules/vyos_lldp_interfaces.py +++ b/plugins/modules/vyos_lldp_interfaces.py @@ -70,28 +70,6 @@ options: - LLDP-MED location data. type: dict suboptions: - civic_based: - description: - - Civic-based location data. - type: dict - suboptions: - ca_info: - description: LLDP-MED address info - type: list - elements: dict - suboptions: - ca_type: - description: LLDP-MED Civic Address type. - type: int - required: true - ca_value: - description: LLDP-MED Civic Address value. - type: str - required: true - country_code: - description: Country Code - type: str - required: true coordinate_based: description: - Coordinate-based location. @@ -154,11 +132,7 @@ EXAMPLES = """ config: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: coordinate_based: @@ -176,10 +150,7 @@ EXAMPLES = """ # before": {} # # "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 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 location elin '0000000911'", # "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'", @@ -205,14 +176,7 @@ EXAMPLES = """ # }, # { # "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" +# "elin": "0000000911" # } # }, # "name": "eth1" @@ -222,8 +186,7 @@ EXAMPLES = """ # ------------- # # vyos@vyos:~$ show configuration commands | grep lldp -# 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 eth1 location elin '0000000911' # 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' @@ -236,8 +199,7 @@ EXAMPLES = """ # ------------- # # vyos@vyos:~$ show configuration commands | grep lldp -# 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 eth1 location elin '0000000911' # 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' @@ -250,11 +212,7 @@ EXAMPLES = """ config: - name: eth2 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth1 location: coordinate_based: @@ -283,15 +241,7 @@ EXAMPLES = """ # }, # { # "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" -# } +# "elin": "0000000911" # }, # "name": "eth1" # } @@ -300,8 +250,7 @@ EXAMPLES = """ # "commands": [ # "delete service lldp interface eth2 location", # "set service lldp interface eth2 'disable'", -# "set service lldp interface eth2 location civic-based country-code 'US'", -# "set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH'", +# "set service lldp interface eth2 location elin '0000000911'", # "delete service lldp interface eth1 location", # "set service lldp interface eth1 'disable'", # "set service lldp interface eth1 location coordinate-based latitude '33.524449N'", @@ -312,15 +261,7 @@ EXAMPLES = """ # # "after": { # "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" -# } +# "elin": "0000000911" # }, # "name": "eth2" # }, @@ -346,8 +287,7 @@ EXAMPLES = """ # set service lldp interface eth1 location coordinate-based latitude '33.524449N' # set service lldp interface eth1 location coordinate-based longitude '222.267255W' # set service lldp interface eth2 'disable' -# set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH' -# set service lldp interface eth2 location civic-based country-code 'US' +# set service lldp interface eth2 location elin '0000000911' # Using overridden @@ -362,8 +302,7 @@ EXAMPLES = """ # set service lldp interface eth1 location coordinate-based latitude '33.524449N' # set service lldp interface eth1 location coordinate-based longitude '222.267255W' # set service lldp interface eth2 'disable' -# set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH' -# set service lldp interface eth2 location civic-based country-code 'US' +# set service lldp interface eth2 location elin '0000000911' # - name: Overrides all device configuration with provided configuration vyos.vyos.vyos_lldp_interfaces: @@ -382,17 +321,7 @@ EXAMPLES = """ # "before": [ # { # "enable": false, -# "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" -# } -# }, +# "elin": "0000000911", # "name": "eth2" # }, # { @@ -476,8 +405,7 @@ EXAMPLES = """ # ------------- # # vyos@192# run show configuration commands | grep lldp -# 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 eth1 location elin '0000000911' # 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' @@ -507,15 +435,7 @@ EXAMPLES = """ # }, # { # "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" -# } +# "elin": "0000000911" # }, # "name": "eth1" # } @@ -526,8 +446,7 @@ EXAMPLES = """ # ------------- # # vyos@192# run show configuration commands | grep lldp -# 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 eth1 location elin '0000000911' # 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' @@ -542,11 +461,7 @@ EXAMPLES = """ config: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: coordinate_based: @@ -564,8 +479,7 @@ EXAMPLES = """ # # # "rendered": [ -# "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 location elin '0000000911'", # "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'", @@ -581,8 +495,7 @@ EXAMPLES = """ - name: Parsed the commands to provide structured configuration. vyos.vyos.vyos_lldp_interfaces: running_config: - "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 eth1 location elin '0000000911' 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' @@ -609,15 +522,7 @@ EXAMPLES = """ # }, # { # "location": { -# "civic_based": { -# "ca_info": [ -# { -# "ca_type": 0, -# "ca_value": "ENGLISH" -# } -# ], -# "country_code": "US" -# } +# "elin": "0000000911" # }, # "name": "eth1" # } diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml index 9cf87b8..66c792c 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/deleted.yaml @@ -14,17 +14,17 @@ - name: Assert that the before dicts were correctly generated assert: that: - - "{{ populate == result['before']}}" + - populate == result['before'] - name: Assert that the correct set of commands were generated assert: that: - - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + - deleted['commands'] | symmetric_difference(result['commands']) |length == 0 - name: Assert that the after dicts were correctly generated assert: that: - - "{{ deleted['after'] == result['after']}}" + - deleted['after'] == result['after'] - name: Delete attributes of given interfaces (IDEMPOTENT) register: result @@ -38,6 +38,6 @@ - name: Assert that the before dicts were correctly generated assert: that: - - "{{ deleted['after'] == result['before'] }}" + - deleted['after'] == result['before'] always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/merged.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/merged.yaml index a2e8e6b..915a290 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/merged.yaml @@ -17,17 +17,17 @@ - name: Assert that before dicts were correctly generated assert: - that: "{{ merged['before'] == result['before'] }}" + that: merged['before'] == result['before'] - name: Assert that correct set of commands were generated assert: that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + - merged['commands'] | symmetric_difference(result['commands']) |length == 0 - name: Assert that after dicts was correctly generated assert: that: - - "{{ merged['after'] == result['after'] }}" + - merged['after'] == result['after'] - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) register: result @@ -41,6 +41,6 @@ - name: Assert that before dicts were correctly generated assert: that: - - "{{ merged['after'] == result['before'] }}" + - merged['after'] == result['before'] always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml index c74aa46..ad0f53b 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/replaced.yaml @@ -19,17 +19,17 @@ - name: Assert that correct set of commands were generated assert: that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + - replaced['commands'] | symmetric_difference(result['commands']) |length == 0 - name: Assert that before dicts are correctly generated assert: that: - - "{{ populate == result['before'] }}" + - populate == result['before'] - name: Assert that after dict is correctly generated assert: that: - - "{{ replaced['after'] == result['after'] }}" + - replaced['after'] == result['after'] - name: Replace device configurations of LLDP service with provided configurarions (IDEMPOTENT) register: result @@ -43,6 +43,6 @@ - name: Assert that before dict is correctly generated assert: that: - - "{{ replaced['after'] == result['before'] }}" + - replaced['after'] == result['before'] always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml b/tests/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml index 10fe454..d4ea595 100644 --- a/tests/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_lldp_global/tests/cli/rtt.yaml @@ -35,7 +35,7 @@ - name: Assert that changes were applied assert: - that: "{{ round_trip['after'] == result['after'] }}" + that: round_trip['after'] == result['after'] - name: Revert back to base config using facts round trip register: revert @@ -45,6 +45,6 @@ - name: Assert that config was reverted assert: - that: "{{ base_config['after'] == revert['after'] }}" + that: base_config['after'] == revert['after'] always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_global/vars/main.yaml b/tests/integration/targets/vyos_lldp_global/vars/main.yaml index 622b8e4..dbfe1f3 100644 --- a/tests/integration/targets/vyos_lldp_global/vars/main.yaml +++ b/tests/integration/targets/vyos_lldp_global/vars/main.yaml @@ -1,7 +1,8 @@ --- merged: before: - address: 192.0.2.17 + addresses: + - 192.0.2.17 enable: true legacy_protocols: - cdp @@ -9,13 +10,16 @@ merged: - set service lldp management-address '192.0.2.11' - set service lldp legacy-protocols 'fdp' after: - address: 192.0.2.11 + addresses: + - 192.0.2.17 + - 192.0.2.11 enable: true legacy_protocols: - cdp - fdp populate: - address: 192.0.2.17 + addresses: + - 192.0.2.17 enable: true legacy_protocols: - cdp @@ -24,8 +28,10 @@ replaced: - set service lldp legacy-protocols 'edp' - set service lldp legacy-protocols 'sonmp' - set service lldp management-address '192.0.2.14' + - delete service lldp management-address '192.0.2.17' after: - address: 192.0.2.14 + addresses: + - 192.0.2.14 enable: true legacy_protocols: - cdp @@ -33,7 +39,8 @@ replaced: - sonmp parsed: after: - address: 192.0.2.17 + addresses: + - 192.0.2.17 enable: true legacy_protocols: - fdp @@ -45,13 +52,14 @@ rendered: - set service lldp management-address '192.0.2.17' deleted: commands: - - delete service lldp management-address - - delete service lldp legacy-protocols - after: - enable: true + - delete service lldp + after: [] + round_trip: after: - address: 192.0.2.14 + addresses: + - 192.0.2.11 + - 192.0.2.14 enable: true legacy_protocols: - cdp 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 index 737449c..767daca 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_parsed_config.cfg @@ -1,5 +1,4 @@ -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 eth1 location elin '0000000911' 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' diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml index 5ed9e98..21f8dd2 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml @@ -2,15 +2,12 @@ - ansible.builtin.include_tasks: _remove_config.yaml - name: Setup - vars: - lines: >- - "set service lldp interface eth1\nset service lldp interface eth1 location - civic-based country-code US\nset service lldp interface eth1 location - civic-based ca-type 0 ca-value ENGLISH\nset service lldp interface - eth2\nset service lldp interface eth2 location coordinate-based latitude - 33.524449N\nset service lldp interface eth2 location coordinate-based - altitude 2200\nset service lldp interface eth2 location coordinate-based - datum WGS84\nset service lldp interface eth2 location coordinate-based - longitude 222.267255W\n" ansible.netcommon.cli_config: - config: "{{ lines }}" + config: |- + set service lldp interface eth1 + set service lldp interface eth1 location elin '0000000911' + set service lldp interface eth2 + 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 diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml index c1e3a8c..334b205 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml @@ -1,10 +1,8 @@ --- - name: Setup vars: - lines: >- - "set service lldp interface eth2 - \nset service lldp interface eth2 location civic-based country-code US - \nset service lldp interface eth2 location civic-based ca-type 0 ca-value ENGLISH - \nset service lldp interface eth2 disable" ansible.netcommon.cli_config: - config: "{{ lines }}" + config: |- + set service lldp interface eth2 + set service lldp interface eth2 location elin '0000000911' + set service lldp interface eth2 disable diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml index c8ab352..abd81ed 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml @@ -1,6 +1,6 @@ --- - name: Remove Config - vars: - lines: "delete service lldp interface\ndelete service lldp\n" ansible.netcommon.cli_config: - config: "{{ lines }}" + config: |- + delete service lldp interface + delete service lldp diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml index 7b8e778..17e660b 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/gathered.yaml @@ -14,6 +14,6 @@ - name: Assert that gathered dicts was correctly generated assert: that: - - "{{ populate | symmetric_difference(result['gathered']) |length == 0 }}" + - populate | symmetric_difference(result['gathered']) |length == 0 always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml index ecf7597..4a8d877 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml @@ -11,11 +11,7 @@ config: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: @@ -28,17 +24,17 @@ - name: Assert that before dicts were correctly generated assert: - that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" + that: merged['before'] | symmetric_difference(result['before']) |length == 0 - name: Assert that correct set of commands were generated assert: that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + - merged['commands'] | symmetric_difference(result['commands']) |length == 0 - name: Assert that after dicts was correctly generated assert: that: - - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" + - merged['after'] | symmetric_difference(result['after']) |length == 0 - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) register: result @@ -52,6 +48,6 @@ - name: Assert that before dicts were correctly generated assert: that: - - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" + - merged['after'] | symmetric_difference(result['before']) |length == 0 always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml index 7050481..539b314 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml @@ -19,17 +19,17 @@ - name: Assert that before dicts were correctly generated assert: that: - - "{{ populate_intf | symmetric_difference(result['before']) |length == 0 }}" + - populate_intf | symmetric_difference(result['before']) |length == 0 - name: Assert that correct commands were generated assert: that: - - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + - overridden['commands'] | symmetric_difference(result['commands']) |length == 0 - name: Assert that after dicts were correctly generated assert: that: - - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" + - overridden['after'] | symmetric_difference(result['after']) |length == 0 - name: Overrides all device configuration with provided configurations (IDEMPOTENT) register: result @@ -43,6 +43,6 @@ - name: Assert that before dicts were correctly generated assert: that: - - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" + - overridden['after'] | symmetric_difference(result['before']) |length == 0 always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml index c312934..0e7b4f0 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/parsed.yaml @@ -11,4 +11,4 @@ - name: Assert that config was correctly parsed assert: that: - - "{{ parsed['after'] | symmetric_difference(result['parsed']) |length == 0 }}" + - parsed['after'] | symmetric_difference(result['parsed']) |length == 0 diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml index 3eb2538..1a7966f 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rendered.yaml @@ -11,11 +11,7 @@ config: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: coordinate_based: @@ -28,6 +24,6 @@ - name: Assert that correct set of commands were generated assert: that: - - "{{ rendered['commands'] | symmetric_difference(result['rendered']) |length == 0 }}" + - rendered['commands'] | symmetric_difference(result['rendered']) |length == 0 always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml index e914c99..5fe2164 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml @@ -12,11 +12,7 @@ - name: eth2 enable: false location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth1 enable: false @@ -31,17 +27,17 @@ - name: Assert that correct set of commands were generated assert: that: - - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + - replaced['commands'] | symmetric_difference(result['commands']) |length == 0 - name: Assert that before dicts are correctly generated assert: that: - - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" + - populate | symmetric_difference(result['before']) |length == 0 - name: Assert that after dict is correctly generated assert: that: - - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" + - replaced['after'] | symmetric_difference(result['after']) |length == 0 - name: Replace device configurations of listed LLDP interfaces with provided configurarions (IDEMPOTENT) register: result @@ -55,6 +51,6 @@ - name: Assert that before dict is correctly generated assert: that: - - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" + - replaced['after'] | symmetric_difference(result['before']) |length == 0 always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml index 6cf5d69..6223985 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml @@ -11,11 +11,7 @@ config: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 state: merged - name: Gather lldp_interfaces facts @@ -40,7 +36,7 @@ - name: Assert that changes were applied assert: - that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" + that: round_trip['after'] | symmetric_difference(result['after']) |length == 0 - name: Revert back to base config using facts round trip register: revert @@ -50,6 +46,6 @@ - name: Assert that config was reverted assert: - that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" + that: base_config['after'] | symmetric_difference(revert['after']) |length == 0 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 092f653..ce1567e 100644 --- a/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml +++ b/tests/integration/targets/vyos_lldp_interfaces/vars/main.yaml @@ -2,8 +2,7 @@ merged: before: [] 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 location elin '0000000911' - 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' @@ -13,11 +12,7 @@ merged: after: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: coordinate_based: @@ -28,11 +23,7 @@ merged: populate: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: coordinate_based: @@ -42,8 +33,7 @@ populate: 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 location elin '0000000911' - 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' @@ -54,8 +44,7 @@ replaced: commands: - delete service lldp interface eth2 location - set service lldp interface eth2 'disable' - - set service lldp interface eth2 location civic-based country-code 'US' - - set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH' + - set service lldp interface eth2 location elin '0000000911' - delete service lldp interface eth1 location - set service lldp interface eth1 'disable' - set service lldp interface eth1 location coordinate-based latitude '33.524449N' @@ -66,11 +55,7 @@ replaced: - name: eth2 enable: false location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth1 enable: false location: @@ -83,16 +68,10 @@ populate_intf: - name: eth2 enable: false location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: "0000000911" overridden: commands: - - delete service lldp interface eth2 location - delete service lldp interface eth2 'disable' - - set service lldp interface eth2 location elin '0000000911' after: - name: eth2 location: @@ -101,11 +80,7 @@ parsed: after: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: coordinate_based: @@ -122,11 +97,7 @@ round_trip: after: - name: eth1 location: - civic_based: - country_code: US - ca_info: - - ca_type: 0 - ca_value: ENGLISH + elin: 0000000911 - name: eth2 location: coordinate_based: diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_lldp_global_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_lldp_global_config.cfg new file mode 100644 index 0000000..05b8fa7 --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_lldp_global_config.cfg @@ -0,0 +1,4 @@ +set service lldp management-address '192.0.2.14' +set service lldp management-address 'ff00::1' +set service lldp legacy-protocols 'cdp' +set service lldp legacy-protocols 'fdp' diff --git a/tests/unit/modules/network/vyos/test_vyos_lldp_global.py b/tests/unit/modules/network/vyos/test_vyos_lldp_global.py new file mode 100644 index 0000000..0dc1a8d --- /dev/null +++ b/tests/unit/modules/network/vyos/test_vyos_lldp_global.py @@ -0,0 +1,139 @@ +# (c) 2021 Red Hat Inc. +# +# This file is part of Ansible +# +# 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 <http://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from unittest.mock import patch + +from ansible_collections.vyos.vyos.plugins.modules import vyos_lldp_global +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + +from .vyos_module import TestVyosModule, load_fixture + + +class TestVyosLLDPModule(TestVyosModule): + module = vyos_lldp_global + + def setUp(self): + super(TestVyosLLDPModule, self).setUp() + + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base.get_resource_connection", + ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", + ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + + self.mock_get_config = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.lldp_global.lldp_global.Lldp_globalFacts.get_config", + ) + self.get_config = self.mock_get_config.start() + + def tearDown(self): + super(TestVyosLLDPModule, self).tearDown() + + self.mock_get_resource_connection_config.stop() + self.mock_get_resource_connection_facts.stop() + self.mock_get_config.stop() + + def load_fixtures(self, commands=None, filename=None): + self.get_config.return_value = load_fixture("vyos_lldp_global_config.cfg") + + def test_vyos_lldp_global_merge_enabled(self): + set_module_args(dict(config=dict(enable=True))) + self.execute_module(changed=False) + + def test_vyos_lldp_global_merge_disabled(self): + set_module_args(dict(config=dict(enable=False))) + self.execute_module(changed=True, commands=["delete service lldp"]) + + def test_vyos_lldp_global_merge_addresses(self): + set_module_args( + dict( + config=dict( + enable=True, + addresses=["192.0.0.1"], + ), + ), + ) + self.execute_module( + changed=True, + commands=["set service lldp management-address '192.0.0.1'"], + ) + + def test_vyos_lldp_global_replace_addresses(self): + set_module_args( + dict( + config=dict( + enable=True, + addresses=["192.0.0.1"], + legacy_protocols=["cdp", "fdp"], + ), + state="replaced", + ), + ) + commands = [ + "set service lldp management-address '192.0.0.1'", + "delete service lldp management-address '192.0.2.14'", + "delete service lldp management-address 'ff00::1'", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_lldp_global_replace_protocols(self): + set_module_args( + dict( + config=dict( + enable=True, + addresses=["192.0.2.14", "ff00::1"], + legacy_protocols=["cdp"], + ), + state="replaced", + ), + ) + commands = [ + "delete service lldp legacy-protocols 'fdp'", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_lldp_global_replace_address(self): + set_module_args( + dict( + config=dict( + enable=True, + address="192.0.0.1", + legacy_protocols=["cdp", "fdp"], + ), + state="replaced", + ), + ) + commands = [ + "set service lldp management-address '192.0.0.1'", + "delete service lldp management-address '192.0.2.14'", + "delete service lldp management-address 'ff00::1'", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_lldp_global_delete_all(self): + set_module_args(dict(config=dict(), state="deleted")) + self.execute_module(changed=True, commands=["delete service lldp"]) |