6e58b6e7abee4bf095e05ac8318def95082169ac
[yardstick.git] / tests / unit / benchmark / scenarios / availability / test_serviceha.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
5 #
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 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.availability.serviceha
13
14 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.availability import serviceha
18
19 @mock.patch('yardstick.benchmark.scenarios.availability.serviceha.basemonitor')
20 @mock.patch('yardstick.benchmark.scenarios.availability.serviceha.baseattacker')
21 class ServicehaTestCase(unittest.TestCase):
22
23     def setUp(self):
24         host = {
25             "ip": "10.20.0.5",
26             "user": "root",
27             "key_filename": "/root/.ssh/id_rsa"
28         }
29         self.ctx = {"nodes": {"node1": host}}
30         attacker_cfg = {
31             "fault_type": "kill-process",
32             "process_name": "nova-api",
33             "host": "node1"
34         }
35         attacker_cfgs = []
36         attacker_cfgs.append(attacker_cfg)
37         monitor_cfg = {
38             "monitor_cmd": "nova image-list",
39             "monitor_time": 0.1
40         }
41         monitor_cfgs = []
42         monitor_cfgs.append(monitor_cfg)
43
44         options = {
45             "attackers": attacker_cfgs,
46             "monitors": monitor_cfgs
47         }
48         sla = {"outage_time": 5}
49         self.args = {"options": options, "sla": sla}
50
51     def test__serviceha_setup_run_successful(self, mock_attacker, mock_monitor):
52         p = serviceha.ServiceHA(self.args, self.ctx)
53
54         p.setup()
55         self.assertEqual(p.setup_done, True)
56         mock_monitor.MonitorMgr().verify_SLA.return_value = True
57         ret = {}
58         p.run(ret)
59         p.teardown()
60 """
61     def test__serviceha_run_sla_error(self, mock_attacker, mock_monitor):
62         p = serviceha.ServiceHA(self.args, self.ctx)
63
64         p.setup()
65         self.assertEqual(p.setup_done, True)
66
67         result = {}
68         result["outage_time"] = 10
69         mock_monitor.Monitor().get_result.return_value = result
70
71         ret = {}
72         self.assertRaises(AssertionError, p.run, ret)
73 """