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
15 import yardstick.ssh as ssh
16 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
18 LOG = logging.getLogger(__name__)
21 def _execute_shell_command(command):
22 """execute shell script with error handling"""
26 output = subprocess.check_output(command, shell=True)
29 LOG.error("exec command '%s' error:\n ", command, exc_info=True)
31 return exitcode, output
34 class MonitorOpenstackCmd(basemonitor.BaseMonitor):
35 """docstring for MonitorApi"""
37 __monitor_type__ = "openstack-cmd"
40 self.connection = None
41 node_name = self._config.get("host", None)
43 host = self._context[node_name]
45 self.connection = ssh.SSH.from_node(host,
46 defaults={"user": "root"})
47 self.connection.wait(timeout=600)
48 LOG.debug("ssh host success!")
50 self.check_script = self.get_script_fullpath(
51 "ha_tools/check_openstack_cmd.bash")
53 self.cmd = self._config["command_name"]
56 insecure = os.environ['OS_INSECURE']
60 if insecure.lower() == "true":
61 self.cmd = self.cmd + " --insecure"
63 def monitor_func(self):
65 exit_status, stdout = _execute_shell_command(self.cmd)
66 LOG.debug("Execute command '%s' and the stdout is:\n%s", self.cmd, stdout)
72 outage_time = self._result.get('outage_time', None)
73 LOG.debug("the _result:%s", self._result)
74 max_outage_time = self._config["sla"]["max_outage_time"]
75 if outage_time > max_outage_time:
76 LOG.info("SLA failure: %f > %f", outage_time, max_outage_time)
79 LOG.info("the sla is passed")
83 def _test(): # pragma: no cover
85 "ip": "192.168.235.22",
87 "key_filename": "/root/.ssh/id_rsa"
89 context = {"node1": host}
92 'monitor_type': 'openstack-cmd',
93 'command_name': 'nova image-list',
96 'sla': {'max_outage_time': 5}
98 monitor_configs.append(config)
100 p = basemonitor.MonitorMgr()
101 p.init_monitors(monitor_configs, context)
107 if __name__ == '__main__': # pragma: no cover