Merge "BugFix: Adopt to latest result structure while parsing the results"
[yardstick.git] / yardstick / benchmark / scenarios / availability / result_checker / result_checker_general.py
index 8c9d160..8f987a6 100644 (file)
@@ -6,9 +6,13 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
+from __future__ import absolute_import
 import logging
 
-from baseresultchecker import BaseResultChecker
+
+from yardstick.benchmark.scenarios.availability.result_checker \
+    .baseresultchecker import \
+    BaseResultChecker
 from yardstick.benchmark.scenarios.availability import Condition
 import yardstick.ssh as ssh
 from yardstick.benchmark.scenarios.availability.util import buildshellparams
@@ -53,30 +57,30 @@ class GeneralResultChecker(BaseResultChecker):
 
     def verify(self):
         if "parameter" in self._config:
-            exit_status, stdout, stderr = self.connection.execute(
-                self.shell_cmd,
-                stdin=open(self.verify_script, "r"))
-            LOG.debug("action script of the operation is: {0}"
-                      .format(self.verify_script))
-            LOG.debug("action parameter the of operation is: {0}"
-                      .format(self.shell_cmd))
+            with open(self.verify_script, "r") as stdin_file:
+                exit_status, stdout, stderr = self.connection.execute(
+                    self.shell_cmd,
+                    stdin=stdin_file)
+            LOG.debug("action script of the operation is: %s",
+                      self.verify_script)
+            LOG.debug("action parameter the of operation is: %s",
+                      self.shell_cmd)
         else:
-            exit_status, stdout, stderr = self.connection.execute(
-                "/bin/bash -s ",
-                stdin=open(self.verify_script, "r"))
-            LOG.debug("action script of the operation is: {0}"
-                      .format(self.verify_script))
+            with open(self.verify_script, "r") as stdin_file:
+                exit_status, stdout, stderr = self.connection.execute(
+                    "/bin/bash -s ",
+                    stdin=stdin_file)
+            LOG.debug("action script of the operation is: %s",
+                      self.verify_script)
 
         LOG.debug("exit_status ,stdout : %s ,%s", exit_status, stdout)
         if exit_status == 0 and stdout:
             self.actualResult = stdout
-            LOG.debug("verifying resultchecker: {0}".format(self.key))
-            LOG.debug("verifying resultchecker,expected: {0}"
-                      .format(self.expectedResult))
-            LOG.debug("verifying resultchecker,actual: {0}"
-                      .format(self.actualResult))
-            LOG.debug("verifying resultchecker,condition: {0}"
-                      .format(self.condition))
+            LOG.debug("verifying resultchecker: %s", self.key)
+            LOG.debug("verifying resultchecker,expected: %s",
+                      self.expectedResult)
+            LOG.debug("verifying resultchecker,actual: %s", self.actualResult)
+            LOG.debug("verifying resultchecker,condition: %s", self.condition)
             if (type(self.expectedResult) is int):
                 self.actualResult = int(self.actualResult)
             if self.condition == Condition.EQUAL:
@@ -94,13 +98,13 @@ class GeneralResultChecker(BaseResultChecker):
             else:
                 self.success = False
                 LOG.debug(
-                    "error happened when resultchecker: {0} Invalid condition"
-                    .format(self.key))
+                    "error happened when resultchecker: %s Invalid condition",
+                    self.key)
         else:
             self.success = False
             LOG.debug(
-                "error happened when resultchecker: {0} verifying the result"
-                .format(self.key))
+                "error happened when resultchecker: %s verifying the result",
+                self.key)
             LOG.error(stderr)
 
         LOG.debug(