aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
authorliang gao <jean.gaoliang@huawei.com>2016-06-30 07:27:44 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-06-30 07:27:45 +0000
commit14c7413448e4690fefd0ecad908ec86d6f774d6f (patch)
treeb8859acb0ca21d8c5ff86a51ef801ccf41fe3256 /yardstick
parentbad1fedef56b1dc5f526c29a5bdc508f7bedf1f4 (diff)
parentf8b52ec5839c804be2f866393462f85f530160d9 (diff)
Merge "Add plugin Command"
Diffstat (limited to 'yardstick')
-rw-r--r--yardstick/benchmark/scenarios/compute/plugintest.py54
-rw-r--r--yardstick/cmd/cli.py4
-rw-r--r--yardstick/cmd/commands/plugin.py156
-rw-r--r--yardstick/resources/script/install/sample.bash18
-rw-r--r--yardstick/resources/script/remove/sample.bash16
5 files changed, 247 insertions, 1 deletions
diff --git a/yardstick/benchmark/scenarios/compute/plugintest.py b/yardstick/benchmark/scenarios/compute/plugintest.py
new file mode 100644
index 000000000..e41fb8399
--- /dev/null
+++ b/yardstick/benchmark/scenarios/compute/plugintest.py
@@ -0,0 +1,54 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import logging
+import json
+
+import yardstick.ssh as ssh
+from yardstick.benchmark.scenarios import base
+
+LOG = logging.getLogger(__name__)
+
+
+class PluginTest(base.Scenario):
+ """Sample scenario file for testing sample plugin"""
+ __scenario_type__ = "PluginTest"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.setup_done = False
+
+ def setup(self):
+ """scenario setup"""
+
+ nodes = self.context_cfg['nodes']
+ node = nodes.get('host1', None)
+ host_user = node.get('user', 'ubuntu')
+ host_ip = node.get('ip', None)
+ host_pwd = node.get('password', 'root')
+ LOG.debug("user:%s, host:%s", host_user, host_ip)
+ self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
+ self.client.wait(timeout=600)
+
+ self.setup_done = True
+
+ def run(self, result):
+ """execute the benchmark"""
+
+ if not self.setup_done:
+ self.setup()
+
+ cmd = "sudo bash test.sh"
+
+ LOG.debug("Executing command: %s", cmd)
+ status, stdout, stderr = self.client.execute(cmd)
+ if status:
+ raise RuntimeError(stderr)
+
+ result.update(json.loads(stdout))
diff --git a/yardstick/cmd/cli.py b/yardstick/cmd/cli.py
index a7ba04f57..dd74836cb 100644
--- a/yardstick/cmd/cli.py
+++ b/yardstick/cmd/cli.py
@@ -23,6 +23,7 @@ from yardstick.cmd.commands import task
from yardstick.cmd.commands import runner
from yardstick.cmd.commands import scenario
from yardstick.cmd.commands import testcase
+from yardstick.cmd.commands import plugin
CONF = cfg.CONF
cli_opts = [
@@ -60,7 +61,8 @@ class YardstickCLI():
'task': task.TaskCommands,
'runner': runner.RunnerCommands,
'scenario': scenario.ScenarioCommands,
- 'testcase': testcase.TestcaseCommands
+ 'testcase': testcase.TestcaseCommands,
+ 'plugin': plugin.PluginCommands
}
def __init__(self):
diff --git a/yardstick/cmd/commands/plugin.py b/yardstick/cmd/commands/plugin.py
new file mode 100644
index 000000000..e65c818fa
--- /dev/null
+++ b/yardstick/cmd/commands/plugin.py
@@ -0,0 +1,156 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+""" Handler for yardstick command 'plugin' """
+
+import sys
+import yaml
+import time
+import logging
+import pkg_resources
+import yardstick.ssh as ssh
+
+from yardstick.common.utils import cliargs
+from yardstick.common.task_template import TaskTemplate
+
+LOG = logging.getLogger(__name__)
+
+
+class PluginCommands(object):
+ '''Plugin commands.
+
+ Set of commands to manage plugins.
+ '''
+
+ @cliargs("input_file", type=str, help="path to plugin configuration file",
+ nargs=1)
+ def do_install(self, args):
+ '''Install a plugin.'''
+
+ total_start_time = time.time()
+ parser = PluginParser(args.input_file[0])
+
+ plugins, deployment = parser.parse_plugin()
+ plugin_name = plugins.get("name")
+ print("Installing plugin: %s" % plugin_name)
+
+ self._install_setup(plugin_name, deployment)
+
+ self._run(plugin_name)
+
+ total_end_time = time.time()
+ LOG.info("total finished in %d secs",
+ total_end_time - total_start_time)
+
+ print("Done, exiting")
+
+ def do_remove(self, args):
+ '''Remove a plugin.'''
+
+ total_start_time = time.time()
+ parser = PluginParser(args.input_file[0])
+
+ plugins, deployment = parser.parse_plugin()
+ plugin_name = plugins.get("name")
+ print("Remove plugin: %s" % plugin_name)
+
+ self._remove_setup(plugin_name, deployment)
+
+ self._run(plugin_name)
+
+ total_end_time = time.time()
+ LOG.info("total finished in %d secs",
+ total_end_time - total_start_time)
+
+ print("Done, exiting")
+
+ def _install_setup(self, plugin_name, deployment):
+ '''Deployment environment setup'''
+ target_script = plugin_name + ".bash"
+ self.script = pkg_resources.resource_filename(
+ 'yardstick.resources', 'script/install/' + target_script)
+
+ deployment_user = deployment.get("user")
+ deployment_ip = deployment.get("ip")
+
+ deployment_password = deployment.get("password")
+ LOG.debug("user:%s, host:%s", deployment_user, deployment_ip)
+ self.client = ssh.SSH(deployment_user, deployment_ip,
+ password=deployment_password)
+ self.client.wait(timeout=600)
+
+ # copy script to host
+ cmd = "cat > ~/%s.sh" % plugin_name
+ self.client.run(cmd, stdin=open(self.script, 'rb'))
+
+ def _remove_setup(self, plugin_name, deployment):
+ '''Deployment environment setup'''
+ target_script = plugin_name + ".bash"
+ self.script = pkg_resources.resource_filename(
+ 'yardstick.resources', 'script/remove/' + target_script)
+
+ deployment_user = deployment.get("user")
+ deployment_ip = deployment.get("ip")
+
+ deployment_password = deployment.get("password")
+ LOG.debug("user:%s, host:%s", deployment_user, deployment_ip)
+ self.client = ssh.SSH(deployment_user, deployment_ip,
+ password=deployment_password)
+ self.client.wait(timeout=600)
+
+ # copy script to host
+ cmd = "cat > ~/%s.sh" % plugin_name
+ self.client.run(cmd, stdin=open(self.script, 'rb'))
+
+ def _run(self, plugin_name):
+ '''Run installation script '''
+ cmd = "sudo bash %s" % plugin_name + ".sh"
+
+ LOG.debug("Executing command: %s", cmd)
+ status, stdout, stderr = self.client.execute(cmd)
+
+
+class PluginParser(object):
+ '''Parser for plugin configration files in yaml format'''
+ def __init__(self, path):
+ self.path = path
+
+ def parse_plugin(self):
+ '''parses the plugin file and return a plugins instance
+ and a deployment instance
+ '''
+
+ print "Parsing plugin config:", self.path
+
+ try:
+ kw = {}
+ with open(self.path) as f:
+ try:
+ input_plugin = f.read()
+ rendered_plugin = TaskTemplate.render(input_plugin, **kw)
+ except Exception as e:
+ print(("Failed to render template:\n%(plugin)s\n%(err)s\n")
+ % {"plugin": input_plugin, "err": e})
+ raise e
+ print(("Input plugin is:\n%s\n") % rendered_plugin)
+
+ cfg = yaml.load(rendered_plugin)
+ except IOError as ioerror:
+ sys.exit(ioerror)
+
+ self._check_schema(cfg["schema"], "plugin")
+
+ return cfg["plugins"], cfg["deployment"]
+
+ def _check_schema(self, cfg_schema, schema_type):
+ '''Check if configration file is using the correct schema type'''
+
+ if cfg_schema != "yardstick:" + schema_type + ":0.1":
+ sys.exit("error: file %s has unknown schema %s" % (self.path,
+ cfg_schema))
diff --git a/yardstick/resources/script/install/sample.bash b/yardstick/resources/script/install/sample.bash
new file mode 100644
index 000000000..21eb14680
--- /dev/null
+++ b/yardstick/resources/script/install/sample.bash
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Sample plugin installation script
+
+set -e
+
+cat > test.sh <<EOF
+echo "{\"Test Output\": \"Hello world!\"}"
+EOF
diff --git a/yardstick/resources/script/remove/sample.bash b/yardstick/resources/script/remove/sample.bash
new file mode 100644
index 000000000..15618df2d
--- /dev/null
+++ b/yardstick/resources/script/remove/sample.bash
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Sample plugin remove script
+
+set -e
+
+rm test.sh