Merge "Cleanup ScenarioGeneral unit tests"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / availability / test_monitor_process.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
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
11 # yardstick.benchmark.scenarios.availability.monitor.monitor_process
12
13 from __future__ import absolute_import
14 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.availability.monitor import monitor_process
18
19
20 @mock.patch(
21     'yardstick.benchmark.scenarios.availability.monitor.monitor_process.ssh')
22 class MonitorProcessTestCase(unittest.TestCase):
23
24     def setUp(self):
25         host = {
26             "ip": "10.20.0.5",
27             "user": "root",
28             "key_filename": "/root/.ssh/id_rsa"
29         }
30         self.context = {"node1": host}
31         self.monitor_cfg = {
32             'monitor_type': 'process',
33             'process_name': 'nova-api',
34             'host': "node1",
35             'monitor_time': 1,
36             'sla': {'max_recover_time': 5}
37         }
38
39     def test__monitor_process_all_successful(self, mock_ssh):
40
41         ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context, {"nova-api": 10})
42
43         mock_ssh.SSH.from_node().execute.return_value = (0, "1", '')
44         ins.setup()
45         ins.monitor_func()
46         ins._result = {"outage_time": 0}
47         ins.verify_SLA()
48
49     def test__monitor_process_down_failuer(self, mock_ssh):
50
51         ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context, {"nova-api": 10})
52
53         mock_ssh.SSH.from_node().execute.return_value = (0, "0", '')
54         ins.setup()
55         ins.monitor_func()
56         ins._result = {"outage_time": 10}
57         ins.verify_SLA()