diff options
Diffstat (limited to 'tests')
16 files changed, 424 insertions, 276 deletions
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/opnfv/test_cases/opnfv_yardstick_tc006.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc006.yaml index 81b42dc4d..fe244e81c 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc006.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc006.yaml @@ -13,7 +13,8 @@ description: > Yardstick TC006 config file; Measure volume storage IOPS, throughput and latency using fio with job file. -{% set directory = directory or "/FIO_Test" %} +{% set job_file_config = job_file_config or '["[random-writers]", ioengine=libaio, rw=randwrite, size=128m, bs=32k, direct=0, size=64m, numjobs=4]' %} +{% set directory = directory or '/FIO_Test' %} {% set volume_size = volume_size or 200 %} {% set provider = provider or none %} {% set physical_network = physical_network or 'physnet1' %} @@ -25,7 +26,10 @@ scenarios: - type: Fio options: - job_file: "job_file.ini" + # input the content of a fio job file directly + job_file_config: {{ job_file_config }} + # or input the job file name + #job_file: "job_file.ini" directory: {{ directory }} host: fio.yardstick-TC006 diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc080.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc080.yaml index 503fe6a45..0da296297 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc080.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc080.yaml @@ -8,10 +8,11 @@ ############################################################################## --- -# Sample benchmark task config file -# measure network latency using ping in container schema: "yardstick:task:0.1" +description: > + Yardstick TC080 config file; + measure network latency between containers in k8s using ping; scenarios: - diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc081.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc081.yaml index d99757e47..0d79a41ed 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc081.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc081.yaml @@ -8,10 +8,12 @@ ############################################################################## --- -# Sample benchmark task config file -# measure network latency using ping betwwen container and VM schema: "yardstick:task:0.1" +description: > + Yardstick TC081 config file; + measure network latency between container and VM using ping; + scenarios: - diff --git a/tests/opnfv/test_suites/opnfv_os-odl-fdio_dvr-noha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-odl-fdio_dvr-noha_daily.yaml new file mode 100644 index 000000000..cd00b4c0c --- /dev/null +++ b/tests/opnfv/test_suites/opnfv_os-odl-fdio_dvr-noha_daily.yaml @@ -0,0 +1,38 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +--- +# os-odl-fdio-dvr-noha daily task suite + +schema: "yardstick:suite:0.1" + +name: "os-odl-fdio-dvr-noha" +test_cases_dir: "tests/opnfv/test_cases/" +test_cases: +- + file_name: opnfv_yardstick_tc002.yaml +- + file_name: opnfv_yardstick_tc005.yaml +- + file_name: opnfv_yardstick_tc010.yaml +- + file_name: opnfv_yardstick_tc011.yaml +- + file_name: opnfv_yardstick_tc012.yaml +- + file_name: opnfv_yardstick_tc014.yaml +- + file_name: opnfv_yardstick_tc037.yaml +- + file_name: opnfv_yardstick_tc069.yaml +- + file_name: opnfv_yardstick_tc070.yaml +- + file_name: opnfv_yardstick_tc071.yaml +- + file_name: opnfv_yardstick_tc072.yaml diff --git a/tests/unit/benchmark/contexts/standalone/test_model.py b/tests/unit/benchmark/contexts/standalone/test_model.py index ddbc1a4bb..6899a0af6 100644 --- a/tests/unit/benchmark/contexts/standalone/test_model.py +++ b/tests/unit/benchmark/contexts/standalone/test_model.py @@ -91,10 +91,12 @@ class ModelLibvirtTestCase(unittest.TestCase): image = Libvirt.create_snapshot_qemu(ssh_mock, "0", "ubuntu.img") self.assertEqual(image, result) + @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.pin_vcpu_for_perf") @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.create_snapshot_qemu") @mock.patch('yardstick.benchmark.contexts.standalone.model.open') @mock.patch('yardstick.benchmark.contexts.standalone.model.write_file') - def test_build_vm_xml(self, mock_open, mock_write_file, mock_create_snapshot_qemu): + def test_build_vm_xml(self, mock_open, mock_write_file, mock_create_snapshot_qemu, + mock_pin_vcpu_for_perf): result = [4] with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -102,17 +104,10 @@ class ModelLibvirtTestCase(unittest.TestCase): mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock mock_create_snapshot_qemu.return_value = "0.img" + status = Libvirt.build_vm_xml(ssh_mock, {}, "test", "vm_0", 0) self.assertEqual(status[0], result[0]) - def test_split_cpu_list(self): - result = Libvirt.split_cpu_list("1,2,3") - self.assertEqual(result, [1, 2, 3]) - - def test_get_numa_nodes(self): - result = Libvirt.get_numa_nodes() - self.assertIsNotNone(result) - def test_update_interrupts_hugepages_perf(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -122,17 +117,16 @@ class ModelLibvirtTestCase(unittest.TestCase): status = Libvirt.update_interrupts_hugepages_perf(ssh_mock) self.assertIsNone(status) - @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.get_numa_nodes") + @mock.patch("yardstick.benchmark.contexts.standalone.model.CpuSysCores") @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.update_interrupts_hugepages_perf") - def test_pin_vcpu_for_perf(self, mock_update_interrupts_hugepages_perf, mock_get_numa_nodes): + def test_pin_vcpu_for_perf(self, mock_update_interrupts_hugepages_perf, mock_CpuSysCores): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock - mock_get_numa_nodes.return_value = {'1': [18, 19, 20, 21], '0': [0, 1, 2, 3]} status = Libvirt.pin_vcpu_for_perf(ssh_mock, "vm_0", 4) - self.assertIsNone(status) + self.assertIsNotNone(status) class StandaloneContextHelperTestCase(unittest.TestCase): diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py index 5444c2bc8..48ee01cf0 100644 --- a/tests/unit/benchmark/contexts/test_model.py +++ b/tests/unit/benchmark/contexts/test_model.py @@ -179,6 +179,7 @@ class NetworkTestCase(unittest.TestCase): test_network = model.Network('foo', self.mock_context, attrs) self.assertIsNone(test_network.gateway_ip) + class ServerTestCase(unittest.TestCase): def setUp(self): @@ -190,7 +191,6 @@ class ServerTestCase(unittest.TestCase): netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'} self.mock_context.networks = [model.Network("some-network", self.mock_context, netattrs)] - def test_construct_defaults(self): attrs = None @@ -227,8 +227,9 @@ class ServerTestCase(unittest.TestCase): @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance(self, mock_template): - - attrs = {'image': 'some-image', 'flavor': 'some-flavor', 'floating_ip': '192.168.1.10', 'floating_ip_assoc': 'some-vm'} + attrs = {'image': 'some-image', 'flavor': 'some-flavor', 'floating_ip': '192.168.1.10', + 'floating_ip_assoc': 'some-vm', + 'availability_zone': 'zone'} test_server = model.Server('foo', self.mock_context, attrs) self.mock_context.flavors = ['flavor1', 'flavor2', 'some-flavor'] @@ -241,7 +242,8 @@ class ServerTestCase(unittest.TestCase): mock_network.subnet_stack_name = 'some-network-stack-subnet' mock_network.provider = 'sriov' mock_network.external_network = 'ext_net' - mock_network.router = model.Router('some-router', 'some-network', self.mock_context, 'ext_net') + mock_network.router = model.Router('some-router', 'some-network', self.mock_context, + 'ext_net') test_server._add_instance(mock_template, 'some-server', [mock_network], 'hints') @@ -277,7 +279,8 @@ class ServerTestCase(unittest.TestCase): user=self.mock_context.user, key_name=self.mock_context.keypair_name, user_data='', - scheduler_hints='hints') + scheduler_hints='hints', + availability_zone='zone') @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance_with_user_data(self, mock_template): @@ -299,7 +302,30 @@ class ServerTestCase(unittest.TestCase): user=self.mock_context.user, key_name=self.mock_context.keypair_name, user_data=user_data, - scheduler_hints='hints') + scheduler_hints='hints', + availability_zone=None) + + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') + def test__add_instance_with_availablity_zone(self, mock_template): + attrs = { + 'image': 'some-image', 'flavor': 'some-flavor', + 'availability_zone': 'zone', + } + test_server = model.Server('foo', self.mock_context, attrs) + + test_server._add_instance(mock_template, 'some-server', + [], 'hints') + + mock_template.add_server.assert_called_with( + 'some-server', 'some-image', + flavor='some-flavor', + flavors=self.mock_context.flavors, + ports=[], + user=self.mock_context.user, + key_name=self.mock_context.keypair_name, + user_data='', + scheduler_hints='hints', + availability_zone='zone') @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance_plus_flavor(self, mock_template): @@ -339,7 +365,8 @@ class ServerTestCase(unittest.TestCase): user=self.mock_context.user, key_name=self.mock_context.keypair_name, user_data=user_data, - scheduler_hints='hints') + scheduler_hints='hints', + availability_zone=None) @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance_misc(self, mock_template): @@ -351,7 +378,7 @@ class ServerTestCase(unittest.TestCase): } test_server = model.Server('ServerFlavor-3', self.mock_context, attrs) - self.mock_context.flavors = ['flavor2'] + self.mock_context.flavors = ['flavor2'] self.mock_context.flavor = {'vcpus': 4} mock_network = mock.Mock() mock_network.name = 'some-network' @@ -361,7 +388,6 @@ class ServerTestCase(unittest.TestCase): test_server._add_instance(mock_template, 'ServerFlavor-3', [mock_network], 'hints') - mock_template.add_port( 'ServerFlavor-3-some-network-port', mock_network.stack_name, @@ -387,5 +413,5 @@ class ServerTestCase(unittest.TestCase): user=self.mock_context.user, key_name=self.mock_context.keypair_name, user_data=user_data, - scheduler_hints='hints') - + scheduler_hints='hints', + availability_zone=None) diff --git a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py index 9514729ba..f163f1914 100644 --- a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py +++ b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py @@ -16,7 +16,6 @@ from __future__ import absolute_import import unittest import mock -from oslo_serialization import jsonutils from yardstick.benchmark.scenarios.compute import qemu_migrate @@ -84,7 +83,7 @@ class QemuMigrateTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') q.run(result) - expected_result = jsonutils.loads(sample_output) + expected_result = {} self.assertEqual(result, expected_result) def test_qemu_migrate_successful_sla(self, mock_ssh): @@ -104,7 +103,7 @@ class QemuMigrateTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') q.run(result) - expected_result = jsonutils.loads(sample_output) + expected_result = {} self.assertEqual(result, expected_result) def test_qemu_migrate_unsuccessful_sla_totaltime(self, mock_ssh): @@ -118,7 +117,8 @@ class QemuMigrateTestCase(unittest.TestCase): sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}' mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') - self.assertRaises(AssertionError, q.run, result) + with self.assertRaises(AssertionError): + q.run(result) def test_qemu_migrate_unsuccessful_sla_downtime(self, mock_ssh): @@ -131,7 +131,8 @@ class QemuMigrateTestCase(unittest.TestCase): sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}' mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') - self.assertRaises(AssertionError, q.run, result) + with self.assertRaises(AssertionError): + q.run(result) def test_qemu_migrate_unsuccessful_sla_setuptime(self, mock_ssh): @@ -142,9 +143,10 @@ class QemuMigrateTestCase(unittest.TestCase): q.setup() sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}' - + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') - self.assertRaises(AssertionError, q.run, result) + with self.assertRaises(AssertionError): + q.run(result) def test_qemu_migrate_unsuccessful_script_error(self, mock_ssh): @@ -154,10 +156,9 @@ 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') - self.assertRaises(RuntimeError, q.run, result) - + with self.assertRaises(RuntimeError): + q.run(result) def main(): unittest.main() diff --git a/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py b/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py new file mode 100644 index 000000000..1fb2f89ca --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py @@ -0,0 +1,84 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Unittest for yardstick.benchmark.scenarios.lib.check_connectivity.CheckConnectivity + +from __future__ import absolute_import + +import mock +import unittest + +from yardstick.benchmark.scenarios.lib import check_connectivity + + +class CheckConnectivityTestCase(unittest.TestCase): + + def setUp(self): + self.ctx = { + 'host': { + 'ip': '172.16.0.137', + 'user': 'root', + 'key_filename': 'mykey.key', + 'ssh_port': '22' + }, + 'target': { + 'ipaddr': '172.16.0.138' + } + } + + @mock.patch('yardstick.benchmark.scenarios.lib.check_connectivity.ssh') + def test_check_connectivity(self, mock_ssh): + + args = { + 'options': {'src_ip_addr': '192.168.23.2', + 'dest_ip_addr': '192.168.23.10', + 'ssh_user': 'root', + 'ssh_passwd': 'root', + 'ssh_port': '22', + 'ssh_timeout': 600, + 'ping_parameter': "-s 2048" + }, + 'sla': {'status': 'True', + 'action': 'assert'} + } + + result = {} + + obj = check_connectivity.CheckConnectivity(args, {}) + obj.setup() + mock_ssh.SSH.execute.return_value = (0, '100', '') + + + @mock.patch('yardstick.benchmark.scenarios.lib.check_connectivity.ssh') + def test_check_connectivity_key(self, mock_ssh): + + args = { + 'options': {'ssh_user': 'root', + 'ssh_key': '/root/.ssh/id_rsa', + 'ssh_port': '22', + 'ssh_timeout': 600, + 'ping_parameter': "-s 2048" + }, + 'sla': {'status': 'True', + 'action': 'assert'} + } + + result = {} + + obj = check_connectivity.CheckConnectivity(args, self.ctx) + obj.setup() + + mock_ssh.SSH.execute.return_value = (0, '100', '') + +def main(): + unittest.main() + + +if __name__ == '__main__': + 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/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py index f3244fdbd..5c2f890e8 100644 --- a/tests/unit/network_services/nfvi/test_resource.py +++ b/tests/unit/network_services/nfvi/test_resource.py @@ -99,7 +99,7 @@ class TestResourceProfile(unittest.TestCase): port_names = \ self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]['vdu'][0]['external-interface'] self.resource_profile = \ - ResourceProfile(mgmt, port_names, [1, 2, 3]) + ResourceProfile(mgmt, port_names) self.resource_profile.connection = self.ssh_mock def test___init__(self): @@ -134,10 +134,6 @@ class TestResourceProfile(unittest.TestCase): self.assertIsNone( self.resource_profile._prepare_collectd_conf("/opt/nsb_bin")) - def test__setup_intel_pmu(self): - self.assertIsNone( - self.resource_profile._setup_intel_pmu(self.ssh_mock, "/opt/nsb_bin")) - def test__setup_ovs_stats(self): self.assertIsNone( self.resource_profile._setup_ovs_stats(self.ssh_mock)) 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_prox_helpers.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py index 3c073812c..84eb5dc0d 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py @@ -44,6 +44,7 @@ if stl_patch: from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxMplsProfileHelper from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxBngProfileHelper from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxVpeProfileHelper + from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxlwAFTRProfileHelper class TestCoreTuple(unittest.TestCase): @@ -533,20 +534,6 @@ class TestProxSocketHelper(unittest.TestCase): result = prox.hz() self.assertEqual(result, expected) - def test_rx_stats(self, mock_time): - core_stats = [ - '3,4,5,6', - '7,8,9,10,NaN', - '11,12,13,14,15', - ] - - mock_socket = mock.MagicMock() - prox = ProxSocketHelper(mock_socket) - prox.get_data = mock.MagicMock(side_effect=core_stats) - expected = 21, 24, 27, 14 - result = prox.rx_stats([3, 4, 5], 16) - self.assertEqual(result, expected) - def test_core_stats(self, mock_time): core_stats = [ '3,4,5,6', @@ -2215,3 +2202,117 @@ class TestProxVpeProfileHelper(unittest.TestCase): helper.run_test(120, 5, 6.5) helper.run_test(-1000, 5, 6.5) # negative pkt_size is the only way to make ratio > 1 + + +class TestProxlwAFTRProfileHelper(unittest.TestCase): + + def test_lwaftr_cores(self): + resource_helper = mock.MagicMock() + resource_helper.setup_helper.prox_config_data = [ + ('section1', []), + ('section2', [ + ('a', 'b'), + ('c', 'd'), + ]), + ('core 1', []), + ('core 2', [ + ('index', 8), + ('mode', ''), + ]), + ('core 3', [ + ('index', 5), + ('mode', 'gen'), + ('name', 'tun'), + ]), + ('core 4', [ + ('index', 7), + ('mode', 'gen'), + ('name', 'inet'), + ]), + ] + + helper = ProxlwAFTRProfileHelper(resource_helper) + helper._cpu_topology = { + 0: { + 1: { + 5: (5, 1, 0) + }, + 2: { + 6: (6, 2, 0) + }, + 3: { + 7: (7, 3, 0) + }, + 4: { + 8: (8, 3, 0) + }, + } + } + + expected_tun = [7] + expected_inet = [8] + expected_combined = (expected_tun, expected_inet) + + self.assertIsNone(helper._cores_tuple) + self.assertEqual(helper.tun_cores, expected_tun) + self.assertEqual(helper.inet_cores, expected_inet) + self.assertEqual(helper._cores_tuple, expected_combined) + + def test_tun_ports(self): + resource_helper = mock.MagicMock() + resource_helper.setup_helper.prox_config_data = [ + ('section1', []), + ('section2', [ + ('a', 'b'), + ('c', 'd'), + ]), + ('port 3', [ + ('index', '5'), + ('name', 'lwB4'), + ('mac', 'hardware'), + ]), + ('port 4', [ + ('index', '7'), + ('name', 'inet'), + ('mac', 'hardware'), + ]), + ] + + helper = ProxlwAFTRProfileHelper(resource_helper) + helper._port_list = { + 0: { + 1: { + 5: 'lwB4' + }, + 2: { + 6: 'inet' + }, + 3: { + 7: 'lwB4' + }, + 4: { + 8: 'inet' + }, + } + } + + expected_tun = [3] + expected_inet = [4] + expected_combined = (expected_tun, expected_inet) + + self.assertIsNone(helper._ports_tuple) + self.assertEqual(helper.tun_ports, expected_tun) + self.assertEqual(helper.inet_ports, expected_inet) + self.assertEqual(helper._ports_tuple, expected_combined) + + @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time') + def test_run_test(self, _): + resource_helper = mock.MagicMock() + resource_helper.step_delta = 0.4 + resource_helper.vnfd_helper.port_pairs.all_ports = list(range(2)) + resource_helper.sut.port_stats.return_value = list(range(10)) + + helper = ProxlwAFTRProfileHelper(resource_helper) + + helper.run_test(120, 5, 6.5) + helper.run_test(-1000, 5, 6.5) # negative pkt_size is the only way to make ratio > 1 diff --git a/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py index a6d40877d..e29e8ddcd 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py @@ -348,9 +348,9 @@ class TestProxApproxVnf(unittest.TestCase): prox_approx_vnf.resource_helper = resource_helper expected = { - 'packets_in': 7, + 'packets_in': 6, 'packets_dropped': 1, - 'packets_fwd': 6, + 'packets_fwd': 7, 'collect_stats': {'core': {'result': 234}}, } result = prox_approx_vnf.collect_kpi() 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 6c102ed59..57f9fac61 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 @@ -29,7 +29,6 @@ from yardstick.benchmark.contexts.base import Context from yardstick.network_services.nfvi.resource import ResourceProfile from yardstick.network_services.traffic_profile.base import TrafficProfile from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper -from yardstick.ssh import SSHError class MockError(BaseException): @@ -609,111 +608,6 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): dpdk_setup_helper._build_pipeline_kwargs() self.assertDictEqual(dpdk_setup_helper.pipeline_kwargs, expected) - def test__get_app_cpu(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.provision_tool.return_value = 'tool_path' - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - - dpdk_setup_helper.CORES = expected = [5, 4, 3] - result = dpdk_setup_helper._get_app_cpu() - self.assertEqual(result, expected) - - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.CpuSysCores') - def test__get_app_cpu_no_cores_sw(self, mock_cpu_sys_cores_class): - mock_cpu_sys_cores = mock_cpu_sys_cores_class() - mock_cpu_sys_cores.get_core_socket.return_value = { - 'socket': [2, 4, 8, 10, 12], - } - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.provision_tool.return_value = 'tool_path' - scenario_helper = mock.Mock() - scenario_helper.vnf_cfg = { - 'worker_threads': '2', - } - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper.CORES = [] - dpdk_setup_helper.SW_DEFAULT_CORE = 1 - dpdk_setup_helper.HW_DEFAULT_CORE = 2 - dpdk_setup_helper.socket = 'socket' - - expected = [2, 4, 8] - result = dpdk_setup_helper._get_app_cpu() - self.assertEqual(result, expected) - - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.CpuSysCores') - def test__get_app_cpu_no_cores_hw(self, mock_cpu_sys_cores_class): - mock_cpu_sys_cores = mock_cpu_sys_cores_class() - mock_cpu_sys_cores.get_core_socket.return_value = { - 'socket': [2, 4, 8, 10, 12], - } - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - scenario_helper.vnf_cfg = { - 'worker_threads': '2', - 'lb_config': 'HW', - } - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper.CORES = [] - dpdk_setup_helper.SW_DEFAULT_CORE = 1 - dpdk_setup_helper.HW_DEFAULT_CORE = 2 - dpdk_setup_helper.socket = 'socket' - - expected = [2, 4, 8, 10] - result = dpdk_setup_helper._get_app_cpu() - self.assertEqual(result, expected) - - def test__get_cpu_sibling_list(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.execute.side_effect = iter([(0, '5', ''), (0, '3,4', ''), (0, '10', '')]) - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._get_app_cpu = mock.Mock(return_value=[]) - - expected = ['5', '3', '4', '10'] - result = dpdk_setup_helper._get_cpu_sibling_list([1, 3, 7]) - self.assertEqual(result, expected) - - def test__get_cpu_sibling_list_no_core_arg(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.execute.side_effect = iter([(0, '5', ''), (0, '3,4', ''), (0, '10', '')]) - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._get_app_cpu = mock.Mock(return_value=[1, 7]) - - expected = ['5', '3', '4'] - result = dpdk_setup_helper._get_cpu_sibling_list() - self.assertEqual(result, expected) - - def test__get_cpu_sibling_list_ssh_failure(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.execute.side_effect = iter([(0, '5', ''), SSHError, (0, '10', '')]) - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._get_app_cpu = mock.Mock(return_value=[]) - - expected = [] - result = dpdk_setup_helper._get_cpu_sibling_list([1, 3, 7]) - self.assertEqual(result, expected) - - def test__validate_cpu_cfg(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.execute.side_effect = iter([(0, '5', ''), (0, '3,4', ''), (0, '10', '')]) - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._get_app_cpu = mock.Mock(return_value=[1, 3, 7]) - - expected = ['5', '3', '4', '10'] - result = dpdk_setup_helper._validate_cpu_cfg() - self.assertEqual(result, expected) - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch('yardstick.ssh.SSH') def test_setup_vnf_environment(self, _, mock_time): @@ -1497,8 +1391,9 @@ class TestRfc2544ResourceHelper(unittest.TestCase): class TestSampleVNFDeployHelper(unittest.TestCase): + @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch('subprocess.check_output') - def test_deploy_vnfs_disabled(self, mock_check_output): + def test_deploy_vnfs_disabled(self, mock_check_output, mock_time): vnfd_helper = mock.Mock() ssh_helper = mock.Mock() ssh_helper.join_bin_path.return_value = 'joined_path' 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) |