3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
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.monitor_command
17 from yardstick.benchmark.scenarios.availability.monitor import monitor_command
19 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.subprocess')
20 class MonitorOpenstackCmdTestCase(unittest.TestCase):
22 def test__fun_execute_shell_command_successful(self, mock_subprocess):
24 mock_subprocess.check_output.return_value = (0, 'unittest')
25 exitcode, output = monitor_command._execute_shell_command(cmd)
26 self.assertEqual(exitcode, 0)
28 def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess):
30 mock_subprocess.check_output.side_effect = RuntimeError
31 exitcode, output = monitor_command._execute_shell_command(cmd)
32 self.assertEqual(exitcode, -1)
34 def test__monitor_command_monitor_func_successful(self, mock_subprocess):
36 'monitor_type': 'openstack-api',
37 'command_name': 'nova image-list',
39 'sla': {'max_outage_time': 5}
42 instance = monitor_command.MonitorOpenstackCmd(config, None)
44 mock_subprocess.check_output.return_value = (0, 'unittest')
45 ret = instance.monitor_func()
46 self.assertEqual(ret, True)
47 instance._result = {"outage_time": 0}
50 def test__monitor_command_monitor_func_failure(self, mock_subprocess):
51 mock_subprocess.check_output.return_value = (1, 'unittest')
53 'monitor_type': 'openstack-api',
54 'command_name': 'nova image-list',
56 'sla': {'max_outage_time': 5}
58 instance = monitor_command.MonitorOpenstackCmd(config, None)
60 mock_subprocess.check_output.side_effect = RuntimeError
61 ret = instance.monitor_func()
62 self.assertEqual(ret, False)
63 instance._result = {"outage_time": 10}