Merge "Add l2fwd module in Tgen mode"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_monitor_general.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_general
12
13 from __future__ import absolute_import
14 import mock
15 import unittest
16 from yardstick.benchmark.scenarios.availability.monitor import monitor_general
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 GeneralMonitorServiceTestCase(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             'key': 'service-status',
39             'monitor_key': 'service-status',
40             'host': 'node1',
41             'monitor_time': 3,
42             'parameter': {'serviceName': 'haproxy'},
43             'sla': {'max_outage_time': 1}
44         }
45         self.monitor_cfg_noparam = {
46             'monitor_type': 'general-monitor',
47             'key': 'service-status',
48             'monitor_key': 'service-status',
49             'host': 'node1',
50             'monitor_time': 3,
51             'sla': {'max_outage_time': 1}
52         }
53
54     def test__monitor_general_all_successful(self, mock_open, mock_ssh):
55         ins = monitor_general.GeneralMonitor(self.monitor_cfg, self.context, {"nova-api": 10})
56
57         ins.setup()
58         mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
59         ins.monitor_func()
60         ins._result = {'outage_time': 0}
61         ins.verify_SLA()
62
63     def test__monitor_general_all_successful_noparam(self, mock_open,
64                                                      mock_ssh):
65         ins = monitor_general.GeneralMonitor(
66             self.monitor_cfg_noparam, self.context, {"nova-api": 10})
67
68         ins.setup()
69         mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
70         ins.monitor_func()
71         ins._result = {'outage_time': 0}
72         ins.verify_SLA()
73
74     def test__monitor_general_failure(self, mock_open, mock_ssh):
75         ins = monitor_general.GeneralMonitor(
76             self.monitor_cfg_noparam, self.context, {"nova-api": 10})
77
78         ins.setup()
79         mock_ssh.SSH.from_node().execute.return_value = (1, "error", 'error')
80         ins.monitor_func()
81         ins._result = {'outage_time': 2}
82         ins.verify_SLA()