diff options
author | QiLiang <liangqi1@huawei.com> | 2015-10-21 12:29:53 +0000 |
---|---|---|
committer | QiLiang <liangqi1@huawei.com> | 2015-10-27 03:34:28 +0000 |
commit | 2e1094d4aee93180126d3ce86db3cc7df2e87bc5 (patch) | |
tree | 221e98fd325ff6fcb4fbbb3e656a3789f3a77342 /yardstick/benchmark/contexts | |
parent | 884926d05f435217c7dac038b3bfbd7e9d05826b (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/benchmark/contexts')
-rw-r--r-- | yardstick/benchmark/contexts/base.py | 8 | ||||
-rw-r--r-- | yardstick/benchmark/contexts/heat.py | 23 |
2 files changed, 24 insertions, 7 deletions
diff --git a/yardstick/benchmark/contexts/base.py b/yardstick/benchmark/contexts/base.py index ae860accd..76a828811 100644 --- a/yardstick/benchmark/contexts/base.py +++ b/yardstick/benchmark/contexts/base.py @@ -48,12 +48,12 @@ class Context(object): @abc.abstractmethod def _get_server(self, attr_name): - '''get server object by name from context + '''get server info by name from context ''' @staticmethod def get_server(attr_name): - '''lookup server object by name from context + '''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 ''' @@ -64,7 +64,7 @@ class Context(object): break if server is None: - raise ValueError("context not found for server '%s'" % - attr_name["name"]) + raise ValueError("context not found for server '%r'" % + attr_name) return server diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py index 9cf29981b..7bd430bc5 100644 --- a/yardstick/benchmark/contexts/heat.py +++ b/yardstick/benchmark/contexts/heat.py @@ -8,6 +8,7 @@ ############################################################################## import sys +import pkg_resources from yardstick.benchmark.contexts.base import Context from yardstick.benchmark.contexts.model import Server @@ -195,10 +196,13 @@ class HeatContext(Context): print "Context '%s' undeployed" % self.name def _get_server(self, attr_name): - '''lookup server object by name from context + '''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 ''' + key_filename = pkg_resources.resource_filename( + 'yardstick.resources', 'files/yardstick_key') + if type(attr_name) is dict: cname = attr_name["name"].split(".")[1] if cname != self.name: @@ -216,8 +220,21 @@ class HeatContext(Context): server = Server(attr_name["name"].split(".")[0], self, {}) server.public_ip = public_ip server.private_ip = private_ip - return server else: if attr_name not in self._server_map: return None - return self._server_map[attr_name] + server = self._server_map[attr_name] + + if server is None: + return None + + result = { + "user": server.context.user, + "key_filename": key_filename, + "private_ip": server.private_ip + } + # Target server may only have private_ip + if server.public_ip: + result["ip"] = server.public_ip + + return result |