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
22 from yardstick.network_services import utils
25 class UtilsTestCase(unittest.TestCase):
26 """Test all VNF helper methods."""
28 DPDK_PATH = "/opt/nsb_bin/dpdk_nic_bind.py"
31 super(UtilsTestCase, self).setUp()
33 def test_get_nsb_options(self):
34 result = utils.get_nsb_option("bin_path", None)
35 self.assertEqual(result, "/opt/nsb_bin")
37 def test_get_nsb_optionsi_invalid_key(self):
38 result = utils.get_nsb_option("bin", None)
39 self.assertEqual(result, None)
41 def test_provision_tool(self):
42 with mock.patch("yardstick.ssh.SSH") as ssh:
43 ssh_mock = mock.Mock(autospec=ssh.SSH)
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)
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)
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)