aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/benchmark/scenarios/availability
diff options
context:
space:
mode:
authorEmma Foley <emma.l.foley@intel.com>2017-11-29 22:56:21 +0000
committerEmma Foley <emma.l.foley@intel.com>2018-02-12 16:57:56 +0000
commitba4e9e6e47bd10ecc803bab920178ea973c2fa86 (patch)
tree54576c199cabe8ccc29d04eedfe0e4f88b2bd598 /yardstick/tests/unit/benchmark/scenarios/availability
parentbabe3cc2882e19c6dafdbf41d502d7ba5560635a (diff)
Move tests: unit/benchmark
* Fix pylint errors * Add TODOs Some errors are ignored locally, as they were a symptom of other problems. These issues have been flagged with a TODO, and should be fixed later. Change-Id: I30eb4b0aafe0575d0cddbc946108291f21a98ed8 Jira: YARDSTICK-837 Signed-off-by: Emma Foley <emma.l.foley@intel.com> Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'yardstick/tests/unit/benchmark/scenarios/availability')
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/__init__.py0
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py88
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_general.py58
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_process.py55
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py119
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_baseoperation.py79
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py91
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_director.py108
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_command.py95
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_general.py84
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py67
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py59
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_operation_general.py76
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py120
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_scenario_general.py67
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_serviceha.py74
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_util.py58
17 files changed, 1298 insertions, 0 deletions
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/__init__.py b/yardstick/tests/unit/benchmark/scenarios/availability/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/__init__.py
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
new file mode 100644
index 000000000..f0921c0f6
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+
+##############################################################################
+# 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
+##############################################################################
+
+# Unittest for
+# yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal
+
+from __future__ import absolute_import
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.attacker import \
+ attacker_baremetal
+
+
+# pylint: disable=unused-argument
+# disable this for now because I keep forgetting mock patch arg ordering
+
+
+@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.subprocess')
+class ExecuteShellTestCase(unittest.TestCase):
+
+ def test__fun_execute_shell_command_successful(self, mock_subprocess):
+ cmd = "env"
+ mock_subprocess.check_output.return_value = (0, 'unittest')
+ exitcode, _ = attacker_baremetal._execute_shell_command(cmd)
+ self.assertEqual(exitcode, 0)
+
+ @mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.LOG')
+ def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log, mock_subprocess):
+ cmd = "env"
+ mock_subprocess.check_output.side_effect = RuntimeError
+ exitcode, _ = attacker_baremetal._execute_shell_command(cmd)
+ self.assertEqual(exitcode, -1)
+ mock_log.error.assert_called_once()
+
+
+@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.subprocess')
+@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.ssh')
+class AttackerBaremetalTestCase(unittest.TestCase):
+
+ def setUp(self):
+ host = {
+ "ipmi_ip": "10.20.0.5",
+ "ipmi_user": "root",
+ "ipmi_pwd": "123456",
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.context = {"node1": host}
+ self.attacker_cfg = {
+ 'fault_type': 'bear-metal-down',
+ 'host': 'node1',
+ }
+
+ def test__attacker_baremetal_all_successful(self, mock_ssh, mock_subprocess):
+ mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
+ ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
+ self.context)
+
+ ins.setup()
+ ins.inject_fault()
+ ins.recover()
+
+ def test__attacker_baremetal_check_failuer(self, mock_ssh, mock_subprocess):
+ mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '')
+ ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
+ self.context)
+ ins.setup()
+
+ def test__attacker_baremetal_recover_successful(self, mock_ssh, mock_subprocess):
+
+ self.attacker_cfg["jump_host"] = 'node1'
+ self.context["node1"]["pwd"] = "123456"
+ mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
+ ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
+ self.context)
+
+ ins.setup()
+ ins.recover()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_general.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
new file mode 100644
index 000000000..612b5a662
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+
+##############################################################################
+# 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
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.availability.attacker
+# .attacker_general
+
+from __future__ import absolute_import
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.attacker import baseattacker
+
+
+@mock.patch('yardstick.benchmark.scenarios.availability.attacker.'
+ 'attacker_general.ssh')
+class GeneralAttackerServiceTestCase(unittest.TestCase):
+
+ def setUp(self):
+ host = {
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.context = {"node1": host}
+ self.attacker_cfg = {
+ 'fault_type': 'general-attacker',
+ 'action_parameter': {'process_name': 'nova_api'},
+ 'rollback_parameter': {'process_name': 'nova_api'},
+ 'key': 'stop-service',
+ 'attack_key': 'stop-service',
+ 'host': 'node1',
+ }
+
+ def test__attacker_service_all_successful(self, mock_ssh):
+
+ cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
+ ins = cls(self.attacker_cfg, self.context)
+
+ mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
+ ins.setup()
+ ins.inject_fault()
+ ins.recover()
+
+ def test__attacker_service_check_failuer(self, mock_ssh):
+
+ cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
+ ins = cls(self.attacker_cfg, self.context)
+
+ mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '')
+ ins.setup()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_process.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_process.py
new file mode 100644
index 000000000..0a8e8322a
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_process.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+##############################################################################
+# 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
+##############################################################################
+
+# Unittest for
+# yardstick.benchmark.scenarios.availability.attacker.attacker_process
+
+from __future__ import absolute_import
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.attacker import baseattacker
+
+
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.attacker.attacker_process.ssh')
+class AttackerServiceTestCase(unittest.TestCase):
+
+ def setUp(self):
+ host = {
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.context = {"node1": host}
+ self.attacker_cfg = {
+ 'fault_type': 'kill-process',
+ 'process_name': 'nova-api',
+ 'host': 'node1',
+ }
+
+ def test__attacker_service_all_successful(self, mock_ssh):
+
+ cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
+ ins = cls(self.attacker_cfg, self.context)
+
+ mock_ssh.SSH.from_node().execute.return_value = (0, "10", '')
+ ins.setup()
+ ins.inject_fault()
+ ins.recover()
+
+ def test__attacker_service_check_failuer(self, mock_ssh):
+
+ cls = baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
+ ins = cls(self.attacker_cfg, self.context)
+
+ mock_ssh.SSH.from_node().execute.return_value = (0, None, '')
+ ins.setup()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
new file mode 100644
index 000000000..9bc04ebf4
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
@@ -0,0 +1,119 @@
+##############################################################################
+# 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 mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.monitor import basemonitor
+
+
+class MonitorMgrTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.monitor_configs = [
+ {
+ "monitor_type": "openstack-cmd",
+ "command_name": "openstack router list",
+ "monitor_time": 10,
+ "monitor_number": 3,
+ "sla": {
+ "max_outage_time": 5
+ }
+ },
+ {
+ "monitor_type": "process",
+ "process_name": "neutron-server",
+ "host": "node1",
+ "monitor_time": 20,
+ "monitor_number": 3,
+ "sla": {
+ "max_recover_time": 20
+ }
+ }
+ ]
+ self.MonitorMgr = basemonitor.MonitorMgr([])
+ self.MonitorMgr.init_monitors(self.monitor_configs, None)
+ self.monitor_list = self.MonitorMgr._monitor_list
+ for mo in self.monitor_list:
+ mo._result = {"outage_time": 10}
+
+ @mock.patch.object(basemonitor, 'BaseMonitor')
+ def test__MonitorMgr_setup_successful(self, *args):
+ instance = basemonitor.MonitorMgr({"nova-api": 10})
+ instance.init_monitors(self.monitor_configs, None)
+ instance.start_monitors()
+ instance.wait_monitors()
+
+ # TODO(elfoley): Check the return value
+ ret = instance.verify_SLA() # pylint: disable=unused-variable
+
+ @mock.patch.object(basemonitor, 'BaseMonitor')
+ def test_MonitorMgr_getitem(self, *args):
+ monitorMgr = basemonitor.MonitorMgr({"nova-api": 10})
+ monitorMgr.init_monitors(self.monitor_configs, None)
+
+ @mock.patch.object(basemonitor, 'BaseMonitor')
+ def test_store_result(self, *args):
+ expect = {'process_neutron-server_outage_time': 10,
+ 'openstack-router-list_outage_time': 10}
+ result = {}
+ self.MonitorMgr.store_result(result)
+ self.assertDictEqual(result, expect)
+
+
+class BaseMonitorTestCase(unittest.TestCase):
+
+ class MonitorSimple(basemonitor.BaseMonitor):
+ __monitor_type__ = "MonitorForTest"
+
+ def setup(self):
+ self.monitor_result = False
+
+ def monitor_func(self):
+ return self.monitor_result
+
+ def setUp(self):
+ self.monitor_cfg = {
+ 'monitor_type': 'MonitorForTest',
+ 'command_name': 'nova image-list',
+ 'monitor_time': 0.01,
+ 'sla': {'max_outage_time': 5}
+ }
+
+ def test__basemonitor_start_wait_successful(self):
+ ins = basemonitor.BaseMonitor(self.monitor_cfg, None, {"nova-api": 10})
+ ins.start_monitor()
+ ins.wait_monitor()
+
+ def test__basemonitor_all_successful(self):
+ ins = self.MonitorSimple(self.monitor_cfg, None, {"nova-api": 10})
+ ins.setup()
+ ins.run()
+ ins.verify_SLA()
+
+ @mock.patch.object(basemonitor, 'multiprocessing')
+ def test__basemonitor_func_false(self, mock_multiprocess):
+ ins = self.MonitorSimple(self.monitor_cfg, None, {"nova-api": 10})
+ ins.setup()
+ mock_multiprocess.Event().is_set.return_value = False
+ ins.run()
+ ins.verify_SLA()
+
+ # TODO(elfoley): fix this test to not throw an error
+ def test__basemonitor_getmonitorcls_successfule(self):
+ cls = None
+ try:
+ cls = basemonitor.BaseMonitor.get_monitor_cls(self.monitor_cfg)
+ except Exception: # pylint: disable=broad-except
+ pass
+ self.assertIsNone(cls)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_baseoperation.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_baseoperation.py
new file mode 100644
index 000000000..b7c9f62ff
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_baseoperation.py
@@ -0,0 +1,79 @@
+##############################################################################
+# 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
+##############################################################################
+
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.operation import baseoperation
+
+
+class OperationMgrTestCase(unittest.TestCase):
+
+ def setUp(self):
+ config = {
+ 'operation_type': 'general-operation',
+ 'key': 'service-status'
+ }
+
+ self.operation_configs = []
+ self.operation_configs.append(config)
+
+ @mock.patch.object(baseoperation, 'BaseOperation')
+ def test_all_successful(self, *args):
+ mgr_ins = baseoperation.OperationMgr()
+ mgr_ins.init_operations(self.operation_configs, None)
+ _ = mgr_ins["service-status"]
+ mgr_ins.rollback()
+
+ @mock.patch.object(baseoperation, 'BaseOperation')
+ def test_getitem_fail(self, *args):
+ mgr_ins = baseoperation.OperationMgr()
+ mgr_ins.init_operations(self.operation_configs, None)
+ with self.assertRaises(KeyError):
+ _ = mgr_ins["operation-not-exist"]
+
+
+class TestOperation(baseoperation.BaseOperation):
+ __operation__type__ = "test-operation"
+
+ def setup(self):
+ pass
+
+ def run(self):
+ pass
+
+ def rollback(self):
+ pass
+
+
+class BaseOperationTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.config = {
+ 'operation_type': 'general-operation',
+ 'key': 'service-status'
+ }
+ self.base_ins = baseoperation.BaseOperation(self.config, None)
+
+ def test_all_successful(self):
+ self.base_ins.setup()
+ self.base_ins.run()
+ self.base_ins.rollback()
+
+ def test_get_script_fullpath(self):
+ self.base_ins.get_script_fullpath("ha_tools/test.bash")
+
+ # TODO(elfoley): Fix test to check on expected outputs
+ # pylint: disable=unused-variable
+ def test_get_operation_cls_successful(self):
+ operation_ins = self.base_ins.get_operation_cls("test-operation")
+
+ def test_get_operation_cls_fail(self):
+ with self.assertRaises(RuntimeError):
+ self.base_ins.get_operation_cls("operation-not-exist")
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py
new file mode 100644
index 000000000..ae74d241c
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py
@@ -0,0 +1,91 @@
+#!/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
+##############################################################################
+
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.result_checker import \
+ baseresultchecker
+
+
+class ResultCheckerMgrTestCase(unittest.TestCase):
+
+ def setUp(self):
+ config = {
+ 'checker_type': 'general-result-checker',
+ 'key': 'process-checker'
+ }
+
+ self.checker_configs = []
+ self.checker_configs.append(config)
+
+ self.mgr_ins = baseresultchecker.ResultCheckerMgr()
+
+ self._mock_basechecker = mock.patch.object(baseresultchecker,
+ 'BaseResultChecker')
+ self.mock_basechecker = self._mock_basechecker.start()
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_basechecker.stop()
+
+ def test_ResultCheckerMgr_setup_successful(self):
+ self.mgr_ins.verify()
+
+ def test_getitem_succeessful(self):
+ self.mgr_ins.init_ResultChecker(self.checker_configs, None)
+ _ = self.mgr_ins["process-checker"]
+
+ def test_getitem_fail(self):
+ self.mgr_ins.init_ResultChecker(self.checker_configs, None)
+ with self.assertRaises(KeyError):
+ _ = self.mgr_ins["checker-not-exist"]
+
+
+class BaseResultCheckerTestCase(unittest.TestCase):
+
+ class ResultCheckeSimple(baseresultchecker.BaseResultChecker):
+ __result_checker__type__ = "ResultCheckeForTest"
+
+ def setup(self):
+ self.success = False
+
+ def verify(self):
+ return self.success
+
+ def setUp(self):
+ self.checker_cfg = {
+ 'checker_type': 'general-result-checker',
+ 'key': 'process-checker'
+ }
+ self.ins = baseresultchecker.BaseResultChecker(self.checker_cfg, None)
+
+ def test_baseresultchecker_setup_verify_successful(self):
+ self.ins.setup()
+ self.ins.verify()
+
+ def test_baseresultchecker_verfiy_pass(self):
+ self.ins.setup()
+ self.ins.actualResult = True
+ self.ins.expectedResult = True
+ self.ins.verify()
+
+ def test_get_script_fullpath(self):
+ self.ins.get_script_fullpath("test.bash")
+
+ def test_get_resultchecker_cls_successful(self):
+ baseresultchecker.BaseResultChecker.get_resultchecker_cls(
+ "ResultCheckeForTest")
+
+ def test_get_resultchecker_cls_fail(self):
+ with self.assertRaises(RuntimeError):
+ baseresultchecker.BaseResultChecker.get_resultchecker_cls(
+ "ResultCheckeNotExist")
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_director.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_director.py
new file mode 100644
index 000000000..72ce7b0d5
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_director.py
@@ -0,0 +1,108 @@
+#!/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.director
+
+from __future__ import absolute_import
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.director import Director
+
+
+# pylint: disable=unused-argument
+# disable this for now because I keep forgetting mock patch arg ordering
+
+
+@mock.patch('yardstick.benchmark.scenarios.availability.director.basemonitor')
+@mock.patch('yardstick.benchmark.scenarios.availability.director.baseattacker')
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.director.baseoperation')
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.director.baseresultchecker')
+class DirectorTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.scenario_cfg = {
+ 'type': "general_scenario",
+ 'options': {
+ 'attackers': [{
+ 'fault_type': "general-attacker",
+ 'key': "kill-process"}],
+ 'monitors': [{
+ 'monitor_type': "general-monitor",
+ 'key': "service-status"}],
+ 'operations': [{
+ 'operation_type': 'general-operation',
+ 'key': 'service-status'}],
+ 'resultCheckers': [{
+ 'checker_type': 'general-result-checker',
+ 'key': 'process-checker', }],
+ 'steps': [
+ {
+ 'actionKey': "service-status",
+ 'actionType': "operation",
+ 'index': 1},
+ {
+ 'actionKey': "kill-process",
+ 'actionType': "attacker",
+ 'index': 2},
+ {
+ 'actionKey': "process-checker",
+ 'actionType': "resultchecker",
+ 'index': 3},
+ {
+ 'actionKey': "service-status",
+ 'actionType': "monitor",
+ 'index': 4},
+ ]
+ }
+ }
+ host = {
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.ctx = {"nodes": {"node1": host}}
+
+ def test_director_all_successful(self, mock_checer, mock_opertion,
+ mock_attacker, mock_monitor):
+ ins = Director(self.scenario_cfg, self.ctx)
+ opertion_action = ins.createActionPlayer("operation", "service-status")
+ attacker_action = ins.createActionPlayer("attacker", "kill-process")
+ checker_action = ins.createActionPlayer("resultchecker",
+ "process-checker")
+ monitor_action = ins.createActionPlayer("monitor", "service-status")
+
+ opertion_rollback = ins.createActionRollbacker("operation",
+ "service-status")
+ attacker_rollback = ins.createActionRollbacker("attacker",
+ "kill-process")
+ ins.executionSteps.append(opertion_rollback)
+ ins.executionSteps.append(attacker_rollback)
+
+ opertion_action.action()
+ attacker_action.action()
+ checker_action.action()
+ monitor_action.action()
+
+ attacker_rollback.rollback()
+ opertion_rollback.rollback()
+
+ ins.stopMonitors()
+ ins.verify()
+ ins.knockoff()
+
+ def test_director_get_wrong_item(self, mock_checer, mock_opertion,
+ mock_attacker, mock_monitor):
+ ins = Director(self.scenario_cfg, self.ctx)
+ ins.createActionPlayer("wrong_type", "wrong_key")
+ ins.createActionRollbacker("wrong_type", "wrong_key")
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_command.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
new file mode 100644
index 000000000..1aebcc85b
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
@@ -0,0 +1,95 @@
+##############################################################################
+# 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 mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.monitor import monitor_command
+
+
+class ExecuteShellTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self._mock_subprocess = mock.patch.object(monitor_command, 'subprocess')
+ self.mock_subprocess = self._mock_subprocess.start()
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_subprocess.stop()
+
+ def test__fun_execute_shell_command_successful(self):
+ cmd = "env"
+ self.mock_subprocess.check_output.return_value = (0, 'unittest')
+ exitcode, _t = monitor_command._execute_shell_command(cmd)
+ self.assertEqual(exitcode, 0)
+
+ @mock.patch.object(monitor_command, 'LOG')
+ def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log):
+ cmd = "env"
+ self.mock_subprocess.check_output.side_effect = RuntimeError
+ exitcode, _ = monitor_command._execute_shell_command(cmd)
+ self.assertEqual(exitcode, -1)
+ mock_log.error.assert_called_once()
+
+
+class MonitorOpenstackCmdTestCase(unittest.TestCase):
+
+ def setUp(self):
+ host = {
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.context = {"node1": host}
+ self.config = {
+ 'monitor_type': 'openstack-api',
+ 'command_name': 'nova image-list',
+ 'monitor_time': 1,
+ 'sla': {'max_outage_time': 5}
+ }
+ self._mock_subprocess = mock.patch.object(monitor_command, 'subprocess')
+ self.mock_subprocess = self._mock_subprocess.start()
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_subprocess.stop()
+
+ def test__monitor_command_monitor_func_successful(self):
+
+ instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10})
+ instance.setup()
+ self.mock_subprocess.check_output.return_value = (0, 'unittest')
+ ret = instance.monitor_func()
+ self.assertTrue(ret)
+ instance._result = {"outage_time": 0}
+ instance.verify_SLA()
+
+ @mock.patch.object(monitor_command, 'LOG')
+ def test__monitor_command_monitor_func_failure(self, mock_log):
+ self.mock_subprocess.check_output.return_value = (1, 'unittest')
+ instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10})
+ instance.setup()
+ self.mock_subprocess.check_output.side_effect = RuntimeError
+ ret = instance.monitor_func()
+ self.assertFalse(ret)
+ mock_log.error.assert_called_once()
+ instance._result = {"outage_time": 10}
+ instance.verify_SLA()
+
+ @mock.patch.object(monitor_command, 'ssh')
+ def test__monitor_command_ssh_monitor_successful(self, mock_ssh):
+
+ self.mock_subprocess.check_output.return_value = (0, 'unittest')
+ self.config["host"] = "node1"
+ instance = monitor_command.MonitorOpenstackCmd(
+ self.config, self.context, {"nova-api": 10})
+ instance.setup()
+ mock_ssh.SSH.from_node().execute.return_value = (0, "0", '')
+ ret = instance.monitor_func()
+ self.assertTrue(ret)
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_general.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
new file mode 100644
index 000000000..7022ea678
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
@@ -0,0 +1,84 @@
+#!/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
+
+from __future__ import absolute_import
+import mock
+import unittest
+from yardstick.benchmark.scenarios.availability.monitor import monitor_general
+
+
+# pylint: disable=unused-argument
+# disable this for now because I keep forgetting mock patch arg ordering
+
+
+@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',
+ 'monitor_key': 'service-status',
+ 'host': 'node1',
+ 'monitor_time': 3,
+ 'parameter': {'serviceName': 'haproxy'},
+ 'sla': {'max_outage_time': 1}
+ }
+ self.monitor_cfg_noparam = {
+ 'monitor_type': 'general-monitor',
+ 'key': 'service-status',
+ 'monitor_key': 'service-status',
+ 'host': 'node1',
+ 'monitor_time': 3,
+ 'sla': {'max_outage_time': 1}
+ }
+
+ def test__monitor_general_all_successful(self, mock_open, mock_ssh):
+ ins = monitor_general.GeneralMonitor(self.monitor_cfg, self.context, {"nova-api": 10})
+
+ ins.setup()
+ mock_ssh.SSH.from_node().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, {"nova-api": 10})
+
+ ins.setup()
+ mock_ssh.SSH.from_node().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, {"nova-api": 10})
+
+ ins.setup()
+ mock_ssh.SSH.from_node().execute.return_value = (1, "error", 'error')
+ ins.monitor_func()
+ ins._result = {'outage_time': 2}
+ ins.verify_SLA()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py
new file mode 100644
index 000000000..0d61d9b15
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py
@@ -0,0 +1,67 @@
+#!/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_multi
+
+from __future__ import absolute_import
+import mock
+import unittest
+from yardstick.benchmark.scenarios.availability.monitor import monitor_multi
+
+
+# pylint: disable=unused-argument
+# disable this for now because I keep forgetting mock patch arg ordering
+
+
+@mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
+ 'monitor_general.ssh')
+@mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
+ 'monitor_general.open')
+class MultiMonitorServiceTestCase(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',
+ 'monitor_number': 3,
+ 'key': 'service-status',
+ 'monitor_key': 'service-status',
+ 'host': 'node1',
+ 'monitor_time': 0.1,
+ 'parameter': {'serviceName': 'haproxy'},
+ 'sla': {'max_outage_time': 1}
+ }
+
+ def test__monitor_multi_all_successful(self, mock_open, mock_ssh):
+ ins = monitor_multi.MultiMonitor(
+ self.monitor_cfg, self.context, {"nova-api": 10})
+
+ mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
+
+ ins.start_monitor()
+ ins.wait_monitor()
+ ins.verify_SLA()
+
+ def test__monitor_multi_all_fail(self, mock_open, mock_ssh):
+ ins = monitor_multi.MultiMonitor(
+ self.monitor_cfg, self.context, {"nova-api": 10})
+
+ mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
+
+ ins.start_monitor()
+ ins.wait_monitor()
+ ins.verify_SLA()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py
new file mode 100644
index 000000000..41ce5445e
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+
+##############################################################################
+# 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
+##############################################################################
+
+# Unittest for
+# yardstick.benchmark.scenarios.availability.monitor.monitor_process
+
+from __future__ import absolute_import
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability.monitor import monitor_process
+
+
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.monitor.monitor_process.ssh')
+class MonitorProcessTestCase(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': 'process',
+ 'process_name': 'nova-api',
+ 'host': "node1",
+ 'monitor_time': 1,
+ 'sla': {'max_recover_time': 5}
+ }
+
+ def test__monitor_process_all_successful(self, mock_ssh):
+
+ ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context, {"nova-api": 10})
+
+ mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
+ ins.setup()
+ ins.monitor_func()
+ ins._result = {"outage_time": 0}
+ ins.verify_SLA()
+
+ def test__monitor_process_down_failuer(self, mock_ssh):
+
+ ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context, {"nova-api": 10})
+
+ mock_ssh.SSH.from_node().execute.return_value = (0, "0", '')
+ ins.setup()
+ ins.monitor_func()
+ ins._result = {"outage_time": 10}
+ ins.verify_SLA()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_operation_general.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_operation_general.py
new file mode 100644
index 000000000..a965f7f64
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_operation_general.py
@@ -0,0 +1,76 @@
+#!/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.operation
+# .operation_general
+
+from __future__ import absolute_import
+import mock
+import unittest
+from yardstick.benchmark.scenarios.availability.operation import \
+ operation_general
+
+
+# pylint: disable=unused-argument
+# disable this for now because I keep forgetting mock patch arg ordering
+
+
+@mock.patch('yardstick.benchmark.scenarios.availability.operation.'
+ 'operation_general.ssh')
+@mock.patch('yardstick.benchmark.scenarios.availability.operation.'
+ 'operation_general.open')
+class GeneralOperaionTestCase(unittest.TestCase):
+
+ def setUp(self):
+ host = {
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.context = {"node1": host}
+ self.operation_cfg = {
+ 'operation_type': 'general-operation',
+ 'action_parameter': {'ins_cup': 2},
+ 'rollback_parameter': {'ins_id': 'id123456'},
+ 'key': 'nova-create-instance',
+ 'operation_key': 'nova-create-instance',
+ 'host': 'node1',
+ }
+ self.operation_cfg_noparam = {
+ 'operation_type': 'general-operation',
+ 'key': 'nova-create-instance',
+ 'operation_key': 'nova-create-instance',
+ 'host': 'node1',
+ }
+
+ def test__operation_successful(self, mock_open, mock_ssh):
+ ins = operation_general.GeneralOperaion(self.operation_cfg,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (0, "success", '')
+ ins.setup()
+ ins.run()
+ ins.rollback()
+
+ def test__operation_successful_noparam(self, mock_open, mock_ssh):
+ ins = operation_general.GeneralOperaion(self.operation_cfg_noparam,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (0, "success", '')
+ ins.setup()
+ ins.run()
+ ins.rollback()
+
+ def test__operation_fail(self, mock_open, mock_ssh):
+ ins = operation_general.GeneralOperaion(self.operation_cfg,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (1, "failed", '')
+ ins.setup()
+ ins.run()
+ ins.rollback()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
new file mode 100644
index 000000000..234adcb6e
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
@@ -0,0 +1,120 @@
+#!/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.result_checker
+# .result_checker_general
+
+from __future__ import absolute_import
+import mock
+import unittest
+import copy
+
+from yardstick.benchmark.scenarios.availability.result_checker import \
+ result_checker_general
+
+
+# pylint: disable=unused-argument
+# disable this for now because I keep forgetting mock patch arg ordering
+
+
+@mock.patch('yardstick.benchmark.scenarios.availability.result_checker.'
+ 'result_checker_general.ssh')
+@mock.patch('yardstick.benchmark.scenarios.availability.result_checker.'
+ 'result_checker_general.open')
+class GeneralResultCheckerTestCase(unittest.TestCase):
+
+ def setUp(self):
+ host = {
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.context = {"node1": host}
+ self.checker_cfg = {
+ 'parameter': {'processname': 'process'},
+ 'checker_type': 'general-result-checker',
+ 'condition': 'eq',
+ 'expectedValue': 1,
+ 'key': 'process-checker',
+ 'checker_key': 'process-checker',
+ 'host': 'node1'
+ }
+
+ def test__result_checker_eq(self, mock_open, mock_ssh):
+ ins = result_checker_general.GeneralResultChecker(self.checker_cfg,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
+ ins.setup()
+ self.assertTrue(ins.verify())
+
+ def test__result_checker_gt(self, mock_open, mock_ssh):
+ config = copy.deepcopy(self.checker_cfg)
+ config['condition'] = 'gt'
+ ins = result_checker_general.GeneralResultChecker(config,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (0, "2", '')
+ ins.setup()
+ self.assertTrue(ins.verify())
+
+ def test__result_checker_gt_eq(self, mock_open, mock_ssh):
+ config = copy.deepcopy(self.checker_cfg)
+ config['condition'] = 'gt_eq'
+ ins = result_checker_general.GeneralResultChecker(config,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
+ ins.setup()
+ self.assertTrue(ins.verify())
+
+ def test__result_checker_lt(self, mock_open, mock_ssh):
+ config = copy.deepcopy(self.checker_cfg)
+ config['condition'] = 'lt'
+ ins = result_checker_general.GeneralResultChecker(config,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (0, "0", '')
+ ins.setup()
+ self.assertTrue(ins.verify())
+
+ def test__result_checker_lt_eq(self, mock_open, mock_ssh):
+ config = copy.deepcopy(self.checker_cfg)
+ config['condition'] = 'lt_eq'
+ ins = result_checker_general.GeneralResultChecker(config,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
+ ins.setup()
+ self.assertTrue(ins.verify())
+
+ def test__result_checker_in(self, mock_open, mock_ssh):
+ config = copy.deepcopy(self.checker_cfg)
+ config['condition'] = 'in'
+ config['expectedValue'] = "value"
+ ins = result_checker_general.GeneralResultChecker(config,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (0, "value return", '')
+ ins.setup()
+ self.assertTrue(ins.verify())
+
+ def test__result_checker_wrong(self, mock_open, mock_ssh):
+ config = copy.deepcopy(self.checker_cfg)
+ config['condition'] = 'wrong'
+ ins = result_checker_general.GeneralResultChecker(config,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
+ ins.setup()
+ self.assertFalse(ins.verify())
+
+ def test__result_checker_fail(self, mock_open, mock_ssh):
+ config = copy.deepcopy(self.checker_cfg)
+ config.pop('parameter')
+ ins = result_checker_general.GeneralResultChecker(config,
+ self.context)
+ mock_ssh.SSH.from_node().execute.return_value = (1, "fail", '')
+ ins.setup()
+ ins.verify()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_scenario_general.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_scenario_general.py
new file mode 100644
index 000000000..45840d569
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_scenario_general.py
@@ -0,0 +1,67 @@
+##############################################################################
+# 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
+##############################################################################
+
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability import scenario_general
+
+class ScenarioGeneralTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.scenario_cfg = {
+ 'type': "general_scenario",
+ 'options': {
+ 'attackers': [{
+ 'fault_type': "general-attacker",
+ 'key': "kill-process"}],
+ 'monitors': [{
+ 'monitor_type': "general-monitor",
+ 'key': "service-status"}],
+ 'steps': [
+ {
+ 'actionKey': "kill-process",
+ 'actionType': "attacker",
+ 'index': 1},
+ {
+ 'actionKey': "service-status",
+ 'actionType': "monitor",
+ 'index': 2}]
+ }
+ }
+ self.instance = scenario_general.ScenarioGeneral(self.scenario_cfg, None)
+
+ self._mock_director = mock.patch.object(scenario_general, 'Director')
+ self.mock_director = self._mock_director.start()
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_director.stop()
+
+ def test_scenario_general_all_successful(self):
+ self.instance.setup()
+ self.instance.run({})
+ self.instance.teardown()
+
+ def test_scenario_general_exception(self):
+ mock_obj = mock.Mock()
+ mock_obj.createActionPlayer.side_effect = KeyError('Wrong')
+ self.instance.director = mock_obj
+ self.instance.director.data = {}
+ self.instance.run({})
+ self.instance.teardown()
+
+ def test_scenario_general_case_fail(self):
+ mock_obj = mock.Mock()
+ mock_obj.verify.return_value = False
+ self.instance.director = mock_obj
+ self.instance.director.data = {}
+ self.instance.run({})
+ self.instance.pass_flag = True
+ self.instance.teardown()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_serviceha.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_serviceha.py
new file mode 100644
index 000000000..6bb3ec63b
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_serviceha.py
@@ -0,0 +1,74 @@
+##############################################################################
+# 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 mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability import serviceha
+
+
+class ServicehaTestCase(unittest.TestCase):
+
+ def setUp(self):
+ host = {
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.ctx = {"nodes": {"node1": host}}
+ attacker_cfg = {
+ "fault_type": "kill-process",
+ "process_name": "nova-api",
+ "host": "node1"
+ }
+ attacker_cfgs = []
+ attacker_cfgs.append(attacker_cfg)
+ monitor_cfg = {
+ "monitor_cmd": "nova image-list",
+ "monitor_time": 0.1
+ }
+ monitor_cfgs = []
+ monitor_cfgs.append(monitor_cfg)
+
+ options = {
+ "attackers": attacker_cfgs,
+ "monitors": monitor_cfgs
+ }
+ sla = {"outage_time": 5}
+ self.args = {"options": options, "sla": sla}
+
+ # NOTE(elfoley): This should be split into test_setup and test_run
+ # NOTE(elfoley): This should explicitly test outcomes and states
+ @mock.patch.object(serviceha, 'baseattacker')
+ @mock.patch.object(serviceha, 'basemonitor')
+ def test__serviceha_setup_run_successful(self, mock_monitor, *args):
+ p = serviceha.ServiceHA(self.args, self.ctx)
+
+ p.setup()
+ self.assertTrue(p.setup_done)
+ mock_monitor.MonitorMgr().verify_SLA.return_value = True
+ ret = {}
+ p.run(ret)
+ p.teardown()
+
+ p.setup()
+ self.assertTrue(p.setup_done)
+
+ # def test__serviceha_run_sla_error(self, mock_attacker, mock_monitor):
+ # p = serviceha.ServiceHA(self.args, self.ctx)
+
+ # p.setup()
+ # self.assertEqual(p.setup_done, True)
+
+ # result = {}
+ # result["outage_time"] = 10
+ # mock_monitor.Monitor().get_result.return_value = result
+
+ # ret = {}
+ # self.assertRaises(AssertionError, p.run, ret)
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_util.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_util.py
new file mode 100644
index 000000000..548efe91b
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_util.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2016 Kanglin Yin and others
+# 14_ykl@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.utils
+
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.availability import util
+
+
+class ExecuteShellTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.param_config = {'serviceName': '@serviceName', 'value': 1}
+ self.intermediate_variables = {'@serviceName': 'nova-api'}
+ self.std_output = '| id | 1 |'
+ self.cmd_config = {'cmd': 'ls', 'param': '-a'}
+
+ self._mock_subprocess = mock.patch.object(util, 'subprocess')
+ self.mock_subprocess = self._mock_subprocess.start()
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_subprocess.stop()
+
+ def test_util_build_command_shell(self):
+ result = util.build_shell_command(self.param_config, True,
+ self.intermediate_variables)
+ self.assertIn("nova-api", result)
+
+ def test_read_stdout_item(self):
+ result = util.read_stdout_item(self.std_output, 'id')
+ self.assertEqual('1', result)
+
+ def test_buildshellparams(self):
+ result = util.buildshellparams(self.cmd_config, True)
+ self.assertEqual('/bin/bash -s {0} {1}', result)
+
+ def test__fun_execute_shell_command_successful(self):
+ cmd = "env"
+ self.mock_subprocess.check_output.return_value = (0, 'unittest')
+ exitcode, _ = util.execute_shell_command(cmd)
+ self.assertEqual(exitcode, 0)
+
+ def test__fun_execute_shell_command_fail_cmd_exception(self):
+ cmd = "env"
+ self.mock_subprocess.check_output.side_effect = RuntimeError
+ exitcode, _ = util.execute_shell_command(cmd)
+ self.assertEqual(exitcode, -1)