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