Code Review
/
yardstick.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
use context manager for stdin files and use _put_file_shell
[yardstick.git]
/
yardstick
/
benchmark
/
scenarios
/
availability
/
attacker
/
attacker_general.py
diff --git
a/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
b/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
index
018362a
..
595067a
100644
(file)
--- a/
yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
+++ b/
yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
@@
-20,17
+20,20
@@
class GeneralAttacker(BaseAttacker):
__attacker_type__ = 'general-attacker'
def setup(self):
__attacker_type__ = 'general-attacker'
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")
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")
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.key = self._config['key']
self.connection.wait(timeout=600)
LOG.debug("ssh host success!")
self.key = self._config['key']
+ self.attack_key = self._config['attack_key']
if "action_parameter" in self._config:
actionParameter = self._config['action_parameter']
if "action_parameter" in self._config:
actionParameter = self._config['action_parameter']
@@
-50,7
+53,7
@@
class GeneralAttacker(BaseAttacker):
l = list(item for item in rollbackParameter.values())
self.rollback_param = str.format(*l)
l = list(item for item in rollbackParameter.values())
self.rollback_param = str.format(*l)
- self.fault_cfg = BaseAttacker.attacker_cfgs.get(self.key)
+ self.fault_cfg = BaseAttacker.attacker_cfgs.get(self.
attack_
key)
self.inject_script = self.get_script_fullpath(
self.fault_cfg['inject_script'])
self.recovery_script = self.get_script_fullpath(
self.inject_script = self.get_script_fullpath(
self.fault_cfg['inject_script'])
self.recovery_script = self.get_script_fullpath(
@@
-62,13
+65,15
@@
class GeneralAttacker(BaseAttacker):
if "action_parameter" in self._config:
LOG.debug("the shell command is: {0}".format(self.action_param))
if "action_parameter" in self._config:
LOG.debug("the shell command is: {0}".format(self.action_param))
- exit_status, stdout, stderr = self.connection.execute(
- self.action_param,
- stdin=open(self.inject_script, "r"))
+ with open(self.inject_script, "r") as stdin_file:
+ exit_status, stdout, stderr = self.connection.execute(
+ self.action_param,
+ stdin=stdin_file)
else:
else:
- exit_status, stdout, stderr = self.connection.execute(
- "/bin/bash -s ",
- stdin=open(self.inject_script, "r"))
+ with open(self.inject_script, "r") as stdin_file:
+ exit_status, stdout, stderr = self.connection.execute(
+ "/bin/bash -s ",
+ stdin=stdin_file)
LOG.debug("the inject_fault's exit status is: {0}".format(exit_status))
if exit_status == 0:
LOG.debug("the inject_fault's exit status is: {0}".format(exit_status))
if exit_status == 0:
@@
-76,16
+81,18
@@
class GeneralAttacker(BaseAttacker):
.format(stdout))
else:
LOG.error(
.format(stdout))
else:
LOG.error(
- "the inject_fault's error, stdout:%s, stderr:%s"
%
-
(stdout, stderr)
)
+ "the inject_fault's error, stdout:%s, stderr:%s"
,
+
stdout, stderr
)
def recover(self):
if "rollback_parameter" in self._config:
LOG.debug("the shell command is: {0}".format(self.rollback_param))
def recover(self):
if "rollback_parameter" in self._config:
LOG.debug("the shell command is: {0}".format(self.rollback_param))
- exit_status, stdout, stderr = self.connection.execute(
- self.rollback_param,
- stdin=open(self.recovery_script, "r"))
+ with open(self.recovery_script, "r") as stdin_file:
+ exit_status, stdout, stderr = self.connection.execute(
+ self.rollback_param,
+ stdin=stdin_file)
else:
else:
- exit_status, stdout, stderr = self.connection.execute(
- "/bin/bash -s ",
- stdin=open(self.recovery_script, "r"))
+ with open(self.recovery_script, "r") as stdin_file:
+ exit_status, stdout, stderr = self.connection.execute(
+ "/bin/bash -s ",
+ stdin=stdin_file)