Merge "Document for Fraser test case results"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_serviceha.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10 import mock
11 import unittest
12
13 from yardstick.benchmark.scenarios.availability import serviceha
14 from yardstick.common import exceptions as y_exc
15
16
17 class ServicehaTestCase(unittest.TestCase):
18
19     def setUp(self):
20         host = {
21             "ip": "10.20.0.5",
22             "user": "root",
23             "key_filename": "/root/.ssh/id_rsa"
24         }
25         self.ctx = {"nodes": {"node1": host}}
26         attacker_cfg = {
27             "fault_type": "kill-process",
28             "process_name": "nova-api",
29             "host": "node1"
30         }
31         attacker_cfgs = []
32         attacker_cfgs.append(attacker_cfg)
33         monitor_cfg = {
34             "monitor_cmd": "nova image-list",
35             "monitor_time": 0.1
36         }
37         monitor_cfgs = []
38         monitor_cfgs.append(monitor_cfg)
39
40         options = {
41             "attackers": attacker_cfgs,
42             "monitors": monitor_cfgs
43         }
44         sla = {"outage_time": 5}
45         self.args = {"options": options, "sla": sla}
46
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)
53
54         p.setup()
55         self.assertTrue(p.setup_done)
56         mock_monitor.MonitorMgr().verify_SLA.return_value = True
57         ret = {}
58         p.run(ret)
59         p.teardown()
60
61         p.setup()
62         self.assertTrue(p.setup_done)
63
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)
68
69         p.setup()
70         self.assertEqual(p.setup_done, True)
71
72         mock_monitor.MonitorMgr().verify_SLA.return_value = False
73
74         ret = {}
75         self.assertRaises(y_exc.SLAValidationError, p.run, ret)
76         self.assertEqual(ret['sla_pass'], 0)
77
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,
81                                                         *args):
82         p = serviceha.ServiceHA(self.args, self.ctx)
83
84         p.setup()
85         self.assertTrue(p.setup_done)
86         p.data["kill-process"] = 0
87
88         mock_monitor.MonitorMgr().verify_SLA.return_value = True
89
90         ret = {}
91         self.assertRaises(y_exc.SLAValidationError, p.run, ret)
92         self.assertEqual(ret['sla_pass'], 0)