diff options
author | 2017-07-19 19:35:02 +0000 | |
---|---|---|
committer | 2017-09-14 15:46:38 -0700 | |
commit | be6e7ed6f053a4a697af939fa0ddcd5dce54c0c8 (patch) | |
tree | 5bc4b5bed762d9d4ddf79369d3e925acf86596e2 /tests/unit/network_services/helpers/test_dpdkbindnic_helper.py | |
parent | ac0c076ffc701333aed7d65112a0f2e15fda825a (diff) |
NSB: fix port topology
Add a new PortPair class to resolve the
topology into list of public and private ports.
Before we were calculating public/private in multiple
locations and using different conventions.
In addition for all the DPDK test we need to use the DPDK
port number and no rely on interface ordering or interface naming
conventions.
We used to use xe0 -> 0, xe1 -> 1, etc. This is not the DPDK port
number.
Use the new dpdknicbind_helper class to parse the output of
dpdk-devbind.py to find the actual DPDK port number at runtime.
We then use this DPDK port number to correctly calculate the
port_mask_hex.
The port mask maps the DPDK port num (PMD ID) to the LINK ID
used in the pipeline config
We also need to make sure we only use the interfaces matched to the
topology and not use all the interfaces, because in some cases we will
have unused interfaces. In particular TRex always requires an even
number of interfaces, so for single port TRex tests we have to create
the second port and not use it.
Thus we had to modify the traffic generator stats code to only dump
stats for used ports and no unused ports.
Ixia was using interface ordering to map to Ixia ports, instead we use
the dpdk_port_num which must be hardcoded for Ixia.
Renamed traffic_profile.execute to traffic_profile.execute_traffic so
we can trace the code easier.
We pass the port used by the traffic profile to generate_samples so we
don't get stats for unused ports.
Fixed up vPE config creation and bring up issues.
Fixed up CGNAPT and UDP_Replay to work correctly.
Tested with 4-port scale-out
Change-Id: I2e4f328bff2904108081e92a4bf712333fa73869
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Signed-off-by: Edward MacGillivray <edward.s.macgillivray@intel.com>
Diffstat (limited to 'tests/unit/network_services/helpers/test_dpdkbindnic_helper.py')
-rw-r--r-- | tests/unit/network_services/helpers/test_dpdkbindnic_helper.py | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py b/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py new file mode 100644 index 000000000..dbd8396c8 --- /dev/null +++ b/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py @@ -0,0 +1,247 @@ +#!/usr/bin/env python + +# 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. + +import mock +import unittest +from yardstick.network_services.helpers.dpdknicbind_helper import DpdkBindHelper +from yardstick.network_services.helpers.dpdknicbind_helper import DpdkBindHelperException +from yardstick.network_services.helpers.dpdknicbind_helper import NETWORK_KERNEL +from yardstick.network_services.helpers.dpdknicbind_helper import NETWORK_DPDK +from yardstick.network_services.helpers.dpdknicbind_helper import CRYPTO_KERNEL +from yardstick.network_services.helpers.dpdknicbind_helper import CRYPTO_DPDK +from yardstick.network_services.helpers.dpdknicbind_helper import NETWORK_OTHER +from yardstick.network_services.helpers.dpdknicbind_helper import CRYPTO_OTHER + +pass + + +class MyTestDpdkBindHelper(unittest.TestCase): + EXAMPLE_OUTPUT = """ + +Network devices using DPDK-compatible driver +============================================ +0000:00:04.0 'Virtio network device' drv=igb_uio unused= +0000:00:05.0 'Virtio network device' drv=igb_uio unused= + +Network devices using kernel driver +=================================== +0000:00:03.0 'Virtio network device' if=ens3 drv=virtio-pci unused=igb_uio *Active* + +Other network devices +===================== +<none> + +Crypto devices using DPDK-compatible driver +=========================================== +<none> + +Crypto devices using kernel driver +================================== +<none> + +Other crypto devices +==================== +<none> +""" + + PARSED_EXAMPLE = { + NETWORK_DPDK: [ + {'active': False, + 'dev_type': 'Virtio network device', + 'driver': 'igb_uio', + 'iface': None, + 'unused': '', + 'vpci': '0000:00:04.0', + }, + {'active': False, + 'dev_type': 'Virtio network device', + 'driver': 'igb_uio', + 'iface': None, + 'unused': '', + 'vpci': '0000:00:05.0', + } + ], + NETWORK_KERNEL: [ + {'active': True, + 'dev_type': 'Virtio network device', + 'driver': 'virtio-pci', + 'iface': 'ens3', + 'unused': 'igb_uio', + 'vpci': '0000:00:03.0', + } + ], + CRYPTO_KERNEL: [], + CRYPTO_DPDK: [], + NETWORK_OTHER: [], + CRYPTO_OTHER: [], + } + + CLEAN_STATUS = { + NETWORK_KERNEL: [], + NETWORK_DPDK: [], + CRYPTO_KERNEL: [], + CRYPTO_DPDK: [], + NETWORK_OTHER: [], + CRYPTO_OTHER: [], + } + + ONE_INPUT_LINE = ("0000:00:03.0 'Virtio network device' if=ens3 " + "drv=virtio-pci unused=igb_uio *Active*") + + ONE_INPUT_LINE_PARSED = [{ + 'vpci': '0000:00:03.0', + 'dev_type': 'Virtio network device', + 'iface': 'ens3', + 'driver': 'virtio-pci', + 'unused': 'igb_uio', + 'active': True, + }] + + def test___init__(self): + conn = mock.Mock() + conn.provision_tool = mock.Mock(return_value='path_to_tool') + + dpdk_bind_helper = DpdkBindHelper(conn) + + self.assertEquals(conn, dpdk_bind_helper.ssh_helper) + self.assertEquals(self.CLEAN_STATUS, dpdk_bind_helper.dpdk_status) + self.assertIsNone(dpdk_bind_helper.status_nic_row_re) + self.assertIsNone(dpdk_bind_helper._dpdk_nic_bind_attr) + self.assertIsNone(dpdk_bind_helper._status_cmd_attr) + + def test__dpdk_execute(self): + conn = mock.Mock() + conn.execute = mock.Mock(return_value=(0, 'output', 'error')) + conn.provision_tool = mock.Mock(return_value='tool_path') + dpdk_bind_helper = DpdkBindHelper(conn) + self.assertEquals((0, 'output', 'error'), dpdk_bind_helper._dpdk_execute('command')) + + def test__dpdk_execute_failure(self): + conn = mock.Mock() + conn.execute = mock.Mock(return_value=(1, 'output', 'error')) + conn.provision_tool = mock.Mock(return_value='tool_path') + dpdk_bind_helper = DpdkBindHelper(conn) + with self.assertRaises(DpdkBindHelperException): + dpdk_bind_helper._dpdk_execute('command') + + def test__addline(self): + conn = mock.Mock() + + dpdk_bind_helper = DpdkBindHelper(conn) + + dpdk_bind_helper._addline(NETWORK_KERNEL, self.ONE_INPUT_LINE) + + self.assertIsNotNone(dpdk_bind_helper.dpdk_status) + self.assertEquals(self.ONE_INPUT_LINE_PARSED, dpdk_bind_helper.dpdk_status[NETWORK_KERNEL]) + + def test__switch_active_dict_by_header(self): + line = "Crypto devices using DPDK-compatible driver" + olddict = 'olddict' + self.assertEqual(CRYPTO_DPDK, DpdkBindHelper._switch_active_dict(line, olddict)) + + def test__switch_active_dict_by_header_empty(self): + line = "<none>" + olddict = 'olddict' + self.assertEqual(olddict, DpdkBindHelper._switch_active_dict(line, olddict)) + + def test_parse_dpdk_status_output(self): + conn = mock.Mock() + + dpdk_bind_helper = DpdkBindHelper(conn) + + dpdk_bind_helper.parse_dpdk_status_output(self.EXAMPLE_OUTPUT) + + self.maxDiff = None + self.assertEquals(self.PARSED_EXAMPLE, dpdk_bind_helper.dpdk_status) + + def test_read_status(self): + conn = mock.Mock() + conn.execute = mock.Mock(return_value=(0, self.EXAMPLE_OUTPUT, '')) + conn.provision_tool = mock.Mock(return_value='path_to_tool') + + dpdk_bind_helper = DpdkBindHelper(conn) + + self.assertEquals(self.PARSED_EXAMPLE, dpdk_bind_helper.read_status()) + + def test__get_bound_pci_addresses(self): + conn = mock.Mock() + + dpdk_bind_helper = DpdkBindHelper(conn) + + dpdk_bind_helper.parse_dpdk_status_output(self.EXAMPLE_OUTPUT) + + self.assertEquals(['0000:00:04.0', '0000:00:05.0'], + dpdk_bind_helper._get_bound_pci_addresses(NETWORK_DPDK)) + self.assertEquals(['0000:00:03.0'], + dpdk_bind_helper._get_bound_pci_addresses(NETWORK_KERNEL)) + + def test_interface_driver_map(self): + conn = mock.Mock() + + dpdk_bind_helper = DpdkBindHelper(conn) + + dpdk_bind_helper.parse_dpdk_status_output(self.EXAMPLE_OUTPUT) + + self.assertEquals({'0000:00:04.0': 'igb_uio', + '0000:00:03.0': 'virtio-pci', + '0000:00:05.0': 'igb_uio', + }, + dpdk_bind_helper.interface_driver_map) + + def test_bind(self): + conn = mock.Mock() + conn.execute = mock.Mock(return_value=(0, '', '')) + conn.provision_tool = mock.Mock(return_value='/opt/nsb_bin/dpdk_nic_bind.py') + + dpdk_bind_helper = DpdkBindHelper(conn) + dpdk_bind_helper.read_status = mock.Mock() + + dpdk_bind_helper.bind(['0000:00:03.0', '0000:00:04.0'], 'my_driver') + + conn.execute.assert_called_with('sudo /opt/nsb_bin/dpdk_nic_bind.py --force ' + '-b my_driver 0000:00:03.0 0000:00:04.0') + dpdk_bind_helper.read_status.assert_called_once() + + def test_rebind_drivers(self): + conn = mock.Mock() + + dpdk_bind_helper = DpdkBindHelper(conn) + + dpdk_bind_helper.bind = mock.Mock() + dpdk_bind_helper.used_drivers = { + '0000:05:00.0': 'd1', + '0000:05:01.0': 'd3', + } + + dpdk_bind_helper.rebind_drivers() + + dpdk_bind_helper.bind.assert_any_call('0000:05:00.0', 'd1', True) + dpdk_bind_helper.bind.assert_any_call('0000:05:01.0', 'd3', True) + + def test_save_used_drivers(self): + conn = mock.Mock() + dpdk_bind_helper = DpdkBindHelper(conn) + dpdk_bind_helper.dpdk_status = self.PARSED_EXAMPLE + + dpdk_bind_helper.save_used_drivers() + + expected = { + '0000:00:04.0': 'igb_uio', + '0000:00:05.0': 'igb_uio', + '0000:00:03.0': 'virtio-pci', + } + + self.assertEqual(expected, dpdk_bind_helper.used_drivers) |