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
14 from __future__ import absolute_import
18 from yardstick.benchmark.scenarios.availability.director import Director
21 @mock.patch('yardstick.benchmark.scenarios.availability.director.basemonitor')
22 @mock.patch('yardstick.benchmark.scenarios.availability.director.baseattacker')
24 'yardstick.benchmark.scenarios.availability.director.baseoperation')
26 'yardstick.benchmark.scenarios.availability.director.baseresultchecker')
27 class DirectorTestCase(unittest.TestCase):
31 'type': "general_scenario",
34 'fault_type': "general-attacker",
35 'key': "kill-process"}],
37 'monitor_type': "general-monitor",
38 'key': "service-status"}],
40 'operation_type': 'general-operation',
41 'key': 'service-status'}],
43 'checker_type': 'general-result-checker',
44 'key': 'process-checker', }],
47 'actionKey': "service-status",
48 'actionType': "operation",
51 'actionKey': "kill-process",
52 'actionType': "attacker",
55 'actionKey': "process-checker",
56 'actionType': "resultchecker",
59 'actionKey': "service-status",
60 'actionType': "monitor",
68 "key_filename": "/root/.ssh/id_rsa"
70 self.ctx = {"nodes": {"node1": host}}
72 def test_director_all_successful(self, mock_checer, mock_opertion,
73 mock_attacker, mock_monitor):
74 ins = Director(self.scenario_cfg, self.ctx)
75 opertion_action = ins.createActionPlayer("operation", "service-status")
76 attacker_action = ins.createActionPlayer("attacker", "kill-process")
77 checker_action = ins.createActionPlayer("resultchecker",
79 monitor_action = ins.createActionPlayer("monitor", "service-status")
81 opertion_rollback = ins.createActionRollbacker("operation",
83 attacker_rollback = ins.createActionRollbacker("attacker",
85 ins.executionSteps.append(opertion_rollback)
86 ins.executionSteps.append(attacker_rollback)
88 opertion_action.action()
89 attacker_action.action()
90 checker_action.action()
91 monitor_action.action()
93 attacker_rollback.rollback()
94 opertion_rollback.rollback()
100 def test_director_get_wrong_item(self, mock_checer, mock_opertion,
101 mock_attacker, mock_monitor):
102 ins = Director(self.scenario_cfg, self.ctx)
103 ins.createActionPlayer("wrong_type", "wrong_key")
104 ins.createActionRollbacker("wrong_type", "wrong_key")