diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ci/cover.awk | 25 | ||||
-rw-r--r-- | tests/ci/cover.sh | 121 | ||||
-rwxr-xr-x | tests/ci/load_images.sh | 15 | ||||
-rwxr-xr-x | tests/functional/test_cli_scenario.py | 20 | ||||
-rw-r--r-- | tests/unit/benchmark/scenarios/compute/test_qemumigrate.py | 19 | ||||
-rw-r--r-- | tests/unit/benchmark/scenarios/test_base.py | 53 | ||||
-rw-r--r-- | tests/unit/network_services/traffic_profile/test_prox_mpls.py | 95 | ||||
-rw-r--r-- | tests/unit/network_services/vnf_generic/vnf/test_base.py | 34 | ||||
-rw-r--r-- | tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py | 73 | ||||
-rw-r--r-- | tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py | 54 |
10 files changed, 165 insertions, 344 deletions
diff --git a/tests/ci/cover.awk b/tests/ci/cover.awk deleted file mode 100644 index e4bb816dc..000000000 --- a/tests/ci/cover.awk +++ /dev/null @@ -1,25 +0,0 @@ -BEGIN{ - template = "%6s %-75s\n" - printf template, "Delta", "Module Path" -} - -/^-/{ - s = substr($1, 2) - x[s] = $3; -}; - -/^+/{ - s = substr($1, 2) - d = $3 - if (s in x) - d = d - x[s] - y[s" "d] = d -} - -END{ - asorti(y, z1, "@val_num_asc") - for (i=1; i <= length(z1); i++){ - split(z1[i], z2, " ") - printf template, z2[2], z2[1] - } -} diff --git a/tests/ci/cover.sh b/tests/ci/cover.sh deleted file mode 100644 index 780a85a22..000000000 --- a/tests/ci/cover.sh +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/bash -############################################################################## -# Copyright 2015: Mirantis Inc. -# All Rights Reserved. -# -# 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. -# yardstick comment: this is a modified copy of -# rally/tests/ci/cover.sh -############################################################################## - -if [[ -n $COVER_DIR_NAME ]]; then - : -elif [[ -n $_ ]]; then - COVER_DIR_NAME=$( dirname $_ ) -else - COVER_DIR_NAME=$( dirname $0 ) -fi - -show_diff () { - diff -U 0 $1 $2 | awk -f $COVER_DIR_NAME/cover.awk -} - -run_coverage_test() { - - ALLOWED_EXTRA_MISSING=10 - # enable debugging - set -x - - # Stash uncommitted changes, checkout master and save coverage report - uncommited=$(git status --porcelain | grep -v "^??") - [[ -n ${uncommited} ]] && git stash > /dev/null - git checkout HEAD^ - - baseline_report=$(mktemp -t yardstick_coverageXXXXXXX) - ls -l .testrepository - - # workaround 'db type could not be determined' bug - # https://bugs.launchpad.net/testrepository/+bug/1229445 - rm -rf .testrepository - find . -type f -name "*.pyc" -delete - - #python setup.py testr --coverage --testr-args="" - python setup.py testr --coverage --slowest --testr-args="$*" - testr failing - coverage report > ${baseline_report} - - # debug awk - tail -1 ${baseline_report} - baseline_missing=$(awk 'END { if (int($3) > 0) print $3 }' ${baseline_report}) - - if [[ -z $baseline_missing ]]; then - echo "Failed to determine baseline missing" - exit 1 - fi - - # Checkout back and unstash uncommitted changes (if any) - git checkout - - [[ -n ${uncommited} ]] && git stash pop > /dev/null - - # Generate and save coverage report - current_report=$(mktemp -t yardstick_coverageXXXXXXX) - ls -l .testrepository - - # workaround 'db type could not be determined' bug - # https://bugs.launchpad.net/testrepository/+bug/1229445 - rm -rf .testrepository - find . -type f -name "*.pyc" -delete - - #python setup.py testr --coverage --testr-args="" - python setup.py testr --coverage --slowest --testr-args="$*" - testr failing - coverage report > ${current_report} - - rm -rf cover-$PY_VER - coverage html -d cover-$PY_VER - - # debug awk - tail -1 ${current_report} - current_missing=$(awk 'END { if (int($3) > 0) print $3 }' ${current_report}) - - if [[ -z $current_missing ]]; then - echo "Failed to determine current missing" - exit 1 - fi - - # Show coverage details - new_missing=$((current_missing - baseline_missing)) - - echo "Missing lines allowed to introduce : ${ALLOWED_EXTRA_MISSING}" - echo "Missing lines introduced : ${new_missing}" - echo "Missing lines in master : ${baseline_missing}" - echo "Missing lines in proposed change : ${current_missing}" - - if [[ ${new_missing} -gt ${ALLOWED_EXTRA_MISSING} ]]; - then - show_diff ${baseline_report} ${current_report} - echo "Please write more unit tests, we should keep our test coverage :( " - rm ${baseline_report} ${current_report} - exit 1 - - elif [[ ${new_missing} -gt 0 ]]; - then - show_diff ${baseline_report} ${current_report} - echo "I believe you can cover all your code with 100% coverage!" - - else - echo "Thank you! You are awesome! Keep writing unit tests! :)" - fi - - rm ${baseline_report} ${current_report} -} diff --git a/tests/ci/load_images.sh b/tests/ci/load_images.sh index e73d7e800..666a78b40 100755 --- a/tests/ci/load_images.sh +++ b/tests/ci/load_images.sh @@ -63,11 +63,14 @@ build_yardstick_image() fi else if [ ! -f "${QCOW_IMAGE}" ];then - local cmd - cmd="sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh" - - # Build the image. Retry once if the build fails - $cmd || $cmd + ANSIBLE_SCRIPTS="${0%/*}/../../ansible" + cd ${ANSIBLE_SCRIPTS} &&\ + ansible-playbook \ + -e img_modify_playbook='ubuntu_server_cloudimg_modify.yml' \ + -e target_os='Ubuntu' \ + -e YARD_IMG_ARCH='amd64' \ + -e ubuntu_img_file="${QCOW_IMAGE}" \ + -vvv -i inventory.ini build_yardstick_image.yml if [ ! -f "${QCOW_IMAGE}" ]; then echo "Failed building QCOW image" @@ -209,7 +212,7 @@ create_nova_flavor() echo echo "========== Creating yardstick-flavor ==========" # Create the nova flavor used by some sample test cases - openstack ${SECURE} flavor create --id 100 --ram 1024 --disk 3 --vcpus 1 yardstick-flavor + openstack ${SECURE} flavor create --id 100 --ram 1024 --disk 10 --vcpus 1 yardstick-flavor # DPDK-enabled OVS requires guest memory to be backed by large pages if [[ $DEPLOY_SCENARIO == *[_-]ovs[_-]* ]]; then openstack ${SECURE} flavor set --property hw:mem_page_size=large yardstick-flavor diff --git a/tests/functional/test_cli_scenario.py b/tests/functional/test_cli_scenario.py index 4741e8244..63b533b85 100755 --- a/tests/functional/test_cli_scenario.py +++ b/tests/functional/test_cli_scenario.py @@ -32,31 +32,25 @@ class ScenarioTestCase(unittest.TestCase): def test_scenario_show_Lmbench(self): res = self.yardstick("scenario show Lmbench") - lmbench = "Execute lmbench memory read latency" - "or memory bandwidth benchmark in a host" in res - self.assertTrue(lmbench) + self.assertIn("Execute lmbench memory read latency or memory " + "bandwidth benchmark in a hos", res) def test_scenario_show_Perf(self): res = self.yardstick("scenario show Perf") - perf = "Execute perf benchmark in a host" in res - self.assertTrue(perf) + self.assertIn("Execute perf benchmark in a host", res) def test_scenario_show_Fio(self): res = self.yardstick("scenario show Fio") - fio = "Execute fio benchmark in a host" in res - self.assertTrue(fio) + self.assertIn("Execute fio benchmark in a host", res) def test_scenario_show_Ping(self): res = self.yardstick("scenario show Ping") - ping = "Execute ping between two hosts" in res - self.assertTrue(ping) + self.assertIn("Execute ping between two hosts", res) def test_scenario_show_Iperf3(self): res = self.yardstick("scenario show Iperf3") - iperf3 = "Execute iperf3 between two hosts" in res - self.assertTrue(iperf3) + self.assertIn("Execute iperf3 between two hosts", res) def test_scenario_show_Pktgen(self): res = self.yardstick("scenario show Pktgen") - pktgen = "Execute pktgen between two hosts" in res - self.assertTrue(pktgen) + self.assertIn("Execute pktgen between two hosts", res) diff --git a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py index f163f1914..1f0ff3c29 100644 --- a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py +++ b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py @@ -16,6 +16,7 @@ from __future__ import absolute_import import unittest import mock +from oslo_serialization import jsonutils from yardstick.benchmark.scenarios.compute import qemu_migrate @@ -83,7 +84,7 @@ class QemuMigrateTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') q.run(result) - expected_result = {} + expected_result = jsonutils.loads(sample_output) self.assertEqual(result, expected_result) def test_qemu_migrate_successful_sla(self, mock_ssh): @@ -103,7 +104,7 @@ class QemuMigrateTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') q.run(result) - expected_result = {} + expected_result = jsonutils.loads(sample_output) self.assertEqual(result, expected_result) def test_qemu_migrate_unsuccessful_sla_totaltime(self, mock_ssh): @@ -117,8 +118,7 @@ class QemuMigrateTestCase(unittest.TestCase): sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}' mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') - with self.assertRaises(AssertionError): - q.run(result) + self.assertRaises(AssertionError, q.run, result) def test_qemu_migrate_unsuccessful_sla_downtime(self, mock_ssh): @@ -131,8 +131,7 @@ class QemuMigrateTestCase(unittest.TestCase): sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}' mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') - with self.assertRaises(AssertionError): - q.run(result) + self.assertRaises(AssertionError, q.run, result) def test_qemu_migrate_unsuccessful_sla_setuptime(self, mock_ssh): @@ -145,8 +144,7 @@ class QemuMigrateTestCase(unittest.TestCase): sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}' mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') - with self.assertRaises(AssertionError): - q.run(result) + self.assertRaises(AssertionError, q.run, result) def test_qemu_migrate_unsuccessful_script_error(self, mock_ssh): @@ -156,9 +154,10 @@ class QemuMigrateTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, '', '') q.setup() + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') - with self.assertRaises(RuntimeError): - q.run(result) + self.assertRaises(RuntimeError, q.run, result) + def main(): unittest.main() diff --git a/tests/unit/benchmark/scenarios/test_base.py b/tests/unit/benchmark/scenarios/test_base.py new file mode 100644 index 000000000..78e342978 --- /dev/null +++ b/tests/unit/benchmark/scenarios/test_base.py @@ -0,0 +1,53 @@ +# Copyright 2017: Intel Ltd. +# All Rights Reserved. +# +# 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 unittest + +from yardstick.benchmark.scenarios import base + + +class ScenarioTestCase(unittest.TestCase): + + def test_get_scenario_type(self): + scenario_type = 'dummy scenario' + + class DummyScenario(base.Scenario): + __scenario_type__ = scenario_type + + self.assertEqual(scenario_type, DummyScenario.get_scenario_type()) + + def test_get_scenario_type_not_defined(self): + class DummyScenario(base.Scenario): + pass + + self.assertEqual(str(None), DummyScenario.get_scenario_type()) + + def test_get_description(self): + docstring = """First line + Second line + Third line + """ + + class DummyScenario(base.Scenario): + __doc__ = docstring + + self.assertEqual(docstring.splitlines()[0], + DummyScenario.get_description()) + + def test_get_description_empty(self): + class DummyScenario(base.Scenario): + pass + + self.assertEqual(str(None), DummyScenario.get_description()) diff --git a/tests/unit/network_services/traffic_profile/test_prox_mpls.py b/tests/unit/network_services/traffic_profile/test_prox_mpls.py deleted file mode 100644 index 00a690d2a..000000000 --- a/tests/unit/network_services/traffic_profile/test_prox_mpls.py +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright (c) 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. -# - -from __future__ import absolute_import - -import unittest -import mock - -from tests.unit import STL_MOCKS - -STLClient = mock.MagicMock() -stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) -stl_patch.start() - -if stl_patch: - from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple - from yardstick.network_services.traffic_profile.prox_mpls_tag_untag import ProxMplsTagUntagProfile - - -class TestProxMplsTagUntagProfile(unittest.TestCase): - - def test_mpls_1(self): - def target(*args, **kwargs): - runs.append(args[2]) - if args[2] < 0 or args[2] > 100: - raise RuntimeError(' '.join([str(args), str(runs)])) - if args[2] > 75.0: - return fail_tuple, {} - return success_tuple, {} - - tp_config = { - 'traffic_profile': { - 'packet_sizes': [200], - }, - } - - runs = [] - success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4) - fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4) - - traffic_generator = mock.MagicMock() - - profile = ProxMplsTagUntagProfile(tp_config) - profile.init(mock.MagicMock()) - profile._profile_helper = profile_helper = mock.MagicMock() - profile_helper.run_test = target - - profile.execute_traffic(traffic_generator) - self.assertEqual(round(profile.current_lower, 2), 74.69) - self.assertEqual(round(profile.current_upper, 2), 75.39) - self.assertEqual(len(runs), 8) - - def test_mpls_2(self): - def target(*args, **kwargs): - runs.append(args[2]) - if args[2] < 0 or args[2] > 100: - raise RuntimeError(' '.join([str(args), str(runs)])) - if args[2] > 25.0: - return fail_tuple, {} - return success_tuple, {} - - tp_config = { - 'traffic_profile': { - 'packet_sizes': [200], - 'test_precision': 2.0, - }, - } - - runs = [] - success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4) - fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4) - - traffic_generator = mock.MagicMock() - - profile = ProxMplsTagUntagProfile(tp_config) - profile.init(mock.MagicMock()) - profile._profile_helper = profile_helper = mock.MagicMock() - profile_helper.run_test = target - - profile.execute_traffic(traffic_generator) - self.assertEqual(round(profile.current_lower, 2), 24.06) - self.assertEqual(round(profile.current_upper, 2), 25.47) - self.assertEqual(len(runs), 7) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_base.py b/tests/unit/network_services/vnf_generic/vnf/test_base.py index 478ce186b..f812d67ef 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_base.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_base.py @@ -243,31 +243,13 @@ class TestGenericVNF(unittest.TestCase): class TestGenericTrafficGen(unittest.TestCase): - def test___init__(self): - vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - generic_traffic_gen = GenericTrafficGen('vnf1', vnfd) - assert generic_traffic_gen.name == "vnf1" - - def test_listen_traffic(self): - vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - generic_traffic_gen = GenericTrafficGen('vnf1', vnfd) - traffic_profile = {} - self.assertIsNone(generic_traffic_gen.listen_traffic(traffic_profile)) - - def test_run_traffic(self): - vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - generic_traffic_gen = GenericTrafficGen('vnf1', vnfd) - traffic_profile = {} - self.assertRaises(NotImplementedError, - generic_traffic_gen.run_traffic, traffic_profile) - - def test_terminate(self): - vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - generic_traffic_gen = GenericTrafficGen('vnf1', vnfd) - self.assertRaises(NotImplementedError, generic_traffic_gen.terminate) - def test_verify_traffic(self): + def test_definition(self): + """Make sure that the abstract class cannot be instantiated""" vnfd = TestGenericVNF.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - generic_traffic_gen = GenericTrafficGen('vnf1', vnfd) - traffic_profile = {} - self.assertIsNone(generic_traffic_gen.verify_traffic(traffic_profile)) + name = 'vnf1' + with self.assertRaises(TypeError) as exc: + GenericTrafficGen(name, vnfd) + msg = ("Can't instantiate abstract class GenericTrafficGen with " + "abstract methods run_traffic, terminate") + self.assertEqual(msg, str(exc.exception)) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py index 57f9fac61..85b10c5a9 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py @@ -2022,55 +2022,32 @@ class TestSampleVNFTrafficGen(unittest.TestCase): sample_vnf_tg.terminate() - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG') - def test_wait_for_instantiate(self, mock_logger, mock_time): + def test__wait_for_process(self): sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) - sample_vnf_tg._check_status = mock.Mock(side_effect=iter([1, 0])) - sample_vnf_tg._tg_process = mock.Mock() - sample_vnf_tg._tg_process.is_alive.return_value = True - sample_vnf_tg._tg_process.exitcode = 234 - - self.assertEqual(sample_vnf_tg.wait_for_instantiate(), 234) - - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG') - def test_wait_for_instantiate_not_alive(self, mock_logger, mock_time): + with mock.patch.object(sample_vnf_tg, '_check_status', + return_value=0) as mock_status, \ + mock.patch.object(sample_vnf_tg, '_tg_process') as mock_proc: + mock_proc.is_alive.return_value = True + mock_proc.exitcode = 234 + self.assertEqual(sample_vnf_tg._wait_for_process(), 234) + mock_proc.is_alive.assert_called_once() + mock_status.assert_called_once() + + def test__wait_for_process_not_alive(self): sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) - sample_vnf_tg._check_status = mock.Mock(return_value=1) - sample_vnf_tg._tg_process = mock.Mock() - sample_vnf_tg._tg_process.is_alive.side_effect = iter([True, False]) - sample_vnf_tg._tg_process.exitcode = 234 - - with self.assertRaises(RuntimeError): - sample_vnf_tg.wait_for_instantiate() - - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG') - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.Process') - def test_wait_for_instantiate_delayed(self, mock_process, mock_logger, mock_time): - class MockClientStarted(mock.Mock): - - def __init__(self, *args, **kwargs): - super(MockClientStarted, self).__init__(*args, **kwargs) - self.iter = iter([0, 0, 1]) - - @property - def value(self): - return next(self.iter) - - mock_traffic_profile = mock.Mock(autospec=TrafficProfile) - mock_traffic_profile.get_traffic_definition.return_value = "64" - mock_traffic_profile.execute_traffic.return_value = "64" - mock_traffic_profile.params = self.TRAFFIC_PROFILE + with mock.patch.object(sample_vnf_tg, '_tg_process') as mock_proc: + mock_proc.is_alive.return_value = False + self.assertRaises(RuntimeError, sample_vnf_tg._wait_for_process) + mock_proc.is_alive.assert_called_once() + def test__wait_for_process_delayed(self): sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) - sample_vnf_tg._check_status = mock.Mock(side_effect=iter([1, 0])) - sample_vnf_tg._tg_process = mock.Mock() - sample_vnf_tg._tg_process.is_alive.return_value = True - sample_vnf_tg._tg_process.exitcode = 234 - sample_vnf_tg.resource_helper = mock.Mock() - sample_vnf_tg.resource_helper.client_started = MockClientStarted() - - self.assertTrue(sample_vnf_tg.run_traffic(mock_traffic_profile)) - self.assertEqual(mock_time.sleep.call_count, 2) + with mock.patch.object(sample_vnf_tg, '_check_status', + side_effect=[1, 0]) as mock_status, \ + mock.patch.object(sample_vnf_tg, + '_tg_process') as mock_proc: + mock_proc.is_alive.return_value = True + mock_proc.exitcode = 234 + self.assertEqual(sample_vnf_tg._wait_for_process(), 234) + mock_proc.is_alive.assert_has_calls([mock.call(), mock.call()]) + mock_status.assert_has_calls([mock.call(), mock.call()]) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py index d08c62e0b..a2a5058fc 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py @@ -18,6 +18,8 @@ from __future__ import absolute_import import unittest + +import copy import mock SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' @@ -75,6 +77,8 @@ class TestTrexTrafficGen(unittest.TestCase): 'driver': "i40e", 'dst_ip': '152.16.100.20', 'local_iface_name': 'xe0', + 'vld_id': 'downlink_0', + 'ifname': 'xe0', 'local_mac': '00:00:00:00:00:02'}, 'vnfd-connection-point-ref': 'xe0', 'name': 'xe0'}, @@ -89,6 +93,8 @@ class TestTrexTrafficGen(unittest.TestCase): 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', + 'vld_id': 'uplink_0', + 'ifname': 'xe1', 'local_mac': '00:00:00:00:00:01'}, 'vnfd-connection-point-ref': 'xe1', 'name': 'xe1'}]}], @@ -386,6 +392,8 @@ class TestTrexTrafficGen(unittest.TestCase): self.sut._connect_client.get_stats = mock.Mock(return_value="0") self.sut.resource_helper.RUN_DURATION = 0 self.sut.resource_helper.QUEUE_WAIT_TIME = 0 + # must generate cfg before we can run traffic so Trex port mapping is created + self.sut.resource_helper.generate_cfg() self.sut._traffic_runner(mock_traffic_profile) @mock.patch(SSH_HELPER) @@ -397,6 +405,52 @@ class TestTrexTrafficGen(unittest.TestCase): self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg()) @mock.patch(SSH_HELPER) + def test_build_ports_reversed_pci_ordering(self, ssh): + mock_ssh(ssh) + vnfd = copy.deepcopy(self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]) + vnfd['vdu'][0]['external-interface'] = [ + {'virtual-interface': + {'dst_mac': '00:00:00:00:00:04', + 'vpci': '0000:05:00.0', + 'local_ip': '152.16.100.19', + 'type': 'PCI-PASSTHROUGH', + 'netmask': '255.255.255.0', + 'dpdk_port_num': 2, + 'bandwidth': '10 Gbps', + 'driver': "i40e", + 'dst_ip': '152.16.100.20', + 'local_iface_name': 'xe0', + 'vld_id': 'downlink_0', + 'ifname': 'xe0', + 'local_mac': '00:00:00:00:00:02'}, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0'}, + {'virtual-interface': + {'dst_mac': '00:00:00:00:00:03', + 'vpci': '0000:04:00.0', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'driver': "i40e", + 'netmask': '255.255.255.0', + 'dpdk_port_num': 0, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_iface_name': 'xe1', + 'vld_id': 'uplink_0', + 'ifname': 'xe1', + 'local_mac': '00:00:00:00:00:01'}, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1'}] + trex_traffic_gen = TrexTrafficGen(NAME, vnfd) + trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock() + trex_traffic_gen.resource_helper.generate_cfg() + trex_traffic_gen.resource_helper._build_ports() + self.assertEqual(sorted(trex_traffic_gen.resource_helper.all_ports), [0, 1]) + # there is a gap in ordering + self.assertEqual(dict(trex_traffic_gen.resource_helper.dpdk_to_trex_port_map), + {0: 0, 2: 1}) + + @mock.patch(SSH_HELPER) def test_run_traffic(self, ssh): mock_ssh(ssh) |