Yardstick framework concurrent support 63/26763/3
authorchenjiankun <chenjiankun1@huawei.com>
Fri, 6 Jan 2017 08:01:53 +0000 (08:01 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Mon, 9 Jan 2017 02:14:26 +0000 (02:14 +0000)
JIRA: YARDSTICK-528

Currently yardstick framework can not support run the same test case at
the same time.
But actually we need to support it.
The reason why framework can't support it is that openstack do not allow
to create stack with the same name.
So I use the task_id to make the stack different.

Change-Id: I9e853793650066dfc56606464f7826f330a1401c
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
yardstick/benchmark/core/task.py

index 397ba00..8fb1177 100644 (file)
@@ -262,7 +262,9 @@ class TaskParser(object):       # pragma: no cover
         else:
             context_cfgs = [{"type": "Dummy"}]
 
+        name_suffix = '-{}'.format(task_id[:8])
         for cfg_attrs in context_cfgs:
+            cfg_attrs['name'] = '{}{}'.format(cfg_attrs['name'], name_suffix)
             context_type = cfg_attrs.get("type", "Heat")
             if "Heat" == context_type and "networks" in cfg_attrs:
                 # bugfix: if there are more than one network,
@@ -270,7 +272,7 @@ class TaskParser(object):       # pragma: no cover
                 # the name of netwrok should follow this rule:
                 # test, test2, test3 ...
                 # sort network with the length of network's name
-                sorted_networks = sorted(cfg_attrs["networks"].keys())
+                sorted_networks = sorted(cfg_attrs["networks"])
                 # config external_network based on env var
                 cfg_attrs["networks"][sorted_networks[0]]["external_network"] \
                     = os.environ.get("EXTERNAL_NETWORK", "net04_ext")
@@ -286,6 +288,13 @@ class TaskParser(object):       # pragma: no cover
             scenario["tc"] = task_name
             scenario["task_id"] = task_id
 
+            change_server_name(scenario, name_suffix)
+
+            try:
+                change_server_name(scenario['nodes'], name_suffix)
+            except KeyError:
+                pass
+
         # TODO we need something better here, a class that represent the file
         return cfg["scenarios"], run_in_parallel, meet_precondition
 
@@ -482,3 +491,21 @@ def check_environment():
             if e.errno != errno.EEXIST:
                 raise
             LOG.debug('OPENRC file not found')
+
+
+def change_server_name(scenario, suffix):
+    try:
+        scenario['host'] += suffix
+    except KeyError:
+        pass
+
+    try:
+        scenario['target'] += suffix
+    except KeyError:
+        pass
+
+    try:
+        key = 'targets'
+        scenario[key] = ['{}{}'.format(a, suffix) for a in scenario[key]]
+    except KeyError:
+        pass