Merge "Log each test case status in a task"
[yardstick.git] / yardstick / benchmark / core / plugin.py
index 3080f5d..56ecd29 100644 (file)
@@ -13,13 +13,13 @@ from __future__ import print_function
 from __future__ import absolute_import
 import os
 import sys
-import yaml
 import time
 import logging
 import pkg_resources
 import yardstick.ssh as ssh
 
 from yardstick.common.task_template import TaskTemplate
+from yardstick.common.yaml_loader import yaml_load
 
 LOG = logging.getLogger(__name__)
 
@@ -38,19 +38,19 @@ class Plugin(object):
 
         plugins, deployment = parser.parse_plugin()
         plugin_name = plugins.get("name")
-        print("Installing plugin: %s" % plugin_name)
+        LOG.info("Installing plugin: %s", plugin_name)
 
-        LOG.info("Executing _install_setup()")
+        LOG.debug("Executing _install_setup()")
         self._install_setup(plugin_name, deployment)
 
-        LOG.info("Executing _run()")
+        LOG.debug("Executing _run()")
         self._run(plugin_name)
 
         total_end_time = time.time()
-        LOG.info("total finished in %d secs",
+        LOG.info("Total finished in %d secs",
                  total_end_time - total_start_time)
 
-        print("Done, exiting")
+        LOG.info("Plugin %s Done, exiting", plugin_name)
 
     def remove(self, args):
         """Remove a plugin."""
@@ -80,33 +80,17 @@ class Plugin(object):
         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)
+            self.client = ssh.SSH.from_node(deployment, overrides={
+                # host can't be None, fail if no JUMP_HOST_IP
+                'ip': os.environ["JUMP_HOST_IP"],
+            })
         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)
+            self.client = ssh.SSH.from_node(deployment)
+        self.client.wait(timeout=600)
+
         # copy script to host
         remotepath = '~/%s.sh' % plugin_name
 
@@ -119,33 +103,16 @@ class Plugin(object):
         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)
+            self.client = ssh.SSH.from_node(deployment, overrides={
+                # host can't be None, fail if no JUMP_HOST_IP
+                'ip': os.environ["JUMP_HOST_IP"],
+            })
         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)
+            self.client = ssh.SSH.from_node(deployment)
+        self.client.wait(timeout=600)
 
         # copy script to host
         remotepath = '~/%s.sh' % plugin_name
@@ -153,23 +120,12 @@ class Plugin(object):
         LOG.info("copying script to host: %s", remotepath)
         self.client._put_file_shell(self.script, remotepath)
 
-    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)
+        self.client.execute(cmd)
 
 
 class PluginParser(object):
@@ -197,7 +153,7 @@ class PluginParser(object):
                     raise e
                 print("Input plugin is:\n%s\n" % rendered_plugin)
 
-                cfg = yaml.load(rendered_plugin)
+                cfg = yaml_load(rendered_plugin)
         except IOError as ioerror:
             sys.exit(ioerror)