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 ##############################################################################
13 # yardstick.benchmark.scenarios.availability.monitor.monitor_command
15 from __future__ import absolute_import
19 from yardstick.benchmark.scenarios.availability.monitor import monitor_command
23 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
25 class ExecuteShellTestCase(unittest.TestCase):
27 def test__fun_execute_shell_command_successful(self, mock_subprocess):
29 mock_subprocess.check_output.return_value = (0, 'unittest')
30 exitcode, output = monitor_command._execute_shell_command(cmd)
31 self.assertEqual(exitcode, 0)
33 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG')
34 def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log,
37 mock_subprocess.check_output.side_effect = RuntimeError
38 exitcode, output = monitor_command._execute_shell_command(cmd)
39 self.assertEqual(exitcode, -1)
40 mock_log.error.assert_called_once()
44 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
46 class MonitorOpenstackCmdTestCase(unittest.TestCase):
52 "key_filename": "/root/.ssh/id_rsa"
54 self.context = {"node1": host}
56 'monitor_type': 'openstack-api',
57 'command_name': 'nova image-list',
59 'sla': {'max_outage_time': 5}
62 def test__monitor_command_monitor_func_successful(self, mock_subprocess):
64 instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10})
66 mock_subprocess.check_output.return_value = (0, 'unittest')
67 ret = instance.monitor_func()
68 self.assertEqual(ret, True)
69 instance._result = {"outage_time": 0}
72 @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG')
73 def test__monitor_command_monitor_func_failure(self, mock_log, mock_subprocess):
74 mock_subprocess.check_output.return_value = (1, 'unittest')
75 instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10})
77 mock_subprocess.check_output.side_effect = RuntimeError
78 ret = instance.monitor_func()
79 self.assertEqual(ret, False)
80 mock_log.error.assert_called_once()
81 instance._result = {"outage_time": 10}
85 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
87 def test__monitor_command_ssh_monitor_successful(self, mock_ssh,
90 self.config["host"] = "node1"
91 instance = monitor_command.MonitorOpenstackCmd(
92 self.config, self.context, {"nova-api": 10})
94 mock_ssh.SSH.from_node().execute.return_value = (0, "0", '')
95 ret = instance.monitor_func()