The secondi HA test case-shutdown controller
[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 yardstick.benchmark.scenarios.availability.monitor.monitor_process
13
14 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.availability.monitor import monitor_process
18
19 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_process.ssh')
20 class MonitorProcessTestCase(unittest.TestCase):
21
22     def setUp(self):
23         host = {
24             "ip": "10.20.0.5",
25             "user": "root",
26             "key_filename": "/root/.ssh/id_rsa"
27         }
28         self.context = {"node1": host}
29         self.monitor_cfg = {
30             'monitor_type': 'process',
31             'process_name': 'nova-api',
32             'host': "node1",
33             'monitor_time': 1,
34             'sla': {'max_recover_time': 5}
35         }
36
37     def test__monitor_process_all_successful(self, mock_ssh):
38
39         ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context)
40
41         mock_ssh.SSH().execute.return_value = (0, "1", '')
42         ins.setup()
43         ins.monitor_func()
44         ins._result = {"outage_time": 0}
45         ins.verify_SLA()
46
47     def test__monitor_process_down_failuer(self, mock_ssh):
48
49         ins = monitor_process.MonitorProcess(self.monitor_cfg, self.context)
50
51         mock_ssh.SSH().execute.return_value = (0, "0", '')
52         ins.setup()
53         ins.monitor_func()
54         ins._result = {"outage_time": 10}
55         ins.verify_SLA()
56