1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd. and others
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from baseattacker import BaseAttacker
12 import yardstick.ssh as ssh
14 LOG = logging.getLogger(__name__)
17 class ProcessAttacker(BaseAttacker):
19 __attacker_type__ = 'kill-process'
22 LOG.debug("config:%s context:%s", self._config, self._context)
23 host = self._context.get(self._config['host'], None)
24 ip = host.get("ip", None)
25 user = host.get("user", "root")
26 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
27 key_filename = host.get("key_filename", "~/.ssh/id_rsa")
29 self.connection = ssh.SSH(user, ip, key_filename=key_filename,
31 self.connection.wait(timeout=600)
32 LOG.debug("ssh host success!")
34 self.service_name = self._config['process_name']
35 self.fault_cfg = BaseAttacker.attacker_cfgs.get('kill-process')
37 self.check_script = self.get_script_fullpath(
38 self.fault_cfg['check_script'])
39 self.inject_script = self.get_script_fullpath(
40 self.fault_cfg['inject_script'])
41 self.recovery_script = self.get_script_fullpath(
42 self.fault_cfg['recovery_script'])
45 self.setup_done = True
48 with open(self.check_script, "r") as stdin_file:
49 exit_status, stdout, stderr = self.connection.execute(
50 "/bin/sh -s {0}".format(self.service_name),
53 if stdout and "running" in stdout:
54 LOG.info("check the envrioment success!")
58 "the host envrioment is error, stdout:%s, stderr:%s",
62 def inject_fault(self):
63 with open(self.inject_script, "r") as stdin_file:
64 exit_status, stdout, stderr = self.connection.execute(
65 "/bin/sh -s {0}".format(self.service_name),
69 with open(self.recovery_script, "r") as stdin_file:
70 exit_status, stdout, stderr = self.connection.execute(
71 "/bin/sh -s {0} ".format(self.service_name),