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 ##############################################################################
9 from __future__ import absolute_import
12 import yardstick.ssh as ssh
13 from yardstick.benchmark.scenarios.availability.attacker.baseattacker import \
16 LOG = logging.getLogger(__name__)
19 class ProcessAttacker(BaseAttacker):
21 __attacker_type__ = 'kill-process'
24 LOG.debug("config:%s context:%s", self._config, self._context)
25 host = self._context.get(self._config['host'], None)
27 self.connection = ssh.SSH.from_node(host, defaults={"user": "root"})
28 self.connection.wait(timeout=600)
29 LOG.debug("ssh host success!")
31 self.service_name = self._config['process_name']
32 self.fault_cfg = BaseAttacker.attacker_cfgs.get('kill-process')
34 self.check_script = self.get_script_fullpath(
35 self.fault_cfg['check_script'])
36 self.inject_script = self.get_script_fullpath(
37 self.fault_cfg['inject_script'])
38 self.recovery_script = self.get_script_fullpath(
39 self.fault_cfg['recovery_script'])
41 self.data[self.service_name] = self.check()
44 with open(self.check_script, "r") as stdin_file:
45 exit_status, stdout, stderr = self.connection.execute(
46 "sudo /bin/sh -s {0}".format(self.service_name),
50 LOG.info("check the environment success!")
51 return int(stdout.strip('\n'))
54 "the host environment is error, stdout:%s, stderr:%s",
58 def inject_fault(self):
59 with open(self.inject_script, "r") as stdin_file:
60 exit_status, stdout, stderr = self.connection.execute(
61 "sudo /bin/sh -s {0}".format(self.service_name),
65 with open(self.recovery_script, "r") as stdin_file:
66 exit_status, stdout, stderr = self.connection.execute(
67 "sudo /bin/bash -s {0} ".format(self.service_name),
70 LOG.info("Fail to restart service!")