aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/cmd/commands/plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/cmd/commands/plugin.py')
-rw-r--r--yardstick/cmd/commands/plugin.py194
1 files changed, 8 insertions, 186 deletions
diff --git a/yardstick/cmd/commands/plugin.py b/yardstick/cmd/commands/plugin.py
index cf6612529..c3e951e8c 100644
--- a/yardstick/cmd/commands/plugin.py
+++ b/yardstick/cmd/commands/plugin.py
@@ -9,18 +9,12 @@
""" Handler for yardstick command 'plugin' """
-import os
-import sys
-import yaml
-import time
-import logging
-import pkg_resources
-import yardstick.ssh as ssh
+from __future__ import print_function
+from __future__ import absolute_import
+from yardstick.benchmark.core.plugin import Plugin
from yardstick.common.utils import cliargs
-from yardstick.common.task_template import TaskTemplate
-
-LOG = logging.getLogger(__name__)
+from yardstick.cmd.commands import change_osloobj_to_paras
class PluginCommands(object):
@@ -33,184 +27,12 @@ class PluginCommands(object):
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)
-
- LOG.info("Executing _install_setup()")
- self._install_setup(plugin_name, deployment)
-
- LOG.info("Executing _run()")
- 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")
+ param = change_osloobj_to_paras(args)
+ Plugin().install(param)
@cliargs("input_file", type=str, help="path to plugin configuration file",
nargs=1)
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("Removing plugin: %s" % plugin_name)
-
- LOG.info("Executing _remove_setup()")
- self._remove_setup(plugin_name, deployment)
-
- LOG.info("Executing _run()")
- 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', 'scripts/install/' + target_script)
-
- deployment_user = deployment.get("user")
- deployment_ssh_port = deployment.get("ssh_port", ssh.DEFAULT_PORT)
- deployment_ip = deployment.get("ip", None)
- deployment_password = deployment.get("password", None)
- deployment_key_filename = deployment.get("key_filename",
- "/root/.ssh/id_rsa")
-
- if deployment_ip == "local":
- installer_ip = os.environ.get("INSTALLER_IP", None)
-
- if deployment_password is not None:
- self._login_via_password(deployment_user, installer_ip,
- deployment_password,
- deployment_ssh_port)
- else:
- self._login_via_key(self, deployment_user, installer_ip,
- deployment_key_filename,
- deployment_ssh_port)
- else:
- if deployment_password is not None:
- self._login_via_password(deployment_user, deployment_ip,
- deployment_password,
- deployment_ssh_port)
- else:
- self._login_via_key(self, deployment_user, deployment_ip,
- deployment_key_filename,
- deployment_ssh_port)
- # copy script to host
- cmd = "cat > ~/%s.sh" % plugin_name
-
- LOG.info("copying script to host: %s", cmd)
- 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', 'scripts/remove/' + target_script)
-
- deployment_user = deployment.get("user")
- deployment_ssh_port = deployment.get("ssh_port", ssh.DEFAULT_PORT)
- deployment_ip = deployment.get("ip", None)
- deployment_password = deployment.get("password", None)
- deployment_key_filename = deployment.get("key_filename",
- "/root/.ssh/id_rsa")
-
- if deployment_ip == "local":
- installer_ip = os.environ.get("INSTALLER_IP", None)
-
- if deployment_password is not None:
- self._login_via_password(deployment_user, installer_ip,
- deployment_password,
- deployment_ssh_port)
- else:
- self._login_via_key(self, deployment_user, installer_ip,
- deployment_key_filename,
- deployment_ssh_port)
- else:
- if deployment_password is not None:
- self._login_via_password(deployment_user, deployment_ip,
- deployment_password,
- deployment_ssh_port)
- else:
- self._login_via_key(self, deployment_user, deployment_ip,
- deployment_key_filename,
- deployment_ssh_port)
-
- # copy script to host
- cmd = "cat > ~/%s.sh" % plugin_name
-
- LOG.info("copying script to host: %s", cmd)
- self.client.run(cmd, stdin=open(self.script, 'rb'))
-
- def _login_via_password(self, user, ip, password, ssh_port):
- LOG.info("Log in via pw, user:%s, host:%s", user, ip)
- self.client = ssh.SSH(user, ip, password=password, port=ssh_port)
- self.client.wait(timeout=600)
-
- def _login_via_key(self, user, ip, key_filename, ssh_port):
- LOG.info("Log in via key, user:%s, host:%s", user, ip)
- self.client = ssh.SSH(user, ip, key_filename=key_filename,
- port=ssh_port)
- self.client.wait(timeout=600)
-
- def _run(self, plugin_name):
- '''Run installation script '''
- cmd = "sudo bash %s" % plugin_name + ".sh"
-
- LOG.info("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))
+ param = change_osloobj_to_paras(args)
+ Plugin().remove(param)