3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
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.serviceha
14 from __future__ import absolute_import
18 from yardstick.benchmark.scenarios.availability import serviceha
21 @mock.patch('yardstick.benchmark.scenarios.availability.serviceha.basemonitor')
23 'yardstick.benchmark.scenarios.availability.serviceha.baseattacker')
24 class ServicehaTestCase(unittest.TestCase):
30 "key_filename": "/root/.ssh/id_rsa"
32 self.ctx = {"nodes": {"node1": host}}
34 "fault_type": "kill-process",
35 "process_name": "nova-api",
39 attacker_cfgs.append(attacker_cfg)
41 "monitor_cmd": "nova image-list",
45 monitor_cfgs.append(monitor_cfg)
48 "attackers": attacker_cfgs,
49 "monitors": monitor_cfgs
51 sla = {"outage_time": 5}
52 self.args = {"options": options, "sla": sla}
54 def test__serviceha_setup_run_successful(self, mock_attacker,
56 p = serviceha.ServiceHA(self.args, self.ctx)
59 self.assertEqual(p.setup_done, True)
60 mock_monitor.MonitorMgr().verify_SLA.return_value = True
65 def test__serviceha_run_sla_error(self, mock_attacker, mock_monitor):
66 p = serviceha.ServiceHA(self.args, self.ctx)
69 self.assertEqual(p.setup_done, True)
72 result["outage_time"] = 10
73 mock_monitor.Monitor().get_result.return_value = result
76 self.assertRaises(AssertionError, p.run, ret)