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 ##############################################################################
10 # Unittest for yardstick.benchmark.scenarios.availability.director
12 from __future__ import absolute_import
16 from yardstick.benchmark.scenarios.availability.director import Director
19 # pylint: disable=unused-argument
20 # disable this for now because I keep forgetting mock patch arg ordering
23 @mock.patch('yardstick.benchmark.scenarios.availability.director.basemonitor')
24 @mock.patch('yardstick.benchmark.scenarios.availability.director.baseattacker')
26 'yardstick.benchmark.scenarios.availability.director.baseoperation')
28 'yardstick.benchmark.scenarios.availability.director.baseresultchecker')
29 class DirectorTestCase(unittest.TestCase):
33 'type': "general_scenario",
36 'fault_type': "general-attacker",
37 'key': "kill-process"}],
39 'monitor_type': "general-monitor",
40 'key': "service-status"}],
42 'operation_type': 'general-operation',
43 'key': 'service-status'}],
45 'checker_type': 'general-result-checker',
46 'key': 'process-checker', }],
49 'actionKey': "service-status",
50 'actionType': "operation",
53 'actionKey': "kill-process",
54 'actionType': "attacker",
57 'actionKey': "process-checker",
58 'actionType': "resultchecker",
61 'actionKey': "service-status",
62 'actionType': "monitor",
70 "key_filename": "/root/.ssh/id_rsa"
72 self.ctx = {"nodes": {"node1": host}}
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",
81 monitor_action = ins.createActionPlayer("monitor", "service-status")
83 opertion_rollback = ins.createActionRollbacker("operation",
85 attacker_rollback = ins.createActionRollbacker("attacker",
87 ins.executionSteps.append(opertion_rollback)
88 ins.executionSteps.append(attacker_rollback)
90 opertion_action.action()
91 attacker_action.action()
92 checker_action.action()
93 monitor_action.action()
95 attacker_rollback.rollback()
96 opertion_rollback.rollback()
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")