Add support for Python 3
[yardstick.git] / tests / unit / benchmark / scenarios / availability / test_monitor_process.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
13 # yardstick.benchmark.scenarios.availability.monitor.monitor_process
14
15 from __future__ import absolute_import
16 import mock
17 import unittest
18
19 from yardstick.benchmark.scenarios.availability.monitor import monitor_process
20
21
22 @mock.patch(
23     'yardstick.benchmark.scenarios.availability.monitor.monitor_process.ssh')
24 class MonitorProcessTestCase(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.context = {"node1": host}
33         self.monitor_cfg = {
34             'monitor_type': 'process',
35             'process_name': 'nova-api',
36             'host': "node1",
37             'monitor_time': 1,
38             'sla': {'max_recover_time': 5}
39         }
40
41     def test__monitor_process_all_successful(self, mock_ssh):
42
43         ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context)
44
45         mock_ssh.SSH().execute.return_value = (0, "1", '')
46         ins.setup()
47         ins.monitor_func()
48         ins._result = {"outage_time": 0}
49         ins.verify_SLA()
50
51     def test__monitor_process_down_failuer(self, mock_ssh):
52
53         ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context)
54
55         mock_ssh.SSH().execute.return_value = (0, "0", '')
56         ins.setup()
57         ins.monitor_func()
58         ins._result = {"outage_time": 10}
59         ins.verify_SLA()