From 5d167549f36c8c7b7758d242e39a27be05ca33c8 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Tue, 24 May 2022 19:39:38 -0400 Subject: [PATCH] IfcfgUtil: Remediate `connection_seems_active()` for controller For the active bonding/bridge connection, when all the port connection profiles are brought down firstly, then the operstate of the controller device will change into "down" automatically, which denotes missing the carrier for the controller device. However, the connection for the controller device should still be considered as active as long as there is any valid IP address configured. Signed-off-by: Wen Liang --- library/network_connections.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/library/network_connections.py b/library/network_connections.py index 6c11c17..02659cc 100644 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -659,7 +659,7 @@ class IfcfgUtil: text_file.write(h) @classmethod - def connection_seems_active(cls, name): + def connection_seems_active(cls, name, run_env): # we don't know whether a ifcfg file is currently active, # and we also don't know which. # @@ -683,7 +683,25 @@ class IfcfgUtil: return None if i_content.strip() != "up": - return False + # For the active bonding/bridge connection, when all the port connection + # profiles are brought down firstly, then the operstate of the controller + # device will change into "down" automatically, which denotes missing the + # carrier for the controller device. However, the connection for the + # controller device stays active in such a situation. + try: + _unused_, out, _ignored_ = run_env.run_command( + ["ip", "address", "show", content["DEVICE"]], + "utf-8", + ) + except Exception: + return None + if "inet" in out: + if out.count("inet") == 1 and "inet6 fe80" in out: + return False + else: + return True + else: + return False return True @@ -2614,7 +2632,7 @@ class Cmd_initscripts(Cmd): ) return - is_active = IfcfgUtil.connection_seems_active(name) + is_active = IfcfgUtil.connection_seems_active(name, self.run_env) is_modified = self.connection_modified_earlier(idx) force_state_change = self.connection_force_state_change(connection)