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 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
22 'monitor_general.ssh')
23 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
24 'monitor_general.open')
25 class GeneralMonitorServiceTestCase(unittest.TestCase):
31 "key_filename": "/root/.ssh/id_rsa"
33 self.context = {"node1": host}
35 'monitor_type': 'general-monitor',
36 'key': 'service-status',
37 'monitor_key': 'service-status',
40 'parameter': {'serviceName': 'haproxy'},
41 'sla': {'max_outage_time': 1}
43 self.monitor_cfg_noparam = {
44 'monitor_type': 'general-monitor',
45 'key': 'service-status',
46 'monitor_key': 'service-status',
49 'sla': {'max_outage_time': 1}
52 def test__monitor_general_all_successful(self, mock_open, mock_ssh):
53 ins = monitor_general.GeneralMonitor(self.monitor_cfg, self.context, {"nova-api": 10})
56 mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
58 ins._result = {'outage_time': 0}
61 def test__monitor_general_all_successful_noparam(self, mock_open,
63 ins = monitor_general.GeneralMonitor(
64 self.monitor_cfg_noparam, self.context, {"nova-api": 10})
67 mock_ssh.SSH.from_node().execute.return_value = (0, "running", '')
69 ins._result = {'outage_time': 0}
72 def test__monitor_general_failure(self, mock_open, mock_ssh):
73 ins = monitor_general.GeneralMonitor(
74 self.monitor_cfg_noparam, self.context, {"nova-api": 10})
77 mock_ssh.SSH.from_node().execute.return_value = (1, "error", 'error')
79 ins._result = {'outage_time': 2}