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',
35 'monitor_key': 'service-status',
38 'parameter': {'serviceName': 'haproxy'},
39 'sla': {'max_outage_time': 1}
41 self.monitor_cfg_noparam = {
42 'monitor_type': 'general-monitor',
43 'key': 'service-status',
44 'monitor_key': 'service-status',
47 'sla': {'max_outage_time': 1}
50 def test__monitor_general_all_successful(self, mock_open, mock_ssh):
51 ins = monitor_general.GeneralMonitor(self.monitor_cfg, self.context)
54 mock_ssh.SSH().execute.return_value = (0, "running", '')
56 ins._result = {'outage_time' : 0}
59 def test__monitor_general_all_successful_noparam(self, mock_open, mock_ssh):
60 ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context)
63 mock_ssh.SSH().execute.return_value = (0, "running", '')
65 ins._result = {'outage_time' : 0}
68 def test__monitor_general_failure(self, mock_open, mock_ssh):
69 ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context)
72 mock_ssh.SSH().execute.return_value = (1, "error", 'error')
74 ins._result = {'outage_time' : 2}