diff options
author | wym_libra <yimin.wang@huawei.com> | 2015-12-07 16:02:18 +0800 |
---|---|---|
committer | qi liang <liangqi1@huawei.com> | 2016-01-10 03:17:21 +0000 |
commit | 93e5a8fefd2574de339d2f1ae2041b9d233bbc7b (patch) | |
tree | ab4a5507c4100cec6485ba9d587aca8728e8d1c7 /yardstick/benchmark/scenarios/availability/monitor/monitor_process.py | |
parent | 9b792a92f1f0b67159de52f8bd6b94806b35ae7b (diff) |
Rewrite the HA test case (2)
idea: refact the Monitor class in old file "monitor.py" with the base
class and sub-class.
detail:
1) the BaseMonitor is the base class of other monitor
2) each monitor run in independent process
3) there are two monitor("openstack-cmd" and "process") for the first test case
4) MonitorMgr class used to manager monitor process
JIRA: YARDSTICK-149
Change-Id: I2eede94481f740812212e6cb673d175b5f543c15
Signed-off-by: wym_libra <yimin.wang@huawei.com>
(cherry picked from commit 2733defda816a84d2b9c2e361a5970b9de4923f4)
Diffstat (limited to 'yardstick/benchmark/scenarios/availability/monitor/monitor_process.py')
-rw-r--r-- | yardstick/benchmark/scenarios/availability/monitor/monitor_process.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py new file mode 100644 index 000000000..64e12f1dd --- /dev/null +++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py @@ -0,0 +1,84 @@ +############################################################################## +# Copyright (c) 2015 Huawei Technologies Co.,Ltd. and others +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import logging +import yardstick.ssh as ssh + +import basemonitor as basemonitor + +LOG = logging.getLogger(__name__) + + +class MonitorProcess(basemonitor.BaseMonitor): + """docstring for MonitorApi""" + + __monitor_type__ = "process" + + def setup(self): + host = self._context[self._config["host"]] + ip = host.get("ip", None) + user = host.get("user", "root") + key_filename = host.get("key_filename", "~/.ssh/id_rsa") + + self.connection = ssh.SSH(user, ip, key_filename=key_filename) + self.connection.wait(timeout=600) + LOG.debug("ssh host success!") + self.check_script = self.get_script_fullpath( + "script_tools/check_service.bash") + self.process_name = self._config["process_name"] + + def monitor_func(self): + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s {0}".format(self.process_name), + stdin=open(self.check_script, "r")) + + if stdout and "running" in stdout: + LOG.info("check the envrioment success!") + return True + else: + LOG.error( + "the host envrioment is error, stdout:%s, stderr:%s" % + (stdout, stderr)) + return False + + def verify_SLA(self): + outage_time = self._result.get('outage_time', None) + max_outage_time = self._config["sla"]["max_recover_time"] + if outage_time > max_outage_time: + LOG.error("SLA failure: %f > %f" % (outage_time, max_outage_time)) + return False + else: + return True + + +def _test(): # pragma: no cover + host = { + "ip": "10.20.0.5", + "user": "root", + "key_filename": "/root/.ssh/id_rsa" + } + context = {"node1": host} + monitor_configs = [] + config = { + 'monitor_type': 'process', + 'process_name': 'nova-api', + 'host': "node1", + 'monitor_time': 1, + 'SLA': {'max_recover_time': 5} + } + monitor_configs.append(config) + + p = basemonitor.MonitorMgr() + p.init_monitors(monitor_configs, context) + p.start_monitors() + p.wait_monitors() + p.verify() + + +if __name__ == '__main__': # pragma: no cover + _test() |