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 ##############################################################################
12 # Unittest for yardstick.benchmark.scenarios.availability.monitor
17 from yardstick.benchmark.scenarios.availability.monitor import monitor_general
20 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
21 'monitor_general.ssh')
22 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
23 'monitor_general.open')
24 class GeneralMonitorServiceTestCase(unittest.TestCase):
29 "key_filename": "/root/.ssh/id_rsa"
31 self.context = {"node1": host}
33 'monitor_type': 'general-monitor',
34 'key': 'service_status',
37 'parameter': {'serviceName': 'haproxy'},
38 'sla': {'max_recover_time': 1}
40 self.monitor_cfg_noparam = {
41 'monitor_type': 'general-monitor',
42 'key': 'service_status',
45 'sla': {'max_recover_time': 1}
48 def test__monitor_general_all_successful(self, mock_open, mock_ssh):
49 ins = monitor_general.GeneralMonitor(self.monitor_cfg, self.context)
52 mock_ssh.SSH().execute.return_value = (0, "running", '')
54 ins._result = {'outage_time' : 0}
57 def test__monitor_general_all_successful_noparam(self, mock_open, mock_ssh):
58 ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context)
61 mock_ssh.SSH().execute.return_value = (0, "running", '')
63 ins._result = {'outage_time' : 0}
66 def test__monitor_general_failure(self, mock_open, mock_ssh):
67 ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context)
70 mock_ssh.SSH().execute.return_value = (1, "error", 'error')
72 ins._result = {'outage_time' : 2}