summaryrefslogtreecommitdiffstats
path: root/tests/unit/network_services/test_utils.py
diff options
context:
space:
mode:
authorDeepak S <deepak.s@linux.intel.com>2016-12-30 09:20:49 -0800
committerDeepak S <deepak.s@linux.intel.com>2017-01-19 08:27:11 +0530
commit6f8fbe8acb94448ef2eb188193e9bea534021e89 (patch)
tree32c7ddf1f9e63ac09e9c4be687c28a14b070fbfe /tests/unit/network_services/test_utils.py
parentff1b12cbd92e39503e37833b4a94f30574c3ccbb (diff)
Generic helper function to provision and get path from config
This patch adds, generic helper function to provision the tools and get required fields from yardstick.conf v2: Added unit tests to keep test coverage :) JIRA: YARDSTICK-484 Change-Id: Id6701924e3488c7f38f29c82e55c27fba67c0d76 Signed-off-by: Deepak S <deepak.s@linux.intel.com>
Diffstat (limited to 'tests/unit/network_services/test_utils.py')
-rw-r--r--tests/unit/network_services/test_utils.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/unit/network_services/test_utils.py b/tests/unit/network_services/test_utils.py
new file mode 100644
index 000000000..ecacac7c3
--- /dev/null
+++ b/tests/unit/network_services/test_utils.py
@@ -0,0 +1,57 @@
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Unittest for yardstick.network_services.utils
+
+from __future__ import absolute_import
+import unittest
+import mock
+
+from yardstick.network_services import utils
+
+
+class UtilsTestCase(unittest.TestCase):
+ """Test all VNF helper methods."""
+
+ DPDK_PATH = "/opt/nsb_bin/dpdk_nic_bind.py"
+
+ def setUp(self):
+ super(UtilsTestCase, self).setUp()
+
+ def test_get_nsb_options(self):
+ result = utils.get_nsb_option("bin_path", None)
+ self.assertEqual(result, "/opt/nsb_bin")
+
+ def test_get_nsb_optionsi_invalid_key(self):
+ result = utils.get_nsb_option("bin", None)
+ self.assertEqual(result, None)
+
+ def test_provision_tool(self):
+ with mock.patch("yardstick.ssh.SSH") as ssh:
+ ssh_mock = mock.Mock(autospec=ssh.SSH)
+ ssh_mock.execute = \
+ mock.Mock(return_value=(0, self.DPDK_PATH, ""))
+ ssh.return_value = ssh_mock
+ tool_path = utils.provision_tool(ssh_mock, self.DPDK_PATH)
+ self.assertEqual(tool_path, self.DPDK_PATH)
+
+ def test_provision_tool_no_path(self):
+ with mock.patch("yardstick.ssh.SSH") as ssh:
+ ssh_mock = mock.Mock(autospec=ssh.SSH)
+ ssh_mock.execute = \
+ mock.Mock(return_value=(1, self.DPDK_PATH, ""))
+ ssh.return_value = ssh_mock
+ tool_path = utils.provision_tool(ssh_mock, self.DPDK_PATH)
+ self.assertEqual(tool_path, self.DPDK_PATH)