Merge "basic tox.ini for python 2.7 and python 3 unittests"
[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 import unittest
20 import mock
21
22 from yardstick.network_services import utils
23
24
25 class UtilsTestCase(unittest.TestCase):
26     """Test all VNF helper methods."""
27
28     DPDK_PATH = "/opt/nsb_bin/dpdk_nic_bind.py"
29
30     def setUp(self):
31         super(UtilsTestCase, self).setUp()
32
33     def test_get_nsb_options(self):
34         result = utils.get_nsb_option("bin_path", None)
35         self.assertEqual(result, "/opt/nsb_bin")
36
37     def test_get_nsb_optionsi_invalid_key(self):
38         result = utils.get_nsb_option("bin", None)
39         self.assertEqual(result, None)
40
41     def test_provision_tool(self):
42         with mock.patch("yardstick.ssh.SSH") as ssh:
43             ssh_mock = mock.Mock(autospec=ssh.SSH)
44             ssh_mock.execute = \
45                 mock.Mock(return_value=(0, self.DPDK_PATH, ""))
46             ssh.return_value = ssh_mock
47             tool_path = utils.provision_tool(ssh_mock, self.DPDK_PATH)
48             self.assertEqual(tool_path, self.DPDK_PATH)
49
50     def test_provision_tool_no_path(self):
51         with mock.patch("yardstick.ssh.SSH") as ssh:
52             ssh_mock = mock.Mock(autospec=ssh.SSH)
53             ssh_mock.execute = \
54                 mock.Mock(return_value=(1, self.DPDK_PATH, ""))
55             ssh.return_value = ssh_mock
56             tool_path = utils.provision_tool(ssh_mock, self.DPDK_PATH)
57             self.assertEqual(tool_path, self.DPDK_PATH)