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
11 import yardstick.ssh as ssh
13 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
15 LOG = logging.getLogger(__name__)
18 class MonitorProcess(basemonitor.BaseMonitor):
19 """docstring for MonitorApi"""
21 __monitor_type__ = "process"
24 host = self._context[self._config["host"]]
26 self.connection = ssh.SSH.from_node(host, defaults={"user": "root"})
27 self.connection.wait(timeout=600)
28 LOG.debug("ssh host (%s) success!", str(host))
29 self.check_script = self.get_script_fullpath(
30 "ha_tools/check_process_python.bash")
31 self.process_name = self._config["process_name"]
33 def monitor_func(self):
34 with open(self.check_script, "r") as stdin_file:
35 _, stdout, _ = self.connection.execute(
36 "sudo /bin/sh -s {0}".format(self.process_name),
39 if not stdout or int(stdout) < self.monitor_data[self.process_name]:
40 LOG.info("the (%s) processes are in recovery!", self.process_name)
43 LOG.info("the (%s) processes have been fully recovered!",
48 outage_time = self._result.get('outage_time', None)
49 if self._config.get("sla"):
50 max_outage_time = self._config["sla"]["max_recover_time"]
51 if outage_time > max_outage_time:
52 LOG.info("SLA failure: %f > %f", outage_time, max_outage_time)
57 def _test(): # pragma: no cover
61 "key_filename": "/root/.ssh/id_rsa"
63 context = {"node1": host}
66 'monitor_type': 'process',
67 'process_name': 'nova-api',
70 'sla': {'max_recover_time': 5}
72 monitor_configs.append(config)
74 p = basemonitor.MonitorMgr({})
75 p.init_monitors(monitor_configs, context)
81 if __name__ == '__main__': # pragma: no cover