Merge "Bug Fix: Start openvswitch service in Centos distro"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_director.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 # Unittest for yardstick.benchmark.scenarios.availability.director
11
12 from __future__ import absolute_import
13 import mock
14 import unittest
15
16 from yardstick.benchmark.scenarios.availability.director import Director
17
18
19 # pylint: disable=unused-argument
20 # disable this for now because I keep forgetting mock patch arg ordering
21
22
23 @mock.patch('yardstick.benchmark.scenarios.availability.director.basemonitor')
24 @mock.patch('yardstick.benchmark.scenarios.availability.director.baseattacker')
25 @mock.patch(
26     'yardstick.benchmark.scenarios.availability.director.baseoperation')
27 @mock.patch(
28     'yardstick.benchmark.scenarios.availability.director.baseresultchecker')
29 class DirectorTestCase(unittest.TestCase):
30
31     def setUp(self):
32         self.scenario_cfg = {
33             'type': "general_scenario",
34             'options': {
35                 'attackers': [{
36                     'fault_type': "general-attacker",
37                     'key': "kill-process"}],
38                 'monitors': [{
39                     'monitor_type': "general-monitor",
40                     'key': "service-status"}],
41                 'operations': [{
42                     'operation_type': 'general-operation',
43                     'key': 'service-status'}],
44                 'resultCheckers': [{
45                     'checker_type': 'general-result-checker',
46                     'key': 'process-checker', }],
47                 'steps': [
48                     {
49                         'actionKey': "service-status",
50                         'actionType': "operation",
51                         'index': 1},
52                     {
53                         'actionKey': "kill-process",
54                         'actionType': "attacker",
55                         'index': 2},
56                     {
57                         'actionKey': "process-checker",
58                         'actionType': "resultchecker",
59                         'index': 3},
60                     {
61                         'actionKey': "service-status",
62                         'actionType': "monitor",
63                         'index': 4},
64                 ]
65             }
66         }
67         host = {
68             "ip": "10.20.0.5",
69             "user": "root",
70             "key_filename": "/root/.ssh/id_rsa"
71         }
72         self.ctx = {"nodes": {"node1": host}}
73
74     def test_director_all_successful(self, mock_checer, mock_opertion,
75                                      mock_attacker, mock_monitor):
76         ins = Director(self.scenario_cfg, self.ctx)
77         opertion_action = ins.createActionPlayer("operation", "service-status")
78         attacker_action = ins.createActionPlayer("attacker", "kill-process")
79         checker_action = ins.createActionPlayer("resultchecker",
80                                                 "process-checker")
81         monitor_action = ins.createActionPlayer("monitor", "service-status")
82
83         opertion_rollback = ins.createActionRollbacker("operation",
84                                                        "service-status")
85         attacker_rollback = ins.createActionRollbacker("attacker",
86                                                        "kill-process")
87         ins.executionSteps.append(opertion_rollback)
88         ins.executionSteps.append(attacker_rollback)
89
90         opertion_action.action()
91         attacker_action.action()
92         checker_action.action()
93         monitor_action.action()
94
95         attacker_rollback.rollback()
96         opertion_rollback.rollback()
97
98         ins.stopMonitors()
99         ins.verify()
100         ins.knockoff()
101
102     def test_director_get_wrong_item(self, mock_checer, mock_opertion,
103                                      mock_attacker, mock_monitor):
104         ins = Director(self.scenario_cfg, self.ctx)
105         ins.createActionPlayer("wrong_type", "wrong_key")
106         ins.createActionRollbacker("wrong_type", "wrong_key")