diff options
author | chenjiankun <chenjiankun1@huawei.com> | 2017-08-30 02:31:40 +0000 |
---|---|---|
committer | chenjiankun <chenjiankun1@huawei.com> | 2017-09-21 11:01:25 +0000 |
commit | 677779ce5267e1265262fa6ae7584a81583113bc (patch) | |
tree | 26569b148bb2491a55a73a8f116919e34663998b /yardstick/benchmark | |
parent | b00112e33caffee6b6b01402537e68007fdc8cb2 (diff) |
Add service in kubernetes context
JIRA: YARDSTICK-803
Currently kubernetes test case can only run in master node.
We need to support it run in jump server.
So I add service and use nodePort type.
Then we can login the pod using nodePort.
Change-Id: Ia7900d263f1c5323f132435addec27ad10547ef9
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'yardstick/benchmark')
-rw-r--r-- | yardstick/benchmark/contexts/kubernetes.py | 35 | ||||
-rw-r--r-- | yardstick/benchmark/core/task.py | 10 |
2 files changed, 31 insertions, 14 deletions
diff --git a/yardstick/benchmark/contexts/kubernetes.py b/yardstick/benchmark/contexts/kubernetes.py index a39f63137..2334e5076 100644 --- a/yardstick/benchmark/contexts/kubernetes.py +++ b/yardstick/benchmark/contexts/kubernetes.py @@ -54,6 +54,7 @@ class KubernetesContext(Context): LOG.info('Launch containers') self._create_rcs() + self._create_services() time.sleep(1) self.template.get_rc_pods() @@ -63,6 +64,7 @@ class KubernetesContext(Context): self._delete_ssh_key() self._delete_rcs() self._delete_pods() + self._delete_services() super(KubernetesContext, self).undeploy() @@ -80,6 +82,14 @@ class KubernetesContext(Context): return False return True + def _create_services(self): + for obj in self.template.service_objs: + obj.create() + + def _delete_services(self): + for obj in self.template.service_objs: + obj.delete() + def _create_rcs(self): for obj in self.template.k8s_objs: self._create_rc(obj.get_template()) @@ -126,15 +136,22 @@ class KubernetesContext(Context): utils.remove_file(self.public_key_path) def _get_server(self, name): - resp = k8s_utils.get_pod_list() - hosts = ({'name': n.metadata.name, - 'ip': n.status.pod_ip, - 'user': 'root', - 'key_filename': self.key_path, - 'private_ip': n.status.pod_ip} - for n in resp.items if n.metadata.name.startswith(name)) - - return next(hosts, None) + service_name = '{}-service'.format(name) + service = k8s_utils.get_service_by_name(service_name).ports[0] + + host = { + 'name': service.name, + 'ip': self._get_node_ip(), + 'private_ip': k8s_utils.get_pod_by_name(name).status.pod_ip, + 'ssh_port': service.node_port, + 'user': 'root', + 'key_filename': self.key_path, + } + + return host + + def _get_node_ip(self): + return k8s_utils.get_node_list().items[0].status.addresses[0].address def _get_network(self, attr_name): return None diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py index 0b6e3230b..a32e990ff 100644 --- a/yardstick/benchmark/core/task.py +++ b/yardstick/benchmark/core/task.py @@ -333,7 +333,7 @@ class Task(object): # pragma: no cover context_cfg['target'] = {"ipaddr": target} else: context_cfg['target'] = Context.get_server(target) - if self._is_same_heat_context(cfg["host"], target): + if self._is_same_context(cfg["host"], target): context_cfg['target']["ipaddr"] = context_cfg['target']["private_ip"] else: context_cfg['target']["ipaddr"] = context_cfg['target']["ip"] @@ -358,8 +358,8 @@ class Task(object): # pragma: no cover context_cfg['target'] = {} else: context_cfg['target'] = Context.get_server(target) - if self._is_same_heat_context(scenario_cfg["host"], - target): + if self._is_same_context(scenario_cfg["host"], + target): ip_list.append(context_cfg["target"]["private_ip"]) else: ip_list.append(context_cfg["target"]["ip"]) @@ -377,7 +377,7 @@ class Task(object): # pragma: no cover return runner - def _is_same_heat_context(self, host_attr, target_attr): + def _is_same_context(self, 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 @@ -385,7 +385,7 @@ class Task(object): # pragma: no cover with attribute name mapping when using external heat templates """ for context in self.contexts: - if context.__context_type__ != "Heat": + if context.__context_type__ not in {"Heat", "Kubernetes"}: continue host = context._get_server(host_attr) |