Bugfix: Support HA test cases in TripleO
[yardstick.git] / yardstick / benchmark / scenarios / availability / attacker / attacker_general.py
index 24888af..48863af 100644 (file)
@@ -24,13 +24,8 @@ class GeneralAttacker(BaseAttacker):
     def setup(self):
         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,
-                                  port=ssh_port)
+        self.connection = ssh.SSH.from_node(host, defaults={"user": "root"})
         self.connection.wait(timeout=600)
         LOG.debug("ssh host success!")
 
@@ -40,19 +35,19 @@ class GeneralAttacker(BaseAttacker):
         if "action_parameter" in self._config:
             actionParameter = self._config['action_parameter']
             str = util.buildshellparams(actionParameter)
-            LOG.debug("inject parameter is: {0}".format(actionParameter))
-            LOG.debug("inject parameter values are: {0}"
-                      .format(list(actionParameter.values())))
-            l = list(item for item in actionParameter.values())
+            LOG.debug("inject parameter is: %s", actionParameter)
+            LOG.debug("inject parameter values are: %s",
+                      list(actionParameter.values()))
+            l = list(actionParameter.values())
             self.action_param = str.format(*l)
 
         if "rollback_parameter" in self._config:
             rollbackParameter = self._config['rollback_parameter']
             str = util.buildshellparams(rollbackParameter)
-            LOG.debug("recover parameter is: {0}".format(rollbackParameter))
-            LOG.debug("recover parameter values are: {0}".
-                      format(list(rollbackParameter.values())))
-            l = list(item for item in rollbackParameter.values())
+            LOG.debug("recover parameter is: %s", rollbackParameter)
+            LOG.debug("recover parameter values are: %s",
+                      list(rollbackParameter.values()))
+            l = list(rollbackParameter.values())
             self.rollback_param = str.format(*l)
 
         self.fault_cfg = BaseAttacker.attacker_cfgs.get(self.attack_key)
@@ -69,18 +64,17 @@ class GeneralAttacker(BaseAttacker):
             LOG.debug("the shell command is: %s", self.action_param)
             with open(self.inject_script, "r") as stdin_file:
                 exit_status, stdout, stderr = self.connection.execute(
-                    self.action_param,
+                    "sudo {}".format(self.action_param),
                     stdin=stdin_file)
         else:
             with open(self.inject_script, "r") as stdin_file:
                 exit_status, stdout, stderr = self.connection.execute(
-                    "/bin/bash -s ",
+                    "sudo /bin/bash -s ",
                     stdin=stdin_file)
 
-        LOG.debug("the inject_fault's exit status is: {0}".format(exit_status))
+        LOG.debug("the inject_fault's exit status is: %s", exit_status)
         if exit_status == 0:
-            LOG.debug("success,the inject_fault's output is: {0}"
-                      .format(stdout))
+            LOG.debug("success,the inject_fault's output is: %s", stdout)
         else:
             LOG.error(
                 "the inject_fault's error, stdout:%s, stderr:%s",
@@ -91,10 +85,10 @@ class GeneralAttacker(BaseAttacker):
             LOG.debug("the shell command is: %s", self.rollback_param)
             with open(self.recovery_script, "r") as stdin_file:
                 exit_status, stdout, stderr = self.connection.execute(
-                    self.rollback_param,
+                    "sudo {}".format(self.rollback_param),
                     stdin=stdin_file)
         else:
             with open(self.recovery_script, "r") as stdin_file:
                 exit_status, stdout, stderr = self.connection.execute(
-                    "/bin/bash -s ",
+                    "sudo /bin/bash -s ",
                     stdin=stdin_file)