aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/availability/monitor.py
diff options
context:
space:
mode:
authorwym_libra <yimin.wang@huawei.com>2015-10-26 07:54:31 +0000
committerwym_libra <yimin.wang@huawei.com>2015-11-13 06:59:51 +0000
commit6a5d8a6d58ab501184313eda84820294ff3597e7 (patch)
tree2fa59c5f95776db6c9461816ba293547c247eed7 /yardstick/benchmark/scenarios/availability/monitor.py
parenteb8320b2e924e22c20af49a0d37bee12417ede95 (diff)
A initial HA test case
1)stop an openstack service 2)then monitor the corresponding api and check the availability of it 3)recovery the openstack service JIRA: YARDSTICK-149 Change-Id: Id7b77d2f5c71844729c04f37442c8cfaa270ab12 Signed-off-by: wym_libra <yimin.wang@huawei.com>
Diffstat (limited to 'yardstick/benchmark/scenarios/availability/monitor.py')
-rwxr-xr-xyardstick/benchmark/scenarios/availability/monitor.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/yardstick/benchmark/scenarios/availability/monitor.py b/yardstick/benchmark/scenarios/availability/monitor.py
new file mode 100755
index 000000000..3193d3304
--- /dev/null
+++ b/yardstick/benchmark/scenarios/availability/monitor.py
@@ -0,0 +1,114 @@
+##############################################################################
+# 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 multiprocessing
+import subprocess
+import traceback
+import time
+
+LOG = logging.getLogger(__name__)
+
+
+def _execute_shell_command(command):
+ '''execute shell script with error handling'''
+ exitcode = 0
+ output = []
+ try:
+ output = subprocess.check_output(command, shell=True)
+ except Exception:
+ exitcode = -1
+ output = traceback.format_exc()
+ LOG.error("exec command '%s' error:\n " % command)
+ LOG.error(traceback.format_exc())
+
+ return exitcode, output
+
+
+def _monitor_process(config, queue, event):
+
+ total_time = 0
+ outage_time = 0
+ total_count = 0
+ outage_count = 0
+ first_outage = 0
+ last_outage = 0
+
+ wait_time = config.get("duration", 0)
+ cmd = config.get("monitor_cmd", None)
+ if cmd is None:
+ LOG.error("There are no monitor cmd!")
+ return
+
+ queue.put("started")
+
+ begin_time = time.time()
+ while True:
+
+ total_count = total_count + 1
+
+ one_check_begin_time = time.time()
+ exit_status, stdout = _execute_shell_command(cmd)
+ one_check_end_time = time.time()
+
+ LOG.info("the exit_status:%s stdout:%s" % (exit_status, stdout))
+ if exit_status:
+ outage_count = outage_count + 1
+
+ outage_time = outage_time + (
+ one_check_end_time - one_check_begin_time)
+
+ if not first_outage:
+ first_outage = one_check_begin_time
+
+ last_outage = one_check_end_time
+
+ if event.is_set():
+ LOG.debug("the monitor process stop")
+ break
+
+ if wait_time > 0:
+ time.sleep(wait_time)
+
+ end_time = time.time()
+ total_time = end_time - begin_time
+
+ queue.put({"total_time": total_time,
+ "outage_time": last_outage-first_outage,
+ "total_count": total_count,
+ "outage_count": outage_count})
+
+
+class Monitor:
+
+ def __init__(self):
+ self._result = []
+ self._monitor_process = []
+
+ def setup(self, config):
+ self._config = config
+
+ def start(self):
+ self._queue = multiprocessing.Queue()
+ self._event = multiprocessing.Event()
+ self._monitor_process = multiprocessing.Process(
+ target=_monitor_process, name="Monitor",
+ args=(self._config, self._queue, self._event))
+
+ self._monitor_process.start()
+ ret = self._queue.get()
+ if ret == "started":
+ LOG.debug("monitor process started!")
+
+ def stop(self):
+ self._event.set()
+ self._result = self._queue.get()
+ LOG.debug("stop the monitor process. the result:%s" % self._result)
+
+ def get_result(self):
+ return self._result