Move tests: unit/benchmark
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_scenario_general.py
1 ##############################################################################
2 # Copyright (c) 2016 Huan Li and others
3 # lihuansse@tongji.edu.cn
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
10 import mock
11 import unittest
12
13 from yardstick.benchmark.scenarios.availability import scenario_general
14
15 class ScenarioGeneralTestCase(unittest.TestCase):
16
17     def setUp(self):
18         self.scenario_cfg = {
19             'type': "general_scenario",
20             'options': {
21                 'attackers': [{
22                     'fault_type': "general-attacker",
23                     'key': "kill-process"}],
24                 'monitors': [{
25                     'monitor_type': "general-monitor",
26                     'key': "service-status"}],
27                 'steps': [
28                     {
29                         'actionKey': "kill-process",
30                         'actionType': "attacker",
31                         'index': 1},
32                     {
33                         'actionKey': "service-status",
34                         'actionType': "monitor",
35                         'index': 2}]
36             }
37         }
38         self.instance = scenario_general.ScenarioGeneral(self.scenario_cfg, None)
39
40         self._mock_director = mock.patch.object(scenario_general, 'Director')
41         self.mock_director = self._mock_director.start()
42         self.addCleanup(self._stop_mock)
43
44     def _stop_mock(self):
45         self._mock_director.stop()
46
47     def test_scenario_general_all_successful(self):
48         self.instance.setup()
49         self.instance.run({})
50         self.instance.teardown()
51
52     def test_scenario_general_exception(self):
53         mock_obj = mock.Mock()
54         mock_obj.createActionPlayer.side_effect = KeyError('Wrong')
55         self.instance.director = mock_obj
56         self.instance.director.data = {}
57         self.instance.run({})
58         self.instance.teardown()
59
60     def test_scenario_general_case_fail(self):
61         mock_obj = mock.Mock()
62         mock_obj.verify.return_value = False
63         self.instance.director = mock_obj
64         self.instance.director.data = {}
65         self.instance.run({})
66         self.instance.pass_flag = True
67         self.instance.teardown()