HA testcase improvement
[yardstick.git] / yardstick / benchmark / scenarios / availability / attacker / attacker_process.py
index 521c579..f7ab23d 100644 (file)
@@ -23,13 +23,8 @@ class ProcessAttacker(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!")
 
@@ -43,18 +38,17 @@ class ProcessAttacker(BaseAttacker):
         self.recovery_script = self.get_script_fullpath(
             self.fault_cfg['recovery_script'])
 
-        if self.check():
-            self.setup_done = True
+        self.data[self.service_name] = self.check()
 
     def check(self):
         with open(self.check_script, "r") as stdin_file:
             exit_status, stdout, stderr = self.connection.execute(
-                "/bin/sh -s {0}".format(self.service_name),
+                "sudo /bin/sh -s {0}".format(self.service_name),
                 stdin=stdin_file)
 
-        if stdout and "running" in stdout:
+        if stdout:
             LOG.info("check the envrioment success!")
-            return True
+            return int(stdout.strip('\n'))
         else:
             LOG.error(
                 "the host envrioment is error, stdout:%s, stderr:%s",
@@ -64,11 +58,13 @@ class ProcessAttacker(BaseAttacker):
     def inject_fault(self):
         with open(self.inject_script, "r") as stdin_file:
             exit_status, stdout, stderr = self.connection.execute(
-                "/bin/sh -s {0}".format(self.service_name),
+                "sudo /bin/sh -s {0}".format(self.service_name),
                 stdin=stdin_file)
 
     def recover(self):
         with open(self.recovery_script, "r") as stdin_file:
             exit_status, stdout, stderr = self.connection.execute(
-                "/bin/sh -s {0} ".format(self.service_name),
+                "sudo /bin/bash -s {0} ".format(self.service_name),
                 stdin=stdin_file)
+        if exit_status:
+            LOG.info("Fail to restart service!")