From b431f7a2cfacd199fa5587487f372dc5589f9126 Mon Sep 17 00:00:00 2001 From: "Markin, Sergiy (sm515x)" Date: Fri, 22 Jul 2022 19:12:18 +0000 Subject: [PATCH] [NIC Card Auto-Detect] NIC Card Auto-Detect This patch is an addition to this patchset: https://review.opendev.org/c/airship/drydock/+/850579 It adds more debug messages. Change-Id: I01061934f5584276e461ef7a7f4c7a87c30755af --- python/drydock_provisioner/objects/node.py | 56 ++++++++++++------- .../deckhand_fullsite_nic_autodetect.yaml | 2 +- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/python/drydock_provisioner/objects/node.py b/python/drydock_provisioner/objects/node.py index 1c8383fc..348a4a2c 100644 --- a/python/drydock_provisioner/objects/node.py +++ b/python/drydock_provisioner/objects/node.py @@ -256,44 +256,58 @@ class BaremetalNode(drydock_provisioner.objects.hostprofile.HostProfile): :param address: String value that is used to find the logicalname. It can be PCI address to identify a vendor or a regexp to match multiple vendors. The regexp has to start from regexp: prefix - for example: - regex:0000\\:(19|01)\\:00\\.[0-9]. + regexp:0000\\:(19|01)\\:00\\.[0-9]. :return: String value of the logicalname or the alias_name if logicalname is not found. """ - if address.find("regex:") != -1: - address_regex = address.replace("regex:", "") + if "regexp:" in address: + self.logger.info( + "Regexp: prefix has been detected in address: %s" % + (address)) + address_regexp = address.replace("regexp:", "") nodes = xml_root.findall(".//node") - counter = 0 logicalnames = [] addresses = [] for node in nodes: if 'class' in node.attrib: if node.get('class') == "network": address = node.find('businfo').text.replace("pci@", "") - addresses.append(address) - if re.match(address_regex, address): - counter += 1 + self.logger.debug( + "A network device PCI address found. Address=%s. Checking for regexp %s match..." % + (address, address_regexp)) + if re.match(address_regexp, address): logicalnames.append(node.find('logicalname').text) - if len(logicalnames) > 1: - self.logger.info( - "Multiple nodes found for businfo=%s@%s" % - (bus_type, address_regex)) - if logicalnames[0]: - logicalname = logicalnames[0] - address = addresses[0] - self.logger.debug( - "Logicalname build dict: node_name = %s, alias_name = %s, " - "bus_type = %s, address = %s, to logicalname = %s" % - (self.get_name(), alias_name, bus_type, address, - logicalname)) - return logicalname + addresses.append(address) + self.logger.debug( + "PCI address=%s is matching the regex %s." % + (address, address_regexp)) + else: + self.logger.debug( + "A network device with PCI address=%s does not match the regex %s." % + (address, address_regexp)) + if len(logicalnames) >= 1 and logicalnames[0]: + if len(logicalnames) > 1: + self.logger.info( + "Multiple nodes found for businfo=%s@%s" % + (bus_type, address_regexp)) + for logicalname in reversed(logicalnames[0].split("/")): + address = addresses[0] + self.logger.info( + "Logicalname build dict: node_name = %s, alias_name = %s, " + "bus_type = %s, address = %s, to logicalname = %s" % + (self.get_name(), alias_name, bus_type, address, + logicalname)) + return logicalname else: + self.logger.info( + "No prefix has been detected in address: %s" % + (address)) nodes = xml_root.findall(".//node[businfo='" + bus_type + "@" + address + "'].logicalname") if len(nodes) >= 1 and nodes[0].text: if (len(nodes) > 1): self.logger.info("Multiple nodes found for businfo=%s@%s" % (bus_type, address)) for logicalname in reversed(nodes[0].text.split("/")): - self.logger.debug( + self.logger.info( "Logicalname build dict: node_name = %s, alias_name = %s, " "bus_type = %s, address = %s, to logicalname = %s" % (self.get_name(), alias_name, bus_type, address, diff --git a/python/tests/yaml_samples/deckhand_fullsite_nic_autodetect.yaml b/python/tests/yaml_samples/deckhand_fullsite_nic_autodetect.yaml index d661ef54..8eb8d55d 100644 --- a/python/tests/yaml_samples/deckhand_fullsite_nic_autodetect.yaml +++ b/python/tests/yaml_samples/deckhand_fullsite_nic_autodetect.yaml @@ -411,7 +411,7 @@ data: pxe_interface: 0 device_aliases: prim_nic01: - address: 'regex:0000\:(19|01)\:00\.[0-9]' + address: 'regexp:0000:(19|01):00\.0' # address: '0000:19:00.0' dev_type: 'NetXtreme BCM5720 Gigabit Ethernet Controller or I350 Gigabit Ethernet Controller' bus_type: 'pci'