aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/scenarios/availability/test_util.py
blob: bb0e6bc79e1b3d471f0c95a6c4352d15daa20ef5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python

##############################################################################
# Copyright (c) 2016 Kanglin Yin and others
# 14_ykl@tongji.edu.cn
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

# Unittest for yardstick.benchmark.scenarios.availability.utils

import mock
import unittest

from yardstick.benchmark.scenarios.availability import util

@mock.patch('yardstick.benchmark.scenarios.availability.util.subprocess')
class ExecuteShellTestCase(unittest.TestCase):

    def test__fun_execute_shell_command_successful(self, mock_subprocess):
        cmd = "env"
        mock_subprocess.check_output.return_value = (0, 'unittest')
        exitcode, output = util.execute_shell_command(cmd)
        self.assertEqual(exitcode, 0)

    def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess):
        cmd = "env"
        mock_subprocess.check_output.side_effect = RuntimeError
        exitcode, output = util.execute_shell_command(cmd)
        self.assertEqual(exitcode, -1)