Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic-host-services]: Fix import and invalid path #10660

Merged
merged 5 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ sudo cp -f $IMAGE_CONFIGS/bash/bash.bashrc $FILESYSTEM_ROOT/etc/
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install libcairo2-dev libdbus-1-dev libgirepository1.0-dev libsystemd-dev pkg-config

# Mark runtime dependencies as manually installed to avoid them being auto-removed while uninstalling build dependencies
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-mark manual gir1.2-glib-2.0 libdbus-1-3 libgirepository-1.0-1 libsystemd0
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-mark manual gir1.2-glib-2.0 libdbus-1-3 libgirepository-1.0-1 libsystemd0 python3-dbus
ganglyu marked this conversation as resolved.
Show resolved Hide resolved

# Install SONiC host services package
SONIC_HOST_SERVICES_PY3_WHEEL_NAME=$(basename {{sonic_host_services_py3_wheel_path}})
Expand Down
15 changes: 12 additions & 3 deletions src/sonic-host-services/scripts/sonic-host-server
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ import dbus.mainloop.glib

from gi.repository import GObject

def register_modules():
def find_module_path():
"""Find path for host_moduels"""
for path in sys.path:
mod_path = path + '/host_modules'
if os.path.exists(mod_path):
return mod_path
return None

def register_modules(mod_path):
"""Register all host modules"""
mod_path = '/usr/local/lib/python3.7/dist-packages/host_modules'
ganglyu marked this conversation as resolved.
Show resolved Hide resolved
sys.path.append(mod_path)
for mod_file in glob.glob(os.path.join(mod_path, '*.py')):
if os.path.isfile(mod_file) and not mod_file.endswith('__init__.py'):
Expand Down Expand Up @@ -62,7 +69,9 @@ class SignalManager(object):
loop.quit()

sigmgr = SignalManager()
register_modules()
mod_path = find_module_path()
if mod_path is not None:
register_modules(mod_path)

# Only run if we actually have some handlers
if handlers:
Expand Down
1 change: 1 addition & 0 deletions src/sonic-host-services/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
],
install_requires = [
'dbus-python',
'systemd-python',
ganglyu marked this conversation as resolved.
Show resolved Hide resolved
'Jinja2>=2.10',
'PyGObject',
'sonic-py-common'
Expand Down