1 ##############################################################################
2 # Copyright (c) 2016 Huan Li and others
3 # lihuansse@tongji.edu.cn
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 ##############################################################################
10 # Unittest for yardstick.benchmark.scenarios.availability.monitor
13 from __future__ import absolute_import
16 from yardstick.benchmark.scenarios.availability.monitor import monitor_general
19 # pylint: disable=unused-argument
20 # disable this for now because I keep forgetting mock patch arg ordering
23 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
24 'monitor_general.ssh')
25 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
26 'monitor_general.open')
27 class GeneralMonitorServiceTestCase(unittest.TestCase):
33 "key_filename": "/root/.ssh/id_rsa"
35 self.context = {"node1": host}
37 'monitor_type': 'general-monitor',
38 'key': 'service-status',
39 'monitor_key': 'service-status',
42 'parameter': {'serviceName': 'haproxy'},
43 'sla': {'max_outage_time': 1}
45 self.monitor_cfg_noparam = {
46 'monitor_type': 'general-monitor',
47 'key': 'service-status',
48 'monitor_key': 'service-status',
51 'sla': {'max_outage_time': 1}
54 def test__monitor_general_all_successful(self, mock_open, mock_ssh):
55 ins = monitor_general.GeneralMonitor(self.monitor_cfg, self.context, {"nova-api": 10})
58 mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
60 ins._result = {'outage_time': 0}
63 def test__monitor_general_all_successful_noparam(self, mock_open,
65 ins = monitor_general.GeneralMonitor(
66 self.monitor_cfg_noparam, self.context, {"nova-api": 10})
69 mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
71 ins._result = {'outage_time': 0}
74 def test__monitor_general_failure(self, mock_open, mock_ssh):
75 ins = monitor_general.GeneralMonitor(
76 self.monitor_cfg_noparam, self.context, {"nova-api": 10})
79 mock_ssh.SSH.from_node().execute.return_value = (1, "error", 'error')
81 ins._result = {'outage_time': 2}