X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Fvpp_object.py;h=a0b9fe3abf284ac972dcedf4ab32dfdec3da6c04;hb=703908aaf4f80ef6bc78166d46eba3a3b3aa15f7;hp=61a96ec2993cc49b5ae877c988af83b19f1ce1e9;hpb=738844871220f853629504f61c248f0c9402dc77;p=vpp.git diff --git a/test/vpp_object.py b/test/vpp_object.py index 61a96ec2993..a0b9fe3abf2 100644 --- a/test/vpp_object.py +++ b/test/vpp_object.py @@ -1,30 +1,33 @@ """ abstract vpp object and object registry """ -from abc import ABCMeta, abstractmethod +import abc +import six +from six import moves + +@six.add_metaclass(abc.ABCMeta) class VppObject(object): """ Abstract vpp object """ - __metaclass__ = ABCMeta - @abstractmethod + @abc.abstractmethod def add_vpp_config(self): """ Add the configuration for this object to vpp. """ pass - @abstractmethod + @abc.abstractmethod def query_vpp_config(self): """Query the vpp configuration. :return: True if the object is configured""" pass - @abstractmethod + @abc.abstractmethod def remove_vpp_config(self): """ Remove the configuration for this object from vpp. """ pass - @abstractmethod + @abc.abstractmethod def object_id(self): """ Return a unique string representing this object. """ pass @@ -50,6 +53,12 @@ class VppObjectRegistry(object): else: logger.debug("REG: duplicate add, ignoring (%s)" % obj) + def unregister_all(self, logger): + """ Remove all object registrations from registry. """ + logger.debug("REG: removing all object registrations") + self._object_registry = [] + self._object_dict = dict() + def remove_vpp_config(self, logger): """ Remove configuration (if present) from vpp and then remove all objects @@ -60,23 +69,21 @@ class VppObjectRegistry(object): return logger.info("REG: Removing VPP configuration for registered objects") # remove the config in reverse order as there might be dependencies + failed = [] for obj in reversed(self._object_registry): if obj.query_vpp_config(): logger.info("REG: Removing configuration for %s" % obj) obj.remove_vpp_config() + if obj.query_vpp_config(): + failed.append(obj) else: logger.info( "REG: Skipping removal for %s, configuration not present" % obj) - failed = [] - for obj in self._object_registry: - if obj.query_vpp_config(): - failed.append(obj) - self._object_registry = [] - self._object_dict = dict() + self.unregister_all(logger) if failed: logger.error("REG: Couldn't remove configuration for object(s):") for obj in failed: - logger.error(repr(obj)) + logger.error(moves.reprlib.repr(obj)) raise Exception("Couldn't remove configuration for object(s): %s" % (", ".join(str(x) for x in failed)))