X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Funit%2Fnetwork_services%2Fvnf_generic%2Fvnf%2Ftest_tg_ixload.py;h=b93f9aad3a285765c2c8504ad1ac1f0b3d12a868;hb=9a71438273cefd57c652b6049c697bdf137088c8;hp=5c81aa8865039fe36deaf00bfbef296a004672fc;hpb=b49d8593d8ebe22aa7f3c9580f6934a92a6fdddd;p=yardstick.git diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py index 5c81aa886..b93f9aad3 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,13 +13,15 @@ # limitations under the License. # -from __future__ import absolute_import +import subprocess -import unittest import mock -import subprocess +import unittest +import six from tests.unit import STL_MOCKS +from yardstick import ssh +from yardstick.common import utils STLClient = mock.MagicMock() @@ -70,7 +70,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -85,7 +85,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): 'type': 'PCI-PASSTHROUGH', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', @@ -123,7 +123,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) - self.assertIsNone(ixload_traffic_gen.data) + self.assertIsNone(ixload_traffic_gen.resource_helper.data) def test_collect_kpi(self): with mock.patch("yardstick.ssh.SSH") as ssh: @@ -147,10 +147,11 @@ class TestIxLoadTrafficGen(unittest.TestCase): ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) self.assertEqual(None, ixload_traffic_gen.listen_traffic({})) - @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.makedirs") + @mock.patch.object(utils, 'find_relative_file') + @mock.patch.object(utils, 'makedirs') @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") - def test_instantiate(self, call, shutil, mock_makedirs): + def test_instantiate(self, shutil, *args): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ @@ -161,7 +162,8 @@ class TestIxLoadTrafficGen(unittest.TestCase): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) scenario_cfg = {'tc': "nsb_test_case", - 'ixia_profile': "ixload.cfg"} + 'ixia_profile': "ixload.cfg", + 'task_path': "/path/to/task"} ixload_traffic_gen.RESULTS_MOUNT = "/tmp/result" shutil.copy = mock.Mock() scenario_cfg.update({'options': {'packetsize': 64, 'traffic_type': 4, @@ -173,16 +175,18 @@ class TestIxLoadTrafficGen(unittest.TestCase): '1C/1T', 'worker_threads': 1}} }}) - self.assertRaises(IOError, - ixload_traffic_gen.instantiate(scenario_cfg, {})) + with mock.patch.object(six.moves.builtins, 'open', + create=True) as mock_open: + mock_open.return_value = mock.MagicMock() + ixload_traffic_gen.instantiate(scenario_cfg, {}) @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") - @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len") - def test_run_traffic(self, call, shutil, main_open, min, max, len): + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") + def test_run_traffic(self, shutil, *args): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE @@ -208,12 +212,12 @@ class TestIxLoadTrafficGen(unittest.TestCase): self.assertIsNone(result) @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") - @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len") - def test_run_traffic_csv(self, call, shutil, main_open, min, max, len): + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil") + def test_run_traffic_csv(self, shutil, *args): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE @@ -241,19 +245,15 @@ class TestIxLoadTrafficGen(unittest.TestCase): self.assertIsNone(result) @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") - def test_terminate(self, call): - with mock.patch("yardstick.ssh.SSH") as ssh: - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) - self.assertEqual(None, ixload_traffic_gen.terminate()) + @mock.patch.object(ssh, 'SSH') + def test_terminate(self, *args): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd) + self.assertEqual(None, ixload_traffic_gen.terminate()) - @mock.patch("yardstick.ssh.SSH") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") - def test_parse_csv_read(self, mock_call, mock_ssh): + @mock.patch.object(ssh, 'SSH') + def test_parse_csv_read(self, mock_ssh, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] kpi_data = { 'HTTP Total Throughput (Kbps)': 1, @@ -275,9 +275,9 @@ class TestIxLoadTrafficGen(unittest.TestCase): for key_left, key_right in IxLoadResourceHelper.KPI_LIST.items(): self.assertEqual(result[key_left][-1], int(kpi_data[key_right])) - @mock.patch("yardstick.ssh.SSH") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") - def test_parse_csv_read_value_error(self, mock_call, mock_ssh): + @mock.patch.object(ssh, 'SSH') + def test_parse_csv_read_value_error(self, mock_ssh, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] http_reader = [{ 'HTTP Total Throughput (Kbps)': 1, @@ -297,9 +297,9 @@ class TestIxLoadTrafficGen(unittest.TestCase): ixload_traffic_gen.resource_helper.parse_csv_read(http_reader) self.assertDictEqual(ixload_traffic_gen.resource_helper.result, init_value) - @mock.patch("yardstick.ssh.SSH") @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call") - def test_parse_csv_read_error(self, mock_call, mock_ssh): + @mock.patch.object(ssh, 'SSH') + def test_parse_csv_read_error(self, mock_ssh, *args): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] http_reader = [{ 'HTTP Total Throughput (Kbps)': 1,