Merge "Add pod.yaml files for Apex"
[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
15
16 class ServicehaTestCase(unittest.TestCase):
17
18     def setUp(self):
19         host = {
20             "ip": "10.20.0.5",
21             "user": "root",
22             "key_filename": "/root/.ssh/id_rsa"
23         }
24         self.ctx = {"nodes": {"node1": host}}
25         attacker_cfg = {
26             "fault_type": "kill-process",
27             "process_name": "nova-api",
28             "host": "node1"
29         }
30         attacker_cfgs = []
31         attacker_cfgs.append(attacker_cfg)
32         monitor_cfg = {
33             "monitor_cmd": "nova image-list",
34             "monitor_time": 0.1
35         }
36         monitor_cfgs = []
37         monitor_cfgs.append(monitor_cfg)
38
39         options = {
40             "attackers": attacker_cfgs,
41             "monitors": monitor_cfgs
42         }
43         sla = {"outage_time": 5}
44         self.args = {"options": options, "sla": sla}
45
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)
52
53         p.setup()
54         self.assertTrue(p.setup_done)
55         mock_monitor.MonitorMgr().verify_SLA.return_value = True
56         ret = {}
57         p.run(ret)
58         p.teardown()
59
60         p.setup()
61         self.assertTrue(p.setup_done)
62
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)
67
68         p.setup()
69         self.assertEqual(p.setup_done, True)
70
71         mock_monitor.MonitorMgr().verify_SLA.return_value = False
72
73         ret = {}
74         self.assertRaises(AssertionError, p.run, ret)
75         self.assertEqual(ret['sla_pass'], 0)