Compare commits

...

4 Commits

View File

@@ -29,18 +29,14 @@ import difflib
# Exit codes # Exit codes
# 1 : Config file invalid, it has no sections # 1 : Config file invalid, it has no sections
# 2 : Config file invalid, sections must define at least CONST.CFG_MANDATORY # 2 : Config file invalid, sections must define at least CONST.CFG_MANDATORY
# 3 : Performing a firewalld rules check failed # 3 : No physical network device found at "/sys/class/net"
# 4 : Performing a firewalld rules encountered a FileNotFoundError # 4 : Linux find command exited non-zero trying to find a physical network device at "/sys/class/net"
# 5 : Unable to open firewalld direct rules file for reading # 5 : Unable to open firewalld direct rules file for reading
# 6 : Source and destination are identical when attempting to back up firewalld direct rules file # 6 : Kernel sysfs export for network devices at "/sys/class/net" doesn't exist
# 7 : An option that must have a non-null value is either unset or null # 7 : An option that must have a non-null value is either unset or null
# 8 : Exception while adding a chain XML element to firewalld direct rules # 8 : Exception while adding a chain XML element to firewalld direct rules
# 9 : Unable to open firewalld direct rules file for updating # 9 : Unable to open firewalld direct rules file for updating
# 10: Unable to restart systemd firewalld.service unit # 10: Unable to restart systemd firewalld.service unit
# 11: Unable to add a <rule/> tag to firewalld
# 12: Kernel sysfs export for network devices at "/sys/class/net" doesn't exist
# 13: Linux find command exited non-zero trying to find a physical network device at "/sys/class/net"
# 14: No physical network device found at "/sys/class/net"
class CONST(object): class CONST(object):
@@ -343,23 +339,23 @@ def get_phy_nics() -> list:
f"{cpe.cmd}\n" f"{cpe.cmd}\n"
f"Verbatim command output was:\n" f"Verbatim command output was:\n"
f"{cpe.output.rstrip()}\n" f"{cpe.output.rstrip()}\n"
f"Exiting 13 ...") f"Exiting 4 ...")
sys.exit(13) sys.exit(4)
else: else:
if not phy_nics_find.stdout: if not phy_nics_find.stdout:
log.error(f"No physical network device found at {linux_sysfs_nics_abs!r}.\n" log.error(f"No physical network device found at {linux_sysfs_nics_abs!r}.\n"
f"Command was:\n" f"Command was:\n"
f"{phy_nics_find.args}\n" f"{phy_nics_find.args}\n"
f"Exiting 14 ...") f"Exiting 3 ...")
sys.exit(14) sys.exit(3)
for line in phy_nics_find.stdout.rstrip().split("\n"): for line in phy_nics_find.stdout.rstrip().split("\n"):
log.debug(f"Found physical network device {(phy_nic := os.path.basename(line))!r}") log.debug(f"Found physical network device {(phy_nic := os.path.basename(line))!r}")
phy_nics.append(phy_nic) phy_nics.append(phy_nic)
else: else:
log.error(f"Path {linux_sysfs_nics_abs!r} does not exist. This might not be a Linux-y operating system. " log.error(f"Path {linux_sysfs_nics_abs!r} does not exist. This might not be a Linux-y operating system. "
f"Without that location we'll not be able to separate physical network interfaces from virtual ones. " f"Without that location we'll not be able to separate physical network interfaces from virtual ones. "
f"Exiting 12 ...") f"Exiting 6 ...")
sys.exit(12) sys.exit(6)
log.debug(f"List of identified physical network interfaces: {phy_nics}") log.debug(f"List of identified physical network interfaces: {phy_nics}")
return phy_nics return phy_nics