Antoni Segura Puimedon has uploaded a new change for review. Change subject: net_configurators: Fix optional configurator importing ......................................................................
net_configurators: Fix optional configurator importing With the arrival of the first truly optional (its dependencies do not need to be installed) configurator, i.e., pyroute_two, a flaw in my getConfiguratorClass was exposed. With this patch, configurators that deem themselves to be optional can raise a vdsm.network.configurators.OptionalConfigurator if some of the dependencies they have are missing and their usage should be prevented Change-Id: Iff38f5e334167e34ba379be164e690f2888f5fea Signed-off-by: Antoni S. Puimedon <[email protected]> --- M vdsm/network/configurators/__init__.py M vdsm/network/configurators/pyroute_two.py M vdsm/vdsm-restore-net-config 3 files changed, 20 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/24/30924/1 diff --git a/vdsm/network/configurators/__init__.py b/vdsm/network/configurators/__init__.py index 2923290..e6d80b5 100644 --- a/vdsm/network/configurators/__init__.py +++ b/vdsm/network/configurators/__init__.py @@ -33,6 +33,12 @@ pass +class OptionalConfigurator(ImportError): + """Configurator modules should raise this exception if they fail to import + their dependencies and are truly optional configurators""" + pass + + class Configurator(object): def __init__(self, configApplier, inRollback=False): self.configApplier = configApplier diff --git a/vdsm/network/configurators/pyroute_two.py b/vdsm/network/configurators/pyroute_two.py index bd7e9b0..5524295 100644 --- a/vdsm/network/configurators/pyroute_two.py +++ b/vdsm/network/configurators/pyroute_two.py @@ -23,10 +23,17 @@ from vdsm import ipwrapper from vdsm.netconfpersistence import RunningConfig from . import libvirt +from . import OptionalConfigurator from .dhclient import DhcpClient -from pyroute2 import IPDB from .iproute2 import Iproute2 +try: + from pyroute2 import IPDB +except ImportError as ie: + oce = OptionalConfigurator('Failed to import the pyroute2_two ' + 'configurator', *ie.args) + raise oce + class PyrouteTwo(Iproute2): def __init__(self, inRollback=False): diff --git a/vdsm/vdsm-restore-net-config b/vdsm/vdsm-restore-net-config index f933547..bdb6b6f 100755 --- a/vdsm/vdsm-restore-net-config +++ b/vdsm/vdsm-restore-net-config @@ -112,7 +112,12 @@ prefix = configurators.__name__ + '.' for importer, moduleName, isPackage in pkgutil.iter_modules( configurators.__path__, prefix): - __import__(moduleName, fromlist="_") + try: + __import__(moduleName, fromlist="_") + except configurators.OptionalConfigurator as oce: + logging.debug('Ignoring optional configurator: %s. Reason: %r', + moduleName, oce.args) + continue for cls in configurators.Configurator.__subclasses__(): yield cls -- To view, visit http://gerrit.ovirt.org/30924 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iff38f5e334167e34ba379be164e690f2888f5fea Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Antoni Segura Puimedon <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
