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"]]
25 ip = host.get("ip", None)
26 user = host.get("user", "root")
27 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
28 key_filename = host.get("key_filename", "~/.ssh/id_rsa")
30 self.connection = ssh.SSH(user, ip, key_filename=key_filename,
32 self.connection.wait(timeout=600)
33 LOG.debug("ssh host success!")
34 self.check_script = self.get_script_fullpath(
35 "ha_tools/check_process_python.bash")
36 self.process_name = self._config["process_name"]
38 def monitor_func(self):
39 with open(self.check_script, "r") as stdin_file:
40 exit_status, stdout, stderr = self.connection.execute(
41 "/bin/sh -s {0}".format(self.process_name),
43 if not stdout or int(stdout) <= 0:
44 LOG.info("the process (%s) is not running!", self.process_name)
50 LOG.debug("the _result:%s", self._result)
51 outage_time = self._result.get('outage_time', None)
52 max_outage_time = self._config["sla"]["max_recover_time"]
53 if outage_time > max_outage_time:
54 LOG.error("SLA failure: %f > %f", outage_time, max_outage_time)
60 def _test(): # pragma: no cover
64 "key_filename": "/root/.ssh/id_rsa"
66 context = {"node1": host}
69 'monitor_type': 'process',
70 'process_name': 'nova-api',
73 'sla': {'max_recover_time': 5}
75 monitor_configs.append(config)
77 p = basemonitor.MonitorMgr()
78 p.init_monitors(monitor_configs, context)
84 if __name__ == '__main__': # pragma: no cover