Merge "Bugfix: report date format wrong when upload result data to mongoDB"
[yardstick.git] / tests / unit / benchmark / scenarios / availability / test_scenario_general.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2016 Huan Li and others
5 # lihuansse@tongji.edu.cn
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.availability.scenario_general
13
14 from __future__ import absolute_import
15 import mock
16 import unittest
17
18 from yardstick.benchmark.scenarios.availability.scenario_general import \
19     ScenarioGeneral
20
21
22 @mock.patch(
23     'yardstick.benchmark.scenarios.availability.scenario_general.Director')
24 class ScenarioGeneralTestCase(unittest.TestCase):
25
26     def setUp(self):
27         self.scenario_cfg = {
28             'type': "general_scenario",
29             'options': {
30                 'attackers': [{
31                     'fault_type': "general-attacker",
32                     'key': "kill-process"}],
33                 'monitors': [{
34                     'monitor_type': "general-monitor",
35                     'key': "service-status"}],
36                 'steps': [
37                     {
38                         'actionKey': "kill-process",
39                         'actionType': "attacker",
40                         'index': 1},
41                     {
42                         'actionKey': "service-status",
43                         'actionType': "monitor",
44                         'index': 2}]
45             }
46         }
47
48     def test_scenario_general_all_successful(self, mock_director):
49         ins = ScenarioGeneral(self.scenario_cfg, None)
50         ins.setup()
51         ins.run(None)
52         ins.teardown()
53
54     def test_scenario_general_exception(self, mock_director):
55         ins = ScenarioGeneral(self.scenario_cfg, None)
56         mock_obj = mock.Mock()
57         mock_obj.createActionPlayer.side_effect = KeyError('Wrong')
58         ins.director = mock_obj
59         ins.run(None)
60         ins.teardown()
61
62     def test_scenario_general_case_fail(self, mock_director):
63         ins = ScenarioGeneral(self.scenario_cfg, None)
64         mock_obj = mock.Mock()
65         mock_obj.verify.return_value = False
66         ins.director = mock_obj
67         ins.run(None)
68         ins.teardown()