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
15 from __future__ import absolute_import
18 from yardstick.benchmark.scenarios.availability.monitor import monitor_general
21 # pylint: disable=unused-argument
22 # disable this for now because I keep forgetting mock patch arg ordering
25 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
26 'monitor_general.ssh')
27 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
28 'monitor_general.open')
29 class GeneralMonitorServiceTestCase(unittest.TestCase):
35 "key_filename": "/root/.ssh/id_rsa"
37 self.context = {"node1": host}
39 'monitor_type': 'general-monitor',
40 'key': 'service-status',
41 'monitor_key': 'service-status',
44 'parameter': {'serviceName': 'haproxy'},
45 'sla': {'max_outage_time': 1}
47 self.monitor_cfg_noparam = {
48 'monitor_type': 'general-monitor',
49 'key': 'service-status',
50 'monitor_key': 'service-status',
53 'sla': {'max_outage_time': 1}
56 def test__monitor_general_all_successful(self, mock_open, mock_ssh):
57 ins = monitor_general.GeneralMonitor(self.monitor_cfg, self.context, {"nova-api": 10})
60 mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
62 ins._result = {'outage_time': 0}
65 def test__monitor_general_all_successful_noparam(self, mock_open,
67 ins = monitor_general.GeneralMonitor(
68 self.monitor_cfg_noparam, self.context, {"nova-api": 10})
71 mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
73 ins._result = {'outage_time': 0}
76 def test__monitor_general_failure(self, mock_open, mock_ssh):
77 ins = monitor_general.GeneralMonitor(
78 self.monitor_cfg_noparam, self.context, {"nova-api": 10})
81 mock_ssh.SSH.from_node().execute.return_value = (1, "error", 'error')
83 ins._result = {'outage_time': 2}