From fa724923e1b7aad8e874c8877e8431d37df354c3 Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Thu, 10 Nov 2016 19:14:43 +0100 Subject: [PATCH] netlink: force python to load ifupdown2's nlmanager cpy instead of python-nlmanager Ticket: CM-13453 Reviewed By: Roopa, Nikhil G, Daniel W Testing Done: ifupdown2-tests We had an issue where python-nlmanager and ifupdown2's nlmanager differed When netd starts it loads ifupdown2's addons, so it also tries to do the imports. Since the current working directy is not /usr/share/ifupdown2 but netd directory it won't load ifupdown2's nlmanager first but python-nlmanager if it exists. Here we insert/hardcode /usr/share/ifupdown2/ first in the path to make sure we load the right nlmanager Signed-off-by: Julien Fortin --- ifupdown/netlink.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ifupdown/netlink.py b/ifupdown/netlink.py index d57b1c5..f98704b 100644 --- a/ifupdown/netlink.py +++ b/ifupdown/netlink.py @@ -6,7 +6,6 @@ try: from ifupdownaddons.utilsbase import utilsBase - from nlmanager.nlmanager import NetlinkManager import ifupdown.ifupdownflags as ifupdownflags except ImportError, e: raise ImportError(str(e) + "- required module not found") @@ -17,7 +16,16 @@ class Netlink(utilsBase): def __init__(self, *args, **kargs): utilsBase.__init__(self, *args, **kargs) - self._nlmanager_api = NetlinkManager(extra_debug=False) + try: + import sys + sys.path.insert(0, '/usr/share/ifupdown2/') + from nlmanager.nlmanager import NetlinkManager + # this should force the use of the local nlmanager + self._nlmanager_api = NetlinkManager(extra_debug=False) + except Exception as e: + self.logger.error('cannot initialize ifupdown2\'s ' + 'netlink manager: %s' % str(e)) + raise def get_iface_index(self, ifacename): if ifupdownflags.flags.DRYRUN: return