1 # Copyright (c) 2016-2017 Intel Corporation
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # Unittest for yardstick.network_services.utils
18 from __future__ import absolute_import
24 from yardstick.network_services import utils
27 class UtilsTestCase(unittest.TestCase):
28 """Test all VNF helper methods."""
30 DPDK_PATH = os.path.join(utils.NSB_ROOT, "dpdk-devbind.py")
33 super(UtilsTestCase, self).setUp()
35 def test_get_nsb_options(self):
36 result = utils.get_nsb_option("bin_path", None)
37 self.assertEqual(result, utils.NSB_ROOT)
39 def test_get_nsb_option_is_invalid_key(self):
40 result = utils.get_nsb_option("bin", None)
41 self.assertEqual(result, None)
43 def test_get_nsb_option_default(self):
45 result = utils.get_nsb_option("nosuch", default)
46 self.assertIs(result, default)
48 def test_provision_tool(self):
49 with mock.patch("yardstick.ssh.SSH") as ssh:
50 ssh_mock = mock.Mock(autospec=ssh.SSH)
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)
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)
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)