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
14 from yardstick.common import exceptions as y_exc
17 class ServicehaTestCase(unittest.TestCase):
23 "key_filename": "/root/.ssh/id_rsa"
25 self.ctx = {"nodes": {"node1": host}}
27 "fault_type": "kill-process",
28 "process_name": "nova-api",
32 attacker_cfgs.append(attacker_cfg)
34 "monitor_cmd": "nova image-list",
38 monitor_cfgs.append(monitor_cfg)
41 "attackers": attacker_cfgs,
42 "monitors": monitor_cfgs
44 sla = {"outage_time": 5}
45 self.args = {"options": options, "sla": sla}
47 # NOTE(elfoley): This should be split into test_setup and test_run
48 # NOTE(elfoley): This should explicitly test outcomes and states
49 @mock.patch.object(serviceha, 'baseattacker')
50 @mock.patch.object(serviceha, 'basemonitor')
51 def test__serviceha_setup_run_successful(self, mock_monitor, *args):
52 p = serviceha.ServiceHA(self.args, self.ctx)
55 self.assertTrue(p.setup_done)
56 mock_monitor.MonitorMgr().verify_SLA.return_value = True
62 self.assertTrue(p.setup_done)
64 @mock.patch.object(serviceha, 'baseattacker')
65 @mock.patch.object(serviceha, 'basemonitor')
66 def test__serviceha_run_sla_error(self, mock_monitor, *args):
67 p = serviceha.ServiceHA(self.args, self.ctx)
70 self.assertEqual(p.setup_done, True)
72 mock_monitor.MonitorMgr().verify_SLA.return_value = False
75 self.assertRaises(y_exc.SLAValidationError, p.run, ret)
76 self.assertEqual(ret['sla_pass'], 0)
78 @mock.patch.object(serviceha, 'baseattacker')
79 @mock.patch.object(serviceha, 'basemonitor')
80 def test__serviceha_run_service_not_found_sla_error(self, mock_monitor,
82 p = serviceha.ServiceHA(self.args, self.ctx)
85 self.assertTrue(p.setup_done)
86 p.data["kill-process"] = 0
88 mock_monitor.MonitorMgr().verify_SLA.return_value = True
91 self.assertRaises(y_exc.SLAValidationError, p.run, ret)
92 self.assertEqual(ret['sla_pass'], 0)