Merge "testcase start service script fail on centos env"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_monitor_multi.py
1 ##############################################################################
2 # Copyright (c) 2016 Huan Li and others
3 # lihuansse@tongji.edu.cn
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 # Unittest for yardstick.benchmark.scenarios.availability.monitor
11 # .monitor_multi
12
13 from __future__ import absolute_import
14 import mock
15 import unittest
16 from yardstick.benchmark.scenarios.availability.monitor import monitor_multi
17
18
19 # pylint: disable=unused-argument
20 # disable this for now because I keep forgetting mock patch arg ordering
21
22
23 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
24             'monitor_general.ssh')
25 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
26             'monitor_general.open')
27 class MultiMonitorServiceTestCase(unittest.TestCase):
28
29     def setUp(self):
30         host = {
31             "ip": "10.20.0.5",
32             "user": "root",
33             "key_filename": "/root/.ssh/id_rsa"
34         }
35         self.context = {"node1": host}
36         self.monitor_cfg = {
37             'monitor_type': 'general-monitor',
38             'monitor_number': 3,
39             'key': 'service-status',
40             'monitor_key': 'service-status',
41             'host': 'node1',
42             'monitor_time': 0.1,
43             'parameter': {'serviceName': 'haproxy'},
44             'sla': {'max_outage_time': 1}
45         }
46
47     def test__monitor_multi_all_successful(self, mock_open, mock_ssh):
48         ins = monitor_multi.MultiMonitor(
49             self.monitor_cfg, self.context, {"nova-api": 10})
50
51         mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
52
53         ins.start_monitor()
54         ins.wait_monitor()
55         ins.verify_SLA()
56
57     def test__monitor_multi_all_fail(self, mock_open, mock_ssh):
58         ins = monitor_multi.MultiMonitor(
59             self.monitor_cfg, self.context, {"nova-api": 10})
60
61         mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
62
63         ins.start_monitor()
64         ins.wait_monitor()
65         ins.verify_SLA()