Merge "ssh.py: add flag to keep stdin open"
[yardstick.git] / yardstick / benchmark / scenarios / availability / attacker / attacker_baremetal.py
index b35869d..3b1f8ef 100644 (file)
@@ -24,24 +24,25 @@ def _execute_shell_command(command, stdin=None):
     except Exception:
         exitcode = -1
         output = traceback.format_exc()
-        LOG.error("exec command '%s' error:\n " % command)
+        LOG.error("exec command '%s' error:\n ", command)
         LOG.error(traceback.format_exc())
 
     return exitcode, output
 
 
 class BaremetalAttacker(BaseAttacker):
-
     __attacker_type__ = 'bare-metal-down'
 
     def setup(self):
-        LOG.debug("config:%s context:%s" % (self._config, self._context))
+        LOG.debug("config:%s context:%s", self._config, self._context)
         host = self._context.get(self._config['host'], None)
         ip = host.get("ip", None)
         user = host.get("user", "root")
+        ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
         key_filename = host.get("key_filename", "~/.ssh/id_rsa")
 
-        self.connection = ssh.SSH(user, ip, key_filename=key_filename)
+        self.connection = ssh.SSH(user, ip, key_filename=key_filename,
+                                  port=ssh_port)
         self.connection.wait(timeout=600)
         LOG.debug("ssh host success!")
         self.host_ip = ip
@@ -64,10 +65,10 @@ class BaremetalAttacker(BaseAttacker):
             "/bin/sh -s {0} -W 10".format(self.host_ip),
             stdin=open(self.check_script, "r"))
 
-        LOG.debug("check ret: %s out:%s err:%s" %
-                  (exit_status, stdout, stderr))
+        LOG.debug("check ret: %s out:%s err:%s",
+                  exit_status, stdout, stderr)
         if not stdout or "running" not in stdout:
-            LOG.info("the host (ipmi_ip:%s) is not running!" % self.ipmi_ip)
+            LOG.info("the host (ipmi_ip:%s) is not running!", self.ipmi_ip)
             return False
 
         return True
@@ -75,8 +76,8 @@ class BaremetalAttacker(BaseAttacker):
     def inject_fault(self):
         exit_status, stdout, stderr = self.connection.execute(
             "shutdown -h now")
-        LOG.debug("inject fault ret: %s out:%s err:%s" %
-                  (exit_status, stdout, stderr))
+        LOG.debug("inject fault ret: %s out:%s err:%s",
+                  exit_status, stdout, stderr)
         if not exit_status:
             LOG.info("inject fault success")
 
@@ -87,10 +88,12 @@ class BaremetalAttacker(BaseAttacker):
             host = self._context.get(jump_host_name, None)
             ip = host.get("ip", None)
             user = host.get("user", "root")
+            ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
             pwd = host.get("pwd", None)
 
-            LOG.debug("jump_host ip:%s user:%s" % (ip, user))
-            self.jump_connection = ssh.SSH(user, ip, password=pwd)
+            LOG.debug("jump_host ip:%s user:%s", ip, user)
+            self.jump_connection = ssh.SSH(user, ip, password=pwd,
+                                           port=ssh_port)
             self.jump_connection.wait(timeout=600)
             LOG.debug("ssh jump host success!")