From 94f67c7535eaac09137f8639f8d9039c036b9ceb Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 17 Jan 2018 18:04:53 +0000 Subject: Add arguments to the traffic profile render In order to render configurable traffic profiles in NSB test cases, a new variable is introduced: "extra_arg". The content of this variable is added to the VNFD render data, under a key called "extra_args". This will allow the user to define Jinja templates for traffic profiles. E.g.: $ cat test_case_definition.yml scenarios: - type: NSPerf traffic_profile: traffic_profile.yml extra_args: vports: 10 $ cat traffic_profile.yml {% set vports = get(extra_args, 'vports', '0') or 4 %} {% for vport in range(vports|int) %} uplink_{{vport}}: data... {% endfor %} JIRA: YARDSTICK-946 Change-Id: Ib3c1f2d89efa012772edf2156e97d5f4742a6b80 Signed-off-by: Rodolfo Alonso Hernandez --- tests/unit/__init__.py | 64 +----------- .../network_services/traffic_profile/test_base.py | 4 +- .../benchmark/scenarios/networking/vnf_generic.py | 10 +- yardstick/tests/__init__.py | 75 ++++++++++++++ yardstick/tests/functional/benchmark/__init__.py | 0 .../functional/benchmark/scenarios/__init__.py | 0 .../benchmark/scenarios/networking/__init__.py | 0 .../scenarios/networking/test_vnf_generic.py | 110 +++++++++++++++++++++ yardstick/tests/unit/__init__.py | 61 +----------- .../scenarios/networking/test_vnf_generic.py | 77 +++++++++------ 10 files changed, 248 insertions(+), 153 deletions(-) create mode 100644 yardstick/tests/functional/benchmark/__init__.py create mode 100644 yardstick/tests/functional/benchmark/scenarios/__init__.py create mode 100644 yardstick/tests/functional/benchmark/scenarios/networking/__init__.py create mode 100644 yardstick/tests/functional/benchmark/scenarios/networking/test_vnf_generic.py diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index a468b272b..5935abbac 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -12,65 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import absolute_import -import mock +from yardstick import tests -STL_MOCKS = { - 'trex_stl_lib': mock.MagicMock(), - 'trex_stl_lib.base64': mock.MagicMock(), - 'trex_stl_lib.binascii': mock.MagicMock(), - 'trex_stl_lib.collections': mock.MagicMock(), - 'trex_stl_lib.copy': mock.MagicMock(), - 'trex_stl_lib.datetime': mock.MagicMock(), - 'trex_stl_lib.functools': mock.MagicMock(), - 'trex_stl_lib.imp': mock.MagicMock(), - 'trex_stl_lib.inspect': mock.MagicMock(), - 'trex_stl_lib.json': mock.MagicMock(), - 'trex_stl_lib.linecache': mock.MagicMock(), - 'trex_stl_lib.math': mock.MagicMock(), - 'trex_stl_lib.os': mock.MagicMock(), - 'trex_stl_lib.platform': mock.MagicMock(), - 'trex_stl_lib.pprint': mock.MagicMock(), - 'trex_stl_lib.random': mock.MagicMock(), - 'trex_stl_lib.re': mock.MagicMock(), - 'trex_stl_lib.scapy': mock.MagicMock(), - 'trex_stl_lib.socket': mock.MagicMock(), - 'trex_stl_lib.string': mock.MagicMock(), - 'trex_stl_lib.struct': mock.MagicMock(), - 'trex_stl_lib.sys': mock.MagicMock(), - 'trex_stl_lib.threading': mock.MagicMock(), - 'trex_stl_lib.time': mock.MagicMock(), - 'trex_stl_lib.traceback': mock.MagicMock(), - 'trex_stl_lib.trex_stl_async_client': mock.MagicMock(), - 'trex_stl_lib.trex_stl_client': mock.MagicMock(), - 'trex_stl_lib.trex_stl_exceptions': mock.MagicMock(), - 'trex_stl_lib.trex_stl_ext': mock.MagicMock(), - 'trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(), - 'trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(), - 'trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(), - 'trex_stl_lib.trex_stl_port': mock.MagicMock(), - 'trex_stl_lib.trex_stl_stats': mock.MagicMock(), - 'trex_stl_lib.trex_stl_streams': mock.MagicMock(), - 'trex_stl_lib.trex_stl_types': mock.MagicMock(), - 'trex_stl_lib.types': mock.MagicMock(), - 'trex_stl_lib.utils': mock.MagicMock(), - 'trex_stl_lib.utils.argparse': mock.MagicMock(), - 'trex_stl_lib.utils.collections': mock.MagicMock(), - 'trex_stl_lib.utils.common': mock.MagicMock(), - 'trex_stl_lib.utils.json': mock.MagicMock(), - 'trex_stl_lib.utils.os': mock.MagicMock(), - 'trex_stl_lib.utils.parsing_opts': mock.MagicMock(), - 'trex_stl_lib.utils.pwd': mock.MagicMock(), - 'trex_stl_lib.utils.random': mock.MagicMock(), - 'trex_stl_lib.utils.re': mock.MagicMock(), - 'trex_stl_lib.utils.string': mock.MagicMock(), - 'trex_stl_lib.utils.sys': mock.MagicMock(), - 'trex_stl_lib.utils.text_opts': mock.MagicMock(), - 'trex_stl_lib.utils.text_tables': mock.MagicMock(), - 'trex_stl_lib.utils.texttable': mock.MagicMock(), - 'trex_stl_lib.warnings': mock.MagicMock(), - 'trex_stl_lib.yaml': mock.MagicMock(), - 'trex_stl_lib.zlib': mock.MagicMock(), - 'trex_stl_lib.zmq': mock.MagicMock(), -} +# NOTE(ralonsoh): to be removed. Replace all occurrences of +# tests.unit.STL_MOCKS with yardstick.tests.STL_MOCKS +STL_MOCKS = tests.STL_MOCKS diff --git a/tests/unit/network_services/traffic_profile/test_base.py b/tests/unit/network_services/traffic_profile/test_base.py index 1089564da..33f803286 100644 --- a/tests/unit/network_services/traffic_profile/test_base.py +++ b/tests/unit/network_services/traffic_profile/test_base.py @@ -22,7 +22,7 @@ import unittest from yardstick.common import exceptions from yardstick.network_services import traffic_profile as tprofile_package from yardstick.network_services.traffic_profile import base -from yardstick.tests import unit as unit_test +from yardstick import tests as y_tests class TestTrafficProfile(unittest.TestCase): @@ -56,7 +56,7 @@ class TestTrafficProfile(unittest.TestCase): 'RFC2544Profile', 'FixedProfile', 'TrafficProfileGenericHTTP', 'IXIARFC2544Profile', 'ProxACLProfile', 'ProxBinSearchProfile', 'ProxProfile', 'ProxRampProfile'] - with mock.patch.dict(sys.modules, unit_test.STL_MOCKS): + with mock.patch.dict(sys.modules, y_tests.STL_MOCKS): tprofile_package.register_modules() for tp in traffic_profile_list: diff --git a/yardstick/benchmark/scenarios/networking/vnf_generic.py b/yardstick/benchmark/scenarios/networking/vnf_generic.py index b81bac70b..c43dabfd4 100644 --- a/yardstick/benchmark/scenarios/networking/vnf_generic.py +++ b/yardstick/benchmark/scenarios/networking/vnf_generic.py @@ -185,17 +185,18 @@ class NetworkServiceTestCase(scenario_base.Scenario): return infile.read() def _fill_traffic_profile(self): - traffic_mapping = self._get_traffic_profile() - traffic_map_data = { + tprofile = self._get_traffic_profile() + extra_args = self.scenario_cfg.get('extra_args', {}) + tprofile_data = { 'flow': self._get_traffic_flow(), 'imix': self._get_traffic_imix(), tprofile_base.TrafficProfile.UPLINK: {}, tprofile_base.TrafficProfile.DOWNLINK: {}, + 'extra_args': extra_args } - traffic_vnfd = vnfdgen.generate_vnfd(traffic_mapping, traffic_map_data) + traffic_vnfd = vnfdgen.generate_vnfd(tprofile, tprofile_data) self.traffic_profile = tprofile_base.TrafficProfile.get(traffic_vnfd) - return self.traffic_profile def _find_vnf_name_from_id(self, vnf_id): return next((vnfd["vnfd-id-ref"] @@ -428,6 +429,7 @@ class NetworkServiceTestCase(scenario_base.Scenario): printf "%s/driver:" $1 ; basename $(readlink -s $1/device/driver); } \ ' sh \{\}/* \; """) + BASE_ADAPTER_RE = re.compile( '^/sys/devices/(.*)/net/([^/]*)/([^:]*):(.*)$', re.M) diff --git a/yardstick/tests/__init__.py b/yardstick/tests/__init__.py index e69de29bb..56e3106b8 100644 --- a/yardstick/tests/__init__.py +++ b/yardstick/tests/__init__.py @@ -0,0 +1,75 @@ +# Copyright (c) 2018 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 + + +STL_MOCKS = { + 'trex_stl_lib': mock.MagicMock(), + 'trex_stl_lib.base64': mock.MagicMock(), + 'trex_stl_lib.binascii': mock.MagicMock(), + 'trex_stl_lib.collections': mock.MagicMock(), + 'trex_stl_lib.copy': mock.MagicMock(), + 'trex_stl_lib.datetime': mock.MagicMock(), + 'trex_stl_lib.functools': mock.MagicMock(), + 'trex_stl_lib.imp': mock.MagicMock(), + 'trex_stl_lib.inspect': mock.MagicMock(), + 'trex_stl_lib.json': mock.MagicMock(), + 'trex_stl_lib.linecache': mock.MagicMock(), + 'trex_stl_lib.math': mock.MagicMock(), + 'trex_stl_lib.os': mock.MagicMock(), + 'trex_stl_lib.platform': mock.MagicMock(), + 'trex_stl_lib.pprint': mock.MagicMock(), + 'trex_stl_lib.random': mock.MagicMock(), + 'trex_stl_lib.re': mock.MagicMock(), + 'trex_stl_lib.scapy': mock.MagicMock(), + 'trex_stl_lib.socket': mock.MagicMock(), + 'trex_stl_lib.string': mock.MagicMock(), + 'trex_stl_lib.struct': mock.MagicMock(), + 'trex_stl_lib.sys': mock.MagicMock(), + 'trex_stl_lib.threading': mock.MagicMock(), + 'trex_stl_lib.time': mock.MagicMock(), + 'trex_stl_lib.traceback': mock.MagicMock(), + 'trex_stl_lib.trex_stl_async_client': mock.MagicMock(), + 'trex_stl_lib.trex_stl_client': mock.MagicMock(), + 'trex_stl_lib.trex_stl_exceptions': mock.MagicMock(), + 'trex_stl_lib.trex_stl_ext': mock.MagicMock(), + 'trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(), + 'trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(), + 'trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(), + 'trex_stl_lib.trex_stl_port': mock.MagicMock(), + 'trex_stl_lib.trex_stl_stats': mock.MagicMock(), + 'trex_stl_lib.trex_stl_streams': mock.MagicMock(), + 'trex_stl_lib.trex_stl_types': mock.MagicMock(), + 'trex_stl_lib.types': mock.MagicMock(), + 'trex_stl_lib.utils': mock.MagicMock(), + 'trex_stl_lib.utils.argparse': mock.MagicMock(), + 'trex_stl_lib.utils.collections': mock.MagicMock(), + 'trex_stl_lib.utils.common': mock.MagicMock(), + 'trex_stl_lib.utils.json': mock.MagicMock(), + 'trex_stl_lib.utils.os': mock.MagicMock(), + 'trex_stl_lib.utils.parsing_opts': mock.MagicMock(), + 'trex_stl_lib.utils.pwd': mock.MagicMock(), + 'trex_stl_lib.utils.random': mock.MagicMock(), + 'trex_stl_lib.utils.re': mock.MagicMock(), + 'trex_stl_lib.utils.string': mock.MagicMock(), + 'trex_stl_lib.utils.sys': mock.MagicMock(), + 'trex_stl_lib.utils.text_opts': mock.MagicMock(), + 'trex_stl_lib.utils.text_tables': mock.MagicMock(), + 'trex_stl_lib.utils.texttable': mock.MagicMock(), + 'trex_stl_lib.warnings': mock.MagicMock(), + 'trex_stl_lib.yaml': mock.MagicMock(), + 'trex_stl_lib.zlib': mock.MagicMock(), + 'trex_stl_lib.zmq': mock.MagicMock(), +} diff --git a/yardstick/tests/functional/benchmark/__init__.py b/yardstick/tests/functional/benchmark/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/yardstick/tests/functional/benchmark/scenarios/__init__.py b/yardstick/tests/functional/benchmark/scenarios/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/yardstick/tests/functional/benchmark/scenarios/networking/__init__.py b/yardstick/tests/functional/benchmark/scenarios/networking/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/yardstick/tests/functional/benchmark/scenarios/networking/test_vnf_generic.py b/yardstick/tests/functional/benchmark/scenarios/networking/test_vnf_generic.py new file mode 100644 index 000000000..da75e3a7e --- /dev/null +++ b/yardstick/tests/functional/benchmark/scenarios/networking/test_vnf_generic.py @@ -0,0 +1,110 @@ +# Copyright (c) 2018 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 copy +import sys + +import mock +import unittest +import yaml + +from yardstick import tests as y_tests +from yardstick.common import utils + + +with mock.patch.dict(sys.modules, y_tests.STL_MOCKS): + from yardstick.benchmark.scenarios.networking import vnf_generic + + +TRAFFIC_PROFILE_1 = """ +schema: nsb:traffic_profile:0.1 +name: rfc2544 +description: Traffic profile to run RFC2544 latency +traffic_profile: + traffic_type : RFC2544Profile + frame_rate : 100 +uplink_0: + ipv4: + id: 1 + outer_l2: + framesize: + 64B: "{{get(imix, 'imix.uplink.64B', '0') }}" + 128B: "{{get(imix, 'imix.uplink.128B', '0') }}" +""" + +TRAFFIC_PROFILE_2 = """ +{% set vports = get(extra_args, 'vports', 1) %} +traffic_profile: + traffic_type : RFC2544Profile +{% for vport in range(vports|int) %} +uplink_{{vport}}: + ipv4: 192.168.0.{{vport}} +{% endfor %} +""" + +class VnfGenericTestCase(unittest.TestCase): + + def setUp(self): + scenario_cfg = {'topology': 'fake_topology', + 'task_path': 'fake_path', + 'traffic_profile': 'fake_fprofile_path'} + context_cfg = {} + topology_yaml = {'nsd:nsd-catalog': {'nsd': [mock.Mock()]}} + with mock.patch.object(yaml, 'load', return_value=topology_yaml), \ + mock.patch.object(utils, 'open_relative_file'): + self.ns_testcase = vnf_generic.NetworkServiceTestCase(scenario_cfg, + context_cfg) + self.ns_testcase._get_traffic_profile = mock.Mock() + + def test__fill_traffic_profile_no_args(self): + traffic_profile = copy.deepcopy(TRAFFIC_PROFILE_1) + self.ns_testcase._get_traffic_profile.return_value = traffic_profile + + self.ns_testcase._fill_traffic_profile() + config = self.ns_testcase.traffic_profile.params + self.assertEqual('nsb:traffic_profile:0.1', config['schema']) + self.assertEqual('rfc2544', config['name']) + self.assertEqual('Traffic profile to run RFC2544 latency', + config['description']) + t_profile = {'traffic_type': 'RFC2544Profile', + 'frame_rate': 100} + self.assertEqual(t_profile, config['traffic_profile']) + uplink_0 = { + 'ipv4': {'id': 1, + 'outer_l2': {'framesize': {'128B': '0', '64B': '0'}} + } + } + self.assertEqual(uplink_0, config['uplink_0']) + + def test__fill_traffic_profile_with_args(self): + traffic_profile = copy.deepcopy(TRAFFIC_PROFILE_2) + self.ns_testcase._get_traffic_profile.return_value = traffic_profile + self.ns_testcase.scenario_cfg['extra_args'] = {'vports': 3} + + self.ns_testcase._fill_traffic_profile() + config = self.ns_testcase.traffic_profile.params + self.assertEqual({'ipv4': '192.168.0.0'}, config['uplink_0']) + self.assertEqual({'ipv4': '192.168.0.1'}, config['uplink_1']) + self.assertEqual({'ipv4': '192.168.0.2'}, config['uplink_2']) + self.assertNotIn('uplink_3', config) + + def test__fill_traffic_profile_incorrect_args(self): + traffic_profile = copy.deepcopy(TRAFFIC_PROFILE_2) + self.ns_testcase._get_traffic_profile.return_value = traffic_profile + self.ns_testcase.scenario_cfg['extra_args'] = {'incorrect_vports': 3} + + self.ns_testcase._fill_traffic_profile() + config = self.ns_testcase.traffic_profile.params + self.assertEqual({'ipv4': '192.168.0.0'}, config['uplink_0']) + self.assertNotIn('uplink_1', config) diff --git a/yardstick/tests/unit/__init__.py b/yardstick/tests/unit/__init__.py index 59318aba7..c05f91c81 100644 --- a/yardstick/tests/unit/__init__.py +++ b/yardstick/tests/unit/__init__.py @@ -16,65 +16,8 @@ import sys import mock +from yardstick import tests -STL_MOCKS = { - 'trex_stl_lib': mock.MagicMock(), - 'trex_stl_lib.base64': mock.MagicMock(), - 'trex_stl_lib.binascii': mock.MagicMock(), - 'trex_stl_lib.collections': mock.MagicMock(), - 'trex_stl_lib.copy': mock.MagicMock(), - 'trex_stl_lib.datetime': mock.MagicMock(), - 'trex_stl_lib.functools': mock.MagicMock(), - 'trex_stl_lib.imp': mock.MagicMock(), - 'trex_stl_lib.inspect': mock.MagicMock(), - 'trex_stl_lib.json': mock.MagicMock(), - 'trex_stl_lib.linecache': mock.MagicMock(), - 'trex_stl_lib.math': mock.MagicMock(), - 'trex_stl_lib.os': mock.MagicMock(), - 'trex_stl_lib.platform': mock.MagicMock(), - 'trex_stl_lib.pprint': mock.MagicMock(), - 'trex_stl_lib.random': mock.MagicMock(), - 'trex_stl_lib.re': mock.MagicMock(), - 'trex_stl_lib.scapy': mock.MagicMock(), - 'trex_stl_lib.socket': mock.MagicMock(), - 'trex_stl_lib.string': mock.MagicMock(), - 'trex_stl_lib.struct': mock.MagicMock(), - 'trex_stl_lib.sys': mock.MagicMock(), - 'trex_stl_lib.threading': mock.MagicMock(), - 'trex_stl_lib.time': mock.MagicMock(), - 'trex_stl_lib.traceback': mock.MagicMock(), - 'trex_stl_lib.trex_stl_async_client': mock.MagicMock(), - 'trex_stl_lib.trex_stl_client': mock.MagicMock(), - 'trex_stl_lib.trex_stl_exceptions': mock.MagicMock(), - 'trex_stl_lib.trex_stl_ext': mock.MagicMock(), - 'trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(), - 'trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(), - 'trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(), - 'trex_stl_lib.trex_stl_port': mock.MagicMock(), - 'trex_stl_lib.trex_stl_stats': mock.MagicMock(), - 'trex_stl_lib.trex_stl_streams': mock.MagicMock(), - 'trex_stl_lib.trex_stl_types': mock.MagicMock(), - 'trex_stl_lib.types': mock.MagicMock(), - 'trex_stl_lib.utils': mock.MagicMock(), - 'trex_stl_lib.utils.argparse': mock.MagicMock(), - 'trex_stl_lib.utils.collections': mock.MagicMock(), - 'trex_stl_lib.utils.common': mock.MagicMock(), - 'trex_stl_lib.utils.json': mock.MagicMock(), - 'trex_stl_lib.utils.os': mock.MagicMock(), - 'trex_stl_lib.utils.parsing_opts': mock.MagicMock(), - 'trex_stl_lib.utils.pwd': mock.MagicMock(), - 'trex_stl_lib.utils.random': mock.MagicMock(), - 'trex_stl_lib.utils.re': mock.MagicMock(), - 'trex_stl_lib.utils.string': mock.MagicMock(), - 'trex_stl_lib.utils.sys': mock.MagicMock(), - 'trex_stl_lib.utils.text_opts': mock.MagicMock(), - 'trex_stl_lib.utils.text_tables': mock.MagicMock(), - 'trex_stl_lib.utils.texttable': mock.MagicMock(), - 'trex_stl_lib.warnings': mock.MagicMock(), - 'trex_stl_lib.yaml': mock.MagicMock(), - 'trex_stl_lib.zlib': mock.MagicMock(), - 'trex_stl_lib.zmq': mock.MagicMock(), -} -mock_stl = mock.patch.dict(sys.modules, STL_MOCKS) +mock_stl = mock.patch.dict(sys.modules, tests.STL_MOCKS) mock_stl.start() diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py index 846de13de..022e66ff1 100644 --- a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py +++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -15,18 +15,31 @@ from copy import deepcopy import errno import os +import sys import mock import six import unittest +from yardstick import tests from yardstick.common import utils -from yardstick.benchmark.scenarios.networking import vnf_generic from yardstick.network_services.collector.subscriber import Collector +from yardstick.network_services.traffic_profile import base +from yardstick.network_services.vnf_generic import vnfdgen from yardstick.network_services.vnf_generic.vnf.base import \ GenericTrafficGen, GenericVNF +stl_patch = mock.patch.dict(sys.modules, tests.STL_MOCKS) +stl_patch.start() + +if stl_patch: + from yardstick.benchmark.scenarios.networking import vnf_generic + +# pylint: disable=unused-argument +# disable this for now because I keep forgetting mock patch arg ordering + + COMPLETE_TREX_VNFD = { 'vnfd:vnfd-catalog': { 'vnfd': [ @@ -305,6 +318,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7', 'tc': 'tc_ipv4_1Mflow_64B_packetsize', 'traffic_profile': 'ipv4_throughput_vpe.yaml', + 'extra_args': {'arg1': 'value1', 'arg2': 'value2'}, 'type': 'ISB', 'tc_options': { 'rfc2544': { @@ -404,11 +418,10 @@ class TestNetworkServiceTestCase(unittest.TestCase): 'public_ip': ['1.1.1.1'], }, } - - # NOTE(ralonsoh): this variable is not used in the test case and maybe - # it should. - #result = {'flow': {'dst_ip0': '152.16.40.2-152.16.40.254', - # 'src_ip0': '152.16.100.2-152.16.100.254'}} + # NOTE(ralonsoh): check the expected output. This test could be + # incorrect + # result = {'flow': {'dst_ip0': '152.16.40.2-152.16.40.254', + # 'src_ip0': '152.16.100.2-152.16.100.254'}} self.assertEqual({'flow': {}}, self.s._get_traffic_flow()) def test___get_traffic_flow_error(self): @@ -418,7 +431,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): def test_get_vnf_imp(self): vnfd = COMPLETE_TREX_VNFD['vnfd:vnfd-catalog']['vnfd'][0]['class-name'] - self.assertIsNotNone(self.s.get_vnf_impl(vnfd)) + with mock.patch.dict(sys.modules, tests.STL_MOCKS): + self.assertIsNotNone(self.s.get_vnf_impl(vnfd)) with self.assertRaises(vnf_generic.IncorrectConfig) as raised: self.s.get_vnf_impl('NonExistentClass') @@ -456,9 +470,9 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.s.map_topology_to_infrastructure() nodes = self.context_cfg["nodes"] - self.assertEqual( - "../../vnf_descriptors/tg_rfc2544_tpl.yaml", nodes['tg__1']['VNF model']) - self.assertEqual("../../vnf_descriptors/vpe_vnf.yaml", + self.assertEqual('../../vnf_descriptors/tg_rfc2544_tpl.yaml', + nodes['tg__1']['VNF model']) + self.assertEqual('../../vnf_descriptors/vpe_vnf.yaml', nodes['vnf__1']['VNF model']) def test_map_topology_to_infrastructure_insufficient_nodes(self): @@ -495,10 +509,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): for interface in self.tg__1['interfaces'].values(): del interface['local_mac'] - with mock.patch( - "yardstick.benchmark.scenarios.networking.vnf_generic.LOG"): - with self.assertRaises(vnf_generic.IncorrectConfig) as raised: - self.s._resolve_topology() + with self.assertRaises(vnf_generic.IncorrectConfig) as raised: + self.s._resolve_topology() self.assertIn('not found', str(raised.exception)) @@ -510,9 +522,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.s.topology["vld"][0]['vnfd-connection-point-ref'].append( self.s.topology["vld"][0]['vnfd-connection-point-ref'][0]) - with mock.patch.object(vnf_generic, 'LOG'): - with self.assertRaises(vnf_generic.IncorrectConfig) as raised: - self.s._resolve_topology() + with self.assertRaises(vnf_generic.IncorrectConfig) as raised: + self.s._resolve_topology() self.assertIn('wrong endpoint count', str(raised.exception)) @@ -520,9 +531,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.s.topology["vld"][0]['vnfd-connection-point-ref'] = \ self.s.topology["vld"][0]['vnfd-connection-point-ref'][:1] - with mock.patch.object(vnf_generic, 'LOG'): - with self.assertRaises(vnf_generic.IncorrectConfig) as raised: - self.s._resolve_topology() + with self.assertRaises(vnf_generic.IncorrectConfig) as raised: + self.s._resolve_topology() self.assertIn('wrong endpoint count', str(raised.exception)) @@ -615,14 +625,25 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.assertEqual({'imix': {'64B': 100}}, self.s._get_traffic_imix()) - def test__fill_traffic_profile(self): - self.scenario_cfg["traffic_profile"] = \ - self._get_file_abspath("ipv4_throughput_vpe.yaml") - self.scenario_cfg["traffic_options"]["flow"] = \ - self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml") - self.scenario_cfg["traffic_options"]["imix"] = \ - self._get_file_abspath("imix_voice.yaml") - self.assertIsNotNone(self.s._fill_traffic_profile()) + @mock.patch.object(base.TrafficProfile, 'get') + @mock.patch.object(vnfdgen, 'generate_vnfd') + def test__fill_traffic_profile(self, mock_generate, mock_tprofile_get): + fake_tprofile = mock.Mock() + fake_vnfd = mock.Mock() + with mock.patch.object(self.s, '_get_traffic_profile', + return_value=fake_tprofile) as mock_get_tp: + mock_generate.return_value = fake_vnfd + self.s._fill_traffic_profile() + mock_get_tp.assert_called_once() + mock_generate.assert_called_once_with( + fake_tprofile, + {'downlink': {}, + 'extra_args': {'arg1': 'value1', 'arg2': 'value2'}, + 'flow': {'flow': {}}, + 'imix': {'imix': {'64B': 100}}, + 'uplink': {}} + ) + mock_tprofile_get.assert_called_once_with(fake_vnfd) def test_teardown(self): vnf = mock.Mock(autospec=GenericVNF) -- cgit 1.2.3-korg