Merge "Add test case description and task file for TC049"
[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 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.availability.scenario_general import ScenarioGeneral
18
19
20 @mock.patch('yardstick.benchmark.scenarios.availability.scenario_general.Director')
21 class ScenarioGeneralTestCase(unittest.TestCase):
22
23     def setUp(self):
24         self.scenario_cfg = {
25             'type': "general_scenario",
26             'options': {
27                 'attackers':[{
28                     'fault_type': "general-attacker",
29                     'key': "kill-process"}],
30                 'monitors': [{
31                     'monitor_type': "general-monitor",
32                     'key': "service_status"}],
33                 'steps':[
34                     {
35                         'actionKey': "kill-process",
36                         'actionType': "attacker",
37                         'index': 1},
38                     {
39                         'actionKey': "service_status",
40                         'actionType': "monitor",
41                         'index': 2}]
42             }
43         }
44
45     def test_scenario_general_all_successful(self, mock_director):
46         ins = ScenarioGeneral(self.scenario_cfg, None)
47         ins.setup()
48         ins.run(None)
49         ins.teardown()
50
51     def test_scenario_general_exception(self, mock_director):
52         ins = ScenarioGeneral(self.scenario_cfg, None)
53         mock_obj = mock.Mock()
54         mock_obj.createActionPlayer.side_effect = KeyError('Wrong')
55         ins.director = mock_obj
56         ins.run(None)
57         ins.teardown()
58
59     def test_scenario_general_case_fail(self, mock_director):
60         ins = ScenarioGeneral(self.scenario_cfg, None)
61         mock_obj = mock.Mock()
62         mock_obj.verify.return_value = False
63         ins.director = mock_obj
64         ins.run(None)
65         ins.teardown()