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 ##############################################################################
12 # Unittest for yardstick.benchmark.scenarios.availability.director
17 from yardstick.benchmark.scenarios.availability.director import Director
18 from yardstick.benchmark.scenarios.availability import actionplayers
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):
29 'type': "general_scenario",
32 'fault_type': "general-attacker",
33 'key': "kill-process"}],
35 'monitor_type': "general-monitor",
36 'key': "service_status"}],
38 'operation_type': 'general-operation',
39 'key' : 'service_status'}],
41 'checker_type': 'general-result-checker',
42 'key' : 'process-checker',}],
45 'actionKey': "service_status",
46 'actionType': "operation",
49 'actionKey': "kill-process",
50 'actionType': "attacker",
53 'actionKey': "process-checker",
54 'actionType': "resultchecker",
57 'actionKey': "service_status",
58 'actionType': "monitor",
66 "key_filename": "/root/.ssh/id_rsa"
68 self.ctx = {"nodes": {"node1": host}}
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")
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)
82 opertion_action.action()
83 attacker_action.action()
84 checker_action.action()
85 monitor_action.action()
87 attacker_rollback.rollback()
88 opertion_rollback.rollback()
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")