Merge "Add API(v1) to get real time log"
[yardstick.git] / tests / unit / network_services / test_utils.py
1 # Copyright (c) 2016-2017 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15
16 # Unittest for yardstick.network_services.utils
17
18 from __future__ import absolute_import
19
20 import os
21 import unittest
22 import mock
23
24 from yardstick.network_services import utils
25
26
27 class UtilsTestCase(unittest.TestCase):
28     """Test all VNF helper methods."""
29
30     DPDK_PATH = os.path.join(utils.NSB_ROOT, "dpdk-devbind.py")
31
32     def setUp(self):
33         super(UtilsTestCase, self).setUp()
34
35     def test_get_nsb_options(self):
36         result = utils.get_nsb_option("bin_path", None)
37         self.assertEqual(result, utils.NSB_ROOT)
38
39     def test_get_nsb_option_is_invalid_key(self):
40         result = utils.get_nsb_option("bin", None)
41         self.assertEqual(result, None)
42
43     def test_get_nsb_option_default(self):
44         default = object()
45         result = utils.get_nsb_option("nosuch", default)
46         self.assertIs(result, default)
47
48     def test_provision_tool(self):
49         with mock.patch("yardstick.ssh.SSH") as ssh:
50             ssh_mock = mock.Mock(autospec=ssh.SSH)
51             ssh_mock.execute = \
52                 mock.Mock(return_value=(0, self.DPDK_PATH, ""))
53             ssh.return_value = ssh_mock
54             tool_path = utils.provision_tool(ssh_mock, self.DPDK_PATH)
55             self.assertEqual(tool_path, self.DPDK_PATH)
56
57     def test_provision_tool_no_path(self):
58         with mock.patch("yardstick.ssh.SSH") as ssh:
59             ssh_mock = mock.Mock(autospec=ssh.SSH)
60             ssh_mock.execute = \
61                 mock.Mock(return_value=(1, self.DPDK_PATH, ""))
62             ssh.return_value = ssh_mock
63             tool_path = utils.provision_tool(ssh_mock, self.DPDK_PATH)
64             self.assertEqual(tool_path, self.DPDK_PATH)