aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/contexts
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-02-13 11:24:20 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-02-16 11:12:10 +0000
commita595d2331df4b85046208c6e13d3933597b7d149 (patch)
treef8b0e2597bf91821bdaa532baa490c00ee74451f /yardstick/benchmark/contexts
parent2c07b32c372594e5d0a936e76baca80ff87993c7 (diff)
Context improvement: add support for configing node environment
JIRA: YARDSTICK-556 Currently we do can not config the node environment before heat create a stack. But in lots of scene, we need to config node environment before heat. So I add support for it. Change-Id: Iac1b74dc780eb40e6ab2c9cf04ed14e2b8f91ca8 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'yardstick/benchmark/contexts')
-rw-r--r--yardstick/benchmark/contexts/node.py82
1 files changed, 76 insertions, 6 deletions
diff --git a/yardstick/benchmark/contexts/node.py b/yardstick/benchmark/contexts/node.py
index c7ed3b3f1..6fa9aa99a 100644
--- a/yardstick/benchmark/contexts/node.py
+++ b/yardstick/benchmark/contexts/node.py
@@ -8,14 +8,18 @@
##############################################################################
from __future__ import absolute_import
-import logging
import errno
+import subprocess
import os
import collections
+import logging
+
import yaml
+import pkg_resources
+from yardstick import ssh
from yardstick.benchmark.contexts.base import Context
-from yardstick.definitions import YARDSTICK_ROOT_PATH
+from yardstick.common.constants import YARDSTICK_ROOT_PATH
LOG = logging.getLogger(__name__)
@@ -32,6 +36,7 @@ class NodeContext(Context):
self.controllers = []
self.computes = []
self.baremetals = []
+ self.env = {}
super(NodeContext, self).__init__()
def read_config_file(self):
@@ -69,13 +74,20 @@ class NodeContext(Context):
LOG.debug("Computes: %r", self.computes)
LOG.debug("BareMetals: %r", self.baremetals)
+ self.env = attrs.get('env', {})
+ LOG.debug("Env: %r", self.env)
+
def deploy(self):
- """don't need to deploy"""
- pass
+ setups = self.env.get('setup', [])
+ for setup in setups:
+ for host, info in setup.items():
+ self._execute_script(host, info)
def undeploy(self):
- """don't need to undeploy"""
- pass
+ teardowns = self.env.get('teardown', [])
+ for teardown in teardowns:
+ for host, info in teardown.items():
+ self._execute_script(host, info)
def _get_server(self, attr_name):
"""lookup server info by name from context
@@ -106,3 +118,61 @@ class NodeContext(Context):
node["name"] = attr_name
return node
+
+ def _execute_script(self, node_name, info):
+ if node_name == 'local':
+ self._execute_local_script(info)
+ else:
+ self._execute_remote_script(node_name, info)
+
+ def _execute_remote_script(self, node_name, info):
+ prefix = self.env.get('prefix', '')
+ script, options = self._get_script(info)
+
+ script_file = pkg_resources.resource_filename(prefix, script)
+
+ self._get_client(node_name)
+ self.client._put_file_shell(script_file, '~/{}'.format(script))
+
+ cmd = 'sudo bash {} {}'.format(script, options)
+ status, stdout, stderr = self.client.execute(cmd)
+ if status:
+ raise RuntimeError(stderr)
+
+ def _execute_local_script(self, info):
+ script, options = self._get_script(info)
+ script = os.path.join(YARDSTICK_ROOT_PATH, script)
+ cmd = ['bash', script, options]
+
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ LOG.debug('\n%s', p.communicate()[0])
+
+ def _get_script(self, info):
+ return info.get('script'), info.get('options', '')
+
+ def _get_client(self, node_name):
+ node = self._get_node_info(node_name.strip())
+
+ if node is None:
+ raise SystemExit('No such node')
+
+ user = node.get('user', 'ubuntu')
+ ssh_port = node.get("ssh_port", ssh.DEFAULT_PORT)
+ ip = node.get('ip')
+ pwd = node.get('password')
+ key_fname = node.get('key_filename', '/root/.ssh/id_rsa')
+
+ if pwd is not None:
+ LOG.debug("Log in via pw, user:%s, host:%s, password:%s",
+ user, ip, pwd)
+ self.client = ssh.SSH(user, ip, password=pwd, port=ssh_port)
+ else:
+ LOG.debug("Log in via key, user:%s, host:%s, key_filename:%s",
+ user, ip, key_fname)
+ self.client = ssh.SSH(user, ip, key_filename=key_fname,
+ port=ssh_port)
+
+ self.client.wait(timeout=600)
+
+ def _get_node_info(self, name):
+ return next((n for n in self.nodes if n['name'].strip() == name))