Adding 2 node ixia generic scale-out test case generation
[yardstick.git] / tests / unit / benchmark / scenarios / availability / test_util.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2016 Kanglin Yin and others
5 # 14_ykl@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 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.availability.utils
13
14 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.availability import util
18
19 @mock.patch('yardstick.benchmark.scenarios.availability.util.subprocess')
20 class ExecuteShellTestCase(unittest.TestCase):
21
22     def setUp(self):
23         self.param_config = {'serviceName': '$serviceName', 'value': 1}
24         self.intermediate_variables = {'$serviceName': 'nova-api'}
25         self.std_output = '| id       | 1                     |'
26         self.cmd_config = {'cmd':'ls','param':'-a'}
27
28     def test_util_build_command_shell(self,mock_subprocess):
29         result = util.build_shell_command(self.param_config, True,
30                                           self.intermediate_variables)
31         self.assertEqual("nova-api" in result, True)
32
33     def test_read_stdout_item(self,mock_subprocess):
34         result = util.read_stdout_item(self.std_output,'id')
35         self.assertEquals('1',result)
36
37     def test_buildshellparams(self,mock_subprocess):
38         result = util.buildshellparams(self.cmd_config,True)
39         self.assertEquals('/bin/bash -s {0} {1}', result)
40
41     def test__fun_execute_shell_command_successful(self, mock_subprocess):
42         cmd = "env"
43         mock_subprocess.check_output.return_value = (0, 'unittest')
44         exitcode, output = util.execute_shell_command(cmd)
45         self.assertEqual(exitcode, 0)
46
47     def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess):
48         cmd = "env"
49         mock_subprocess.check_output.side_effect = RuntimeError
50         exitcode, output = util.execute_shell_command(cmd)
51         self.assertEqual(exitcode, -1)