From 03fce4f762e161fac47a4401f9bc226d21ed0134 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 19 Jul 2023 12:15:01 -0400 Subject: [PATCH] Adjust sys.path logic in macmap and osimage Ensure the sys.path logic is before attempting the relevant imports. --- confluent_server/confluent/networking/macmap.py | 13 +++++++------ confluent_server/confluent/osimage.py | 14 ++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/confluent_server/confluent/networking/macmap.py b/confluent_server/confluent/networking/macmap.py index a9c6b86a..d1377dbf 100644 --- a/confluent_server/confluent/networking/macmap.py +++ b/confluent_server/confluent/networking/macmap.py @@ -31,7 +31,14 @@ # this module will provide mac to switch and full 'ifName' label # This functionality is restricted to the null tenant +import os +import sys + if __name__ == '__main__': + path = os.path.dirname(os.path.realpath(__file__)) + path = os.path.realpath(os.path.join(path, '..', '..')) + if path.startswith('/opt'): + sys.path.append(path) import confluent.config.configmanager as cfm import confluent.snmputil as snmp @@ -43,8 +50,6 @@ import eventlet.green.select as select import eventlet.green.socket as socket -import os -import sys import confluent.exceptions as exc import confluent.log as log import confluent.messages as msg @@ -690,10 +695,6 @@ def rescan(cfg): if __name__ == '__main__': - path = os.path.dirname(os.path.realpath(__file__)) - path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) - if path.startswith('/opt'): - sys.path.append(path) if len(sys.argv) > 1 and sys.argv[1] == '-o': try: upacker = msgpack.Unpacker(encoding='utf8') diff --git a/confluent_server/confluent/osimage.py b/confluent_server/confluent/osimage.py index c6454235..b1643135 100644 --- a/confluent_server/confluent/osimage.py +++ b/confluent_server/confluent/osimage.py @@ -1,6 +1,4 @@ #!/usr/bin/python -import confluent.exceptions as exc -import confluent.messages as msg import eventlet import eventlet.green.select as select import eventlet.green.subprocess as subprocess @@ -14,6 +12,14 @@ import shutil import sys import time import yaml +if __name__ == '__main__': + path = os.path.dirname(os.path.realpath(__file__)) + path = os.path.realpath(os.path.join(path, '..')) + if path.startswith('/opt'): + sys.path.append(path) + +import confluent.exceptions as exc +import confluent.messages as msg COPY = 1 EXTRACT = 2 @@ -930,10 +936,6 @@ def get_importing_status(importkey): if __name__ == '__main__': os.umask(0o022) - path = os.path.dirname(os.path.realpath(__file__)) - path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) - if path.startswith('/opt'): - sys.path.append(path) if len(sys.argv) > 2: mfd = os.environ.get('CONFLUENT_MEDIAFD', None) sys.exit(import_image(sys.argv[1], callback=printit, backend=True, mfd=mfd))