Skip to content

[action] [PR:3832] [show][config][plugin] add processing of ModuleNotFoundError with log_warning#3992

Merged
mssonicbld merged 1 commit intosonic-net:202505from
mssonicbld:cherry/202505/3832
Jul 22, 2025
Merged

[action] [PR:3832] [show][config][plugin] add processing of ModuleNotFoundError with log_warning#3992
mssonicbld merged 1 commit intosonic-net:202505from
mssonicbld:cherry/202505/3832

Conversation

@mssonicbld
Copy link
Copy Markdown
Collaborator

There is the case of rare situation of race condition when plugin script file is removed right before the stage of its load via cli (e.g. in case of dynamic removing with app extensions). This situation has no impact but generate additional error messages to syslog

What I did

Add separate processing ModuleNotFoundError with log_warning messages to avoid excess ERR printing

How to verify it

It happens very rarely in nature but you can just try to remove plugin script manually right before its loading stage. I used this changes on top of my commit for testing:

diff --git a/utilities_common/util_base.py b/utilities_common/util_base.py
index 95098b7..c808b0a 100644
--- a/utilities_common/util_base.py
+++ b/utilities_common/util_base.py
@@ -2,6 +2,8 @@ import os
 import pkgutil
 import importlib

+import subprocess
+
 from sonic_py_common import logger

 # Constants ====================================================================
@@ -11,6 +13,7 @@ PDDF_SUPPORT_FILE = '/usr/share/sonic/platform/pddf_support'

 log = logger.Logger()

+plugin_path = "/usr/local/lib/python3.11/dist-packages/show/plugins/dhcp-relay.py"

 class UtilHelper(object):
     def __init__(self):
@@ -28,11 +31,15 @@ class UtilHelper(object):
                 continue
             log.log_debug('importing plugin: {}'.format(module_name))
             try:
+                if module_name == "show.plugins.dhcp-relay":
+                    subprocess.run(['mv', plugin_path, '/root/' ])
                 module = importlib.import_module(module_name)

             except ModuleNotFoundError as err:
                 log.log_warning('failed to import plugin {}: {}'.format(module_name, err),
                               also_print_to_console=True)
+                if module_name == "show.plugins.dhcp-relay":
+                    subprocess.run(['mv', '/root/dhcp-relay.py', plugin_path ])
                 continue

             except Exception as err:

…_warning

There is the case of rare situation of race condition when plugin script file is removed right before the stage of its load via cli (e.g. in case of dynamic removing with app extensions). This situation has no impact but generate additional error messages to syslog

#### What I did
Add separate processing ModuleNotFoundError with log_warning messages to avoid excess ERR printing

#### How to verify it
It happens very rarely in nature but you can just try to remove plugin script manually right before its loading stage. I used this changes on top of my commit for testing:
```
diff --git a/utilities_common/util_base.py b/utilities_common/util_base.py
index 95098b7..c808b0a 100644
--- a/utilities_common/util_base.py
+++ b/utilities_common/util_base.py
@@ -2,6 +2,8 @@ import os
 import pkgutil
 import importlib

+import subprocess
+
 from sonic_py_common import logger

 # Constants ====================================================================
@@ -11,6 +13,7 @@ PDDF_SUPPORT_FILE = '/usr/share/sonic/platform/pddf_support'

 log = logger.Logger()

+plugin_path = "/usr/local/lib/python3.11/dist-packages/show/plugins/dhcp-relay.py"

 class UtilHelper(object):
     def __init__(self):
@@ -28,11 +31,15 @@ class UtilHelper(object):
                 continue
             log.log_debug('importing plugin: {}'.format(module_name))
             try:
+                if module_name == "show.plugins.dhcp-relay":
+                    subprocess.run(['mv', plugin_path, '/root/' ])
                 module = importlib.import_module(module_name)

             except ModuleNotFoundError as err:
                 log.log_warning('failed to import plugin {}: {}'.format(module_name, err),
                               also_print_to_console=True)
+                if module_name == "show.plugins.dhcp-relay":
+                    subprocess.run(['mv', '/root/dhcp-relay.py', plugin_path ])
                 continue

             except Exception as err:

```
@mssonicbld
Copy link
Copy Markdown
Collaborator Author

Original PR: #3832

@mssonicbld
Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld mssonicbld merged commit f36ac95 into sonic-net:202505 Jul 22, 2025
7 checks passed
kktheballer pushed a commit to kktheballer/sonic-utilities that referenced this pull request Jan 14, 2026
```<br>* 42b28bb - (HEAD -> 202506, origin/202505) `vnet_route_check.py` should not report VNET routes in APP DB but not in STATE DB and ASIC DB as mismatches (sonic-net#3991) (2025-07-22) [mssonicbld]
* f36ac95 - [show][config][plugin] add processing of ModuleNotFoundError with log_warning (sonic-net#3992) (2025-07-22) [mssonicbld]
* 6a4a8ff - [sonic-package-manager] Save tag that was used to install the application (sonic-net#3975) (2025-07-16) [mssonicbld]
* 54a961f - [SPM] Add support for configuring systemd service Type in package manifests (sonic-net#3974) (2025-07-15) [mssonicbld]
* 0b977d1 - [trim]: Add Packet Trimming Asym DSCP CLI (sonic-net#3971) (2025-07-14) [mssonicbld]
* b51e117 - Add GCU Support for SKU Mellanox-SN4280-C48/O8C40/O8V40 (sonic-net#3965) (2025-07-10) [mssonicbld]
* dbc5be9 - [Arista] Add support for LodogaPrime platform (sonic-net#3966) (2025-07-10) [mssonicbld]<br>```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant