1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
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 ##############################################################################
13 from yardstick.benchmark.scenarios.availability import serviceha
16 class ServicehaTestCase(unittest.TestCase):
22 "key_filename": "/root/.ssh/id_rsa"
24 self.ctx = {"nodes": {"node1": host}}
26 "fault_type": "kill-process",
27 "process_name": "nova-api",
31 attacker_cfgs.append(attacker_cfg)
33 "monitor_cmd": "nova image-list",
37 monitor_cfgs.append(monitor_cfg)
40 "attackers": attacker_cfgs,
41 "monitors": monitor_cfgs
43 sla = {"outage_time": 5}
44 self.args = {"options": options, "sla": sla}
46 # NOTE(elfoley): This should be split into test_setup and test_run
47 # NOTE(elfoley): This should explicitly test outcomes and states
48 @mock.patch.object(serviceha, 'baseattacker')
49 @mock.patch.object(serviceha, 'basemonitor')
50 def test__serviceha_setup_run_successful(self, mock_monitor, *args):
51 p = serviceha.ServiceHA(self.args, self.ctx)
54 self.assertTrue(p.setup_done)
55 mock_monitor.MonitorMgr().verify_SLA.return_value = True
61 self.assertTrue(p.setup_done)
63 @mock.patch.object(serviceha, 'baseattacker')
64 @mock.patch.object(serviceha, 'basemonitor')
65 def test__serviceha_run_sla_error(self, mock_monitor, *args):
66 p = serviceha.ServiceHA(self.args, self.ctx)
69 self.assertEqual(p.setup_done, True)
71 mock_monitor.MonitorMgr().verify_SLA.return_value = False
74 self.assertRaises(AssertionError, p.run, ret)
75 self.assertEqual(ret['sla_pass'], 0)