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 def test__fun_execute_shell_command_fail_cmd_exception(self,
36 mock_subprocess.check_output.side_effect = RuntimeError
37 exitcode, output = monitor_command._execute_shell_command(cmd)
38 self.assertEqual(exitcode, -1)
42 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
44 class MonitorOpenstackCmdTestCase(unittest.TestCase):
50 "key_filename": "/root/.ssh/id_rsa"
52 self.context = {"node1": host}
54 'monitor_type': 'openstack-api',
55 'command_name': 'nova image-list',
57 'sla': {'max_outage_time': 5}
60 def test__monitor_command_monitor_func_successful(self, mock_subprocess):
62 instance = monitor_command.MonitorOpenstackCmd(self.config, None)
64 mock_subprocess.check_output.return_value = (0, 'unittest')
65 ret = instance.monitor_func()
66 self.assertEqual(ret, True)
67 instance._result = {"outage_time": 0}
70 def test__monitor_command_monitor_func_failure(self, mock_subprocess):
71 mock_subprocess.check_output.return_value = (1, 'unittest')
72 instance = monitor_command.MonitorOpenstackCmd(self.config, None)
74 mock_subprocess.check_output.side_effect = RuntimeError
75 ret = instance.monitor_func()
76 self.assertEqual(ret, False)
77 instance._result = {"outage_time": 10}
81 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
83 def test__monitor_command_ssh_monitor_successful(self, mock_ssh,
86 self.config["host"] = "node1"
87 instance = monitor_command.MonitorOpenstackCmd(
88 self.config, self.context)
90 mock_ssh.SSH.from_node().execute.return_value = (0, "0", '')
91 ret = instance.monitor_func()