summaryrefslogtreecommitdiffstats
path: root/yardstick/cmd
diff options
context:
space:
mode:
authorQiLiang <liangqi1@huawei.com>2015-10-21 12:29:53 +0000
committerQiLiang <liangqi1@huawei.com>2015-10-27 03:34:28 +0000
commit2e1094d4aee93180126d3ce86db3cc7df2e87bc5 (patch)
tree221e98fd325ff6fcb4fbbb3e656a3789f3a77342 /yardstick/cmd
parent884926d05f435217c7dac038b3bfbd7e9d05826b (diff)
Heat context code refactor part 2
Heat context code refactor to cater for the evolution of the Yardstick framework. Refactor runner_cfg host/target info handle, as specified at https://etherpad.opnfv.org/p/yardstick_framework step 4. Get general Context info (use Context.get). Before this refactor host and target vm must have the same user name and ssh key, that is not general enough for later extension. test_case.yaml do NOT need to change. JIRA: YARDSTICK-168 Change-Id: I5cfe868f3c6f633214ef550bc9676fe1de0709db Signed-off-by: QiLiang <liangqi1@huawei.com>
Diffstat (limited to 'yardstick/cmd')
-rwxr-xr-xyardstick/cmd/commands/task.py66
1 files changed, 42 insertions, 24 deletions
diff --git a/yardstick/cmd/commands/task.py b/yardstick/cmd/commands/task.py
index 5eb38989a..8db6e77e6 100755
--- a/yardstick/cmd/commands/task.py
+++ b/yardstick/cmd/commands/task.py
@@ -13,7 +13,6 @@ import sys
import os
import yaml
import atexit
-import pkg_resources
import ipaddress
from yardstick.benchmark.contexts.base import Context
@@ -242,42 +241,61 @@ def is_ip_addr(addr):
return False
-def run_one_scenario(scenario_cfg, output_file):
- '''run one scenario using context'''
- key_filename = pkg_resources.resource_filename(
- 'yardstick.resources', 'files/yardstick_key')
+def _is_same_heat_context(host_attr, target_attr):
+ '''check if two servers are in the same heat context
+ host_attr: either a name for a server created by yardstick or a dict
+ with attribute name mapping when using external heat templates
+ target_attr: either a name for a server created by yardstick or a dict
+ with attribute name mapping when using external heat templates
+ '''
+ host = None
+ target = None
+ for context in Context.list:
+ if context.__context_type__ != "Heat":
+ continue
+
+ host = context._get_server(host_attr)
+ if host is None:
+ continue
+
+ target = context._get_server(target_attr)
+ if target is None:
+ return False
+
+ # Both host and target is not None, then they are in the
+ # same heat context.
+ return True
+
+ return False
- # TODO support get multi hosts/vms info
- host = Context.get_server(scenario_cfg["host"])
+def run_one_scenario(scenario_cfg, output_file):
+ '''run one scenario using context'''
runner_cfg = scenario_cfg["runner"]
- runner_cfg['host'] = host.public_ip
- runner_cfg['user'] = host.context.user
- runner_cfg['key_filename'] = key_filename
runner_cfg['output_filename'] = output_file
+ # TODO support get multi hosts/vms info
+ context_cfg = {}
+ context_cfg['host'] = Context.get_server(scenario_cfg["host"])
+
if "target" in scenario_cfg:
if is_ip_addr(scenario_cfg["target"]):
- scenario_cfg["ipaddr"] = scenario_cfg["target"]
+ context_cfg['target'] = {}
+ context_cfg['target']["ipaddr"] = scenario_cfg["target"]
else:
- target = Context.get_server(scenario_cfg["target"])
-
- # get public IP for target server, some scenarios require it
- if target.public_ip:
- runner_cfg['target'] = target.public_ip
-
- # TODO scenario_cfg["ipaddr"] is bad naming
- if host.context != target.context:
- # target is in another context, get its public IP
- scenario_cfg["ipaddr"] = target.public_ip
+ context_cfg['target'] = Context.get_server(scenario_cfg["target"])
+ if _is_same_heat_context(scenario_cfg["host"],
+ scenario_cfg["target"]):
+ context_cfg["target"]["ipaddr"] = \
+ context_cfg["target"]["private_ip"]
else:
- # target is in the same context, get its private IP
- scenario_cfg["ipaddr"] = target.private_ip
+ context_cfg["target"]["ipaddr"] = \
+ context_cfg["target"]["ip"]
runner = base_runner.Runner.get(runner_cfg)
print "Starting runner of type '%s'" % runner_cfg["type"]
- runner.run(scenario_cfg["type"], scenario_cfg)
+ runner.run(scenario_cfg, context_cfg)
return runner