From 5efb64ed2f0c715312bfa27875852d0e5c59f94f Mon Sep 17 00:00:00 2001 From: James Antill Date: Thu, 26 May 2022 14:06:49 -0400 Subject: [PATCH] Auto sync2gitlab import of redfish-finder-0.3-6.el8.src.rpm --- .gitignore | 1 + EMPTY | 1 - hostconfig-dhcp-parse.patch | 28 +++ hostname-null-check.patch | 70 ++++++++ redfish-finder-multi-block.patch | 283 +++++++++++++++++++++++++++++++ redfish-finder.spec | 89 ++++++++++ sources | 1 + 7 files changed, 472 insertions(+), 1 deletion(-) create mode 100644 .gitignore delete mode 100644 EMPTY create mode 100644 hostconfig-dhcp-parse.patch create mode 100644 hostname-null-check.patch create mode 100644 redfish-finder-multi-block.patch create mode 100644 redfish-finder.spec create mode 100644 sources diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71c4e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/redfish-finder-0.3.tar.gz diff --git a/EMPTY b/EMPTY deleted file mode 100644 index 0519ecb..0000000 --- a/EMPTY +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/hostconfig-dhcp-parse.patch b/hostconfig-dhcp-parse.patch new file mode 100644 index 0000000..8d9a412 --- /dev/null +++ b/hostconfig-dhcp-parse.patch @@ -0,0 +1,28 @@ +commit 581327fd45351dd53c06a26517bb7f92e19d8f31 +Author: Charles Rose +Date: Mon Aug 31 17:40:08 2020 -0500 + + fix parsing HostConfig for DHCP + + assigntype.append(AssignType.DHCP) fails for DHCP because + assigntype [] is not set. + + Signed-off-by: Charles Rose + +diff --git a/redfish-finder b/redfish-finder +old mode 100644 +new mode 100755 +index 9a185b3..461eff9 +--- a/redfish-finder ++++ b/redfish-finder +@@ -124,8 +124,8 @@ class HostConfig(): + if cursor == None: + printf("redfish-finder: Unable to parse SMBIOS Host IP Assignment Type") + return None ++ self.assigntype = [] + if cursor.split()[0] == "Static": +- self.assigntype = [] + self.assigntype.append(AssignType.STATIC) + cursor = cursor_consume_next(cursor, "Host IP Address Format: ") + if cursor.split()[0] == "IPv4": + diff --git a/hostname-null-check.patch b/hostname-null-check.patch new file mode 100644 index 0000000..9320f38 --- /dev/null +++ b/hostname-null-check.patch @@ -0,0 +1,70 @@ +commit 74c305647c892b9035332aaf179d11544104caba +Author: Adrian Huang +Date: Thu Jul 11 15:50:40 2019 +0800 + + Fix the exception if hostname is empty + + Redfish Host Interface Specification [1] defines the field "Redfish + Service Hostname" as "Varies", which means it can be empty. Moreover, + this field is not mandatory for well-defined configuration (a valid + string). + + The original design assumes that this field is the non-empty string + shown as follows: + + ------------------------------------------------------------------- + self.hostname = cursor.split()[0] + ------------------------------------------------------------------- + + This leads to the exception, and the "self.hostname" is not configured. + Here is the error output: + + ------------------------------------------------------------------- + redfish-finder: Getting dmidecode info + redfish-finder: Unexpected error parsing ServiceConfig + redfish-finder: Building NetworkManager connection info + redfish-finder: Obtaining OS config info + redfish-finder: Converting SMBIOS Host Config to NetworkManager Connection info + redfish-finder: Applying NetworkManager connection configuration changes + Error: 'enp6s0f3u2u3c2' is not an active connection. + Error: no active connection provided. + Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5) + redfish-finder: Adding redfish host info to OS config + Traceback (most recent call last): + File "./redfish-finder", line 526, in + main() + File "./redfish-finder", line 520, in main + svc.update_redfish_info() + File "./redfish-finder", line 349, in update_redfish_info + if h.find(self.sconf.hostname) != -1: + AttributeError: ServiceConfig instance has no attribute 'hostname' + ------------------------------------------------------------------- + + This patch fixes the above-mentioned issue accordingly. + + [1] https://www.dmtf.org/sites/default/files/standards/documents/DSP0270_1.1.0.pdf + + Signed-off-by: Adrian Huang + +diff --git a/redfish-finder b/redfish-finder +index 429cc42..c2cba75 100755 +--- a/redfish-finder ++++ b/redfish-finder +@@ -235,7 +235,16 @@ class ServiceConfig(): + cursor = cursor_consume_next(cursor, "Redfish Service Vlan: ") + self.vlan = int(cursor.split()[0]) + cursor = cursor_consume_next(cursor, "Redfish Service Hostname: ") +- self.hostname = cursor.split()[0] ++ ++ # ++ # Sanity check: If it contains the consecutive spaces ++ # only, reference to the index '0' will throw an ++ # exception. ++ # ++ if len(cursor.split()) != 0: ++ self.hostname = cursor.split()[0] ++ else: ++ self.hostname = "" + except: + print("redfish-finder: Unexpected error parsing ServiceConfig") + diff --git a/redfish-finder-multi-block.patch b/redfish-finder-multi-block.patch new file mode 100644 index 0000000..41ab1a2 --- /dev/null +++ b/redfish-finder-multi-block.patch @@ -0,0 +1,283 @@ +commit 44853a940a2b3c52395e26a3632e10cc6b5f2e5d +Author: Neil Horman +Date: Thu Jun 27 11:26:48 2019 -0400 + + Add support for multiple type 42 blocks in SMBIOS + + DMTF recently updated their host API specification to allow for multiple + type 42 blocks (in support of ipv4/ipv6 in the constrained space of a + single block). Enhance redfish-finder to parse and merge those blocks + + Signed-off-by: Neil Horman + +diff --git a/redfish-finder b/redfish-finder +index 45c4ea8..429cc42 100755 +--- a/redfish-finder ++++ b/redfish-finder +@@ -1,4 +1,4 @@ +-#!/usr/bin/python3 ++#!/usr/libexec/platform-python + + import sys + import os +@@ -49,6 +49,9 @@ class NetDevice(object): + def getifcname(self): + return self.name + ++ def merge(self, newdev): ++ return self ++ + def __str__(self): + return "Interface: " + self.name + +@@ -112,9 +115,9 @@ class USBNetDevice(NetDevice): + ###################################################### + class HostConfig(): + def __init__(self, cursor): +- self.address = None +- self.mask = None +- self.network = None ++ self.address = [] ++ self.mask = [] ++ self.network = [] + + try: + cursor = cursor_consume_next(cursor, "Host IP Assignment Type: ") +@@ -122,26 +125,30 @@ class HostConfig(): + printf("redfish-finder: Unable to parse SMBIOS Host IP Assignment Type") + return None + if cursor.split()[0] == "Static": +- self.assigntype = AssignType.STATIC ++ self.assigntype = [] ++ self.assigntype.append(AssignType.STATIC) + cursor = cursor_consume_next(cursor, "Host IP Address Format: ") + if cursor.split()[0] == "IPv4": + cursor = cursor_consume_next(cursor, "IPv4 Address: ") + addr = cursor.split()[0] +- self.address = ipaddress.IPv4Address(addr) ++ self.address.append(ipaddress.IPv4Address(addr)) + cursor = cursor_consume_next(cursor, "IPv4 Mask: ") + mask = cursor.split()[0] +- self.mask = ipaddress.IPv4Address(mask) +- self.network = ipaddress.IPv4Network(addr + "/" + mask, strict=False) ++ self.mask.append(ipaddress.IPv4Address(mask)) ++ self.network.append(ipaddress.IPv4Network(addr + "/" + mask, strict=False)) + elif cursor.split()[0] == "IPv6": + cursor = cursor_consume_next(cursor, "IPv6 Address: ") + addr = cursor.split()[0] +- self.address = ipaddress.IPv6Address(addr) ++ self.address.append(ipaddress.IPv6Address(addr)) + cursor = cursor_consume_next(cursor, "IPv6 Mask: ") + mask = cursor.split()[0] +- self.mask = ipaddress.IPv4Address(mask) +- self.network = ipaddress.IPv6Network(addr + "/" + mask, strict=False) ++ self.mask.append(ipaddress.IPv4Address(mask)) ++ self.network.append(ipaddress.IPv6Network(addr + "/" + mask, strict=False)) + elif cursor.split()[0] == "DHCP": +- self.assigntype = AssignType.DHCP ++ self.assigntype.append(AssignType.DHCP) ++ self.address.append(0) ++ self.mask.append(0) ++ self.network.append(0) + else: + # Support the other types later + print("redfish-finder: Unable to parse SMBIOS Host configuaration") +@@ -150,6 +157,13 @@ class HostConfig(): + print("redfish-finder: Unexpected error while parsing HostConfig!") + return None + ++ def merge(self, newconfig): ++ self.assigntype.extend(newconfig.assigntype) ++ self.address.extend(newconfig.address) ++ self.mask.extend(newconfig.mask) ++ self.network.extend(newconfig.network) ++ return self ++ + # + # Using the smbios host config info, set the appropriate + # attributes of the network manager connection object +@@ -157,20 +171,22 @@ class HostConfig(): + def generate_nm_config(self, device, nmcon): + assignmap = { AssignType.STATIC: "manual", AssignType.DHCP: "auto"} + methodp = "ipv4.method" +- if self.assigntype == AssignType.STATIC: +- if self.address.version == 4: +- methodp = "ipv4.method" +- addrp = "ipv4.addresses" +- else: +- methodp = "ipv6.method" +- addrp = "ipv6.addresses" +- try: +- nmcon.update_property(methodp, assignmap[self.assigntype]) +- if self.assigntype == AssignType.STATIC: +- nmcon.update_property(addrp, str(self.address) + "/" + str(self.network.prefixlen)) +- except: +- print("redfish-finder: Error generating nm_config") +- return False ++ for i in range(len(self.assigntype)): ++ assigntype = self.assigntype[i] ++ if assigntype == AssignType.STATIC: ++ if self.address[i].version == 4: ++ methodp = "ipv4.method" ++ addrp = "ipv4.addresses" ++ else: ++ methodp = "ipv6.method" ++ addrp = "ipv6.addresses" ++ try: ++ nmcon.update_property(methodp, assignmap[assigntype]) ++ if assigntype == AssignType.STATIC: ++ nmcon.update_property(addrp, str(self.address[i]) + "/" + str(self.network[i].prefixlen)) ++ except: ++ print("redfish-finder: Error generating nm_config") ++ return False + + return True + +@@ -188,8 +204,8 @@ class HostConfig(): + ###################################################### + class ServiceConfig(): + def __init__(self, cursor): +- self.address = None +- self.mask = None ++ self.address = [] ++ self.mask = [] + try: + cursor = cursor_consume_next(cursor, "Redfish Service IP Discovery Type: ") + if cursor == None: +@@ -200,14 +216,14 @@ class ServiceConfig(): + cursor = cursor_consume_next(cursor, "Redfish Service IP Address Format: ") + if cursor.split()[0] == "IPv4": + cursor = cursor_consume_next(cursor, "IPv4 Redfish Service Address: ") +- self.address = ipaddress.IPv4Address(cursor.split()[0]) ++ self.address.append(ipaddress.IPv4Address(cursor.split()[0])) + cursor = cursor_consume_next(cursor, "IPv4 Redfish Service Mask: ") +- self.mask = ipaddress.IPv4Address(cursor.split()[0]) ++ self.mask.append(ipaddress.IPv4Address(cursor.split()[0])) + elif cursor.split()[0] == "IPv6": + cursor = cursor_consume_next(cursor, "IPv6 Redfish Service Address: ") +- self.address = ipaddress.IPv6Address(unicode(cursor.split()[0], "utf-8")) ++ self.address.append(ipaddress.IPv6Address(unicode(cursor.split()[0], "utf-8"))) + cursor = cursor_consume_next(cursor, "IPv6 Mask: ") +- self.mask = ipaddress.IPv4Address(unicode(cursor.split()[0], "utf-8")) ++ self.mask.append(ipaddress.IPv4Address(unicode(cursor.split()[0], "utf-8"))) + elif cursor.split()[0] == "DHCP": + self.assigntype = AssignType.DHCP + else: +@@ -223,6 +239,11 @@ class ServiceConfig(): + except: + print("redfish-finder: Unexpected error parsing ServiceConfig") + ++ def merge(self, newconfig): ++ self.address.extend(newconfig.address) ++ self.mask.extend(newconfig.mask) ++ return self ++ + def __str__(self): + val = "Service Config(" + AssignType.typestring[self.assigntype] + ")" + if (self.assigntype == AssignType.STATIC): +@@ -236,42 +257,63 @@ class ServiceConfig(): + ###################################################### + class dmiobject(): + def __init__(self, dmioutput): ++ self.device = None ++ self.hostconfig = None ++ self.serviceconfig = None + cursor = dmioutput + # Find the type 42 header, if not found, nothing to do here +- cursor = cursor_consume_next(cursor, "Management Controller Host Interface\n") +- if (cursor == None): +- return None +- cursor = cursor_consume_next(cursor, "Host Interface Type: Network\n") +- if (cursor == None): +- return None ++ cursor = cursor_consume_next(cursor, "Management Controller Host Interface\n") ++ while (cursor != None): ++ if (cursor == None): ++ return None ++ cursor = cursor_consume_next(cursor, "Host Interface Type: Network\n") ++ if (cursor == None): ++ return None + +- # If we get here then we know this is a network interface device +- cursor = cursor_consume_next(cursor, "Device Type: ") +- # The next token should either be: +- # USB +- # PCI/PCIe +- # OEM +- # Unknown +- dtype = cursor.split()[0] +- if (dtype == "USB"): +- self.device = USBNetDevice(cursor) +- +- if self.device == None: +- return None ++ # If we get here then we know this is a network interface device ++ cursor = cursor_consume_next(cursor, "Device Type: ") ++ # The next token should either be: ++ # USB ++ # PCI/PCIe ++ # OEM ++ # Unknown ++ dtype = cursor.split()[0] ++ if (dtype == "USB"): ++ newdev = USBNetDevice(cursor) ++ ++ if newdev == None: ++ return None + +- # Now find the Redfish over IP section +- cursor = cursor_consume_next(cursor, "Protocol ID: 04 (Redfish over IP)\n") +- if (cursor == None): +- print("redfish-finder: Unable to find Redfish Protocol") +- return None ++ if self.device == None: ++ self.device = newdev ++ else: ++ self.device.merge(newdev) + +- self.hostconfig = HostConfig(cursor) +- if self.hostconfig == None: +- return None ++ # Now find the Redfish over IP section ++ cursor = cursor_consume_next(cursor, "Protocol ID: 04 (Redfish over IP)\n") ++ if (cursor == None): ++ print("redfish-finder: Unable to find Redfish Protocol") ++ return None + +- self.serviceconfig = ServiceConfig(cursor) +- if self.serviceconfig == None: +- return None ++ newhostconfig = HostConfig(cursor) ++ if newhostconfig == None: ++ return None ++ ++ if self.hostconfig == None: ++ self.hostconfig = newhostconfig ++ else: ++ self.hostconfig.merge(newhostconfig) ++ ++ serviceconfig = ServiceConfig(cursor) ++ if serviceconfig == None: ++ return None ++ ++ if self.serviceconfig == None: ++ self.serviceconfig = serviceconfig ++ elif self.serviceconfig == None: ++ self.serviceconfig.merge(serviceconfig) ++ ++ cursor = cursor_consume_next(cursor, "Management Controller Host Interface\n") + + + def __str__(self): +@@ -309,7 +351,10 @@ class OSServiceData(): + continue + + # Now add the new entries in +- newentry = str(self.sconf.address) + " " + self.constant_name ++ addresses="" ++ for i in self.sconf.address: ++ addresses = addresses + str(i) + " " ++ newentry = addresses + " " + self.constant_name + newentry = newentry + " " + self.sconf.hostname + self.host_entries.append(newentry) + diff --git a/redfish-finder.spec b/redfish-finder.spec new file mode 100644 index 0000000..98f9632 --- /dev/null +++ b/redfish-finder.spec @@ -0,0 +1,89 @@ +Name: redfish-finder +Version: 0.3 +Release: 6%{?dist} +Summary: Utility for parsing SMBIOS information and configuring canonical BMC access +BuildArch: noarch + +License: GPLv2 +URL: https://github.com/nhorman/redfish-finder +Source0: %url/archive/V%{version}/%{name}-%{version}.tar.gz + +Patch0: redfish-finder-multi-block.patch +Patch1: hostname-null-check.patch +Patch2: hostconfig-dhcp-parse.patch + +%{?systemd_requires} +BuildRequires: systemd + +Requires: python3 NetworkManager dmidecode + +%description +Scans Smbios information for type 42 management controller information, and uses +that to configure the appropriate network interface so that the BMC is +canonically accessible via the host name redfish-localhost + +%prep +%autosetup + + +%build +#noop here + +%install +install -D -p -m 0755 redfish-finder %{buildroot}/%{_bindir}/redfish-finder +install -D -p -m 0644 redfish-finder.1 %{buildroot}/%{_mandir}/man1/redfish-finder.1 +install -D -p -m 0644 ./redfish-finder.service %{buildroot}/%{_unitdir}/redfish-finder.service + +%post +%systemd_post redfish-finder.service + +%preun +%systemd_preun redfish-finder.service + +%postun +%systemd_postun_with_restart redfish-finder.service + + +%files +%doc README.md +%license COPYING +%{_bindir}/redfish-finder +%{_mandir}/man1/redfish-finder.1.* +%{_unitdir}/redfish-finder.service + +%changelog +* Fri Feb 12 2021 Joel Savitz - 0.3-6 +- Fix typo in spec file (bz1951216) + +* Fri Feb 12 2021 Joel Savitz - 0.3-5 +- Fix parsing HostConfig for DHCP (bz1874653) + +* Thu Oct 17 2019 Neil Horman - 0.3-4 +- Fix null hostname check (bz1729343) + +* Mon Jul 01 2019 Neil Horman - 0.3-3 +- Enhance to support multiple type 42 blocks (bz1715914) + +* Fri Apr 26 2019 Neil Horman - 0.3-2 +- Bump release number to test CI gating + +* Mon Apr 01 2019 Neil Horman - 0.3-1 +- Update to latest upstream release (bz1687111) + +* Fri Oct 19 2018 Neil Horman - 0.2-1 +- Update to new upstream release + +* Thu Oct 04 2018 Neil Horman - 0.1-3 +- Fixed missing BuildRequires/Requires +- Fixed missing dist tag +- Fixed Source url + +* Wed Oct 03 2018 Neil Horman - 0.1-2 +- Updated requires for python3 +- Removed unneeded BuildRequires +- Globed the inclusion of man page +- Fixed license file tagging + +* Mon Oct 01 2018 Neil Horman - 0.1-1 +- Initial import + diff --git a/sources b/sources new file mode 100644 index 0000000..e55a73d --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (redfish-finder-0.3.tar.gz) = 7fea1b2702b5b17cccc60229f8397c2bf58c5f684eae22841f925021db6a12ff142317a5df0e7bf415d336c0ae3af48dd740f01b1f0234b578506e3494571d94