aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/ping-multiple-vm.yaml42
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_basemonitor.py6
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_monitor_general.py73
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_ping.py4
-rw-r--r--yardstick/benchmark/scenarios/availability/monitor/basemonitor.py14
-rw-r--r--yardstick/benchmark/scenarios/availability/monitor/monitor_general.py70
-rw-r--r--yardstick/benchmark/scenarios/availability/monitor_conf.yaml11
-rw-r--r--yardstick/benchmark/scenarios/networking/ping.py39
-rw-r--r--yardstick/cmd/commands/task.py14
9 files changed, 252 insertions, 21 deletions
diff --git a/samples/ping-multiple-vm.yaml b/samples/ping-multiple-vm.yaml
new file mode 100644
index 000000000..4055af14b
--- /dev/null
+++ b/samples/ping-multiple-vm.yaml
@@ -0,0 +1,42 @@
+---
+# Sample benchmark task config file measure network latency using ping
+# between mutiple virtual machines
+
+
+schema: "yardstick:task:0.1"
+
+scenarios:
+-
+ type: Ping
+ options:
+ packetsize: 200
+ host: athena.demo
+ # key 'targets' for multiple targets
+ targets:
+ - ares.demo
+ - kratos.demo
+
+ runner:
+ type: Duration
+ duration: 60
+ interval: 1
+
+ sla:
+ max_rtt: 10
+ action: monitor
+
+context:
+ name: demo
+ image: cirros-0.3.3
+ flavor: m1.tiny
+ user: cirros
+
+ servers:
+ athena:
+ floating_ip: true
+ ares:
+ kratos:
+
+ networks:
+ test:
+ cidr: '10.0.1.0/24'
diff --git a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
index 13295273b..140841075 100644
--- a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
+++ b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
@@ -23,6 +23,7 @@ class MonitorMgrTestCase(unittest.TestCase):
def setUp(self):
config = {
'monitor_type': 'openstack-api',
+ 'key' : 'service_status'
}
self.monitor_configs = []
@@ -36,6 +37,11 @@ class MonitorMgrTestCase(unittest.TestCase):
ret = instance.verify_SLA()
+ def test_MonitorMgr_getitem(self, mock_monitor):
+ monitorMgr = basemonitor.MonitorMgr()
+ monitorMgr.init_monitors(self.monitor_configs, None)
+ monitorIns = monitorMgr['service_status']
+
class BaseMonitorTestCase(unittest.TestCase):
class MonitorSimple(basemonitor.BaseMonitor):
diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_general.py b/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
new file mode 100644
index 000000000..85487a574
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2016 Huan Li and others
+# lihuansse@tongji.edu.cn
+# 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
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.availability.monitor
+# .monitor_general
+
+import mock
+import unittest
+from yardstick.benchmark.scenarios.availability.monitor import monitor_general
+
+
+@mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
+ 'monitor_general.ssh')
+@mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
+ 'monitor_general.open')
+class GeneralMonitorServiceTestCase(unittest.TestCase):
+ def setUp(self):
+ host = {
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.context = {"node1": host}
+ self.monitor_cfg = {
+ 'monitor_type': 'general-monitor',
+ 'key': 'service_status',
+ 'host': 'node1',
+ 'monitor_time': 3,
+ 'parameter': {'serviceName': 'haproxy'},
+ 'sla': {'max_recover_time': 1}
+ }
+ self.monitor_cfg_noparam = {
+ 'monitor_type': 'general-monitor',
+ 'key': 'service_status',
+ 'host': 'node1',
+ 'monitor_time': 3,
+ 'sla': {'max_recover_time': 1}
+ }
+
+ def test__monitor_general_all_successful(self, mock_open, mock_ssh):
+ ins = monitor_general.GeneralMonitor(self.monitor_cfg, self.context)
+
+ ins.setup()
+ mock_ssh.SSH().execute.return_value = (0, "running", '')
+ ins.monitor_func()
+ ins._result = {'outage_time' : 0}
+ ins.verify_SLA()
+
+ def test__monitor_general_all_successful_noparam(self, mock_open, mock_ssh):
+ ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context)
+
+ ins.setup()
+ mock_ssh.SSH().execute.return_value = (0, "running", '')
+ ins.monitor_func()
+ ins._result = {'outage_time' : 0}
+ ins.verify_SLA()
+
+ def test__monitor_general_failure(self, mock_open, mock_ssh):
+ ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context)
+
+ ins.setup()
+ mock_ssh.SSH().execute.return_value = (1, "error", 'error')
+ ins.monitor_func()
+ ins._result = {'outage_time' : 2}
+ ins.verify_SLA()
diff --git a/tests/unit/benchmark/scenarios/networking/test_ping.py b/tests/unit/benchmark/scenarios/networking/test_ping.py
index 3a897d0f8..600974510 100644
--- a/tests/unit/benchmark/scenarios/networking/test_ping.py
+++ b/tests/unit/benchmark/scenarios/networking/test_ping.py
@@ -43,7 +43,7 @@ class PingTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, '100', '')
p.run(result)
- self.assertEqual(result, {'rtt': 100.0})
+ self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}})
@mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
def test_ping_successful_sla(self, mock_ssh):
@@ -58,7 +58,7 @@ class PingTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, '100', '')
p.run(result)
- self.assertEqual(result, {'rtt': 100.0})
+ self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}})
@mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
def test_ping_unsuccessful_sla(self, mock_ssh):
diff --git a/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py b/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py
index 983c3a3ac..d26c99c75 100644
--- a/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py
+++ b/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py
@@ -12,6 +12,7 @@ import multiprocessing
import time
import os
import yardstick.common.utils as utils
+import yaml
LOG = logging.getLogger(__name__)
@@ -32,9 +33,16 @@ class MonitorMgr(object):
monitor_type = monitor_cfg["monitor_type"]
monitor_cls = BaseMonitor.get_monitor_cls(monitor_type)
monitor_ins = monitor_cls(monitor_cfg, context)
-
+ if "key" in monitor_cfg:
+ monitor_ins.key = monitor_cfg["key"]
self._monitor_list.append(monitor_ins)
+ def __getitem__(self, item):
+ for obj in self._monitor_list:
+ if obj.key == item:
+ return obj
+ raise KeyError("No such monitor instance of key - %s" % item)
+
def start_monitors(self):
for _monotor_instace in self._monitor_list:
_monotor_instace.start_monitor()
@@ -52,8 +60,12 @@ class MonitorMgr(object):
class BaseMonitor(multiprocessing.Process):
"""docstring for BaseMonitor"""
+ monitor_cfgs = {}
def __init__(self, config, context):
+ if not BaseMonitor.monitor_cfgs:
+ with open(monitor_conf_path) as stream:
+ BaseMonitor.monitor_cfgs = yaml.load(stream)
multiprocessing.Process.__init__(self)
self._config = config
self._context = context
diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py
new file mode 100644
index 000000000..515514c29
--- /dev/null
+++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py
@@ -0,0 +1,70 @@
+##############################################################################
+# Copyright (c) 2016 Juan Qiu and others
+# juan_ qiu@tongji.edu.cn
+# 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
+from yardstick.benchmark.scenarios.availability.util import buildshellparams
+
+
+LOG = logging.getLogger(__name__)
+
+
+class GeneralMonitor(basemonitor.BaseMonitor):
+ """docstring for MonitorApi"""
+
+ __monitor_type__ = "general-monitor"
+
+ 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.key = self._config["key"]
+ self.monitor_type = self._config["monitor_type"]
+
+ if "parameter" in self._config:
+ parameter = self._config['parameter']
+ str = buildshellparams(parameter)
+ l = list(item for item in parameter.values())
+ self.cmd_param = str.format(*l)
+
+ self.monitor_cfg = basemonitor.BaseMonitor.monitor_cfgs.get(self.key)
+ self.monitor_script = self.get_script_fullpath(
+ self.monitor_cfg['monitor_script'])
+ self.connection = ssh.SSH(user, ip, key_filename=key_filename)
+ self.connection.wait(timeout=600)
+ LOG.debug("ssh host success!")
+
+ def monitor_func(self):
+ if "parameter" in self._config:
+ exit_status, stdout, stderr = self.connection.execute(
+ self.cmd_param,
+ stdin=open(self.monitor_script, "r"))
+ else:
+ exit_status, stdout, stderr = self.connection.execute(
+ "/bin/bash -s ",
+ stdin=open(self.monitor_script, "r"))
+
+ if exit_status:
+ return False
+ 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 is None:
+ LOG.error("There is no outage_time in monitor result.")
+ return False
+ if outage_time > max_outage_time:
+ LOG.error("SLA failure: %f > %f" % (outage_time, max_outage_time))
+ return False
+ else:
+ return True
diff --git a/yardstick/benchmark/scenarios/availability/monitor_conf.yaml b/yardstick/benchmark/scenarios/availability/monitor_conf.yaml
new file mode 100644
index 000000000..9efceed88
--- /dev/null
+++ b/yardstick/benchmark/scenarios/availability/monitor_conf.yaml
@@ -0,0 +1,11 @@
+---
+# sample config file for ha test
+#
+schema: "yardstick:task:0.1"
+
+process_status:
+ monitor_script: ha_tools/check_process_python.bash
+nova_image_list:
+ monitor_script: ha_tools/nova_image_list.bash
+service_status:
+ monitor_script: ha_tools/check_service.bash
diff --git a/yardstick/benchmark/scenarios/networking/ping.py b/yardstick/benchmark/scenarios/networking/ping.py
index ae2166687..3af354850 100644
--- a/yardstick/benchmark/scenarios/networking/ping.py
+++ b/yardstick/benchmark/scenarios/networking/ping.py
@@ -57,29 +57,32 @@ class Ping(base.Scenario):
else:
options = ""
- destination = self.context_cfg['target'].get("ipaddr", '127.0.0.1')
+ destination = self.context_cfg['target'].get('ipaddr', '127.0.0.1')
+ dest_list = [s.strip() for s in destination.split(',')]
- LOG.debug("ping '%s' '%s'", options, destination)
+ result["rtt"] = {}
+ rtt_result = result["rtt"]
- exit_status, stdout, stderr = self.connection.execute(
- "/bin/sh -s {0} {1}".format(destination, options),
- stdin=open(self.target_script, "r"))
+ for dest in dest_list:
+ LOG.debug("ping '%s' '%s'", options, dest)
+ exit_status, stdout, stderr = self.connection.execute(
+ "/bin/sh -s {0} {1}".format(dest, options),
+ stdin=open(self.target_script, "r"))
- if exit_status != 0:
- raise RuntimeError(stderr)
+ if exit_status != 0:
+ raise RuntimeError(stderr)
- if stdout:
- result["rtt"] = float(stdout)
-
- if "sla" in self.scenario_cfg:
- sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"])
- assert result["rtt"] <= sla_max_rtt, \
- "rtt %f > sla:max_rtt(%f); " % (result["rtt"], sla_max_rtt)
- else:
- LOG.error("ping '%s' '%s' timeout", options, destination)
+ if stdout:
+ rtt_result[dest] = float(stdout)
+ if "sla" in self.scenario_cfg:
+ sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"])
+ assert rtt_result[dest] <= sla_max_rtt, "rtt %f > sla:\
+ max_rtt(%f); " % (rtt_result[dest], sla_max_rtt)
+ else:
+ LOG.error("ping '%s' '%s' timeout", options, dest)
-def _test():
+def _test(): # pragma: no cover
'''internal test function'''
key_filename = pkg_resources.resource_filename("yardstick.resources",
"files/yardstick_key")
@@ -104,5 +107,5 @@ def _test():
p.run(result)
print result
-if __name__ == '__main__':
+if __name__ == '__main__': # pragma: no cover
_test()
diff --git a/yardstick/cmd/commands/task.py b/yardstick/cmd/commands/task.py
index 55898e1cb..2bc5abe29 100644
--- a/yardstick/cmd/commands/task.py
+++ b/yardstick/cmd/commands/task.py
@@ -374,6 +374,20 @@ def run_one_scenario(scenario_cfg, output_file):
context_cfg["target"]["ipaddr"] = \
context_cfg["target"]["ip"]
+ if "targets" in scenario_cfg:
+ ip_list = []
+ for target in scenario_cfg["targets"]:
+ if is_ip_addr(target):
+ ip_list.append(target)
+ context_cfg['target'] = {}
+ else:
+ context_cfg['target'] = Context.get_server(target)
+ if _is_same_heat_context(scenario_cfg["host"], target):
+ ip_list.append(context_cfg["target"]["private_ip"])
+ else:
+ ip_list.append(context_cfg["target"]["ip"])
+ context_cfg['target']['ipaddr'] = ','.join(ip_list)
+
if "nodes" in scenario_cfg:
context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg)
runner = base_runner.Runner.get(runner_cfg)