# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
import logging
import yardstick.ssh as ssh
-import basemonitor as basemonitor
+from yardstick.benchmark.scenarios.availability.monitor import basemonitor
LOG = logging.getLogger(__name__)
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 = ssh.SSH.from_node(host, defaults={"user": "root"})
self.connection.wait(timeout=600)
LOG.debug("ssh host success!")
self.check_script = self.get_script_fullpath(
- "script_tools/check_service.bash")
+ "ha_tools/check_process_python.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"))
+ with open(self.check_script, "r") as stdin_file:
+ exit_status, stdout, stderr = self.connection.execute(
+ "sudo /bin/sh -s {0}".format(self.process_name),
+ stdin=stdin_file)
- 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
+ if not stdout or int(stdout) < self.monitor_data[self.process_name]:
+ LOG.info("the (%s) processes are in recovery!", self.process_name)
+ return False
+
+ LOG.info("the (%s) processes have been fully recovered!",
+ self.process_name)
+ return True
def verify_SLA(self):
+ LOG.debug("the _result:%s", self._result)
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))
+ LOG.error("SLA failure: %f > %f", outage_time, max_outage_time)
return False
else:
+ LOG.info("the sla is passed")
return True
'process_name': 'nova-api',
'host': "node1",
'monitor_time': 1,
- 'SLA': {'max_recover_time': 5}
+ 'sla': {'max_recover_time': 5}
}
monitor_configs.append(config)
p.init_monitors(monitor_configs, context)
p.start_monitors()
p.wait_monitors()
- p.verify()
+ p.verify_SLA()
if __name__ == '__main__': # pragma: no cover