X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fcontexts%2Fbase.py;h=e362c6a3d62cd38c8cd8db5c628044c683f3c57f;hb=c1a4f5028f88e7e97e3ae2cc3f8aae6bf67c07b2;hp=9f2b2153711b0b24e0268925587d8eb669ceef86;hpb=61c9612197d9a204cc7efa0a324a2b136886506f;p=yardstick.git diff --git a/yardstick/benchmark/contexts/base.py b/yardstick/benchmark/contexts/base.py index 9f2b21537..e362c6a3d 100644 --- a/yardstick/benchmark/contexts/base.py +++ b/yardstick/benchmark/contexts/base.py @@ -23,7 +23,7 @@ class Context(object): @abc.abstractmethod def init(self, attrs): - "Initiate context." + """Initiate context.""" @staticmethod def get_cls(context_type): @@ -46,26 +46,44 @@ class Context(object): @abc.abstractmethod def undeploy(self): """Undeploy context.""" + self._delete_context() + + def _delete_context(self): + Context.list.remove(self) @abc.abstractmethod def _get_server(self, attr_name): """get server info by name from context """ + @abc.abstractmethod + def _get_network(self, attr_name): + """get network info by name from context + """ + @staticmethod def get_server(attr_name): """lookup server info by name from context attr_name: either a name for a server created by yardstick or a dict with attribute name mapping when using external heat templates """ - server = None - for context in Context.list: - server = context._get_server(attr_name) - if server is not None: - break - - if server is None: + servers = (context._get_server(attr_name) for context in Context.list) + try: + return next(s for s in servers if s) + except StopIteration: raise ValueError("context not found for server '%r'" % attr_name) - return server + @staticmethod + def get_network(attr_name): + """lookup server info by name from context + attr_name: either a name for a server created by yardstick or a dict + with attribute name mapping when using external heat templates + """ + + networks = (context._get_network(attr_name) for context in Context.list) + try: + return next(n for n in networks if n) + except StopIteration: + raise ValueError("context not found for server '%r'" % + attr_name)