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