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 # pylint: disable=unused-argument
22 # disable this for now because I keep forgetting mock patch arg ordering
25 @mock.patch('yardstick.benchmark.scenarios.availability.director.basemonitor')
26 @mock.patch('yardstick.benchmark.scenarios.availability.director.baseattacker')
28 'yardstick.benchmark.scenarios.availability.director.baseoperation')
30 'yardstick.benchmark.scenarios.availability.director.baseresultchecker')
31 class DirectorTestCase(unittest.TestCase):
35 'type': "general_scenario",
38 'fault_type': "general-attacker",
39 'key': "kill-process"}],
41 'monitor_type': "general-monitor",
42 'key': "service-status"}],
44 'operation_type': 'general-operation',
45 'key': 'service-status'}],
47 'checker_type': 'general-result-checker',
48 'key': 'process-checker', }],
51 'actionKey': "service-status",
52 'actionType': "operation",
55 'actionKey': "kill-process",
56 'actionType': "attacker",
59 'actionKey': "process-checker",
60 'actionType': "resultchecker",
63 'actionKey': "service-status",
64 'actionType': "monitor",
72 "key_filename": "/root/.ssh/id_rsa"
74 self.ctx = {"nodes": {"node1": host}}
76 def test_director_all_successful(self, mock_checer, mock_opertion,
77 mock_attacker, mock_monitor):
78 ins = Director(self.scenario_cfg, self.ctx)
79 opertion_action = ins.createActionPlayer("operation", "service-status")
80 attacker_action = ins.createActionPlayer("attacker", "kill-process")
81 checker_action = ins.createActionPlayer("resultchecker",
83 monitor_action = ins.createActionPlayer("monitor", "service-status")
85 opertion_rollback = ins.createActionRollbacker("operation",
87 attacker_rollback = ins.createActionRollbacker("attacker",
89 ins.executionSteps.append(opertion_rollback)
90 ins.executionSteps.append(attacker_rollback)
92 opertion_action.action()
93 attacker_action.action()
94 checker_action.action()
95 monitor_action.action()
97 attacker_rollback.rollback()
98 opertion_rollback.rollback()
104 def test_director_get_wrong_item(self, mock_checer, mock_opertion,
105 mock_attacker, mock_monitor):
106 ins = Director(self.scenario_cfg, self.ctx)
107 ins.createActionPlayer("wrong_type", "wrong_key")
108 ins.createActionRollbacker("wrong_type", "wrong_key")