diff options
Diffstat (limited to 'yardstick/benchmark/scenarios/availability/operation/operation_general.py')
-rw-r--r-- | yardstick/benchmark/scenarios/availability/operation/operation_general.py | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/yardstick/benchmark/scenarios/availability/operation/operation_general.py b/yardstick/benchmark/scenarios/availability/operation/operation_general.py index e43f6e1d5..c82df836d 100644 --- a/yardstick/benchmark/scenarios/availability/operation/operation_general.py +++ b/yardstick/benchmark/scenarios/availability/operation/operation_general.py @@ -19,13 +19,15 @@ class GeneralOperaion(BaseOperation): __operation__type__ = "general-operation" 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!") @@ -53,27 +55,31 @@ class GeneralOperaion(BaseOperation): def run(self): if "action_parameter" in self._config: - exit_status, stdout, stderr = self.connection.execute( - self.action_param, - stdin=open(self.action_script, "r")) + with open(self.action_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.action_param, + stdin=stdin_file) else: - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s ", - stdin=open(self.action_script, "r")) + with open(self.action_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s ", + stdin=stdin_file) if exit_status == 0: LOG.debug("success,the operation's output is: {0}".format(stdout)) else: LOG.error( - "the operation's error, stdout:%s, stderr:%s" % - (stdout, stderr)) + "the operation's error, stdout:%s, stderr:%s", + stdout, stderr) def rollback(self): if "rollback_parameter" in self._config: - exit_status, stdout, stderr = self.connection.execute( - self.rollback_param, - stdin=open(self.rollback_script, "r")) + with open(self.rollback_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.rollback_param, + stdin=stdin_file) else: - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s ", - stdin=open(self.rollback_script, "r")) + with open(self.rollback_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s ", + stdin=stdin_file) |