From d8a4539ef719d6666862a38f0085f689ec29d943 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Wed, 27 Sep 2023 13:14:03 +0200 Subject: [PATCH 1/2] poed: assume no Platform file means no PoE support Instead of loudly complaining about failing to load the PoE platform due to a missing file, treat the absence as no PoE support. Reduces the log error: > Sep 14 14:25:19 localhost systemd[1]: Started DentOS POE Agent. > Sep 14 14:25:19 localhost poed.py[1008]: ALERT: Failed to load PoE platform. err: [Errno 2] No such file or directory: '/opt/poeagent/bin/../platforms/delta/tn48m-dn-r0/poe_platform.py' To just: > Sep 21 13:12:32 localhost systemd[1]: Started DentOS POE Agent. > Sep 21 13:12:32 localhost poed.py[977]: INFO: No PoE platform found, assuming no PoE support. Signed-off-by: Jonas Gorski --- dentos-poe-agent/opt/poeagent/bin/poed.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dentos-poe-agent/opt/poeagent/bin/poed.py b/dentos-poe-agent/opt/poeagent/bin/poed.py index 97f76aa..8598e9d 100755 --- a/dentos-poe-agent/opt/poeagent/bin/poed.py +++ b/dentos-poe-agent/opt/poeagent/bin/poed.py @@ -183,11 +183,14 @@ def platform_src_path(self): def load_poe_plat(self): poe_plat = None - try: - plat_src = imp.load_source("poe_plat", self.platform_src_path()) - poe_plat = plat_src.get_poe_platform() - except Exception as e: - self.log.alert("Failed to load PoE platform. err: %s" % str(e)) + if os.path.exists(self.platform_src_path()): + try: + plat_src = imp.load_source("poe_plat", self.platform_src_path()) + poe_plat = plat_src.get_poe_platform() + except Exception as e: + self.log.alert("Failed to load PoE platform. err: %s" % str(e)) + else: + self.log.info("No PoE platform found, assuming no PoE support.") return poe_plat def is_valid_plat(self, poe_plat): From 89d1dbcab126221b5f26b99c4e5a9e2723632576 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Wed, 27 Sep 2023 13:20:41 +0200 Subject: [PATCH 2/2] poecli: assume no Platform file means no PoE support If there is no PoE platform file, assume this platform does not support PoE instead of passing on the raw error message to the user. Before: > root@localhost:~# poecli > Failed to load poe platform! ([Errno 2] No such file or directory: '/opt/poeagent/bin/../platforms/delta/tn48m-dn-r0/poe_platform.py') After: > root@localhost:~# poecli > This platform does not support PoE. Signed-off-by: Jonas Gorski --- dentos-poe-agent/opt/poeagent/bin/poecli.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dentos-poe-agent/opt/poeagent/bin/poecli.py b/dentos-poe-agent/opt/poeagent/bin/poecli.py index e626297..78a0407 100755 --- a/dentos-poe-agent/opt/poeagent/bin/poecli.py +++ b/dentos-poe-agent/opt/poeagent/bin/poecli.py @@ -430,6 +430,9 @@ def send_ipc_event(self, action=POECLI_SET): def main(argv): try: poecli = PoeCLI() + except FileNotFoundError as e: + print_stderr("This platform does not support PoE.") + os._exit(-10) except Exception as e: print_stderr("Failed to load poe platform! (%s)" % str(e)) os._exit(-9)