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