aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/contexts/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/benchmark/contexts/base.py')
-rw-r--r--yardstick/benchmark/contexts/base.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/yardstick/benchmark/contexts/base.py b/yardstick/benchmark/contexts/base.py
index e362c6a3d..c9b5b51c9 100644
--- a/yardstick/benchmark/contexts/base.py
+++ b/yardstick/benchmark/contexts/base.py
@@ -18,6 +18,15 @@ class Context(object):
"""Class that represents a context in the logical model"""
list = []
+ @staticmethod
+ def split_name(name, sep='.'):
+ try:
+ name_iter = iter(name.split(sep))
+ except AttributeError:
+ # name is not a string
+ return None, None
+ return next(name_iter), next(name_iter, None)
+
def __init__(self):
Context.list.append(self)
@@ -71,7 +80,23 @@ class Context(object):
try:
return next(s for s in servers if s)
except StopIteration:
- raise ValueError("context not found for server '%r'" %
+ raise ValueError("context not found for server %r" %
+ attr_name)
+
+ @staticmethod
+ def get_context_from_server(attr_name):
+ """lookup context info by name from node config
+ attr_name: either a name of the node created by yardstick or a dict
+ with attribute name mapping when using external templates
+
+ :returns Context instance
+ """
+ servers = ((context._get_server(attr_name), context)
+ for context in Context.list)
+ try:
+ return next(con for s, con in servers if s)
+ except StopIteration:
+ raise ValueError("context not found for name %r" %
attr_name)
@staticmethod
@@ -85,5 +110,5 @@ class Context(object):
try:
return next(n for n in networks if n)
except StopIteration:
- raise ValueError("context not found for server '%r'" %
+ raise ValueError("context not found for server %r" %
attr_name)