diff options
Diffstat (limited to 'tests')
64 files changed, 3151 insertions, 1591 deletions
diff --git a/tests/ci/yardstick-verify b/tests/ci/yardstick-verify index ca8a0b27a..f3e7a49e3 100755 --- a/tests/ci/yardstick-verify +++ b/tests/ci/yardstick-verify @@ -87,7 +87,9 @@ error_exit() exitcode=$rc fi - cleanup + if [[ "${DEPLOY_SCENARIO:0:2}" == 'os' ]];then + source "${YARDSTICK_REPO_DIR}/tests/ci/clean_images.sh" + fi echo "Exiting with RC=$exitcode" diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc006.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc006.yaml index a35629f81..81b42dc4d 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc006.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc006.yaml @@ -14,6 +14,7 @@ description: > Measure volume storage IOPS, throughput and latency using fio with job file. {% 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' %} {% set segmentation_id = segmentation_id or none %} @@ -53,7 +54,7 @@ context: floating_ip: true volume: name: test-volume - size: 200 + size: {{volume_size}} volume_mountpoint: /dev/vdb networks: diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc011.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc011.yaml index eef1a7a62..b2077d59e 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc011.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc011.yaml @@ -13,6 +13,10 @@ description: > Yardstick TC011 config file; Measure packet delay variation (jitter) using iperf3. +{% set udp = udp or "udp" %} +{% set bandwidth = bandwidth or "20m" %} +{% set length = length or "8K" %} +{% set window = window or 29200 %} {% set provider = provider or none %} {% set physical_network = physical_network or 'physnet1' %} {% set segmentation_id = segmentation_id or none %} @@ -21,10 +25,10 @@ scenarios: - type: Iperf3 options: - udp: udp - bandwidth: 20m - length: 8K - window: 29200 + udp: {{udp}} + bandwidth: {{bandwidth}} + length: {{length}} + window: {{window}} host: zeus.demo target: hera.demo diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc019.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc019.yaml index 15bbddaa6..046d51731 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc019.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc019.yaml @@ -34,10 +34,10 @@ scenarios: - monitor_type: "process" process_name: "nova-api" host: node1 - monitor_time: 20 + monitor_time: 30 monitor_number: 3 sla: - max_recover_time: 20 + max_recover_time: 30 nodes: node1: node1.LF diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc045.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc045.yaml index fdaaa838a..dfe44ed12 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc045.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc045.yaml @@ -33,10 +33,10 @@ scenarios: - monitor_type: "process" process_name: "neutron-server" host: node1 - monitor_time: 20 + monitor_time: 30 monitor_number: 3 sla: - max_recover_time: 20 + max_recover_time: 30 nodes: node1: node1.LF diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc046.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc046.yaml index fe16f388c..1d553268c 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc046.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc046.yaml @@ -33,10 +33,10 @@ scenarios: - monitor_type: "process" process_name: "keystone" host: node1 - monitor_time: 20 + monitor_time: 30 monitor_number: 3 sla: - max_recover_time: 20 + max_recover_time: 30 nodes: node1: node1.LF diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc047.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc047.yaml index c888967da..33bc5cd5f 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc047.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc047.yaml @@ -33,10 +33,10 @@ scenarios: - monitor_type: "process" process_name: "glance-api" host: node1 - monitor_time: 20 + monitor_time: 30 monitor_number: 3 sla: - max_recover_time: 20 + max_recover_time: 30 nodes: node1: node1.LF diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc048.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc048.yaml index 4ad19f3bd..a13afe3bf 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc048.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc048.yaml @@ -33,10 +33,10 @@ scenarios: - monitor_type: "process" process_name: "cinder-api" host: node1 - monitor_time: 20 + monitor_time: 30 monitor_number: 3 sla: - max_recover_time: 20 + max_recover_time: 30 nodes: node1: node1.LF diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc049.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc049.yaml index da17a59c1..394b98721 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc049.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc049.yaml @@ -33,10 +33,10 @@ scenarios: - monitor_type: "process" process_name: "swift-proxy" host: node1 - monitor_time: 20 + monitor_time: 30 monitor_number: 3 sla: - max_recover_time: 20 + max_recover_time: 30 nodes: node1: node1.LF diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc053.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc053.yaml index 3ecbc308c..f987e2b45 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc053.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc053.yaml @@ -32,10 +32,10 @@ scenarios: key: "service-status" process_name: "haproxy" host: node1 - monitor_time: 20 + monitor_time: 30 monitor_number: 3 sla: - max_recover_time: 20 + max_recover_time: 30 - monitor_type: "openstack-cmd" diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc056.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc056.yaml index 7f1dc1010..40e8f9c13 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc056.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc056.yaml @@ -59,9 +59,9 @@ scenarios: - monitor_type: "process" process_name: "rabbitmq-server" host: {{attack_host}} - monitor_time: 20 + monitor_time: 30 sla: - max_recover_time: 20 + max_recover_time: 30 nodes: {{attack_host}}: {{attack_host}}.LF diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml index e9feb97f5..dc0675bec 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc058.yaml @@ -36,9 +36,9 @@ scenarios: process_name: "neutron-l3-agent" host: {{attack_host}} key: "monitor-recovery" - monitor_time: 20 + monitor_time: 30 sla: - max_recover_time: 20 + max_recover_time: 30 - monitor_type: "general-monitor" diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc063.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc063.yaml index 48288ef62..254c214d2 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc063.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc063.yaml @@ -13,8 +13,8 @@ description: > Yardstick TC063 config file; Measure disk size, block size and disk utilization using fdisk and iostat. -{% set host = host or "node5.yardstick-TC063" %} {% set file = file or '/etc/yardstick/pod.yaml' %} +{% set node = node or "node5" %} scenarios: - @@ -22,7 +22,7 @@ scenarios: options: test_type: "disk_size" - host: {{host}} + host: {{node}}.yardstick-TC063 runner: type: Iteration diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc078.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc078.yaml index b89f7674b..94256125f 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc078.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc078.yaml @@ -20,7 +20,11 @@ scenarios: type: SpecCPU2006 options: - benchmark_subset: int + SPECint_benchmark: int^429 + runspec_iterations: 1 + runspec_tune: base + runspec_size: ref + runspec_rate: 1 host: node1.yardstick-TC078 diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc082.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc082.yaml new file mode 100644 index 000000000..4b67f0f20 --- /dev/null +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc082.yaml @@ -0,0 +1,64 @@ +############################################################################## +# Copyright (c) 2017 kristian.hunt@gmail.com 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 +############################################################################## +--- +# Sample benchmark task config file +# use perf to perform Linux performance measurements +# this sample demonstrates measurements of various software perf events + +schema: "yardstick:task:0.1" +description: > + Yardstick TC082 config file; + Measure various software perf events by perf. + +{% set provider = provider or none %} +{% set physical_network = physical_network or 'physnet1' %} +{% set segmentation_id = segmentation_id or none %} + +scenarios: +- + type: Perf + options: + load: true + events: + - task-clock + - cpu-clock + - context-switches + - page-faults + - cpu-migrations + host: hades.demo + + runner: + type: Duration + duration: 30 + + sla: + metric: context-switches + smaller_than_expected: true + expected_value: 300 + action: monitor + +context: + name: demo + image: yardstick-image + flavor: yardstick-flavor + user: ubuntu + + servers: + hades: + floating_ip: true + networks: + test: + cidr: "10.0.1.0/24" + {% if provider == "vlan" %} + provider: {{provider}} + physical_network: {{physical_network}} + {% if segmentation_id %} + segmentation_id: {{segmentation_id}} + {% endif %} + {% endif %}
\ No newline at end of file diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc083.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc083.yaml new file mode 100755 index 000000000..6315fdc07 --- /dev/null +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc083.yaml @@ -0,0 +1,90 @@ +############################################################################## +# 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 +############################################################################## +--- +# Sample benchmark task config file +# measure network latency and throughput using netperf +# There are two sample scenarios: bulk test and request/response test +# In bulk test, UDP_STREAM and TCP_STREAM can be used +# send_msg_size and recv_msg_size are options of bulk test +# In req/rsp test, TCP_RR TCP_CRR UDP_RR can be used +# req_rsp_size is option of req/rsp test + +schema: "yardstick:task:0.1" + +description: > + Yardstick TC083 config file; + Measure network latency and throughput using netperf. + +{% set provider = provider or none %} +{% set physical_network = physical_network or 'physnet1' %} +{% set segmentation_id = segmentation_id or none %} + +scenarios: +- + type: Netperf + options: + testname: 'UDP_STREAM' + send_msg_size: 1024 + duration: 20 + + host: Chang'e.demo + target: Houyi.demo + + runner: + type: Iteration + iterations: 1 + interval: 1 + sla: + mean_latency: 100 + action: monitor +- + type: Netperf + options: + testname: 'TCP_RR' + req_rsp_size: '32,1024' + + host: Chang'e.demo + target: Houyi.demo + + runner: + type: Duration + duration: 20 + interval: 1 + sla: + mean_latency: 300 + action: monitor + +context: + name: demo + image: yardstick-image + flavor: yardstick-flavor + user: ubuntu + + placement_groups: + pgrp1: + policy: "availability" + + servers: + Chang'e: + floating_ip: true + placement: "pgrp1" + Houyi: + floating_ip: true + placement: "pgrp1" + + networks: + test: + cidr: '10.0.1.0/24' + {% if provider == "vlan" %} + provider: {{provider}} + physical_network: {{physical_network}} + {% if segmentation_id %} + segmentation_id: {{segmentation_id}} + {% endif %} + {% endif %} diff --git a/tests/opnfv/test_suites/opnfv_k8-ovn-lb-noha_daily.yaml b/tests/opnfv/test_suites/opnfv_k8-ovn-lb-noha_daily.yaml new file mode 100644 index 000000000..207030073 --- /dev/null +++ b/tests/opnfv/test_suites/opnfv_k8-ovn-lb-noha_daily.yaml @@ -0,0 +1,18 @@ +############################################################################## +# 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 +############################################################################## +--- +# k8 ovn lb noha daily task suite + +schema: "yardstick:suite:0.1" + +name: "k8-ovn-lb-noha" +test_cases_dir: "tests/opnfv/test_cases/" +test_cases: +- + file_name: opnfv_yardstick_tc080.yaml diff --git a/tests/opnfv/test_suites/opnfv_os-nosdn-bar-ha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-nosdn-bar-ha_daily.yaml new file mode 100644 index 000000000..35bc0ebd8 --- /dev/null +++ b/tests/opnfv/test_suites/opnfv_os-nosdn-bar-ha_daily.yaml @@ -0,0 +1,161 @@ +############################################################################## +# 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-nosdn-bar-ha daily task suite + +schema: "yardstick:suite:0.1" + +name: "os-nosdn-bar-ha" +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_tc043.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node4.LF","target": "node5.LF"}' +- + file_name: opnfv_yardstick_tc019.yaml + constraint: + installer: compass,fuel + pod: huawei-pod2,ericsson-pod1 + task_args: + huawei-pod2: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml"}' + ericsson-pod1: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc045.yaml + constraint: + installer: compass,fuel + pod: huawei-pod2,ericsson-pod1 + task_args: + huawei-pod2: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml"}' + ericsson-pod1: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc046.yaml + constraint: + installer: fuel + task_args: + default: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc047.yaml + constraint: + installer: compass,fuel + pod: huawei-pod2,ericsson-pod1 + task_args: + huawei-pod2: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml"}' + ericsson-pod1: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc048.yaml + constraint: + installer: compass,fuel + pod: huawei-pod2,ericsson-pod1 + task_args: + huawei-pod2: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml"}' + ericsson-pod1: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc049.yaml + constraint: + installer: fuel + task_args: + default: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc050.yaml + constraint: + installer: fuel + task_args: + default: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc051.yaml + constraint: + installer: compass,fuel + pod: huawei-pod2,ericsson-pod1 + task_args: + huawei-pod2: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml"}' + ericsson-pod1: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc052.yaml + constraint: + installer: fuel + task_args: + default: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc053.yaml + constraint: + installer: fuel + task_args: + default: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml"}' +- + file_name: opnfv_yardstick_tc055.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5.yardstick-TC055"}' +- + file_name: opnfv_yardstick_tc063.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5.yardstick-TC063"}' +- + file_name: opnfv_yardstick_tc069.yaml +- + file_name: opnfv_yardstick_tc070.yaml +- + file_name: opnfv_yardstick_tc071.yaml +- + file_name: opnfv_yardstick_tc072.yaml +- + file_name: opnfv_yardstick_tc074.yaml + constraint: + installer: compass + pod: huawei-pod1, huawei-pod2 + task_args: + huawei-pod1: '{"public_network": "ext-net", + "StorPerf_ip": "192.168.10.6"}' + huawei-pod2: '{"public_network": "ext-net", + "StorPerf_ip": "192.168.11.2"}' +- + file_name: opnfv_yardstick_tc075.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node1.LF"}' +- + file_name: opnfv_yardstick_tc027.yaml + constraint: + installer: compass,fuel + pod: huawei-pod1,lf-pod2,ericsson-pod3,ericsson-pod4 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml"}' + lf-pod2: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml", "openrc":"/root/openrc", "external_network":"admin_floating_net"}' + ericsson-pod3: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml", "openrc":"/root/openrc", "external_network":"admin_floating_net"}' + ericsson-pod4: '{"file": "etc/yardstick/nodes/fuel_baremetal/pod.yaml", "openrc":"/root/openrc", "external_network":"admin_floating_net"}' + diff --git a/tests/opnfv/test_suites/opnfv_os-nosdn-bar-noha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-nosdn-bar-noha_daily.yaml new file mode 100644 index 000000000..26e92e704 --- /dev/null +++ b/tests/opnfv/test_suites/opnfv_os-nosdn-bar-noha_daily.yaml @@ -0,0 +1,62 @@ +############################################################################## +# 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-nosdn-bar-noha daily task suite + +schema: "yardstick:suite:0.1" + +name: "os-nosdn-bar-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_tc055.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5.yardstick-TC055"}' +- + file_name: opnfv_yardstick_tc063.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5.yardstick-TC063"}' +- + file_name: opnfv_yardstick_tc069.yaml +- + file_name: opnfv_yardstick_tc070.yaml +- + file_name: opnfv_yardstick_tc071.yaml +- + file_name: opnfv_yardstick_tc072.yaml +- + file_name: opnfv_yardstick_tc075.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node1.LF"}' diff --git a/tests/opnfv/test_suites/opnfv_os-odl-fdio-dvr-ha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-odl-fdio-dvr-ha_daily.yaml new file mode 100644 index 000000000..825fea7c1 --- /dev/null +++ b/tests/opnfv/test_suites/opnfv_os-odl-fdio-dvr-ha_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-ha daily task suite + +schema: "yardstick:suite:0.1" + +name: "os-odl-fdio-dvr-ha" +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/opnfv/test_suites/opnfv_os-odl-fdio-noha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-odl-fdio-noha_daily.yaml new file mode 100644 index 000000000..cc8df99b6 --- /dev/null +++ b/tests/opnfv/test_suites/opnfv_os-odl-fdio-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-noha daily task suite + +schema: "yardstick:suite:0.1" + +name: "os-odl-fdio-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/opnfv/test_suites/opnfv_os-odl-nofeature-ha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-odl-nofeature-ha_daily.yaml new file mode 100644 index 000000000..1ab16e5d1 --- /dev/null +++ b/tests/opnfv/test_suites/opnfv_os-odl-nofeature-ha_daily.yaml @@ -0,0 +1,64 @@ +############################################################################## +# 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-nofeature-ha daily task suite + +schema: "yardstick:suite:0.1" + +name: "os-odl-nofeature-ha" +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 + constraint: + installer: compass +- + file_name: opnfv_yardstick_tc012.yaml +- + file_name: opnfv_yardstick_tc014.yaml +- + file_name: opnfv_yardstick_tc037.yaml +- + file_name: opnfv_yardstick_tc055.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5.yardstick-TC055"}' +- + file_name: opnfv_yardstick_tc063.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5.yardstick-TC063"}' +- + file_name: opnfv_yardstick_tc069.yaml +- + file_name: opnfv_yardstick_tc070.yaml +- + file_name: opnfv_yardstick_tc071.yaml +- + file_name: opnfv_yardstick_tc072.yaml +- + file_name: opnfv_yardstick_tc075.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node1.LF"}' diff --git a/tests/opnfv/test_suites/opnfv_os-odl-ovs-ha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-odl-ovs-ha_daily.yaml new file mode 100644 index 000000000..b5e53b94c --- /dev/null +++ b/tests/opnfv/test_suites/opnfv_os-odl-ovs-ha_daily.yaml @@ -0,0 +1,64 @@ +############################################################################## +# 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-ovs-ha daily task suite + +schema: "yardstick:suite:0.1" + +name: "os-odl-ovs-ha" +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 + constraint: + installer: compass +- + file_name: opnfv_yardstick_tc012.yaml +- + file_name: opnfv_yardstick_tc014.yaml +- + file_name: opnfv_yardstick_tc037.yaml +- + file_name: opnfv_yardstick_tc055.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5.yardstick-TC055"}' +- + file_name: opnfv_yardstick_tc063.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node5.yardstick-TC063"}' +- + file_name: opnfv_yardstick_tc069.yaml +- + file_name: opnfv_yardstick_tc070.yaml +- + file_name: opnfv_yardstick_tc071.yaml +- + file_name: opnfv_yardstick_tc072.yaml +- + file_name: opnfv_yardstick_tc075.yaml + constraint: + installer: compass + pod: huawei-pod1 + task_args: + huawei-pod1: '{"file": "etc/yardstick/nodes/compass_sclab_physical/pod.yaml", + "host": "node1.LF"}' diff --git a/tests/unit/apiserver/__init__.py b/tests/unit/apiserver/__init__.py index 1c9d5a672..5e1ed2ea1 100644 --- a/tests/unit/apiserver/__init__.py +++ b/tests/unit/apiserver/__init__.py @@ -1,5 +1,6 @@ from __future__ import absolute_import +import mock import os import socket import unittest @@ -16,6 +17,10 @@ class APITestCase(unittest.TestCase): self.db_fd, self.db_path = tempfile.mkstemp() consts.SQLITE = 'sqlite:///{}'.format(self.db_path) + # server calls gethostbyname which takes 4 seconds, and we should mock it anyway + self.socket_mock = mock.patch.dict("sys.modules", {"socket": mock.MagicMock( + **{"gethostbyname.return_value": "127.0.0.1", "gethostname.return_value": "localhost"})}) + self.socket_mock.start() try: from api import server except socket.gaierror: @@ -30,6 +35,7 @@ class APITestCase(unittest.TestCase): def tearDown(self): os.close(self.db_fd) os.unlink(self.db_path) + self.socket_mock.stop() def _post(self, url, data): headers = {'Content-Type': 'application/json'} diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py index cc0c7bc8e..2e546805d 100644 --- a/tests/unit/benchmark/contexts/test_heat.py +++ b/tests/unit/benchmark/contexts/test_heat.py @@ -13,7 +13,6 @@ from __future__ import absolute_import -import ipaddress import logging import os import unittest @@ -147,30 +146,6 @@ class HeatContextTestCase(unittest.TestCase): self.test_context.user = 'foo' @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - @mock.patch('yardstick.benchmark.contexts.heat.get_neutron_client') - def test_attrs_get(self, mock_neutron, mock_template): - image, flavor, user = expected_tuple = 'foo1', 'foo2', 'foo3' - self.assertNotEqual(self.test_context.image, image) - self.assertNotEqual(self.test_context.flavor, flavor) - self.assertNotEqual(self.test_context.user, user) - self.test_context._image = image - self.test_context._flavor = flavor - self.test_context._user = user - attr_tuple = self.test_context.image, self.test_context.flavor, self.test_context.user - self.assertEqual(attr_tuple, expected_tuple) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test_attrs_set_negative(self, mock_template): - with self.assertRaises(AttributeError): - self.test_context.image = 'foo' - - with self.assertRaises(AttributeError): - self.test_context.flavor = 'foo' - - with self.assertRaises(AttributeError): - self.test_context.user = 'foo' - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test_deploy(self, mock_template): self.test_context.name = 'foo' self.test_context.template_file = '/bar/baz/some-heat-file' @@ -207,11 +182,17 @@ class HeatContextTestCase(unittest.TestCase): u'd-mac_address': u'00:10', u'd-device_id': u'dev43', u'd-network_id': u'net987', + u'e': u'40.30.20.15', + u'e-subnet_id': 2, + u'e-mac_address': u'00:10', + u'e-device_id': u'dev43', + u'e-network_id': u'net987', } server = mock.MagicMock() server.ports = OrderedDict([ - ('a', {'stack_name': 'b'}), - ('c', {'stack_name': 'd'}), + ('a', [{'stack_name': 'b', 'port': 'port_a'}]), + ('c', [{'stack_name': 'd', 'port': 'port_c'}, + {'stack_name': 'e', 'port': 'port_f'}]), ]) expected = { @@ -230,8 +211,8 @@ class HeatContextTestCase(unittest.TestCase): } self.test_context.add_server_port(server) self.assertEqual(server.private_ip, '10.20.30.45') - self.assertEqual(len(server.interfaces), 2) - self.assertDictEqual(server.interfaces['a'], expected) + self.assertEqual(len(server.interfaces), 3) + self.assertDictEqual(server.interfaces['port_a'], expected) @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test_undeploy(self, mock_template): @@ -246,19 +227,20 @@ class HeatContextTestCase(unittest.TestCase): mock_os.path.exists.return_value = True self.assertIsNone(self.test_context.undeploy()) - def test__get_server_found_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to get a server that matches based on a dictionary input. """ foo2_server = mock.Mock() - foo2_server.key_filename = 'key_file' + foo2_server.key_filename = None foo2_server.private_ip = '10.0.0.2' foo2_server.public_ip = '127.0.0.2' foo2_server.context.user = 'oof' baz3_server = mock.Mock() - baz3_server.key_filename = 'key_filename' + baz3_server.key_filename = None baz3_server.private_ip = '10.0.0.3' baz3_server.public_ip = '127.0.0.3' baz3_server.context.user = 'zab' @@ -283,11 +265,11 @@ class HeatContextTestCase(unittest.TestCase): } result = self.test_context._get_server(attr_name) self.assertEqual(result['user'], 'bot') - self.assertIsNotNone(result['key_filename']) self.assertEqual(result['ip'], '127.0.0.1') self.assertEqual(result['private_ip'], '10.0.0.1') - def test__get_server_found_dict_no_attrs(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_dict_no_attrs(self, mock_pkg_resources): """ Use HeatContext._get_server to get a server that matches based on a dictionary input. @@ -320,13 +302,13 @@ class HeatContextTestCase(unittest.TestCase): } result = self.test_context._get_server(attr_name) self.assertEqual(result['user'], 'bot') - self.assertIsNotNone(result['key_filename']) # no private ip attr mapping in the map results in None value in the result self.assertIsNone(result['private_ip']) # no public ip attr mapping in the map results in no value in the result self.assertNotIn('ip', result) - def test__get_server_found_not_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_found_not_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to get a server that matches based on a non-dictionary input @@ -358,12 +340,12 @@ class HeatContextTestCase(unittest.TestCase): attr_name = 'baz3' result = self.test_context._get_server(attr_name) self.assertEqual(result['user'], 'zab') - self.assertIsNotNone(result['key_filename']) self.assertEqual(result['private_ip'], '10.0.0.3') # no public_ip on the server results in no value in the result self.assertNotIn('public_ip', result) - def test__get_server_none_found_not_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_none_found_not_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to not get a server due to None value associated with the match to a non-dictionary @@ -396,7 +378,8 @@ class HeatContextTestCase(unittest.TestCase): result = self.test_context._get_server(attr_name) self.assertIsNone(result) - def test__get_server_not_found_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_not_found_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to not get a server for lack of a match to a dictionary input @@ -431,7 +414,8 @@ class HeatContextTestCase(unittest.TestCase): result = self.test_context._get_server(attr_name) self.assertIsNone(result) - def test__get_server_not_found_not_dict(self): + @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") + def test__get_server_not_found_not_dict(self, mock_pkg_resources): """ Use HeatContext._get_server to not get a server for lack of a match to a non-dictionary input @@ -472,7 +456,6 @@ class HeatContextTestCase(unittest.TestCase): network2 = mock.MagicMock() network2.name = 'net_2' - network2.vld_id = 'vld999' network2.segmentation_id = 'seg45' network2.network_type = 'type_b' network2.physical_network = 'virt' @@ -488,16 +471,15 @@ class HeatContextTestCase(unittest.TestCase): attr_name = {} self.assertIsNone(self.test_context._get_network(attr_name)) - attr_name = {'vld_id': 'vld777'} + attr_name = {'network_type': 'nosuch'} self.assertIsNone(self.test_context._get_network(attr_name)) attr_name = 'vld777' self.assertIsNone(self.test_context._get_network(attr_name)) - attr_name = {'vld_id': 'vld999'} + attr_name = {'segmentation_id': 'seg45'} expected = { "name": 'net_2', - "vld_id": 'vld999', "segmentation_id": 'seg45', "network_type": 'type_b', "physical_network": 'virt', @@ -508,7 +490,6 @@ class HeatContextTestCase(unittest.TestCase): attr_name = 'a' expected = { "name": 'net_1', - "vld_id": 'vld111', "segmentation_id": 'seg54', "network_type": 'type_a', "physical_network": 'phys', diff --git a/tests/unit/benchmark/contexts/test_kubernetes.py b/tests/unit/benchmark/contexts/test_kubernetes.py index b0ee792db..4976a9fe0 100644 --- a/tests/unit/benchmark/contexts/test_kubernetes.py +++ b/tests/unit/benchmark/contexts/test_kubernetes.py @@ -81,9 +81,14 @@ class KubernetesTestCase(unittest.TestCase): self.assertTrue(mock_get_rc_pods.called) self.assertTrue(mock_wait_until_running.called) + @mock.patch('{}.paramiko'.format(prefix), **{"resource_filename.return_value": ""}) + @mock.patch('{}.pkg_resources'.format(prefix), **{"resource_filename.return_value": ""}) + @mock.patch('{}.utils'.format(prefix)) + @mock.patch('{}.open'.format(prefix), create=True) @mock.patch('{}.k8s_utils.delete_config_map'.format(prefix)) @mock.patch('{}.k8s_utils.create_config_map'.format(prefix)) - def test_ssh_key(self, mock_create, mock_delete): + def test_ssh_key(self, mock_create, mock_delete, mock_open, mock_utils, mock_resources, + mock_paramiko): k8s_context = KubernetesContext() k8s_context.init(context_cfg) diff --git a/tests/unit/benchmark/core/test_task.py b/tests/unit/benchmark/core/test_task.py index 14027e43c..737e7058b 100644 --- a/tests/unit/benchmark/core/test_task.py +++ b/tests/unit/benchmark/core/test_task.py @@ -66,31 +66,27 @@ class TaskTestCase(unittest.TestCase): nodes = { 'node1': { 'interfaces': { - 'eth0': { - 'name': 'mgmt', + 'mgmt': { + 'network_name': 'mgmt', }, - 'eth1': { - 'name': 'external', - 'vld_id': '23', + 'xe0': { + 'network_name': 'uplink_0', }, - 'eth10': { - 'name': 'internal', - 'vld_id': '55', + 'xe1': { + 'network_name': 'downlink_0', }, }, }, 'node2': { 'interfaces': { - 'eth4': { - 'name': 'mgmt', + 'mgmt': { + 'network_name': 'mgmt', }, - 'eth2': { - 'name': 'external', - 'vld_id': '32', + 'uplink_0': { + 'network_name': 'uplink_0', }, - 'eth11': { - 'name': 'internal', - 'vld_id': '55', + 'downlink_0': { + 'network_name': 'downlink_0', }, }, }, @@ -99,30 +95,30 @@ class TaskTestCase(unittest.TestCase): mock_context.get_network.side_effect = iter([ None, { - 'name': 'a', - 'network_type': 'private', + 'name': 'mgmt', + 'network_type': 'flat', }, {}, { - 'name': 'b', - 'vld_id': 'y', + 'name': 'uplink_0', 'subnet_cidr': '10.20.0.0/16', }, { - 'name': 'c', - 'vld_id': 'x', + 'name': 'downlink_0', + 'segmentation_id': '1001', }, { - 'name': 'd', - 'vld_id': 'w', + 'name': 'uplink_1', }, ]) - # once for each vld_id in the nodes dict - expected_get_network_calls = 4 + # one for each interface + expected_get_network_calls = 6 expected = { - 'a': {'name': 'a', 'network_type': 'private'}, - 'b': {'name': 'b', 'vld_id': 'y', 'subnet_cidr': '10.20.0.0/16'}, + 'mgmt': {'name': 'mgmt', 'network_type': 'flat'}, + 'uplink_0': {'name': 'uplink_0', 'subnet_cidr': '10.20.0.0/16'}, + 'uplink_1': {'name': 'uplink_1'}, + 'downlink_0': {'name': 'downlink_0', 'segmentation_id': '1001'}, } networks = task.get_networks_from_nodes(nodes) diff --git a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py index 3b7e07376..92ae8aa88 100644 --- a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py +++ b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py @@ -25,13 +25,32 @@ from yardstick.benchmark.scenarios.availability.monitor import basemonitor class MonitorMgrTestCase(unittest.TestCase): def setUp(self): - config = { - 'monitor_type': 'openstack-api', - 'key': 'service-status' - } - - self.monitor_configs = [] - self.monitor_configs.append(config) + self.monitor_configs = [ + { + "monitor_type": "openstack-cmd", + "command_name": "openstack router list", + "monitor_time": 10, + "monitor_number": 3, + "sla": { + "max_outage_time": 5 + } + }, + { + "monitor_type": "process", + "process_name": "neutron-server", + "host": "node1", + "monitor_time": 20, + "monitor_number": 3, + "sla": { + "max_recover_time": 20 + } + } + ] + self.MonitorMgr = basemonitor.MonitorMgr([]) + self.MonitorMgr.init_monitors(self.monitor_configs, None) + self.monitor_list = self.MonitorMgr._monitor_list + for mo in self.monitor_list: + mo._result = {"outage_time": 10} def test__MonitorMgr_setup_successful(self, mock_monitor): instance = basemonitor.MonitorMgr({"nova-api": 10}) @@ -44,7 +63,13 @@ class MonitorMgrTestCase(unittest.TestCase): def test_MonitorMgr_getitem(self, mock_monitor): monitorMgr = basemonitor.MonitorMgr({"nova-api": 10}) monitorMgr.init_monitors(self.monitor_configs, None) - monitorIns = monitorMgr['service-status'] + + def test_store_result(self, mock_monitor): + expect = {'process_neutron-server_outage_time': 10, + 'openstack-router-list_outage_time': 10} + result = {} + self.MonitorMgr.store_result(result) + self.assertDictEqual(result, expect) class BaseMonitorTestCase(unittest.TestCase): @@ -94,3 +119,7 @@ class BaseMonitorTestCase(unittest.TestCase): except Exception: pass self.assertIsNone(cls) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml b/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml index cfa166a74..2123e4705 100644 --- a/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml +++ b/tests/unit/benchmark/scenarios/networking/ipv4_throughput_vpe.yaml @@ -49,13 +49,13 @@ private: ipv4: outer_l2: framesize: - 64B: "{{ get(imix, 'imix.private.imix_small', '0') }}" - 128B: "{{ get(imix, 'imix.private.imix_128B', '0') }}" - 256B: "{{ get(imix, 'imix.private.imix_256B', '0') }}" - 373b: "{{ get(imix, 'imix.private.imix_373B', '0') }}" - 570B: "{{get(imix, 'imix.private.imix_570B', '0') }}" - 1400B: "{{get(imix, 'imix.private.imix_1400B', '0') }}" - 1518B: "{{get(imix, 'imix.private.imix_1500B', '0') }}" + 64B: "{{ get(imix, 'imix.uplink.imix_small', '0') }}" + 128B: "{{ get(imix, 'imix.uplink.imix_128B', '0') }}" + 256B: "{{ get(imix, 'imix.uplink.imix_256B', '0') }}" + 373b: "{{ get(imix, 'imix.uplink.imix_373B', '0') }}" + 570B: "{{get(imix, 'imix.uplink.imix_570B', '0') }}" + 1400B: "{{get(imix, 'imix.uplink.imix_1400B', '0') }}" + 1518B: "{{get(imix, 'imix.uplink.imix_1500B', '0') }}" QinQ: S-VLAN: @@ -81,13 +81,13 @@ public: ipv4: outer_l2: framesize: - 64B: "{{ get(imix, 'imix.private.imix_small', '0') }}" - 128B: "{{ get(imix, 'imix.private.imix_128B', '0') }}" - 256B: "{{ get(imix, 'imix.private.imix_256B', '0') }}" - 373b: "{{ get(imix, 'imix.private.imix_373B', '0') }}" - 570B: "{{get(imix, 'imix.private.imix_570B', '0') }}" - 1400B: "{{get(imix, 'imix.private.imix_1400B', '0') }}" - 1518B: "{{get(imix, 'imix.private.imix_1500B', '0') }}" + 64B: "{{ get(imix, 'imix.uplink.imix_small', '0') }}" + 128B: "{{ get(imix, 'imix.uplink.imix_128B', '0') }}" + 256B: "{{ get(imix, 'imix.uplink.imix_256B', '0') }}" + 373b: "{{ get(imix, 'imix.uplink.imix_373B', '0') }}" + 570B: "{{get(imix, 'imix.uplink.imix_570B', '0') }}" + 1400B: "{{get(imix, 'imix.uplink.imix_1400B', '0') }}" + 1518B: "{{get(imix, 'imix.uplink.imix_1500B', '0') }}" outer_l3v4: proto: "tcp" diff --git a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py index 58244b8f5..fa9b8549d 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py +++ b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -24,6 +24,8 @@ import errno import unittest import mock +from copy import deepcopy + from tests.unit import STL_MOCKS from yardstick.benchmark.scenarios.networking.vnf_generic import \ SshManager, NetworkServiceTestCase, IncorrectConfig, \ @@ -240,11 +242,11 @@ class TestNetworkServiceTestCase(unittest.TestCase): 'vnf__1': self.vnf__1, }, 'networks': { - 'private': { - 'vld_id': 'private', + GenericVNF.UPLINK: { + 'vld_id': GenericVNF.UPLINK, }, - 'public': { - 'vld_id': 'public', + GenericVNF.DOWNLINK: { + 'vld_id': GenericVNF.DOWNLINK, }, }, } @@ -263,7 +265,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): } ], 'type': 'ELAN', - 'id': 'private', + 'id': GenericVNF.UPLINK, 'name': 'tg__1 to vnf__1 link 1' } @@ -281,7 +283,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): } ], 'type': 'ELAN', - 'id': 'public', + 'id': GenericVNF.DOWNLINK, 'name': 'vnf__1 to tg__1 link 2' } @@ -365,6 +367,24 @@ class TestNetworkServiceTestCase(unittest.TestCase): result = '152.16.100.2-152.16.100.254' self.assertEqual(result, self.s._get_ip_flow_range({"tg__1": 'xe0'})) + @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.ipaddress') + def test__get_ip_flow_range_no_node_data(self, mock_ipaddress): + scenario_cfg = deepcopy(self.scenario_cfg) + scenario_cfg["traffic_options"]["flow"] = \ + self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml") + + mock_ipaddress.ip_network.return_value = ipaddr = mock.Mock() + ipaddr.hosts.return_value = [] + + expected = '0.0.0.0' + result = self.s._get_ip_flow_range({"tg__2": 'xe0'}) + self.assertEqual(result, expected) + + def test__get_ip_flow_range_no_nodes(self): + expected = '0.0.0.0' + result = self.s._get_ip_flow_range({}) + self.assertEqual(result, expected) + def test___get_traffic_flow(self): self.scenario_cfg["traffic_options"]["flow"] = \ self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml") @@ -653,12 +673,6 @@ class TestNetworkServiceTestCase(unittest.TestCase): res = NetworkServiceTestCase.parse_netdev_info(output) assert res == self.SAMPLE_VM_NETDEVS - def test_sort_dpdk_port_num(self): - netdevs = self.SAMPLE_NETDEVS.copy() - NetworkServiceTestCase._sort_dpdk_port_num(netdevs) - assert netdevs['lan']['dpdk_port_num'] == 0 - assert netdevs['enp11s0']['dpdk_port_num'] == 1 - def test_probe_missing_values(self): netdevs = self.SAMPLE_NETDEVS.copy() network = {'local_mac': '0a:de:ad:be:ef:f5'} diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py index de5bae2f3..5759f0a90 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py +++ b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py @@ -118,7 +118,8 @@ class VsperfDPDKTestCase(unittest.TestCase): result = p._is_dpdk_setup() self.assertEqual(result, True) - def test_vsperf_dpdk_dpdk_setup_first(self, mock_ssh, mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') + def test_vsperf_dpdk_dpdk_setup_first(self, mock_time, mock_ssh, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks @@ -135,42 +136,43 @@ class VsperfDPDKTestCase(unittest.TestCase): self.assertEqual(p._is_dpdk_setup(), False) self.assertEqual(p.dpdk_setup_done, True) - def test_vsperf_dpdk_dpdk_setup_next(self, mock_ssh, mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') + def test_vsperf_dpdk_dpdk_setup_next(self, mock_time, mock_ssh, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() self.assertIsNotNone(p.client) self.assertEqual(p.setup_done, True) - # dpdk_setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') - p.dpdk_setup() self.assertEqual(p._is_dpdk_setup(), True) self.assertEqual(p.dpdk_setup_done, True) - def test_vsperf_dpdk_dpdk_setup_fail(self, mock_ssh, mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') + def test_vsperf_dpdk_dpdk_setup_fail(self, mock_time, mock_ssh, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) - - # dpdk_setup() specific mocks mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + self.assertEqual(p.setup_done, True) self.assertRaises(RuntimeError, p.dpdk_setup) - def test_vsperf_dpdk_run_ok(self, mock_ssh, mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') + def test_vsperf_dpdk_run_ok(self, mock_time, mock_ssh, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() @@ -179,7 +181,6 @@ class VsperfDPDKTestCase(unittest.TestCase): # run() specific mocks mock_subprocess.call().execute.return_value = None - mock_subprocess.call().execute.return_value = None mock_ssh.SSH.from_node().execute.return_value = ( 0, 'throughput_rx_fps\r\n14797660.000\r\n', '') @@ -193,6 +194,7 @@ class VsperfDPDKTestCase(unittest.TestCase): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() @@ -211,6 +213,7 @@ class VsperfDPDKTestCase(unittest.TestCase): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() diff --git a/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml b/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml index 0de4b6e79..1ac6c1f89 100644 --- a/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml +++ b/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml @@ -27,7 +27,7 @@ nsd:nsd-catalog: VNF model: ../../vnf_descriptors/vpe_vnf.yaml #tg_l3fwd.yaml #tg_trex_tpl.yaml #TREX vld: - - id: private + - id: uplink name: tg__1 to vnf__1 link 1 type: ELAN vnfd-connection-point-ref: @@ -38,7 +38,7 @@ nsd:nsd-catalog: vnfd-connection-point-ref: xe0 vnfd-id-ref: vnf__1 #VNF - - id: public + - id: downlink name: vnf__1 to tg__1 link 2 type: ELAN vnfd-connection-point-ref: diff --git a/tests/unit/network_services/helpers/acl_vnf_topology_ixia.yaml b/tests/unit/network_services/helpers/acl_vnf_topology_ixia.yaml index 606d557e9..f60834fbd 100644 --- a/tests/unit/network_services/helpers/acl_vnf_topology_ixia.yaml +++ b/tests/unit/network_services/helpers/acl_vnf_topology_ixia.yaml @@ -27,7 +27,7 @@ nsd:nsd-catalog: VNF model: ../../vnf_descriptors/acl_vnf.yaml vld: - - id: private_1 + - id: uplink_1 name: tg__1 to vnf__1 link 1 type: ELAN vnfd-connection-point-ref: @@ -38,7 +38,7 @@ nsd:nsd-catalog: vnfd-connection-point-ref: xe0 vnfd-id-ref: vnf__1 #VNF - - id: public_1 + - id: downlink_1 name: vnf__1 to tg__1 link 2 type: ELAN vnfd-connection-point-ref: 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) diff --git a/tests/unit/network_services/helpers/test_samplevnf_helper.py b/tests/unit/network_services/helpers/test_samplevnf_helper.py index 608f31747..0ac363f28 100644 --- a/tests/unit/network_services/helpers/test_samplevnf_helper.py +++ b/tests/unit/network_services/helpers/test_samplevnf_helper.py @@ -18,91 +18,152 @@ from __future__ import absolute_import from __future__ import division -import os import unittest import mock -from yardstick.network_services.helpers.samplevnf_helper import MultiPortConfig +from yardstick.network_services.helpers.samplevnf_helper import MultiPortConfig, PortPairs +from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper + + +class TestPortPairs(unittest.TestCase): + def test_port_pairs_list(self): + vnfd = TestMultiPortConfig.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + interfaces = vnfd['vdu'][0]['external-interface'] + port_pairs = PortPairs(interfaces) + self.assertEqual(port_pairs.port_pair_list, [("xe0", "xe1")]) + + def test_valid_networks(self): + vnfd = TestMultiPortConfig.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + interfaces = vnfd['vdu'][0]['external-interface'] + port_pairs = PortPairs(interfaces) + self.assertEqual(port_pairs.valid_networks, [("uplink_0", "downlink_0")]) + + def test_all_ports(self): + vnfd = TestMultiPortConfig.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + interfaces = vnfd['vdu'][0]['external-interface'] + port_pairs = PortPairs(interfaces) + self.assertEqual(set(port_pairs.all_ports), {"xe0", "xe1"}) + + def test_uplink_ports(self): + vnfd = TestMultiPortConfig.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + interfaces = vnfd['vdu'][0]['external-interface'] + port_pairs = PortPairs(interfaces) + self.assertEqual(port_pairs.uplink_ports, ["xe0"]) + + def test_downlink_ports(self): + vnfd = TestMultiPortConfig.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + interfaces = vnfd['vdu'][0]['external-interface'] + port_pairs = PortPairs(interfaces) + self.assertEqual(port_pairs.downlink_ports, ["xe1"]) class TestMultiPortConfig(unittest.TestCase): - VNFD = {'vnfd:vnfd-catalog': - {'vnfd': - [{'short-name': 'VpeVnf', - 'vdu': - [{'routing_table': - [{'network': '152.16.100.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.100.20', - 'if': 'xe0'}, - {'network': '152.16.40.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.40.20', - 'if': 'xe1'}], - 'description': 'VPE approximation using DPDK', - 'name': 'vpevnf-baremetal', - 'nd_route_tbl': - [{'network': '0064:ff9b:0:0:0:0:9810:6414', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:6414', - 'if': 'xe0'}, - {'network': '0064:ff9b:0:0:0:0:9810:2814', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:2814', - 'if': 'xe1'}], - 'id': 'vpevnf-baremetal', - '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': '0', - 'bandwidth': '10 Gbps', - 'driver': "i40e", - 'dst_ip': '152.16.100.20', - 'ifname': 'xe0', - 'local_iface_name': 'eth0', - 'local_mac': '00:00:00:00:00:02', - 'vld_id': 'private_1', - }, - 'vnfd-connection-point-ref': 'xe0', - 'name': 'xe0'}, - {'virtual-interface': - { - 'dst_mac': '00:00:00:00:00:03', - 'vpci': '0000:05:00.1', - 'local_ip': '152.16.40.19', - 'type': 'PCI-PASSTHROUGH', - 'driver': "i40e", - 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', - 'bandwidth': '10 Gbps', - 'dst_ip': '152.16.40.20', - 'ifname': 'xe1', - 'local_iface_name': 'eth1', - 'local_mac': '00:00:00:00:00:01', - 'vld_id': 'public_1', - }, - 'vnfd-connection-point-ref': 'xe1', - 'name': 'xe1'} - ]}], - 'description': 'Vpe approximation using DPDK', - 'mgmt-interface': - {'vdu-id': 'vpevnf-baremetal', - 'host': '1.2.1.1', - 'password': 'r00t', - 'user': 'root', - 'ip': '1.2.1.1'}, - 'benchmark': - {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']}, - 'connection-point': [{'type': 'VPORT', 'name': 'xe0'}, - {'type': 'VPORT', 'name': 'xe1'}], - 'id': 'AclApproxVnf', 'name': 'VPEVnfSsh'}]}} + + VNFD_0 = {'short-name': 'VpeVnf', + 'vdu': + [{'routing_table': + [{'network': '152.16.100.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'if': 'xe0'}, + {'network': '152.16.40.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'if': 'xe1'}], + 'description': 'VPE approximation using DPDK', + 'name': 'vpevnf-baremetal', + 'nd_route_tbl': + [{'network': '0064:ff9b:0:0:0:0:9810:6414', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0'}, + {'network': '0064:ff9b:0:0:0:0:9810:2814', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1'}], + 'id': 'vpevnf-baremetal', + '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': 0, + 'bandwidth': '10 Gbps', + 'driver': "i40e", + 'dst_ip': '152.16.100.20', + 'ifname': 'xe0', + 'local_iface_name': 'eth0', + 'local_mac': '00:00:00:00:00:02', + 'vld_id': 'uplink_0', + }, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0'}, + {'virtual-interface': + { + 'dst_mac': '00:00:00:00:00:03', + 'vpci': '0000:05:00.1', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'driver': "i40e", + 'netmask': '255.255.255.0', + 'dpdk_port_num': 1, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'ifname': 'xe1', + 'local_iface_name': 'eth1', + 'local_mac': '00:00:00:00:00:01', + 'vld_id': 'downlink_0', + }, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1'} + ]}], + 'description': 'Vpe approximation using DPDK', + 'mgmt-interface': + {'vdu-id': 'vpevnf-baremetal', + 'host': '1.2.1.1', + 'password': 'r00t', + 'user': 'root', + 'ip': '1.2.1.1'}, + 'benchmark': + {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']}, + 'connection-point': [{'type': 'VPORT', 'name': 'xe0'}, + {'type': 'VPORT', 'name': 'xe1'}], + 'id': 'AclApproxVnf', 'name': 'VPEVnfSsh'} + + VNFD = { + 'vnfd:vnfd-catalog': { + 'vnfd': [ + VNFD_0, + ] + } + } + + def test_validate_ip_and_prefixlen(self): + ip_addr, prefix_len = MultiPortConfig.validate_ip_and_prefixlen('10.20.30.40', '16') + self.assertEqual(ip_addr, '10.20.30.40') + self.assertEqual(prefix_len, 16) + + ip_addr, prefix_len = MultiPortConfig.validate_ip_and_prefixlen('::1', '40') + self.assertEqual(ip_addr, '0000:0000:0000:0000:0000:0000:0000:0001') + self.assertEqual(prefix_len, 40) + + def test_validate_ip_and_prefixlen_negative(self): + with self.assertRaises(AttributeError): + MultiPortConfig.validate_ip_and_prefixlen('', '') + + with self.assertRaises(AttributeError): + MultiPortConfig.validate_ip_and_prefixlen('10.20.30.400', '16') + + with self.assertRaises(AttributeError): + MultiPortConfig.validate_ip_and_prefixlen('10.20.30.40', '33') + + with self.assertRaises(AttributeError): + MultiPortConfig.validate_ip_and_prefixlen('::1', '129') @mock.patch('yardstick.network_services.helpers.samplevnf_helper.open') @mock.patch('yardstick.network_services.helpers.samplevnf_helper.os') @@ -111,11 +172,12 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) self.assertEqual(0, opnfv_vnf.swq) mock_os.path = mock.MagicMock() mock_os.path.isfile = mock.Mock(return_value=False) - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) self.assertEqual(0, opnfv_vnf.swq) @mock.patch('yardstick.network_services.helpers.samplevnf_helper.open') @@ -125,7 +187,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -139,7 +202,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = VnfdHelper(self.VNFD_0) + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -148,7 +212,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] self.assertIsNotNone(opnfv_vnf.generate_script(self.VNFD)) opnfv_vnf.lb_config = 'HW' self.assertIsNotNone(opnfv_vnf.generate_script(self.VNFD)) @@ -160,12 +224,13 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 opnfv_vnf.update_write_parser = mock.MagicMock() - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.vnf_type = 'ACL' opnfv_vnf.generate_link_config = mock.Mock() opnfv_vnf.generate_arp_config = mock.Mock() @@ -181,7 +246,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -190,7 +256,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.get_port_pairs = mock.Mock() opnfv_vnf.vnf_type = 'ACL' opnfv_vnf.get_ports_gateway = mock.Mock(return_value=u'1.1.1.1') @@ -212,7 +278,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -221,7 +288,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.get_port_pairs = mock.Mock() opnfv_vnf.vnf_type = 'VFW' opnfv_vnf.get_ports_gateway = mock.Mock(return_value=u'1.1.1.1') @@ -239,7 +306,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -248,7 +316,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.get_port_pairs = mock.Mock() opnfv_vnf.vnf_type = 'VFW' opnfv_vnf.get_ports_gateway = mock.Mock(return_value=u'1.1.1.1') @@ -268,7 +336,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -277,7 +346,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.get_port_pairs = mock.Mock() opnfv_vnf.vnf_type = 'VFW' opnfv_vnf.get_ports_gateway = mock.Mock(return_value=u'1.1.1.1') @@ -297,7 +366,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -306,7 +376,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.get_port_pairs = mock.Mock() opnfv_vnf.vnf_type = 'VFW' opnfv_vnf.txrx_pipeline = '' @@ -323,7 +393,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -332,7 +403,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.get_port_pairs = mock.Mock() opnfv_vnf.vnf_type = 'VFW' opnfv_vnf.txrx_pipeline = '' @@ -349,7 +420,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -358,7 +430,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.get_port_pairs = mock.Mock() opnfv_vnf.vnf_type = 'VFW' opnfv_vnf.txrx_pipeline = '' @@ -375,7 +447,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -384,7 +457,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.get_port_pairs = mock.Mock() opnfv_vnf.vnf_type = 'VFW' opnfv_vnf.txrx_pipeline = '' @@ -401,7 +474,9 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -410,7 +485,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.get_port_pairs = mock.Mock() opnfv_vnf.vnf_type = 'VFW' opnfv_vnf.txrx_pipeline = '' @@ -418,7 +493,11 @@ class TestMultiPortConfig(unittest.TestCase): opnfv_vnf.get_ports_gateway6 = mock.Mock() opnfv_vnf.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] opnfv_vnf.interfaces = opnfv_vnf.vnfd['vdu'][0]['external-interface'] - self.assertIsNotNone(opnfv_vnf.generate_link_config()) + opnfv_vnf.all_ports = ['32', '1', '987'] + opnfv_vnf.validate_ip_and_prefixlen = mock.Mock(return_value=('10.20.30.40', 16)) + + result = opnfv_vnf.generate_link_config() + self.assertEqual(len(result.splitlines()), 9) @mock.patch('yardstick.network_services.helpers.samplevnf_helper.open') @mock.patch('yardstick.network_services.helpers.samplevnf_helper.os') @@ -427,7 +506,8 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.get_config_tpl_data = mock.MagicMock() opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 @@ -436,7 +516,7 @@ class TestMultiPortConfig(unittest.TestCase): mock.Mock(return_value={'link_config': 0, 'arp_config': '', 'arp_config6': '', 'actions': '', 'rules': ''}) - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.get_ports_gateway6 = mock.Mock() @@ -459,10 +539,11 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -482,10 +563,11 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -505,10 +587,11 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -533,10 +616,11 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -556,10 +640,11 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -581,10 +666,11 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -614,10 +700,11 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -649,10 +736,10 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = VnfdHelper(self.VNFD_0) + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -666,10 +753,12 @@ class TestMultiPortConfig(unittest.TestCase): opnfv_vnf.worker_config = '1t' opnfv_vnf.start_core = 0 opnfv_vnf.lb_count = 1 + opnfv_vnf._port_pairs = PortPairs(vnfd_mock.interfaces) + opnfv_vnf.port_pair_list = opnfv_vnf._port_pairs.port_pair_list result = opnfv_vnf.generate_lb_to_port_pair_mapping() self.assertEqual(None, result) result = opnfv_vnf.set_priv_to_pub_mapping() - self.assertEqual('(0, 1)', result) + self.assertEqual('(0,1)', result) @mock.patch('yardstick.network_services.helpers.samplevnf_helper.open') @mock.patch('yardstick.network_services.helpers.samplevnf_helper.os') @@ -680,11 +769,12 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = VnfdHelper(self.VNFD_0) + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] - opnfv_vnf.port_pairs = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] + opnfv_vnf.port_pairs = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -702,6 +792,43 @@ class TestMultiPortConfig(unittest.TestCase): self.assertEqual(None, result) @mock.patch('yardstick.network_services.helpers.samplevnf_helper.open') + @mock.patch('yardstick.network_services.helpers.samplevnf_helper.ConfigParser') + def test_generate_arp_route_tbl(self, *_): + topology_file = mock.Mock() + config_tpl = mock.Mock() + tmp_file = mock.Mock() + vnfd_mock = mock.MagicMock() + vnfd_mock.port_num.side_effect = ['32', '1', '987'] + vnfd_mock.find_interface.side_effect = [ + { + 'virtual-interface': { + 'dst_ip': '10.20.30.40', + 'netmask': '20', + }, + }, + { + 'virtual-interface': { + 'dst_ip': '10.200.30.40', + 'netmask': '24', + }, + }, + { + 'virtual-interface': { + 'dst_ip': '10.20.3.40', + 'netmask': '8', + }, + }, + ] + + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) + opnfv_vnf.all_ports = [3, 2, 5] + + expected = '(0a141000,fffff000,32,0a141e28) (0ac81e00,ffffff00,1,0ac81e28) ' \ + '(0a000000,ff000000,987,0a140328)' + result = opnfv_vnf.generate_arp_route_tbl() + self.assertEqual(result, expected) + + @mock.patch('yardstick.network_services.helpers.samplevnf_helper.open') @mock.patch('yardstick.network_services.helpers.samplevnf_helper.os') @mock.patch('yardstick.network_services.helpers.samplevnf_helper.ConfigParser') @mock.patch('yardstick.network_services.helpers.samplevnf_helper.OrderedDict') @@ -710,11 +837,12 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] - opnfv_vnf.port_pairs = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] + opnfv_vnf.port_pairs = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -754,11 +882,12 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] - opnfv_vnf.port_pairs = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] + opnfv_vnf.port_pairs = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -795,11 +924,12 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] - opnfv_vnf.port_pairs = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] + opnfv_vnf.port_pairs = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -848,11 +978,12 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] - opnfv_vnf.port_pairs = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] + opnfv_vnf.port_pairs = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -884,11 +1015,12 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] - opnfv_vnf.port_pairs = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] + opnfv_vnf.port_pairs = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -932,11 +1064,12 @@ class TestMultiPortConfig(unittest.TestCase): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = VnfdHelper(self.VNFD_0) + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] - opnfv_vnf.port_pairs = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] + opnfv_vnf.port_pairs = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() @@ -982,7 +1115,7 @@ class TestMultiPortConfig(unittest.TestCase): opnfv_vnf.loadb_tpl = mock.MagicMock() opnfv_vnf.vnf_type = 'CGNAPT' opnfv_vnf.update_timer = mock.Mock() - opnfv_vnf.port_pair_list = [[[0], [1], [2]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1"), ("xe0", "xe2")] opnfv_vnf.lb_to_port_pair_mapping = [0, 1] opnfv_vnf.generate_arpicmp_data = mock.Mock() result = opnfv_vnf.generate_config_data() @@ -992,66 +1125,17 @@ class TestMultiPortConfig(unittest.TestCase): @mock.patch('yardstick.network_services.helpers.samplevnf_helper.os') @mock.patch('yardstick.network_services.helpers.samplevnf_helper.ConfigParser') @mock.patch('yardstick.network_services.helpers.samplevnf_helper.OrderedDict') - def test_get_port_pairs(self, mock_open, mock_os, ConfigParser, - OrderedDict): - topology_file = mock.Mock() - config_tpl = mock.Mock() - tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) - opnfv_vnf.socket = 0 - opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] - opnfv_vnf.port_pairs = [[[0], [1]]] - opnfv_vnf.txrx_pipeline = '' - opnfv_vnf.rules = '' - opnfv_vnf.write_parser = mock.MagicMock() - opnfv_vnf.read_parser = mock.MagicMock() - opnfv_vnf.read_parser.sections = mock.Mock(return_value=['MASTER']) - opnfv_vnf.read_parser.has_option = mock.Mock(return_value=[]) - opnfv_vnf.write_parser.set = mock.Mock() - opnfv_vnf.write_parser.add_section = mock.Mock() - opnfv_vnf.read_parser.items = mock.MagicMock() - opnfv_vnf.pipeline_counter = 0 - opnfv_vnf.worker_config = '1t' - opnfv_vnf.start_core = 0 - opnfv_vnf.lb_count = 1 - opnfv_vnf.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - opnfv_vnf.interfaces = opnfv_vnf.vnfd['vdu'][0]['external-interface'] - opnfv_vnf.lb_to_port_pair_mapping = [0, 1] - opnfv_vnf.lb_index = 1 - opnfv_vnf.ports_len = 1 - opnfv_vnf.pktq_out = ['1', '2'] - opnfv_vnf.prv_que_handler = 0 - opnfv_vnf.init_write_parser_template = mock.Mock() - opnfv_vnf.arpicmp_tpl = mock.MagicMock() - opnfv_vnf.txrx_tpl = mock.MagicMock() - opnfv_vnf.loadb_tpl = mock.MagicMock() - opnfv_vnf.vnf_tpl = {'public_ip_port_range': '98164810 (1,65535)', - 'vnf_set': '(2,4,5)'} - opnfv_vnf.generate_vnf_data = mock.Mock(return_value={}) - opnfv_vnf.update_write_parser = mock.Mock() - - curr_path = os.path.dirname(os.path.abspath(__file__)) - opnfv_vnf.topology_file = \ - os.path.join(curr_path, 'acl_vnf_topology_ixia.yaml') - opnfv_vnf.lb_count = 10 - result = opnfv_vnf.get_port_pairs(opnfv_vnf.interfaces) - self.assertEqual(result[0], [('xe0', 'xe1')]) - - @mock.patch('yardstick.network_services.helpers.samplevnf_helper.open') - @mock.patch('yardstick.network_services.helpers.samplevnf_helper.os') - @mock.patch('yardstick.network_services.helpers.samplevnf_helper.ConfigParser') - @mock.patch('yardstick.network_services.helpers.samplevnf_helper.OrderedDict') def test_init_eal(self, mock_open, mock_os, ConfigParser, OrderedDict): topology_file = mock.Mock() config_tpl = mock.Mock() tmp_file = mock.Mock() - opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file) + vnfd_mock = mock.MagicMock() + opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock) opnfv_vnf.socket = 0 opnfv_vnf.start_core = 0 - opnfv_vnf.port_pair_list = [[[0], [1]]] - opnfv_vnf.port_pairs = [[[0], [1]]] + opnfv_vnf.port_pair_list = [("xe0", "xe1")] + opnfv_vnf.port_pairs = [("xe0", "xe1")] opnfv_vnf.txrx_pipeline = '' opnfv_vnf.rules = '' opnfv_vnf.write_parser = mock.MagicMock() diff --git a/tests/unit/network_services/libs/ixia_libs/test_IxNet.py b/tests/unit/network_services/libs/ixia_libs/test_IxNet.py index 7fe83406a..0c82d74a8 100644 --- a/tests/unit/network_services/libs/ixia_libs/test_IxNet.py +++ b/tests/unit/network_services/libs/ixia_libs/test_IxNet.py @@ -26,6 +26,9 @@ from yardstick.network_services.libs.ixia_libs.IxNet.IxNet import IP_VERSION_4 from yardstick.network_services.libs.ixia_libs.IxNet.IxNet import IP_VERSION_6 +UPLINK = "uplink" +DOWNLINK = "downlink" + class TestIxNextgen(unittest.TestCase): def test___init__(self): @@ -97,7 +100,7 @@ class TestIxNextgen(unittest.TestCase): def test_ix_update_frame(self): static_traffic_params = { - "private": { + UPLINK: { "id": 1, "bidir": "False", "duration": 60, @@ -139,7 +142,7 @@ class TestIxNextgen(unittest.TestCase): }, "traffic_type": "continuous" }, - "public": { + DOWNLINK: { "id": 2, "bidir": "False", "duration": 60, @@ -268,7 +271,7 @@ class TestIxNextgen(unittest.TestCase): def test_add_ip_header_v4(self): static_traffic_params = { - "private_1": { + "uplink_0": { "id": 1, "bidir": "False", "duration": 60, @@ -308,7 +311,7 @@ class TestIxNextgen(unittest.TestCase): }, "traffic_type": "continuous" }, - "public_1": { + "downlink_0": { "id": 2, "bidir": "False", "duration": 60, @@ -366,7 +369,7 @@ class TestIxNextgen(unittest.TestCase): def test_add_ip_header_v4_nothing_to_do(self): static_traffic_params = { - "private_1": { + "uplink_0": { "id": 1, "bidir": "False", "duration": 60, @@ -406,7 +409,7 @@ class TestIxNextgen(unittest.TestCase): }, "traffic_type": "continuous" }, - "public_1": { + "downlink_0": { "id": 2, "bidir": "False", "duration": 60, @@ -464,7 +467,7 @@ class TestIxNextgen(unittest.TestCase): def test_add_ip_header_v6(self): static_traffic_profile = { - "private_1": { + "uplink_0": { "id": 1, "bidir": "False", "duration": 60, @@ -497,7 +500,7 @@ class TestIxNextgen(unittest.TestCase): }, "traffic_type": "continuous" }, - "public_1": { + "downlink_0": { "id": 2, "bidir": "False", "duration": 60, @@ -547,7 +550,7 @@ class TestIxNextgen(unittest.TestCase): def test_add_ip_header_v6_nothing_to_do(self): static_traffic_params = { - "private_1": { + "uplink_0": { "id": 1, "bidir": "False", "duration": 60, @@ -579,7 +582,7 @@ class TestIxNextgen(unittest.TestCase): }, "traffic_type": "continuous" }, - "public_1": { + "downlink_0": { "id": 2, "bidir": "False", "duration": 60, @@ -684,7 +687,7 @@ class TestIxNextgen(unittest.TestCase): def test_ix_update_ether(self): static_traffic_params = { - "private_1": { + "uplink_0": { "id": 1, "bidir": "False", "duration": 60, @@ -723,7 +726,7 @@ class TestIxNextgen(unittest.TestCase): }, "traffic_type": "continuous" }, - "public_1": { + "downlink_0": { "id": 2, "bidir": "False", "duration": 60, @@ -787,7 +790,7 @@ class TestIxNextgen(unittest.TestCase): def test_ix_update_ether_nothing_to_do(self): static_traffic_params = { - "private_1": { + "uplink_0": { "id": 1, "bidir": "False", "duration": 60, @@ -820,7 +823,7 @@ class TestIxNextgen(unittest.TestCase): }, "traffic_type": "continuous" }, - "public_1": { + "downlink_0": { "id": 2, "bidir": "False", "duration": 60, diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py index 21beba882..1c2c1f3e2 100644 --- a/tests/unit/network_services/nfvi/test_resource.py +++ b/tests/unit/network_services/nfvi/test_resource.py @@ -54,7 +54,7 @@ class TestResourceProfile(unittest.TestCase): 'local_ip': '172.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'dst_ip': '172.16.100.20', 'local_mac': '3c:fd:fe:a1:2b:80'}, @@ -66,7 +66,7 @@ class TestResourceProfile(unittest.TestCase): 'local_ip': '172.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '172.16.40.20', 'local_mac': '3c:fd:fe:a1:2b:81'}, diff --git a/tests/unit/network_services/traffic_profile/test_base.py b/tests/unit/network_services/traffic_profile/test_base.py index 72b097b52..290610361 100644 --- a/tests/unit/network_services/traffic_profile/test_base.py +++ b/tests/unit/network_services/traffic_profile/test_base.py @@ -48,7 +48,7 @@ class TestTrafficProfile(unittest.TestCase): def test_execute(self): traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) - self.assertRaises(NotImplementedError, traffic_profile.execute, {}) + self.assertRaises(NotImplementedError, traffic_profile.execute_traffic, {}) def test_get(self): traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE) diff --git a/tests/unit/network_services/traffic_profile/test_fixed.py b/tests/unit/network_services/traffic_profile/test_fixed.py index 84843178e..eb182a2fb 100644 --- a/tests/unit/network_services/traffic_profile/test_fixed.py +++ b/tests/unit/network_services/traffic_profile/test_fixed.py @@ -74,7 +74,7 @@ class TestFixedProfile(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.100.20', 'local_mac': '00:00:00:00:00:01'}, @@ -86,7 +86,7 @@ class TestFixedProfile(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_mac': '00:00:00:00:00:02'}, diff --git a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py index cd0aacba6..6fffb9ede 100644 --- a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py +++ b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py @@ -20,6 +20,8 @@ from __future__ import division import unittest import mock +from copy import deepcopy + from tests.unit import STL_MOCKS STLClient = mock.MagicMock() @@ -35,6 +37,7 @@ if stl_patch: class TestIXIARFC2544Profile(unittest.TestCase): + TRAFFIC_PROFILE = { "schema": "isb:traffic_profile:0.1", "name": "fixed", @@ -43,13 +46,15 @@ class TestIXIARFC2544Profile(unittest.TestCase): "traffic_type": "FixedTraffic", "frame_rate": 100, # pps "flow_number": 10, - "frame_size": 64}} + "frame_size": 64, + }, + } PROFILE = {'description': 'Traffic profile to run RFC2544 latency', 'name': 'rfc2544', 'traffic_profile': {'traffic_type': 'IXIARFC2544Profile', 'frame_rate': 100}, - 'public': {'ipv4': + IXIARFC2544Profile.DOWNLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -61,7 +66,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): 'dscp': 0, 'ttl': 32}, 'outer_l4': {'srcport': '2001', 'dsrport': '1234'}}}, - 'private': {'ipv4': + IXIARFC2544Profile.UPLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -78,12 +83,12 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_ixia_traffic_profile_error(self): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [-1] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) STATIC_TRAFFIC = { - "private": { + IXIARFC2544Profile.UPLINK: { "id": 1, "bidir": "False", "duration": 60, @@ -122,7 +127,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): }, "traffic_type": "continuous" }, - "public": { + IXIARFC2544Profile.DOWNLINK: { "id": 2, "bidir": "False", "duration": 60, @@ -178,17 +183,16 @@ class TestIXIARFC2544Profile(unittest.TestCase): self.PROFILE, mac, xfile="tmp", static_traffic=STATIC_TRAFFIC) - @mock.patch("yardstick.network_services.traffic_profile.ixia_rfc2544.open") def test_get_ixia_traffic_profile(self, mock_open): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [-1] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) STATIC_TRAFFIC = { - "private": { + IXIARFC2544Profile.UPLINK: { "id": 1, "bidir": "False", "duration": 60, @@ -230,7 +234,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): }, "traffic_type": "continuous" }, - "public": { + IXIARFC2544Profile.DOWNLINK: { "id": 2, "bidir": "False", "duration": 60, @@ -293,12 +297,12 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_ixia_traffic_profile_v6(self, mock_open): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [-1] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) STATIC_TRAFFIC = { - "private": { + IXIARFC2544Profile.UPLINK: { "id": 1, "bidir": "False", "duration": 60, @@ -337,7 +341,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): }, "traffic_type": "continuous" }, - "public": { + IXIARFC2544Profile.DOWNLINK: { "id": 2, "bidir": "False", "duration": 60, @@ -394,7 +398,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): 'traffic_profile': {'traffic_type': 'IXIARFC2544Profile', 'frame_rate': 100}, - 'public': + IXIARFC2544Profile.DOWNLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', @@ -411,7 +415,7 @@ class TestIXIARFC2544Profile(unittest.TestCase): 'dscp': 0, 'ttl': 32}, 'outer_l4': {'srcport': '2001', 'dsrport': '1234'}}}, - 'private': {'ipv4': + IXIARFC2544Profile.UPLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -435,15 +439,23 @@ class TestIXIARFC2544Profile(unittest.TestCase): profile_data, mac, static_traffic=STATIC_TRAFFIC) self.assertIsNotNone(result) + def test__get_ixia_traffic_profile_default_args(self): + r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) + + expected = {} + result = r_f_c2544_profile._get_ixia_traffic_profile({}) + self.assertDictEqual(result, expected) + def test__ixia_traffic_generate(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) - traffic = {"public": {'iload': 10}, - "private": {'iload': 10}} + traffic = {IXIARFC2544Profile.DOWNLINK: {'iload': 10}, + IXIARFC2544Profile.UPLINK: {'iload': 10}} ixia_obj = mock.MagicMock() r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.rate = 100 @@ -453,15 +465,16 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_execute(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.first_run = True - r_f_c2544_profile.params = {"public": {'iload': 10}, - "private": {'iload': 10}} + r_f_c2544_profile.params = {IXIARFC2544Profile.DOWNLINK: {'iload': 10}, + IXIARFC2544Profile.UPLINK: {'iload': 10}} r_f_c2544_profile.get_streams = mock.Mock() r_f_c2544_profile.full_profile = {} @@ -469,14 +482,40 @@ class TestIXIARFC2544Profile(unittest.TestCase): r_f_c2544_profile.get_multiplier = mock.Mock() r_f_c2544_profile._ixia_traffic_generate = mock.Mock() ixia_obj = mock.MagicMock() - self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator, - ixia_obj)) + self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator, ixia_obj)) + + def test_update_traffic_profile(self): + traffic_generator = mock.Mock(autospec=TrexProfile) + traffic_generator.networks = { + "uplink_0": ["xe0"], # private, one value for intfs + "downlink_0": ["xe1", "xe2"], # public, two values for intfs + "downlink_1": ["xe3"], # not in TRAFFIC PROFILE + "tenant_0": ["xe4"], # not public or private + } + + ports_expected = [8, 3, 5] + traffic_generator.vnfd_helper.port_num.side_effect = ports_expected + traffic_generator.client.return_value = True + + traffic_profile = deepcopy(self.TRAFFIC_PROFILE) + traffic_profile.update({ + "uplink_0": ["xe0"], + "downlink_0": ["xe1", "xe2"], + }) + + r_f_c2544_profile = IXIARFC2544Profile(traffic_profile) + r_f_c2544_profile.full_profile = {} + r_f_c2544_profile.get_streams = mock.Mock() + + self.assertIsNone(r_f_c2544_profile.update_traffic_profile(traffic_generator)) + self.assertEqual(r_f_c2544_profile.ports, ports_expected) def test_get_drop_percentage(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) @@ -509,8 +548,8 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_drop_percentage_update(self): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [0] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) @@ -543,8 +582,8 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_get_drop_percentage_div_zero(self): traffic_generator = mock.Mock(autospec=TrexProfile) traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.uplink_ports = [0] + traffic_generator.downlink_ports = [1] traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) @@ -583,9 +622,10 @@ class TestIXIARFC2544Profile(unittest.TestCase): def test_start_ixia_latency(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = IXIARFC2544Profile(self.TRAFFIC_PROFILE) diff --git a/tests/unit/network_services/traffic_profile/test_prox_acl.py b/tests/unit/network_services/traffic_profile/test_prox_acl.py index be172f26b..a0c60186c 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_acl.py +++ b/tests/unit/network_services/traffic_profile/test_prox_acl.py @@ -29,19 +29,38 @@ if stl_patch: from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple -class TestProxRampProfile(unittest.TestCase): +class TestProxACLProfile(unittest.TestCase): def test_run_test_with_pkt_size(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, {} + + def get_mock_samples(*args, **kwargs): + if args[2] < 0: + raise RuntimeError(' '.join([str(args), str(runs)])) + return success_tuple + tp_config = { - 'traffic_profile': { + 'traffic_profile': { 'upper_bound': 100.0, + 'lower_bound': 0.0, + 'tolerated_loss': 50.0, + 'attempts': 20 }, } + 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_gen = mock.MagicMock() + traffic_gen.run_test = target + traffic_gen.resource_helper.run_test.side_effect = [ success_tuple, success_tuple, @@ -53,14 +72,15 @@ class TestProxRampProfile(unittest.TestCase): fail_tuple, ] - fill_values = [1, 2, 3, 4, RuntimeError] - profile = ProxACLProfile(tp_config) - profile.fill_samples = fill_samples = mock.MagicMock(side_effect=fill_values) - profile.queue = mock.MagicMock() + profile.init(mock.MagicMock()) - with self.assertRaises(RuntimeError): - profile.run_test_with_pkt_size(traffic_gen, 128, 30) + profile.prox_config["attempts"] = 20 + profile.queue = mock.MagicMock() + profile.tolerated_loss = 50.0 + profile.pkt_size = 128 + profile.duration = 30 + profile.test_value = 100.0 + profile.tolerated_loss = 100.0 - self.assertEqual(traffic_gen.resource_helper.run_test.call_count, 5) - self.assertEqual(fill_samples.call_count, 5) + profile.run_test_with_pkt_size(traffic_gen, profile.pkt_size, profile.duration) diff --git a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py index 0edce7a14..f56a7fba9 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py +++ b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py @@ -56,7 +56,7 @@ class TestProxBinSearchProfile(unittest.TestCase): profile = ProxBinSearchProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + 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) @@ -87,7 +87,7 @@ class TestProxBinSearchProfile(unittest.TestCase): profile = ProxBinSearchProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + 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/traffic_profile/test_prox_mpls.py b/tests/unit/network_services/traffic_profile/test_prox_mpls.py index 77bca9cc0..642fecc35 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_mpls.py +++ b/tests/unit/network_services/traffic_profile/test_prox_mpls.py @@ -56,7 +56,7 @@ class TestProxMplsTagUntagProfile(unittest.TestCase): profile = ProxMplsTagUntagProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + 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) @@ -87,7 +87,7 @@ class TestProxMplsTagUntagProfile(unittest.TestCase): profile = ProxMplsTagUntagProfile(tp_config) profile.init(mock.MagicMock()) - profile.execute(traffic_generator) + 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/traffic_profile/test_prox_profile.py b/tests/unit/network_services/traffic_profile/test_prox_profile.py index 14223da0f..9899d9909 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_profile.py +++ b/tests/unit/network_services/traffic_profile/test_prox_profile.py @@ -65,7 +65,7 @@ class TestProxProfile(unittest.TestCase): profile.init(234) self.assertEqual(profile.queue, 234) - def test_execute(self): + def test_execute_traffic(self): packet_sizes = [ 10, 100, @@ -83,9 +83,9 @@ class TestProxProfile(unittest.TestCase): self.assertFalse(profile.done) for _ in packet_sizes: with self.assertRaises(NotImplementedError): - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) - self.assertIsNone(profile.execute(traffic_generator)) + self.assertIsNone(profile.execute_traffic(traffic_generator)) def test_bounds_iterator(self): tp_config = { diff --git a/tests/unit/network_services/traffic_profile/test_rfc2544.py b/tests/unit/network_services/traffic_profile/test_rfc2544.py index aef0b93de..221233710 100644 --- a/tests/unit/network_services/traffic_profile/test_rfc2544.py +++ b/tests/unit/network_services/traffic_profile/test_rfc2544.py @@ -50,7 +50,7 @@ class TestRFC2544Profile(unittest.TestCase): 'name': 'rfc2544', 'traffic_profile': {'traffic_type': 'RFC2544Profile', 'frame_rate': 100}, - 'public_1': {'ipv4': + 'downlink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -62,7 +62,7 @@ class TestRFC2544Profile(unittest.TestCase): 'dscp': 0, 'ttl': 32, 'count': 1}, 'outer_l4': {'srcport': '2001', 'dsrport': '1234', 'count': 1}}}, - 'private_1': {'ipv4': + 'uplink_0': {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -82,27 +82,29 @@ class TestRFC2544Profile(unittest.TestCase): def test_execute(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE r_f_c2544_profile.first_run = True - self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator)) + self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator)) def test_get_drop_percentage(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE r_f_c2544_profile.register_generator(traffic_generator) - self.assertIsNone(r_f_c2544_profile.execute(traffic_generator)) + self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator)) samples = {} for ifname in range(1): @@ -140,15 +142,16 @@ class TestRFC2544Profile(unittest.TestCase): def test_get_drop_percentage_update(self): traffic_generator = mock.Mock(autospec=RFC2544Profile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE r_f_c2544_profile.register_generator(traffic_generator) - self.assertIsNone(r_f_c2544_profile.execute()) + self.assertIsNone(r_f_c2544_profile.execute_traffic()) samples = {} for ifname in range(1): @@ -187,14 +190,15 @@ class TestRFC2544Profile(unittest.TestCase): def test_get_drop_percentage_div_zero(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [0] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "uplink_0": ["xe0"], + "downlink_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) r_f_c2544_profile.params = self.PROFILE - self.assertEqual(None, r_f_c2544_profile.execute(traffic_generator)) + self.assertEqual(None, r_f_c2544_profile.execute_traffic(traffic_generator)) samples = {} for ifname in range(1): name = "xe{}".format(ifname) @@ -254,9 +258,10 @@ class TestRFC2544Profile(unittest.TestCase): def test_execute_latency(self): traffic_generator = mock.Mock(autospec=TrexProfile) - traffic_generator.my_ports = [0, 1] - traffic_generator.priv_ports = [-1] - traffic_generator.pub_ports = [1] + traffic_generator.networks = { + "private_0": ["xe0"], + "public_0": ["xe1"], + } traffic_generator.client = \ mock.Mock(return_value=True) r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE) diff --git a/tests/unit/network_services/traffic_profile/test_traffic_profile.py b/tests/unit/network_services/traffic_profile/test_traffic_profile.py index 9a78c36a3..8355c85b6 100644 --- a/tests/unit/network_services/traffic_profile/test_traffic_profile.py +++ b/tests/unit/network_services/traffic_profile/test_traffic_profile.py @@ -29,8 +29,16 @@ stl_patch.start() if stl_patch: from yardstick.network_services.traffic_profile.base import TrafficProfile - from yardstick.network_services.traffic_profile.traffic_profile import \ - TrexProfile + from yardstick.network_services.traffic_profile.traffic_profile import TrexProfile + from yardstick.network_services.traffic_profile.traffic_profile import SRC + from yardstick.network_services.traffic_profile.traffic_profile import DST + from yardstick.network_services.traffic_profile.traffic_profile import ETHERNET + from yardstick.network_services.traffic_profile.traffic_profile import IP + from yardstick.network_services.traffic_profile.traffic_profile import IPv6 + from yardstick.network_services.traffic_profile.traffic_profile import UDP + from yardstick.network_services.traffic_profile.traffic_profile import SRC_PORT + from yardstick.network_services.traffic_profile.traffic_profile import DST_PORT + from yardstick.network_services.traffic_profile.traffic_profile import TYPE_OF_SERVICE class TestTrexProfile(unittest.TestCase): @@ -44,28 +52,32 @@ class TestTrexProfile(unittest.TestCase): "flow_number": 10, "frame_size": 64}} + EXAMPLE_ETHERNET_ADDR = "00:00:00:00:00:01" + EXAMPLE_IP_ADDR = "10.0.0.1" + EXAMPLE_IPv6_ADDR = "0064:ff9b:0:0:0:0:9810:6414" + PROFILE = {'description': 'Traffic profile to run RFC2544 latency', 'name': 'rfc2544', 'traffic_profile': {'traffic_type': 'RFC2544Profile', 'frame_rate': 100}, - 'public': {'ipv4': {'outer_l2': {'framesize': {'64B': '100', + TrafficProfile.DOWNLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', '256B': '0', '373b': '0', '570B': '0'}, - "srcmac": "00:00:00:00:00:02", - "dstmac": "00:00:00:00:00:01"}, - 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2', + "srcmac": "00:00:00:00:00:02", + "dstmac": "00:00:00:00:00:01"}, + 'outer_l3v4': {'dstip4': '1.1.1.1-1.1.2.2', 'proto': 'udp', 'srcip4': '9.9.1.1-90.1.2.2', 'dscp': 0, 'ttl': 32, 'count': 1}, - 'outer_l4': {'srcport': '2001', + 'outer_l4': {'srcport': '2001', 'dsrport': '1234', 'count': 1}}}, - 'private': {'ipv4': + TrafficProfile.UPLINK: {'ipv4': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -85,22 +97,22 @@ class TestTrexProfile(unittest.TestCase): 'name': 'rfc2544', 'traffic_profile': {'traffic_type': 'RFC2544Profile', 'frame_rate': 100}, - 'public': {'ipv6': {'outer_l2': {'framesize': + TrafficProfile.DOWNLINK: {'ipv6': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', '256B': '0', '373b': '0', '570B': '0'}, "srcmac": "00:00:00:00:00:02", "dstmac": "00:00:00:00:00:01"}, - 'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420', + 'outer_l3v4': {'dstip6': '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420', 'proto': 'udp', 'srcip6': '0064:ff9b:0:0:0:0:9810:2814-0064:ff9b:0:0:0:0:9810:2820', 'dscp': 0, 'ttl': 32, 'count': 1}, - 'outer_l4': {'srcport': '2001', + 'outer_l4': {'srcport': '2001', 'dsrport': '1234', 'count': 1}}}, - 'private': + TrafficProfile.UPLINK: {'ipv6': {'outer_l2': {'framesize': {'64B': '100', '1518B': '0', '128B': '0', '1400B': '0', @@ -124,92 +136,6 @@ class TestTrexProfile(unittest.TestCase): TrexProfile(TrafficProfile) self.assertEqual(trex_profile.pps, 100) - def test_execute(self): - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.execute({})) - - def test_set_src_mac(self): - src_mac = "00:00:00:00:00:01" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_src_mac(src_mac)) - - src_mac = "00:00:00:00:00:01-00:00:00:00:00:02" - self.assertEqual(None, trex_profile.set_src_mac(src_mac)) - - def test_set_dst_mac(self): - dst_mac = "00:00:00:00:00:03" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dst_mac(dst_mac)) - - dst_mac = "00:00:00:00:00:03-00:00:00:00:00:04" - self.assertEqual(None, trex_profile.set_dst_mac(dst_mac)) - - def test_set_src_ip4(self): - src_ipv4 = "152.16.100.20" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_src_ip4(src_ipv4)) - - src_ipv4 = "152.16.100.20-152.16.100.30" - self.assertEqual(None, trex_profile.set_src_ip4(src_ipv4)) - - def test_set_dst_ip4(self): - dst_ipv4 = "152.16.100.20" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dst_ip4(dst_ipv4)) - - dst_ipv4 = "152.16.100.20-152.16.100.30" - self.assertEqual(None, trex_profile.set_dst_ip4(dst_ipv4)) - - def test_set_src_ip6(self): - src_ipv6 = "0064:ff9b:0:0:0:0:9810:6414" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_src_ip6(src_ipv6)) - - src_ipv6 = "0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420" - self.assertEqual(None, trex_profile.set_src_ip6(src_ipv6)) - - def test_set_dst_ip6(self): - dst_ipv6 = "0064:ff9b:0:0:0:0:9810:6414" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dst_ip6(dst_ipv6)) - - dst_ipv6 = "0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420" - self.assertEqual(None, trex_profile.set_dst_ip6(dst_ipv6)) - - def test_dscp(self): - dscp = "0" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dscp(dscp)) - - dscp = "0-1" - self.assertEqual(None, trex_profile.set_dscp(dscp)) - - def test_src_port(self): - port = "1234" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_src_port(port)) - - port = "1234-5678" - self.assertEqual(None, trex_profile.set_src_port(port)) - - def test_dst_port(self): - port = "1234" - trex_profile = \ - TrexProfile(TrafficProfile) - self.assertEqual(None, trex_profile.set_dst_port(port)) - - port = "1234-5678" - self.assertEqual(None, trex_profile.set_dst_port(port)) - def test_qinq(self): qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0}, "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}} @@ -222,47 +148,47 @@ class TestTrexProfile(unittest.TestCase): "C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}} self.assertEqual(None, trex_profile.set_qinq(qinq)) - def test_set_outer_l2_fields(self): + def test__set_outer_l2_fields(self): trex_profile = \ TrexProfile(TrafficProfile) qinq = {"S-VLAN": {"id": 128, "priority": 0, "cfi": 0}, "C-VLAN": {"id": 512, "priority": 0, "cfi": 0}} - outer_l2 = self.PROFILE['private']['ipv4']['outer_l2'] + outer_l2 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l2'] outer_l2['QinQ'] = qinq - self.assertEqual(None, trex_profile.set_outer_l2_fields(outer_l2)) + self.assertEqual(None, trex_profile._set_outer_l2_fields(outer_l2)) - def test_set_outer_l3v4_fields(self): + def test__set_outer_l3v4_fields(self): trex_profile = \ TrexProfile(TrafficProfile) - outer_l3v4 = self.PROFILE['private']['ipv4']['outer_l3v4'] + outer_l3v4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l3v4'] outer_l3v4['proto'] = 'tcp' - self.assertEqual(None, trex_profile.set_outer_l3v4_fields(outer_l3v4)) + self.assertEqual(None, trex_profile._set_outer_l3v4_fields(outer_l3v4)) - def test_set_outer_l3v6_fields(self): + def test__set_outer_l3v6_fields(self): trex_profile = \ TrexProfile(TrafficProfile) - outer_l3v6 = self.PROFILE_v6['private']['ipv6']['outer_l3v4'] + outer_l3v6 = self.PROFILE_v6[TrafficProfile.UPLINK]['ipv6']['outer_l3v4'] outer_l3v6['proto'] = 'tcp' outer_l3v6['tc'] = 1 outer_l3v6['hlim'] = 10 - self.assertEqual(None, trex_profile.set_outer_l3v6_fields(outer_l3v6)) + self.assertEqual(None, trex_profile._set_outer_l3v6_fields(outer_l3v6)) - def test_set_outer_l4_fields(self): + def test__set_outer_l4_fields(self): trex_profile = \ TrexProfile(TrafficProfile) - outer_l4 = self.PROFILE['private']['ipv4']['outer_l4'] - self.assertEqual(None, trex_profile.set_outer_l4_fields(outer_l4)) + outer_l4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l4'] + self.assertEqual(None, trex_profile._set_outer_l4_fields(outer_l4)) def test_get_streams(self): trex_profile = \ TrexProfile(TrafficProfile) trex_profile.params = self.PROFILE - profile_data = self.PROFILE["private"] + profile_data = self.PROFILE[TrafficProfile.UPLINK] self.assertIsNotNone(trex_profile.get_streams(profile_data)) trex_profile.pg_id = 1 self.assertIsNotNone(trex_profile.get_streams(profile_data)) trex_profile.params = self.PROFILE_v6 - trex_profile.profile_data = self.PROFILE_v6["private"] + trex_profile.profile_data = self.PROFILE_v6[TrafficProfile.UPLINK] self.assertIsNotNone(trex_profile.get_streams(profile_data)) trex_profile.pg_id = 1 self.assertIsNotNone(trex_profile.get_streams(profile_data)) @@ -284,3 +210,37 @@ class TestTrexProfile(unittest.TestCase): TrexProfile(TrafficProfile) self.assertRaises(SystemExit, trex_profile._get_start_end_ipv6, "1.1.1.3", "1.1.1.1") + + def test__general_single_action_partial(self): + trex_profile = TrexProfile(TrafficProfile) + + trex_profile._general_single_action_partial(ETHERNET)(SRC)(self.EXAMPLE_ETHERNET_ADDR) + self.assertEqual(self.EXAMPLE_ETHERNET_ADDR, trex_profile.ether_packet.src) + + trex_profile._general_single_action_partial(IP)(DST)(self.EXAMPLE_IP_ADDR) + self.assertEqual(self.EXAMPLE_IP_ADDR, trex_profile.ip_packet.dst) + + trex_profile._general_single_action_partial(IPv6)(DST)(self.EXAMPLE_IPv6_ADDR) + self.assertEqual(self.EXAMPLE_IPv6_ADDR, trex_profile.ip6_packet.dst) + + trex_profile._general_single_action_partial(UDP)(SRC_PORT)(5060) + self.assertEqual(5060, trex_profile.udp_packet.sport) + + trex_profile._general_single_action_partial(IP)(TYPE_OF_SERVICE)(0) + self.assertEqual(0, trex_profile.ip_packet.tos) + + def test__set_proto_addr(self): + trex_profile = TrexProfile(TrafficProfile) + + ether_range = "00:00:00:00:00:01-00:00:00:00:00:02" + ip_range = "1.1.1.2-1.1.1.10" + ipv6_range = '0064:ff9b:0:0:0:0:9810:6414-0064:ff9b:0:0:0:0:9810:6420' + + trex_profile._set_proto_addr(ETHERNET, SRC, ether_range) + trex_profile._set_proto_addr(ETHERNET, DST, ether_range) + trex_profile._set_proto_addr(IP, SRC, ip_range) + trex_profile._set_proto_addr(IP, DST, ip_range) + trex_profile._set_proto_addr(IPv6, SRC, ipv6_range) + trex_profile._set_proto_addr(IPv6, DST, ipv6_range) + trex_profile._set_proto_addr(UDP, SRC_PORT, "5060-5090") + trex_profile._set_proto_addr(UDP, DST_PORT, "5060") diff --git a/tests/unit/network_services/vnf_generic/test_vnfdgen.py b/tests/unit/network_services/vnf_generic/test_vnfdgen.py index c2b923568..ee881c963 100644 --- a/tests/unit/network_services/vnf_generic/test_vnfdgen.py +++ b/tests/unit/network_services/vnf_generic/test_vnfdgen.py @@ -24,6 +24,10 @@ from six.moves import range from yardstick.common.yaml_loader import yaml_load from yardstick.network_services.vnf_generic import vnfdgen + +UPLINK = "uplink" +DOWNLINK = "downlink" + TREX_VNFD_TEMPLATE = """ vnfd:vnfd-catalog: vnfd: @@ -183,22 +187,23 @@ NODE_CFG = {'ip': '1.1.1.1', } +# need to template, but can't use {} so use %s TRAFFIC_PROFILE_TPL = """ -private: +%(0)s: - ipv4: outer_l2: framesize: - 64B: "{{ get(imix, 'private.imix_small', 10) }}" - 128B: "{{ get(imix, 'private.imix_128B', 10) }}" - 256B: "{{ get(imix, 'private.imix_256B', 10) }}" - 373B: "{{ get(imix, 'private.imix_373B', 10) }}" - 570B: "{{get(imix, 'private.imix_570B', 10) }}" - 1400B: "{{get(imix, 'private.imix_1400B', 10) }}" - 1518B: "{{get(imix, 'private.imix_1500B', 40) }}" -""" + 64B: "{{ get(imix, '%(0)s.imix_small', 10) }}" + 128B: "{{ get(imix, '%(0)s.imix_128B', 10) }}" + 256B: "{{ get(imix, '%(0)s.imix_256B', 10) }}" + 373B: "{{ get(imix, '%(0)s.imix_373B', 10) }}" + 570B: "{{get(imix, '%(0)s.imix_570B', 10) }}" + 1400B: "{{get(imix, '%(0)s.imix_1400B', 10) }}" + 1518B: "{{get(imix, '%(0)s.imix_1500B', 40) }}" +""" % {"0": UPLINK} TRAFFIC_PROFILE = { - "private": [{"ipv4": {"outer_l2": + UPLINK: [{"ipv4": {"outer_l2": {"framesize": {"64B": '10', "128B": '10', "256B": '10', "373B": '10', "570B": '10', "1400B": '10', @@ -269,8 +274,8 @@ class TestVnfdGen(unittest.TestCase): generated_tp = \ vnfdgen.generate_vnfd(TRAFFIC_PROFILE_TPL, - {"imix": {"private": {"imix_small": '20'}}}) + {"imix": {UPLINK: {"imix_small": '20'}}}) self.maxDiff = None tp2 = dict(TRAFFIC_PROFILE) - tp2["private"][0]["ipv4"]["outer_l2"]["framesize"]["64B"] = '20' + tp2[UPLINK][0]["ipv4"]["outer_l2"]["framesize"]["64B"] = '20' self.assertDictEqual(tp2, generated_tp) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py index 2e83353cd..e9444b493 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py @@ -75,7 +75,7 @@ class TestAclApproxVnf(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -90,7 +90,7 @@ class TestAclApproxVnf(unittest.TestCase): 'type': 'PCI-PASSTHROUGH', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', @@ -144,7 +144,7 @@ class TestAclApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens513f0', - 'vld_id': 'public', + 'vld_id': AclApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -172,7 +172,7 @@ class TestAclApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens785f0', - 'vld_id': 'private', + 'vld_id': AclApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -197,7 +197,7 @@ class TestAclApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens786f0', - 'vld_id': 'private', + 'vld_id': AclApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -207,7 +207,7 @@ class TestAclApproxVnf(unittest.TestCase): 'vpci': '0000:05:00.0', 'dpdk_port_num': 0}, 'xe1': {'local_iface_name': 'ens786f1', - 'vld_id': 'public', + 'vld_id': AclApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', 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 e1c69e7b3..478ce186b 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_base.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_base.py @@ -150,7 +150,7 @@ class TestGenericVNF(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.100.20', 'local_mac': '00:00:00:00:00:01' @@ -165,7 +165,7 @@ class TestGenericVNF(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_mac': '00:00:00:00:00:02' diff --git a/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py index e5503697a..0a4c12446 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py @@ -21,6 +21,8 @@ import os import unittest import mock +from copy import deepcopy + from tests.unit import STL_MOCKS from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh @@ -66,15 +68,22 @@ link 1 up """ header = "This is a header" - out = CgnaptApproxSetupEnvHelper._update_cgnat_script_file(header, sample.splitlines(), "") + out = CgnaptApproxSetupEnvHelper._update_cgnat_script_file(header, sample.splitlines()) self.assertNotIn("This is a header", out) - def test__get_cgnapt_confgi(self): + def test__get_cgnapt_config(self): + vnfd_helper = mock.Mock() + vnfd_helper.port_pairs.uplink_ports = [{"name": 'a'}, {"name": "b"}, {"name": "c"}] + + helper = CgnaptApproxSetupEnvHelper(vnfd_helper, mock.Mock(), mock.Mock()) + helper._get_ports_gateway = mock.Mock(side_effect=[3, 5, 2]) + result = helper._get_cgnapt_config([{"name": 'a'}, {}, {"name": "b"}, {}, {"name": "c"}]) + self.assertEqual(result, [3, 5, 2]) - c = CgnaptApproxSetupEnvHelper(mock.MagicMock(), mock.MagicMock(), mock.MagicMock()) - c._get_ports_gateway = mock.Mock(return_value=3) - ret = c._get_cgnapt_config([{"name": 'a'}, {}, {"name": "b"}, {}, {"name": "c"}]) - self.assertEqual(ret, [3, 3, 3]) + def test_scale(self): + helper = CgnaptApproxSetupEnvHelper(mock.Mock(), mock.Mock(), mock.Mock()) + with self.assertRaises(NotImplementedError): + helper.scale() @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process") @@ -111,7 +120,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -126,7 +135,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'type': 'PCI-PASSTHROUGH', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', @@ -146,31 +155,48 @@ class TestCgnaptApproxVnf(unittest.TestCase): {'type': 'VPORT', 'name': 'xe1'}], 'id': 'CgnaptApproxVnf', 'name': 'VPEVnfSsh'}]}} - scenario_cfg = {'options': {'packetsize': 64, 'traffic_type': 4, - 'rfc2544': {'allowed_drop_rate': '0.8 - 1'}, - 'vnf__1': {'rules': 'acl_1rule.yaml', - 'vnf_config': {'lb_config': 'SW', - 'lb_count': 1, - 'worker_config': - '1C/1T', - 'worker_threads': 1}} - }, - 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7', - 'task_path': '/tmp', - 'tc': 'tc_ipv4_1Mflow_64B_packetsize', - 'runner': {'object': 'NetworkServiceTestCase', - 'interval': 35, - 'output_filename': '/tmp/yardstick.out', - 'runner_id': 74476, 'duration': 400, - 'type': 'Duration'}, - 'traffic_profile': 'ipv4_throughput_acl.yaml', - 'traffic_options': {'flow': 'ipv4_Packets_acl.yaml', - 'imix': 'imix_voice.yaml'}, - 'type': 'ISB', - 'nodes': {'tg__2': 'trafficgen_2.yardstick', - 'tg__1': 'trafficgen_1.yardstick', - 'vnf__1': 'vnf.yardstick'}, - 'topology': 'vpe-tg-topology-baremetal.yaml'} + SCENARIO_CFG = { + 'options': { + 'packetsize': 64, + 'traffic_type': 4, + 'rfc2544': { + 'allowed_drop_rate': '0.8 - 1', + }, + 'vnf__1': { + 'napt': 'dynamic', + 'vnf_config': { + 'lb_config': 'SW', + 'lb_count': 1, + 'worker_config': + '1C/1T', + 'worker_threads': 1, + }, + }, + }, + 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7', + 'task_path': '/tmp', + 'tc': 'tc_ipv4_1Mflow_64B_packetsize', + 'runner': { + 'object': 'NetworkServiceTestCase', + 'interval': 35, + 'output_filename': '/tmp/yardstick.out', + 'runner_id': 74476, + 'duration': 400, + 'type': 'Duration', + }, + 'traffic_profile': 'ipv4_throughput_acl.yaml', + 'traffic_options': { + 'flow': 'ipv4_Packets_acl.yaml', + 'imix': 'imix_voice.yaml', + }, + 'type': 'ISB', + 'nodes': { + 'tg__2': 'trafficgen_2.yardstick', + 'tg__1': 'trafficgen_1.yardstick', + 'vnf__1': 'vnf.yardstick', + }, + 'topology': 'vpe-tg-topology-baremetal.yaml', + } context_cfg = {'nodes': {'tg__2': {'member-vnf-index': '3', @@ -180,7 +206,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens513f0', - 'vld_id': 'public', + 'vld_id': CgnaptApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -208,7 +234,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens785f0', - 'vld_id': 'private', + 'vld_id': CgnaptApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -233,7 +259,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens786f0', - 'vld_id': 'private', + 'vld_id': CgnaptApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -243,7 +269,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'vpci': '0000:05:00.0', 'dpdk_port_num': 0}, 'xe1': {'local_iface_name': 'ens786f1', - 'vld_id': 'public', + 'vld_id': CgnaptApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', @@ -277,12 +303,15 @@ class TestCgnaptApproxVnf(unittest.TestCase): 'password': 'r00t', 'VNF model': 'cgnapt_vnf.yaml'}}} + def setUp(self): + self.scenario_cfg = deepcopy(self.SCENARIO_CFG) + def test___init__(self, mock_process): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd) self.assertIsNone(cgnapt_approx_vnf._vnf_process) - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch(SSH_HELPER) def test_collect_kpi(self, ssh, mock_time, mock_process): mock_ssh(ssh) @@ -296,7 +325,7 @@ class TestCgnaptApproxVnf(unittest.TestCase): result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0} self.assertEqual(result, cgnapt_approx_vnf.collect_kpi()) - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') @mock.patch(SSH_HELPER) def test_vnf_execute_command(self, ssh, mock_time, mock_process): mock_ssh(ssh) @@ -386,9 +415,24 @@ class TestCgnaptApproxVnf(unittest.TestCase): self.assertEqual(None, cgnapt_approx_vnf.terminate()) @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") - @mock.patch("yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.time") @mock.patch(SSH_HELPER) - def test__vnf_up_post(self, ssh, mock_time, mock_cgnapt_time, mock_process): + def test__vnf_up_post(self, ssh, mock_time, mock_process): + mock_ssh(ssh) + + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + self.scenario_cfg['options'][name]['napt'] = 'static' + + cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd) + cgnapt_approx_vnf._vnf_process = mock.MagicMock() + cgnapt_approx_vnf._vnf_process.terminate = mock.Mock() + cgnapt_approx_vnf.vnf_execute = mock.MagicMock() + cgnapt_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg + cgnapt_approx_vnf._resource_collect_stop = mock.Mock() + cgnapt_approx_vnf._vnf_up_post() + + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") + @mock.patch(SSH_HELPER) + def test__vnf_up_post_short(self, ssh, mock_time, mock_process): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -399,7 +443,6 @@ class TestCgnaptApproxVnf(unittest.TestCase): cgnapt_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg cgnapt_approx_vnf._resource_collect_stop = mock.Mock() cgnapt_approx_vnf._vnf_up_post() - cgnapt_approx_vnf.vnf_execute.assert_called_once() if __name__ == '__main__': diff --git a/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py b/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py index 15d6adea1..1ad8df9c6 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_iniparser.py @@ -28,6 +28,7 @@ stl_patch.start() if stl_patch: from yardstick.network_services.vnf_generic.vnf.iniparser import ParseError + from yardstick.network_services.vnf_generic.vnf.iniparser import LineParser from yardstick.network_services.vnf_generic.vnf.iniparser import BaseParser from yardstick.network_services.vnf_generic.vnf.iniparser import ConfigParser @@ -38,16 +39,18 @@ key1=value1 list1: value2 value3 value4 -key2="double quote value" key3='single quote value' ; comment here key4= -[section2] +[section2] ; comment with #2 other symbol # here is a comment line list2: value5 -key with no value +key with no value # mixed comment ; symbols ; another comment line key5= + +[section1] ; reopen a section! +key2="double quote value" """ PARSE_TEXT_2 = """\ @@ -86,6 +89,17 @@ class TestParseError(unittest.TestCase): self.assertEqual(str(error), "at line 2, a: 'c'") +class TestLineParser(unittest.TestCase): + + def test___repr__(self): + line_parser = LineParser('', 101) + self.assertIsNotNone(repr(line_parser)) + + def test_error_invalid_assignment(self): + line_parser = LineParser('', 101) + self.assertIsNotNone(line_parser.error_invalid_assignment()) + + class TestBaseParser(unittest.TestCase): @staticmethod @@ -96,23 +110,26 @@ class TestBaseParser(unittest.TestCase): return internal_open - @mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open') - def test_parse_none(self, mock_open): - mock_open.side_effect = self.make_open('') - + def test_parse(self): parser = BaseParser() + parser.parse() - parser.parse([]) + def test_parse_empty_string(self): + parser = BaseParser() + self.assertIsNone(parser.parse('')) def test_not_implemented_methods(self): parser = BaseParser() with self.assertRaises(NotImplementedError): - parser.assignment('key', 'value') + parser.assignment('key', 'value', LineParser('', 100)) with self.assertRaises(NotImplementedError): parser.new_section('section') + with self.assertRaises(NotImplementedError): + parser.comment('comment') + class TestConfigParser(unittest.TestCase): @@ -128,18 +145,25 @@ class TestConfigParser(unittest.TestCase): def test_parse(self, mock_open): mock_open.side_effect = self.make_open(PARSE_TEXT_1) - config_parser = ConfigParser('my_file', []) + existing_data = [['section0', [['key0', 'value0']]]] + config_parser = ConfigParser('my_file', existing_data) config_parser.parse() expected = [ [ + 'section0', + [ + ['key0', 'value0'], + ], + ], + [ 'section1', [ ['key1', 'value1'], ['list1', 'value2\nvalue3\nvalue4'], - ['key2', 'double quote value'], ['key3', 'single quote value'], ['key4', ''], + ['key2', 'double quote value'], ], ], [ @@ -153,12 +177,16 @@ class TestConfigParser(unittest.TestCase): ] self.assertEqual(config_parser.sections, expected) + self.assertIsNotNone(config_parser.find_section('section1')) + self.assertIsNone(config_parser.find_section('section3')) + self.assertEqual(config_parser.find_section_index('section1'), 1) + self.assertEqual(config_parser.find_section_index('section3'), -1) @mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open') def test_parse_2(self, mock_open): mock_open.side_effect = self.make_open(PARSE_TEXT_2) - config_parser = ConfigParser('my_file', []) + config_parser = ConfigParser('my_file') config_parser.parse() expected = [ 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 cba3d449f..995b4a2cc 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 @@ -17,6 +17,7 @@ from __future__ import absolute_import +import copy import os import socket import unittest @@ -25,6 +26,7 @@ from contextlib import contextmanager import mock from tests.unit import STL_MOCKS +from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper STLClient = mock.MagicMock() stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) @@ -634,6 +636,111 @@ class TestProxSocketHelper(unittest.TestCase): class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): + + VNFD0 = { + 'short-name': 'ProxVnf', + 'vdu': [ + { + 'routing_table': [ + { + 'network': '152.16.100.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'if': 'xe0', + }, + { + 'network': '152.16.40.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'if': 'xe1', + }, + ], + 'description': 'PROX approximation using DPDK', + 'name': 'proxvnf-baremetal', + 'nd_route_tbl': [ + { + 'network': '0064:ff9b:0:0:0:0:9810:6414', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0', + }, + { + 'network': '0064:ff9b:0:0:0:0:9810:2814', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1', + }, + ], + 'id': 'proxvnf-baremetal', + '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', + 'vld_id': 'uplink_0', + 'netmask': '255.255.255.0', + 'dpdk_port_num': 0, + 'bandwidth': '10 Gbps', + 'driver': "i40e", + 'dst_ip': '152.16.100.19', + 'local_iface_name': 'xe0', + 'local_mac': '00:00:00:00:00:02', + 'ifname': 'xe0', + }, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0', + }, + { + 'virtual-interface': { + 'dst_mac': '00:00:00:00:00:03', + 'vpci': '0000:05:00.1', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'vld_id': 'downlink_0', + 'driver': "i40e", + 'netmask': '255.255.255.0', + 'dpdk_port_num': 1, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_iface_name': 'xe1', + 'local_mac': '00:00:00:00:00:01', + 'ifname': 'xe1', + }, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1', + }, + ], + }, + ], + 'description': 'PROX approximation using DPDK', + 'mgmt-interface': { + 'vdu-id': 'proxvnf-baremetal', + 'host': '1.2.1.1', + 'password': 'r00t', + 'user': 'root', + 'ip': '1.2.1.1', + }, + 'benchmark': { + 'kpi': [ + 'packets_in', + 'packets_fwd', + 'packets_dropped', + ], + }, + 'id': 'ProxApproxVnf', + 'name': 'ProxVnf', + } + + VNFD = { + 'vnfd:vnfd-catalog': { + 'vnfd': [ + VNFD0, + ], + }, + } + def test__replace_quoted_with_value(self): # empty string input_str = '' @@ -751,33 +858,6 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): result = ProxDpdkVnfSetupEnvHelper.write_prox_config(input_data) self.assertEqual(result, expected) - def test_rebind_drivers(self): - def find_drivers(*args, **kwargs): - setup_helper.used_drivers = used_drivers - - used_drivers = { - 'a': (1, 'b'), - 'c': (2, 'd'), - } - - vnfd_helper = mock.MagicMock() - ssh_helper = mock.MagicMock() - scenario_helper = mock.MagicMock() - setup_helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - setup_helper._find_used_drivers = mock_find = mock.MagicMock(side_effect=find_drivers) - - setup_helper.rebind_drivers() - self.assertEqual(mock_find.call_count, 1) - self.assertEqual(ssh_helper.execute.call_count, 2) - self.assertIn('--force', ssh_helper.execute.call_args[0][0]) - - mock_find.reset_mock() - ssh_helper.execute.reset_mock() - setup_helper.rebind_drivers(False) - self.assertEqual(mock_find.call_count, 0) - self.assertEqual(ssh_helper.execute.call_count, 2) - self.assertNotIn('--force', ssh_helper.execute.call_args[0][0]) - @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file') def test_build_config_file_no_additional_file(self, mock_find_path): vnf1 = { @@ -804,11 +884,11 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): helper.upload_prox_config = mock.MagicMock(return_value='5') self.assertEqual(helper.additional_files, {}) - self.assertNotEqual(helper.prox_config_dict, '4') + self.assertNotEqual(helper._prox_config_data, '4') self.assertNotEqual(helper.remote_path, '5') helper.build_config_file() self.assertEqual(helper.additional_files, {}) - self.assertEqual(helper.prox_config_dict, '4') + self.assertEqual(helper._prox_config_data, '4') self.assertEqual(helper.remote_path, '5') @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file') @@ -854,7 +934,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): ], } - mock_find_path.side_effect = ['1', '2'] + mock_find_path.side_effect = ['1', '2'] + [str(i) for i in range(len(vnf1['prox_files']))] vnfd_helper = mock.MagicMock() ssh_helper = mock.MagicMock() scenario_helper = ScenarioHelper('vnf1') @@ -871,12 +951,12 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): helper.upload_prox_config = mock.MagicMock(return_value='55') self.assertEqual(helper.additional_files, {}) - self.assertNotEqual(helper.prox_config_dict, '44') + self.assertNotEqual(helper._prox_config_data, '44') self.assertNotEqual(helper.remote_path, '55') expected = {'h.i': '33', 'l': '34', 'm_n': '35'} helper.build_config_file() self.assertDictEqual(helper.additional_files, expected) - self.assertEqual(helper.prox_config_dict, '44') + self.assertEqual(helper._prox_config_data, '44') self.assertEqual(helper.remote_path, '55') @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file') @@ -906,9 +986,10 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) helper.remote_path = "/tmp/prox.cfg" - prox_cmd = helper.build_config() expected = "sudo bash -c 'cd /opt/nsb_bin; /opt/nsb_bin/prox -o cli -f -f /tmp/prox.cfg '" - self.assertEqual(prox_cmd, expected) + with mock.patch.object(helper, "build_config_file") as mock_build_config: + prox_cmd = helper.build_config() + self.assertEqual(prox_cmd, expected) def test__insert_additional_file(self): vnfd_helper = mock.MagicMock() @@ -931,8 +1012,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): mock_parser_type.side_effect = init - vnfd_helper = mock.MagicMock() - vnfd_helper.interfaces = [] + vnfd_helper = VnfdHelper(self.VNFD0) ssh_helper = mock.MagicMock() scenario_helper = mock.MagicMock() @@ -946,23 +1026,6 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): helper.additional_files = {"ipv4.lua": "/tmp/ipv4.lua"} helper.remote_prox_file_name = 'remote' - vnfd_helper.interfaces = [ - { - 'virtual-interface': { - 'dst_mac': '00:00:00:de:ad:88', - }, - }, - { - 'virtual-interface': { - 'dst_mac': '00:00:00:de:ad:ee', - }, - }, - { - 'virtual-interface': { - 'dst_mac': '00:00:00:de:ad:ff', - }, - }, - ] sections_data = [ [ 'lua', @@ -975,7 +1038,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): [ ['ip', ''], ['mac', 'foo'], - ['dst mac', '@@2'], + ['dst mac', '@@1'], ['tx port', '1'], ], ], @@ -1004,7 +1067,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): [ ['ip', ''], ['mac', 'hardware'], - ['dst mac', '00:00:00:de:ad:ff'], + ['dst mac', '00:00:00:00:00:03'], ['tx port', '1'], ], ], @@ -1012,7 +1075,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): 'port 2', [ ['ip', ''], - ['$sut_mac0', '00 00 00 de ad 88'], + ['$sut_mac0', '00 00 00 00 00 04'], ['tx port', '0'], ['single', '@'], ['user_table', 'dofile("/tmp/ipv4.lua")'], @@ -1079,48 +1142,26 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): helper.generate_prox_config_file('a/b') def test_generate_prox_lua_file(self): - vnfd_helper = mock.MagicMock() - vnfd_helper.interfaces = [] + vnfd_helper = VnfdHelper(self.VNFD0) ssh_helper = mock.MagicMock() scenario_helper = mock.MagicMock() helper = ProxDpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) helper.LUA_PARAMETER_NAME = 'sut' - expected = '' - result = helper.generate_prox_lua_file() - self.assertEqual(result, expected) - - vnfd_helper.interfaces = [ - { - 'local_ip': '10.20.30.40', - 'dst_ip': '10.11.12.13', - 'virtual-interface': { - 'dpdk_port_num': 3, - }, - }, - { - 'local_ip': '10.20.30.45', - 'dst_ip': '10.11.12.19', - 'virtual-interface': { - 'dpdk_port_num': 7, - }, - }, + expected = [ + 'sut_hex_ip_port_0:"98 10 64 13"', + 'sut_ip_port_0:"152.16.100.19"', + 'gen_hex_ip_port_0:"98 10 64 13"', + 'gen_ip_port_0:"152.16.100.19"', + + 'sut_hex_ip_port_1:"98 10 28 13"', + 'sut_ip_port_1:"152.16.40.19"', + 'gen_hex_ip_port_1:"98 10 28 14"', + 'gen_ip_port_1:"152.16.40.20"', ] - - expected = os.linesep.join([ - 'sut_hex_ip_port_3:"0a 14 1e 28"', - 'sut_ip_port_3:"10.20.30.40"', - 'gen_hex_ip_port_3:"0a 0b 0c 0d"', - 'gen_ip_port_3:"10.11.12.13"', - - 'sut_hex_ip_port_7:"0a 14 1e 2d"', - 'sut_ip_port_7:"10.20.30.45"', - 'gen_hex_ip_port_7:"0a 0b 0c 13"', - 'gen_ip_port_7:"10.11.12.19"', - ]) result = helper.generate_prox_lua_file() - self.assertEqual(result, expected) + self.assertListEqual(result.splitlines(), expected) def test_upload_prox_lua(self): def identity(*args): @@ -1198,6 +1239,111 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase): class TestProxResourceHelper(unittest.TestCase): + + VNFD0 = { + 'short-name': 'ProxVnf', + 'vdu': [ + { + 'routing_table': [ + { + 'network': '152.16.100.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'if': 'xe0', + }, + { + 'network': '152.16.40.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'if': 'xe1', + }, + ], + 'description': 'PROX approximation using DPDK', + 'name': 'proxvnf-baremetal', + 'nd_route_tbl': [ + { + 'network': '0064:ff9b:0:0:0:0:9810:6414', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0', + }, + { + 'network': '0064:ff9b:0:0:0:0:9810:2814', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1', + }, + ], + 'id': 'proxvnf-baremetal', + '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', + 'vld_id': 'uplink_0', + 'netmask': '255.255.255.0', + 'dpdk_port_num': 0, + 'bandwidth': '10 Gbps', + 'driver': "i40e", + 'dst_ip': '152.16.100.19', + 'local_iface_name': 'xe0', + 'local_mac': '00:00:00:00:00:02', + 'ifname': 'xe0', + }, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0', + }, + { + 'virtual-interface': { + 'dst_mac': '00:00:00:00:00:03', + 'vpci': '0000:05:00.1', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'vld_id': 'downlink_0', + 'driver': "i40e", + 'netmask': '255.255.255.0', + 'dpdk_port_num': 1, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_iface_name': 'xe1', + 'local_mac': '00:00:00:00:00:01', + 'ifname': 'xe1', + }, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1', + }, + ], + }, + ], + 'description': 'PROX approximation using DPDK', + 'mgmt-interface': { + 'vdu-id': 'proxvnf-baremetal', + 'host': '1.2.1.1', + 'password': 'r00t', + 'user': 'root', + 'ip': '1.2.1.1', + }, + 'benchmark': { + 'kpi': [ + 'packets_in', + 'packets_fwd', + 'packets_dropped', + ], + }, + 'id': 'ProxApproxVnf', + 'name': 'ProxVnf', + } + + VNFD = { + 'vnfd:vnfd-catalog': { + 'vnfd': [ + VNFD0, + ], + }, + } + def test_line_rate_to_pps(self): expected = 0.25 * 1e8 result = ProxResourceHelper.line_rate_to_pps(180, 4) @@ -1247,7 +1393,7 @@ class TestProxResourceHelper(unittest.TestCase): def test_test_cores(self): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} + setup_helper.prox_config_data = [] helper = ProxResourceHelper(setup_helper) helper._cpu_topology = [] @@ -1256,7 +1402,7 @@ class TestProxResourceHelper(unittest.TestCase): result = helper.test_cores self.assertEqual(result, expected) - setup_helper.prox_config_dict = [ + setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1304,10 +1450,9 @@ class TestProxResourceHelper(unittest.TestCase): def test_get_test_type(self): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} - helper = ProxResourceHelper(setup_helper) - setup_helper.prox_config_dict = [ + + setup_helper.prox_config_data = [ ('global', [ ('name', helper.PROX_CORE_MPLS_TEST) ]), @@ -1334,27 +1479,7 @@ class TestProxResourceHelper(unittest.TestCase): def test_get_cores(self): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} - - helper = ProxResourceHelper(setup_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) - }, - } - } - - setup_helper.prox_config_dict = [ + setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1375,14 +1500,6 @@ class TestProxResourceHelper(unittest.TestCase): ]), ] - expected = [7, 8] - result = helper.get_cores(helper.PROX_CORE_GEN_MODE) - self.assertEqual(result, expected) - - def test_get_cores_mpls(self): - setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} - helper = ProxResourceHelper(setup_helper) helper._cpu_topology = { 0: { @@ -1401,7 +1518,13 @@ class TestProxResourceHelper(unittest.TestCase): } } - setup_helper.prox_config_dict = [ + expected = [7, 8] + result = helper.get_cores(helper.PROX_CORE_GEN_MODE) + self.assertEqual(result, expected) + + def test_get_cores_mpls(self): + setup_helper = mock.MagicMock() + setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1424,6 +1547,24 @@ class TestProxResourceHelper(unittest.TestCase): ]), ] + helper = ProxResourceHelper(setup_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_tagged = [7] expected_plain = [8] result_tagged, result_plain = helper.get_cores_mpls(helper.PROX_CORE_GEN_MODE) @@ -1432,7 +1573,7 @@ class TestProxResourceHelper(unittest.TestCase): def test_latency_cores(self): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} + setup_helper.prox_config_data= [] helper = ProxResourceHelper(setup_helper) helper._cpu_topology = [] @@ -1441,7 +1582,7 @@ class TestProxResourceHelper(unittest.TestCase): result = helper.latency_cores self.assertEqual(result, expected) - setup_helper.prox_config_dict = [ + setup_helper.prox_config_data = [ ('section1', []), ('section2', [ ('a', 'b'), @@ -1504,7 +1645,9 @@ class TestProxResourceHelper(unittest.TestCase): def test_start_collect(self): setup_helper = mock.MagicMock() helper = ProxResourceHelper(setup_helper) + helper.resource = resource = mock.MagicMock() self.assertIsNone(helper.start_collect()) + resource.start.assert_called_once() def test_terminate(self): setup_helper = mock.MagicMock() @@ -1536,7 +1679,7 @@ class TestProxResourceHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time') def test_traffic_context(self, mock_time): setup_helper = mock.MagicMock() - setup_helper.prox_config_dict = {} + setup_helper.vnfd_helper.interfaces = [] helper = ProxResourceHelper(setup_helper) helper._cpu_topology = { @@ -1556,7 +1699,7 @@ class TestProxResourceHelper(unittest.TestCase): } } - setup_helper.prox_config_dict = [ + setup_helper.prox_config_data = [ ('global', [ ('name', helper.PROX_CORE_MPLS_TEST) ]), @@ -1582,8 +1725,6 @@ class TestProxResourceHelper(unittest.TestCase): ]), ] - setup_helper = mock.MagicMock() - setup_helper.vnfd_helper.interfaces = [] client = mock.MagicMock() client.hz.return_value = 2 @@ -1603,8 +1744,30 @@ class TestProxResourceHelper(unittest.TestCase): def measure(*args, **kwargs): yield stats + bad_vnfd = copy.deepcopy(self.VNFD0) + bad_vnfd['vdu'][0]['external-interface'].append({ + 'virtual-interface': { + 'dst_mac': '00:00:00:00:00:05', + 'vpci': '0000:06:00.0', + 'local_ip': '152.16.100.20', + 'type': 'PCI-PASSTHROUGH', + 'vld_id': 'uplink_1', + 'netmask': '255.255.255.0', + 'dpdk_port_num': 0, + 'bandwidth': '10 Gbps', + 'driver': "i40e", + 'dst_ip': '152.16.100.20', + 'local_iface_name': 'xe2', + 'local_mac': '00:00:00:00:00:07', + 'ifname': 'xe2', + }, + 'vnfd-connection-point-ref': 'xe2', + 'name': 'xe2', + }) + + bad_vnfd_helper = VnfdHelper(bad_vnfd) setup_helper = mock.MagicMock() - setup_helper.vnfd_helper.interfaces = [] + setup_helper.vnfd_helper = bad_vnfd_helper stats = { 'delta': TotStatsTuple(6, 7, 8, 9), @@ -1622,25 +1785,21 @@ class TestProxResourceHelper(unittest.TestCase): with self.assertRaises(AssertionError): helper.run_test(980, 15, 45) - setup_helper.vnfd_helper.interfaces = [ - {'name': 'a', 'virtual-interface': {'vpci': 'z'}}, - {'name': 'b', 'virtual-interface': {'vpci': 'y'}}, - {'name': 'c', 'virtual-interface': {'vpci': 'x'}}, - {'name': 'd', 'virtual-interface': {'vpci': 'w'}}, - ] + vnfd_helper = VnfdHelper(self.VNFD0) + setup_helper.vnfd_helper = vnfd_helper + helper = ProxResourceHelper(setup_helper) + helper.client = client + helper.get_latency = mock.MagicMock(return_value=[3.3, 3.6, 3.8]) helper._test_cores = [3, 4] - expected_test_data = ProxTestDataTuple(0.0, 2.0, 6, 7, 8, [3.3, 3.6, 3.8], 6, 7, 1.3e7) + expected_test_data = ProxTestDataTuple(0.0, 2.0, 6, 7, 8, [3.3, 3.6, 3.8], 6, 7, 6.5e6) expected_port_samples = { - 'a': {'in_packets': 6, 'out_packets': 7}, - 'b': {'in_packets': 6, 'out_packets': 7}, - 'c': {'in_packets': 6, 'out_packets': 7}, - 'd': {'in_packets': 6, 'out_packets': 7}, + 'xe0': {'in_packets': 6, 'out_packets': 7}, + 'xe1': {'in_packets': 6, 'out_packets': 7}, } test_data, port_samples = helper.run_test(230, 60, 65) - self.assertEqual(test_data, expected_test_data, '\n'.join(str(x) for x in test_data)) - self.assertEqual(port_samples, expected_port_samples, - '\n'.join(str(x) for x in port_samples)) + self.assertTupleEqual(test_data, expected_test_data) + self.assertDictEqual(port_samples, expected_port_samples) def test_get_latency(self): setup_helper = mock.MagicMock() @@ -1660,20 +1819,6 @@ class TestProxResourceHelper(unittest.TestCase): result = helper.get_latency() self.assertIs(result, expected) - def test__get_logical_if_name(self): - setup_helper = mock.MagicMock() - setup_helper.vnfd_helper.interfaces = [] - - helper = ProxResourceHelper(setup_helper) - helper._vpci_to_if_name_map = { - 'key1': 234, - 'key2': 432, - } - - expected = 234 - result = helper._get_logical_if_name('key1') - self.assertEqual(result, expected) - @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time') @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.ProxSocketHelper') def test__connect(self, mock_socket_helper_type, mock_time): 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 4b115f2d6..c88b1528c 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 @@ -86,8 +86,9 @@ class TestProxApproxVnf(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'vld_id': '', + 'ifname': 'xe1', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -104,9 +105,10 @@ class TestProxApproxVnf(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'vld_id': '', + 'ifname': 'xe3', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', @@ -187,7 +189,7 @@ class TestProxApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens513f0', - 'vld_id': 'public', + 'vld_id': ProxApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -221,7 +223,7 @@ class TestProxApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens785f0', - 'vld_id': 'private', + 'vld_id': ProxApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -252,7 +254,7 @@ class TestProxApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens786f0', - 'vld_id': 'private', + 'vld_id': ProxApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -264,7 +266,7 @@ class TestProxApproxVnf(unittest.TestCase): }, 'xe1': { 'local_iface_name': 'ens786f1', - 'vld_id': 'public', + 'vld_id': ProxApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', @@ -340,7 +342,7 @@ class TestProxApproxVnf(unittest.TestCase): resource_helper = mock.MagicMock() resource_helper.execute.return_value = list(range(12)) - resource_helper.collect_kpi.return_value = {'core': {'result': 234}} + resource_helper.collect_collectd_kpi.return_value = {'core': {'result': 234}} prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf.resource_helper = resource_helper @@ -372,8 +374,10 @@ class TestProxApproxVnf(unittest.TestCase): file_path = os.path.join(curr_path, filename) return file_path + @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True) + @mock.patch('yardstick.network_services.vnf_generic.vnf.iniparser.open', create=True) @mock.patch(SSH_HELPER) - def test_run_prox(self, ssh, mock_time): + def test_run_prox(self, ssh, *_): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) @@ -382,7 +386,7 @@ class TestProxApproxVnf(unittest.TestCase): prox_approx_vnf.setup_helper.remote_path = 'configs/file56.cfg' expected = "sudo bash -c 'cd /tool_path12; " \ - "/tool_path12/tool_file34 -o cli -t -f configs/file56.cfg '" + "/tool_path12/tool_file34 -o cli -t -f /tmp/l3-swap-2.cfg '" prox_approx_vnf._run() result = prox_approx_vnf.ssh_helper.run.call_args[0][0] @@ -395,7 +399,7 @@ class TestProxApproxVnf(unittest.TestCase): prox_approx_vnf.setup_helper = mock.MagicMock() # we can't mock super prox_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG) - prox_approx_vnf.setup_helper.build_config.assert_called_once + prox_approx_vnf.setup_helper.build_config.assert_called_once() @mock.patch(SSH_HELPER) def test_wait_for_instantiate_panic(self, ssh, mock_time): 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 0264facf5..4b9f4172e 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 @@ -98,10 +98,12 @@ class TestVnfSshHelper(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.100.20', - 'local_mac': '00:00:00:00:00:01' + 'local_mac': '00:00:00:00:00:01', + 'vld_id': 'uplink_0', + 'ifname': 'xe0', }, 'vnfd-connection-point-ref': 'xe0', 'name': 'xe0' @@ -113,10 +115,12 @@ class TestVnfSshHelper(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', - 'local_mac': '00:00:00:00:00:02' + 'local_mac': '00:00:00:00:00:02', + 'vld_id': 'downlink_0', + 'ifname': 'xe1', }, 'vnfd-connection-point-ref': 'xe1', 'name': 'xe1' @@ -186,6 +190,7 @@ class TestVnfSshHelper(unittest.TestCase): @mock.patch('yardstick.ssh.paramiko') def test_upload_config_file(self, mock_paramiko): ssh_helper = VnfSshHelper(self.VNFD_0['mgmt-interface'], 'my/bin/path') + ssh_helper._run = mock.MagicMock() self.assertFalse(ssh_helper.is_connected) cfg_file = ssh_helper.upload_config_file('my/prefix', 'my content') @@ -227,6 +232,7 @@ class TestVnfSshHelper(unittest.TestCase): @mock.patch('yardstick.ssh.provision_tool') def test_provision_tool(self, mock_provision_tool, mock_paramiko): ssh_helper = VnfSshHelper(self.VNFD_0['mgmt-interface'], 'my/bin/path') + ssh_helper._run = mock.MagicMock() self.assertFalse(ssh_helper.is_connected) ssh_helper.provision_tool() @@ -290,10 +296,12 @@ class TestSetupEnvHelper(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.100.20', - 'local_mac': '00:00:00:00:00:01' + 'local_mac': '00:00:00:00:00:01', + 'vld_id': 'uplink_0', + 'ifname': 'xe0', }, 'vnfd-connection-point-ref': 'xe0', 'name': 'xe0' @@ -305,10 +313,12 @@ class TestSetupEnvHelper(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', - 'local_mac': '00:00:00:00:00:02' + 'local_mac': '00:00:00:00:00:02', + 'vld_id': 'downlink_0', + 'ifname': 'xe1', }, 'vnfd-connection-point-ref': 'xe1', 'name': 'xe1' @@ -412,14 +422,16 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): 'virtual-interface': { 'dst_mac': '00:00:00:00:00:03', 'vpci': '0000:05:00.0', + 'dpdk_port_num': 0, 'driver': 'i40e', 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', 'bandwidth': '10 Gbps', 'dst_ip': '152.16.100.20', - 'local_mac': '00:00:00:00:00:01' + 'local_mac': '00:00:00:00:00:01', + 'vld_id': 'uplink_0', + 'ifname': 'xe0', }, 'vnfd-connection-point-ref': 'xe0', 'name': 'xe0' @@ -428,14 +440,16 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): 'virtual-interface': { 'dst_mac': '00:00:00:00:00:04', 'vpci': '0000:05:00.1', + 'dpdk_port_num': 1, 'driver': 'ixgbe', 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', - 'local_mac': '00:00:00:00:00:02' + 'local_mac': '00:00:00:00:00:02', + 'vld_id': 'downlink_0', + 'ifname': 'xe1', }, 'vnfd-connection-point-ref': 'xe1', 'name': 'xe1' @@ -541,7 +555,8 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): call_args_iter = (args[0][0] for args in ssh_helper.execute.call_args_list) self.assertIsNone(result) self.assertEqual(ssh_helper.execute.call_count, 3) - for expect_start, expect_in, arg0 in zip(expect_start_list, expect_in_list, call_args_iter): + for expect_start, expect_in, arg0 in zip(expect_start_list, expect_in_list, + call_args_iter): self.assertTrue(arg0.startswith(expect_start)) self.assertIn(expect_in, arg0) @@ -558,19 +573,11 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): call_args_iter = (args[0][0] for args in ssh_helper.execute.call_args_list) self.assertIsNone(result) self.assertEqual(ssh_helper.execute.call_count, 3) - for expect_start, expect_in, arg0 in zip(expect_start_list, expect_in_list, call_args_iter): + for expect_start, expect_in, arg0 in zip(expect_start_list, expect_in_list, + call_args_iter): self.assertTrue(arg0.startswith(expect_start)) self.assertIn(expect_in, arg0) - def test__get_dpdk_port_num(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - expected = '0' - result = dpdk_setup_helper._get_dpdk_port_num('xe0') - self.assertEqual(result, expected) - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.open') @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.find_relative_file') @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig') @@ -582,7 +589,6 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): scenario_helper.vnf_cfg = {} scenario_helper.all_options = {} dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper.all_ports = [] dpdk_setup_helper.PIPELINE_COMMAND = expected = 'pipeline command' result = dpdk_setup_helper.build_config() @@ -600,13 +606,13 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) dpdk_setup_helper.CFG_CONFIG = 'config' dpdk_setup_helper.CFG_SCRIPT = 'script' - dpdk_setup_helper.all_ports = [3, 4, 5] dpdk_setup_helper.pipeline_kwargs = {} + dpdk_setup_helper.all_ports = [0, 1, 2] expected = { 'cfg_file': 'config', 'script': 'script', - 'ports_len_hex': '0xf', + 'port_mask_hex': '0x3', 'tool_path': 'tool_path', } dpdk_setup_helper._build_pipeline_kwargs() @@ -717,73 +723,24 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): result = dpdk_setup_helper._validate_cpu_cfg() self.assertEqual(result, expected) - def test__find_used_drivers(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - stdout = ''' -00:01.2 foo drv=name1 -00:01.4 drv foo=name2 -00:02.2 drv=name3 -00:02.3 drv=name4 -''' - ssh_helper.execute.return_value = 0, stdout, '' - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper.used_drivers = None - dpdk_setup_helper._dpdk_nic_bind = '' - dpdk_setup_helper.bound_pci = [ - 'pci 00:01.2', - 'pci 00:02.3', - ] + @mock.patch('yardstick.ssh.SSH') + def test_setup_vnf_environment(self, _): + def execute(cmd, *args, **kwargs): + if cmd.startswith('which '): + return exec_failure + return exec_success - expected = { - '00:01.2': (0, 'name1'), - '00:02.3': (2, 'name4'), - } - dpdk_setup_helper._find_used_drivers() - self.assertEqual(dpdk_setup_helper.used_drivers, expected) + exec_success = (0, 'good output', '') + exec_failure = (1, 'bad output', 'error output') - def test_dpdk_nic_bind(self): vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() - ssh_helper.provision_tool.return_value = nic_bind = object() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - - self.assertIsNone(dpdk_setup_helper._dpdk_nic_bind) - self.assertIs(dpdk_setup_helper.dpdk_nic_bind, nic_bind) - self.assertIs(dpdk_setup_helper.dpdk_nic_bind, nic_bind) - self.assertEqual(ssh_helper.provision_tool.call_count, 1) + ssh_helper.execute = execute - # ensure provision tool is not called a second time - self.assertIs(dpdk_setup_helper.dpdk_nic_bind, nic_bind) - self.assertEqual(ssh_helper.provision_tool.call_count, 1) + dpdk_vnf_setup_env_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, mock.Mock()) + dpdk_vnf_setup_env_helper._validate_cpu_cfg = mock.Mock(return_value=[]) - @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time') - @mock.patch('yardstick.ssh.SSH') - def test_setup_vnf_environment(self, _, mock_time): - cores = ['3', '4'] - - vnfd_helper = VnfdHelper(deepcopy(self.VNFD_0)) - ssh_helper = mock.Mock() - ssh_helper.execute.return_value = 1, 'bad output', 'error output' - ssh_helper.join_bin_path.return_value = 'joined_path' - ssh_helper.provision_tool.return_value = 'provision string' - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._setup_hugepages = mock.Mock() - dpdk_setup_helper._validate_cpu_cfg = mock.Mock(return_value=cores) - dpdk_setup_helper._find_used_drivers = mock.Mock() - dpdk_setup_helper.used_drivers = { - '0000:05:00.0': (1, ''), - '0000:05:01.0': (3, ''), - } - - result = dpdk_setup_helper.setup_vnf_environment() - self.assertIsInstance(result, ResourceProfile) - self.assertEqual(result.cores, cores) - self.assertEqual(vnfd_helper.interfaces[0]['dpdk_port_num'], 1) - self.assertNotIn('dpdk_port_num', vnfd_helper.interfaces[1]) + self.assertIsInstance(dpdk_vnf_setup_env_helper.setup_vnf_environment(), ResourceProfile) def test__setup_dpdk_early_success(self): vnfd_helper = VnfdHelper(self.VNFD_0) @@ -843,83 +800,146 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase): self.assertIsInstance(result, ResourceProfile) self.assertEqual(dpdk_setup_helper.socket, 1) - def test__bind_dpdk_unforced(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - - dpdk_setup_helper._bind_dpdk('x', 'y', force=False) - self.assertNotIn('--force', ssh_helper.execute.call_args_list[0][0][0]) - - def test__detect_and_bind_dpdk_short(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.execute.return_value = 0, 'output', '' - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - - self.assertIsNone(dpdk_setup_helper._detect_and_bind_dpdk('a', 'b')) - self.assertEqual(ssh_helper.execute.call_count, 1) - - def test__detect_and_bind_dpdk_fail_to_bind(self): - vnfd_helper = VnfdHelper(self.VNFD_0) + def test__detect_and_bind_drivers(self): + vnfd_helper = VnfdHelper(deepcopy(self.VNFD_0)) ssh_helper = mock.Mock() - ssh_helper.execute.return_value = 1, 'bad output', 'error output' + # ssh_helper.execute = mock.Mock(return_value = (0, 'text', '')) + # ssh_helper.execute.return_value = 0, 'output', '' scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._bind_dpdk = mock.Mock() + rv = ['0000:05:00.1', '0000:05:00.0'] - self.assertIsNone(dpdk_setup_helper._detect_and_bind_dpdk('a', 'b')) - self.assertEqual(ssh_helper.execute.call_count, 2) - - def test__detect_and_bind_dpdk(self): - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - ssh_helper.execute.side_effect = iter([ - (1, 'bad output', 'error output'), - (0, 'output', ''), - ]) - scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._bind_dpdk = mock.Mock() + dpdk_setup_helper.dpdk_bind_helper._get_bound_pci_addresses = mock.Mock(return_value=rv) + dpdk_setup_helper.dpdk_bind_helper.bind = mock.Mock() + dpdk_setup_helper.dpdk_bind_helper.read_status = mock.Mock() - self.assertEqual(dpdk_setup_helper._detect_and_bind_dpdk('a', 'b'), 'output') - self.assertEqual(ssh_helper.execute.call_count, 2) + self.assertIsNone(dpdk_setup_helper._detect_and_bind_drivers()) - def test__bind_kernel_devices(self): - bind_iter = iter([ - None, - 'output', - ]) - - vnfd_helper = VnfdHelper(self.VNFD_0) - ssh_helper = mock.Mock() - scenario_helper = mock.Mock() - dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._detect_and_bind_dpdk = mock.Mock(side_effect=bind_iter) - - self.assertIsNone(dpdk_setup_helper._bind_kernel_devices()) + intf_0 = vnfd_helper.vdu[0]['external-interface'][0]['virtual-interface'] + intf_1 = vnfd_helper.vdu[0]['external-interface'][1]['virtual-interface'] + self.assertEquals(0, intf_0['dpdk_port_num']) + self.assertEquals(1, intf_1['dpdk_port_num']) def test_tear_down(self): vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) - dpdk_setup_helper._dpdk_nic_bind = 'a' - dpdk_setup_helper.used_drivers = { - '0000:05:00.0': (1, 'd1'), - '0000:05:01.0': (3, 'd3'), + dpdk_setup_helper.dpdk_bind_helper.bind = mock.Mock() + dpdk_setup_helper.dpdk_bind_helper.used_drivers = { + '0000:05:00.0': 'd1', + '0000:05:01.0': 'd3', } self.assertIsNone(dpdk_setup_helper.tear_down()) + dpdk_setup_helper.dpdk_bind_helper.bind.assert_any_call('0000:05:00.0', 'd1', True) + dpdk_setup_helper.dpdk_bind_helper.bind.assert_any_call('0000:05:01.0', 'd3', True) class TestResourceHelper(unittest.TestCase): + VNFD_0 = { + 'short-name': 'VpeVnf', + 'vdu': [ + { + 'routing_table': [ + { + 'network': '152.16.100.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'if': 'xe0' + }, + { + 'network': '152.16.40.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'if': 'xe1' + }, + ], + 'description': 'VPE approximation using DPDK', + 'name': 'vpevnf-baremetal', + 'nd_route_tbl': [ + { + 'network': '0064:ff9b:0:0:0:0:9810:6414', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0' + }, + { + 'network': '0064:ff9b:0:0:0:0:9810:2814', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1' + }, + ], + 'id': 'vpevnf-baremetal', + 'external-interface': [ + { + 'virtual-interface': { + 'dst_mac': '00:00:00:00:00:03', + 'vpci': '0000:05:00.0', + 'driver': 'i40e', + 'local_ip': '152.16.100.19', + 'type': 'PCI-PASSTHROUGH', + 'netmask': '255.255.255.0', + 'dpdk_port_num': 0, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.100.20', + 'local_mac': '00:00:00:00:00:01' + }, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0' + }, + { + 'virtual-interface': { + 'dst_mac': '00:00:00:00:00:04', + 'vpci': '0000:05:00.1', + 'driver': 'ixgbe', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'netmask': '255.255.255.0', + 'dpdk_port_num': 1, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_mac': '00:00:00:00:00:02' + }, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1' + }, + ], + }, + ], + 'description': 'Vpe approximation using DPDK', + 'mgmt-interface': { + 'vdu-id': 'vpevnf-baremetal', + 'host': '1.1.1.1', + 'password': 'r00t', + 'user': 'root', + 'ip': '1.1.1.1' + }, + 'benchmark': { + 'kpi': [ + 'packets_in', + 'packets_fwd', + 'packets_dropped', + ], + }, + 'connection-point': [ + { + 'type': 'VPORT', + 'name': 'xe0', + }, + { + 'type': 'VPORT', + 'name': 'xe1', + }, + ], + 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh' + } + def test_setup(self): resource = object() - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -930,7 +950,7 @@ class TestResourceHelper(unittest.TestCase): self.assertIs(resource_helper.resource, resource) def test_generate_cfg(self): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -939,7 +959,7 @@ class TestResourceHelper(unittest.TestCase): self.assertIsNone(resource_helper.generate_cfg()) def test_stop_collect(self): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -949,7 +969,7 @@ class TestResourceHelper(unittest.TestCase): self.assertIsNone(resource_helper.stop_collect()) def test_stop_collect_none(self): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -958,6 +978,7 @@ class TestResourceHelper(unittest.TestCase): self.assertIsNone(resource_helper.stop_collect()) + class TestClientResourceHelper(unittest.TestCase): VNFD_0 = { @@ -1004,10 +1025,12 @@ class TestClientResourceHelper(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.100.20', - 'local_mac': '00:00:00:00:00:01' + 'local_mac': '00:00:00:00:00:01', + 'vld_id': 'uplink_0', + 'ifname': 'xe0', }, 'vnfd-connection-point-ref': 'xe0', 'name': 'xe0' @@ -1020,10 +1043,12 @@ class TestClientResourceHelper(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', - 'local_mac': '00:00:00:00:00:02' + 'local_mac': '00:00:00:00:00:02', + 'vld_id': 'downlink_0', + 'ifname': 'xe1', }, 'vnfd-connection-point-ref': 'xe1', 'name': 'xe1' @@ -1036,7 +1061,7 @@ class TestClientResourceHelper(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 2, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.30', 'local_mac': '00:00:00:00:00:11' @@ -1087,7 +1112,7 @@ class TestClientResourceHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.STLError', new_callable=lambda: MockError) def test_get_stats_not_connected(self, mock_state_error, mock_logger): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -1143,16 +1168,9 @@ class TestClientResourceHelper(unittest.TestCase): "in_packets": 0, "out_packets": 48791, }, - 'xe2': { - "rx_throughput_fps": 0.0, - "tx_throughput_fps": 0.0, - "rx_throughput_mbps": 0.0, - "tx_throughput_mbps": 0.0, - "in_packets": 0, - "out_packets": 0, - }, } - result = client_resource_helper.generate_samples() + ports = vnfd_helper.port_nums(vnfd_helper.port_pairs.all_ports) + result = client_resource_helper.generate_samples(ports) self.assertDictEqual(result, expected) def test_generate_samples_with_key(self): @@ -1203,7 +1221,8 @@ class TestClientResourceHelper(unittest.TestCase): "out_packets": 48791, }, } - result = client_resource_helper.generate_samples('key_name') + ports = vnfd_helper.port_nums(vnfd_helper.port_pairs.all_ports) + result = client_resource_helper.generate_samples(ports, 'key_name') self.assertDictEqual(result, expected) def test_generate_samples_with_key_and_default(self): @@ -1253,11 +1272,12 @@ class TestClientResourceHelper(unittest.TestCase): "out_packets": 48791, }, } - result = client_resource_helper.generate_samples('key_name', 'default') + ports = vnfd_helper.port_nums(vnfd_helper.port_pairs.all_ports) + result = client_resource_helper.generate_samples(ports, 'key_name', 'default') self.assertDictEqual(result, expected) def test_clear_stats(self): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -1268,7 +1288,7 @@ class TestClientResourceHelper(unittest.TestCase): self.assertEqual(client_resource_helper.client.clear_stats.call_count, 1) def test_clear_stats_of_ports(self): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -1279,7 +1299,7 @@ class TestClientResourceHelper(unittest.TestCase): self.assertEqual(client_resource_helper.client.clear_stats.call_count, 1) def test_start(self): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -1290,7 +1310,7 @@ class TestClientResourceHelper(unittest.TestCase): self.assertEqual(client_resource_helper.client.start.call_count, 1) def test_start_ports(self): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -1301,7 +1321,7 @@ class TestClientResourceHelper(unittest.TestCase): self.assertEqual(client_resource_helper.client.start.call_count, 1) def test_collect_kpi_with_queue(self): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -1324,7 +1344,7 @@ class TestClientResourceHelper(unittest.TestCase): @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.STLError', new_callable=lambda: MockError) def test__connect_with_failures(self, mock_error, mock_logger, mock_time): - vnfd_helper = VnfdHelper({}) + vnfd_helper = VnfdHelper(self.VNFD_0) ssh_helper = mock.Mock() scenario_helper = mock.Mock() dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper) @@ -1659,7 +1679,7 @@ class TestSampleVnf(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.100.20', 'local_mac': '00:00:00:00:00:01' @@ -1674,7 +1694,7 @@ class TestSampleVnf(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_mac': '00:00:00:00:00:02' @@ -1749,7 +1769,6 @@ class TestSampleVnf(unittest.TestCase): class MySetupEnvHelper(SetupEnvHelper): pass - class MyResourceHelper(ResourceHelper): pass @@ -1887,6 +1906,16 @@ class TestSampleVnf(unittest.TestCase): self.assertEqual(sample_vnf.wait_for_instantiate(), 0) + def test__build_ports(self): + vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] + sample_vnf = SampleVNF('vnf1', vnfd) + + self.assertIsNone(sample_vnf._build_ports()) + self.assertIsNotNone(sample_vnf.networks) + self.assertIsNotNone(sample_vnf.uplink_ports) + self.assertIsNotNone(sample_vnf.downlink_ports) + self.assertIsNotNone(sample_vnf.my_ports) + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") def test_vnf_execute_with_queue_data(self, mock_time): queue_size_list = [ @@ -2014,7 +2043,7 @@ class TestSampleVNFTrafficGen(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.100.20', 'local_mac': '00:00:00:00:00:01' @@ -2030,7 +2059,7 @@ class TestSampleVNFTrafficGen(unittest.TestCase): 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_mac': '00:00:00:00:00:02' @@ -2038,22 +2067,6 @@ class TestSampleVNFTrafficGen(unittest.TestCase): 'vnfd-connection-point-ref': 'xe1', 'name': 'xe1' }, - { - 'virtual-interface': { - 'dst_mac': '00:00:00:00:00:13', - 'vpci': '0000:05:00.2', - 'driver': 'ixgbe', - 'local_ip': '152.16.40.19', - 'type': 'PCI-PASSTHROUGH', - 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', - 'bandwidth': '10 Gbps', - 'dst_ip': '152.16.40.30', - 'local_mac': '00:00:00:00:00:11' - }, - 'vnfd-connection-point-ref': 'xe2', - 'name': 'xe2' - }, ], }, ], @@ -2166,7 +2179,7 @@ class TestSampleVNFTrafficGen(unittest.TestCase): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" - mock_traffic_profile.execute.return_value = "64" + mock_traffic_profile.execute_traffic.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE sample_vnf_tg = SampleVNFTrafficGen('tg1', self.VNFD_0) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py index c65c0ab0a..e6e4b882e 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py @@ -70,7 +70,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -85,7 +85,7 @@ class TestIxLoadTrafficGen(unittest.TestCase): 'type': 'PCI-PASSTHROUGH', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py index 45bbfaea3..c1b2d27eb 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py @@ -20,6 +20,7 @@ from __future__ import absolute_import import unittest import mock from multiprocessing import Queue +import multiprocessing from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from tests.unit import STL_MOCKS @@ -31,11 +32,40 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) stl_patch.start() if stl_patch: - from yardstick.network_services.vnf_generic.vnf.tg_ping import PingParser, PingTrafficGen - from yardstick.network_services.traffic_profile.base import TrafficProfile + from yardstick.network_services.vnf_generic.vnf.tg_ping import PingParser + from yardstick.network_services.vnf_generic.vnf.tg_ping import PingTrafficGen + from yardstick.network_services.vnf_generic.vnf.tg_ping import PingResourceHelper + from yardstick.network_services.vnf_generic.vnf.tg_ping import PingSetupEnvHelper from yardstick.network_services.vnf_generic.vnf.sample_vnf import VnfSshHelper +class TestPingResourceHelper(unittest.TestCase): + def test___init__(self): + setup_helper = mock.Mock() + helper = PingResourceHelper(setup_helper) + + self.assertIsInstance(helper._queue, multiprocessing.queues.Queue) + self.assertIsInstance(helper._parser, PingParser) + + def test_run_traffic(self): + setup_helper = mock.Mock() + traffic_profile = mock.Mock() + traffic_profile.params = { + 'traffic_profile': { + 'frame_size': 64, + }, + } + + helper = PingResourceHelper(setup_helper) + helper.cmd_kwargs = {'target_ip': '10.0.0.2', + 'local_ip': '10.0.0.1', + 'local_if_name': 'eth0', + } + helper.ssh_helper = mock.Mock() + helper.run_traffic(traffic_profile) + helper.ssh_helper.run.called_with('ping-s 64 10.0.0.2') + + class TestPingParser(unittest.TestCase): def test___init__(self): q_out = Queue() @@ -69,7 +99,6 @@ class TestPingParser(unittest.TestCase): class TestPingTrafficGen(unittest.TestCase): - VNFD_0_EXT_IF_0 = { 'virtual-interface': { 'dst_mac': '00:00:00:00:00:04', @@ -77,7 +106,6 @@ class TestPingTrafficGen(unittest.TestCase): 'local_ip': u'152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': u'152.16.100.20', @@ -96,14 +124,13 @@ class TestPingTrafficGen(unittest.TestCase): 'type': 'PCI-PASSTHROUGH', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', 'bandwidth': '10 Gbps', 'dst_ip': u'152.16.40.20', 'local_iface_name': 'xe1', 'local_mac': '00:00:00:00:00:01', }, - 'vnfd-connection-point-ref': 'xe1', - 'name': 'xe1', + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1', } VNFD_0_EXT_IF_LIST = [ @@ -151,7 +178,7 @@ class TestPingTrafficGen(unittest.TestCase): ], 'description': 'Vpe approximation using DPDK', 'mgmt-interface': { - 'vdu-id': 'vpevnf-baremetal', + 'vdu-id': 'vpevnf-baremetal', 'host': '1.1.1.1', 'password': 'r00t', 'user': 'root', @@ -198,11 +225,20 @@ class TestPingTrafficGen(unittest.TestCase): }, } + CMD_KWARGS = { + 'target_ip': u'152.16.100.20', + 'local_ip': u'152.16.100.19', + 'local_if_name': u'xe0', + } + @mock.patch("yardstick.ssh.SSH") def test___init__(self, ssh): ssh.from_node.return_value.execute.return_value = 0, "success", "" ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0) - self.assertIsNotNone(ping_traffic_gen._queue) + + self.assertIsInstance(ping_traffic_gen.setup_helper, PingSetupEnvHelper) + self.assertIsInstance(ping_traffic_gen.resource_helper, PingResourceHelper) + self.assertEquals(ping_traffic_gen._result, {}) @mock.patch("yardstick.ssh.SSH") def test__bind_device_kernel_with_failure(self, ssh): @@ -234,35 +270,23 @@ class TestPingTrafficGen(unittest.TestCase): mock_ssh(ssh, spec=VnfSshHelper, exec_result=(0, "success", "")) ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0) ping_traffic_gen.setup_helper.ssh_helper = mock.MagicMock( - **{"execute.return_value": (0, "", "")}) + **{"execute.return_value": (0, "success", "")}) self.assertIsInstance(ping_traffic_gen.ssh_helper, mock.Mock) self.assertEqual(ping_traffic_gen._result, {}) + self.assertIsNone(ping_traffic_gen.instantiate({}, {})) + + self.assertEqual( + ping_traffic_gen.vnfd_helper.interfaces[0]['virtual-interface']['local_iface_name'], + 'success') + self.assertEqual(self.CMD_KWARGS, ping_traffic_gen.resource_helper.cmd_kwargs) self.assertIsNotNone(ping_traffic_gen._result) @mock.patch("yardstick.ssh.SSH") def test_listen_traffic(self, ssh): - ssh.from_node.return_value.execute.return_value = 0, "success", "" ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0) self.assertIsNone(ping_traffic_gen.listen_traffic({})) - @mock.patch(SSH_HELPER) - def test_run_traffic_process(self, ssh): - mock_ssh(ssh) - - mock_traffic_profile = mock.Mock(autospec=TrafficProfile) - mock_traffic_profile.get_traffic_definition.return_value = "64" - mock_traffic_profile.params = self.TRAFFIC_PROFILE - - ssh.from_node.return_value.execute.return_value = 0, "success", "" - ssh.from_node.return_value.run.return_value = 0, "success", "" - - sut = PingTrafficGen('vnf1', self.VNFD_0) - sut._traffic_runner(mock_traffic_profile) - sut.ssh_helper.run.assert_called_with( - "ping -s 64 152.16.100.20", - stdout=sut._parser, keep_stdin_open=True, pty=True) - @mock.patch("yardstick.ssh.SSH") def test_scale_negative(self, ssh): ssh.from_node.return_value.execute.return_value = 0, "success", "" @@ -277,4 +301,4 @@ class TestPingTrafficGen(unittest.TestCase): ssh.from_node.return_value.run.return_value = 0, "success", "" ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0) - self.assertIsNone(ping_traffic_gen.terminate())
\ No newline at end of file + self.assertIsNone(ping_traffic_gen.terminate()) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py index a12abb625..eb569cfe6 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py @@ -20,7 +20,6 @@ import mock from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from tests.unit import STL_MOCKS -from yardstick.network_services.nfvi.resource import ResourceProfile SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' NAME = 'vnf__1' @@ -80,7 +79,7 @@ class TestProxTrafficGen(unittest.TestCase): 'type': 'PCI-PASSTHROUGH', 'vld_id': '', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -99,7 +98,7 @@ class TestProxTrafficGen(unittest.TestCase): 'vld_id': '', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', @@ -180,7 +179,7 @@ class TestProxTrafficGen(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens513f0', - 'vld_id': 'public', + 'vld_id': ProxTrafficGen.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -214,7 +213,7 @@ class TestProxTrafficGen(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens785f0', - 'vld_id': 'private', + 'vld_id': ProxTrafficGen.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -245,7 +244,7 @@ class TestProxTrafficGen(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens786f0', - 'vld_id': 'private', + 'vld_id': ProxTrafficGen.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -257,7 +256,7 @@ class TestProxTrafficGen(unittest.TestCase): }, 'xe1': { 'local_iface_name': 'ens786f1', - 'vld_id': 'public', + 'vld_id': ProxTrafficGen.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', @@ -331,7 +330,8 @@ class TestProxTrafficGen(unittest.TestCase): mock_ssh(ssh) prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0) - prox_traffic_gen._vnf_wrapper.resource = mock.Mock(autospec=ResourceProfile) + prox_traffic_gen._vnf_wrapper.resource_helper.resource = mock.MagicMock( + **{"check_if_sa_running.return_value": [False]}) prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="") self.assertEqual({}, prox_traffic_gen.collect_kpi()) @@ -349,8 +349,10 @@ class TestProxTrafficGen(unittest.TestCase): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] prox_traffic_gen = ProxTrafficGen(NAME, vnfd) - prox_traffic_gen.ssh_helper = mock.MagicMock( + ssh_helper = mock.MagicMock( **{"execute.return_value": (0, "", ""), "bin_path": ""}) + prox_traffic_gen.ssh_helper = ssh_helper + prox_traffic_gen.setup_helper.dpdk_bind_helper.ssh_helper = ssh_helper prox_traffic_gen.setup_helper._setup_resources = mock.MagicMock() prox_traffic_gen.setup_hugepages = mock.MagicMock() prox_traffic_gen.generate_prox_config_file = mock.MagicMock() @@ -369,12 +371,12 @@ class TestProxTrafficGen(unittest.TestCase): 'task_path': '', 'options': {'tg__1': {'prox_args': {'-e': '', '-t': ''}, - 'prox_config': 'configs/l3-gen-2.cfg', - 'prox_path': '/root/dppd-PROX-v035/build/prox'}, - 'vnf__1': {'prox_args': {'-t': ''}, - 'prox_config': 'configs/l3-swap-2.cfg', - 'prox_path': '/root/dppd-PROX-v035/build/prox'} - } + 'prox_config': 'configs/l3-gen-2.cfg', + 'prox_path': '/root/dppd-PROX-v035/build/prox'}, + 'vnf__1': {'prox_args': {'-t': ''}, + 'prox_config': 'configs/l3-swap-2.cfg', + 'prox_path': '/root/dppd-PROX-v035/build/prox'} + } } prox_traffic_gen.instantiate(scenario_cfg, {}) @@ -384,15 +386,15 @@ class TestProxTrafficGen(unittest.TestCase): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" - mock_traffic_profile.execute.return_value = "64" + mock_traffic_profile.execute_traffic.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] sut = ProxTrafficGen(NAME, vnfd) - sut.prox_config_dict = {} sut._get_socket = mock.MagicMock() sut.ssh_helper = mock.Mock() sut.ssh_helper.run = mock.Mock() + sut.setup_helper.prox_config_dict = {} sut._vpci_ascending = ["0000:05:00.0", "0000:05:00.1"] sut._connect_client = mock.Mock(autospec=STLClient) sut._connect_client.get_stats = mock.Mock(return_value="0") diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py index 661e885ca..0e303dc3b 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py @@ -23,7 +23,6 @@ import mock from tests.unit import STL_MOCKS - STLClient = mock.MagicMock() stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) stl_patch.start() @@ -36,13 +35,11 @@ if stl_patch: TEST_FILE_YAML = 'nsb_test_case.yaml' - NAME = "tg__1" @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen") class TestIxiaResourceHelper(unittest.TestCase): - def test___init___with_custom_rfc_helper(self, mock_ix_nextgen): class MyRfcHelper(IxiaRfc2544Helper): pass @@ -63,71 +60,71 @@ class TestIxiaResourceHelper(unittest.TestCase): @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.IxNextgen") class TestIXIATrafficGen(unittest.TestCase): VNFD = {'vnfd:vnfd-catalog': - {'vnfd': - [{'short-name': 'VpeVnf', - 'vdu': - [{'routing_table': - [{'network': '152.16.100.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.100.20', - 'if': 'xe0'}, - {'network': '152.16.40.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.40.20', - 'if': 'xe1'}], - 'description': 'VPE approximation using DPDK', - 'name': 'vpevnf-baremetal', - 'nd_route_tbl': - [{'network': '0064:ff9b:0:0:0:0:9810:6414', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:6414', - 'if': 'xe0'}, - {'network': '0064:ff9b:0:0:0:0:9810:2814', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:2814', - 'if': 'xe1'}], - 'id': 'vpevnf-baremetal', - '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': '0', - 'bandwidth': '10 Gbps', - 'driver': "i40e", - 'dst_ip': '152.16.100.20', - 'local_iface_name': '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:05:00.1', - 'local_ip': '152.16.40.19', - 'type': 'PCI-PASSTHROUGH', - 'driver': "i40e", - 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', - 'bandwidth': '10 Gbps', - 'dst_ip': '152.16.40.20', - 'local_iface_name': 'xe1', - 'local_mac': '00:00:00:00:00:01'}, - 'vnfd-connection-point-ref': 'xe1', - 'name': 'xe1'}]}], - 'description': 'Vpe approximation using DPDK', - 'mgmt-interface': - {'vdu-id': 'vpevnf-baremetal', - 'host': '1.1.1.1', - 'password': 'r00t', - 'user': 'root', - 'ip': '1.1.1.1'}, - 'benchmark': - {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']}, - 'connection-point': [{'type': 'VPORT', 'name': 'xe0'}, - {'type': 'VPORT', 'name': 'xe1'}], - 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}} + {'vnfd': + [{'short-name': 'VpeVnf', + 'vdu': + [{'routing_table': + [{'network': '152.16.100.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'if': 'xe0'}, + {'network': '152.16.40.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'if': 'xe1'}], + 'description': 'VPE approximation using DPDK', + 'name': 'vpevnf-baremetal', + 'nd_route_tbl': + [{'network': '0064:ff9b:0:0:0:0:9810:6414', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0'}, + {'network': '0064:ff9b:0:0:0:0:9810:2814', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1'}], + 'id': 'vpevnf-baremetal', + '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': 0, + 'bandwidth': '10 Gbps', + 'driver': "i40e", + 'dst_ip': '152.16.100.20', + 'local_iface_name': '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:05:00.1', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'driver': "i40e", + 'netmask': '255.255.255.0', + 'dpdk_port_num': 1, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_iface_name': 'xe1', + 'local_mac': '00:00:00:00:00:01'}, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1'}]}], + 'description': 'Vpe approximation using DPDK', + 'mgmt-interface': + {'vdu-id': 'vpevnf-baremetal', + 'host': '1.1.1.1', + 'password': 'r00t', + 'user': 'root', + 'ip': '1.1.1.1'}, + 'benchmark': + {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']}, + 'connection-point': [{'type': 'VPORT', 'name': 'xe0'}, + {'type': 'VPORT', 'name': 'xe1'}], + 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}} TRAFFIC_PROFILE = { "schema": "isb:traffic_profile:0.1", @@ -140,12 +137,12 @@ class TestIXIATrafficGen(unittest.TestCase): "frame_size": 64}} TC_YAML = {'scenarios': [{'tc_options': - {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}}, + {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}}, 'runner': {'duration': 400, 'interval': 35, 'type': 'Duration'}, 'traffic_options': - {'flow': 'ipv4_1flow_Packets_vpe.yaml', - 'imix': 'imix_voice.yaml'}, + {'flow': 'ipv4_1flow_Packets_vpe.yaml', + 'imix': 'imix_voice.yaml'}, 'vnf_options': {'vpe': {'cfg': 'vpe_config'}}, 'traffic_profile': 'ipv4_throughput_vpe.yaml', 'type': 'NSPerf', @@ -195,7 +192,7 @@ class TestIXIATrafficGen(unittest.TestCase): 'vnf_config': {'lb_config': 'SW', 'lb_count': 1, 'worker_config': - '1C/1T', + '1C/1T', 'worker_threads': 1}} }}) ixnet_traffic_gen.topology = "" @@ -255,6 +252,7 @@ class TestIXIATrafficGen(unittest.TestCase): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE + mock_traffic_profile.ports = [0, 1] mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH) mock_ssh_instance.execute.return_value = 0, "", "" @@ -306,11 +304,10 @@ class TestIXIATrafficGen(unittest.TestCase): }, ] - mock_traffic_profile.execute.return_value = ['Completed', samples] + mock_traffic_profile.execute_traffic.return_value = ['Completed', samples] mock_traffic_profile.get_drop_percentage.return_value = ['Completed', samples] sut = IxiaTrafficGen(name, vnfd) - sut.tg_port_pairs = [[[0], [1]]] sut.vnf_port_pairs = [[[0], [1]]] sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML) sut.topology = "" @@ -325,13 +322,15 @@ class TestIXIATrafficGen(unittest.TestCase): sut.resource_helper.client = mock.MagicMock() sut.resource_helper.client_started = mock.MagicMock() sut.resource_helper.client_started.value = 1 + sut.resource_helper.rfc_helper.iteration.value = 11 sut.scenario_helper.scenario_cfg = { 'options': { 'packetsize': 64, 'traffic_type': 4, 'rfc2544': { - 'allowed_drop_rate': '0.8 - 1' + 'allowed_drop_rate': '0.8 - 1', + 'latency': True }, 'vnf__1': { 'rules': 'acl_1rule.yaml', @@ -347,7 +346,8 @@ class TestIXIATrafficGen(unittest.TestCase): 'task_path': '/path/to/task' } - with mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True) as mock_open: + with mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', + create=True) as mock_open: mock_open.return_value = mock.MagicMock() result = sut._traffic_runner(mock_traffic_profile) self.assertIsNone(result) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py index ad8c6494e..637706fb4 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py @@ -21,10 +21,9 @@ import unittest import mock from tests.unit import STL_MOCKS +SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' -SSH_HELPER = "yardstick.ssh.SSH" - STLClient = mock.MagicMock() stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) stl_patch.start() @@ -101,8 +100,8 @@ class TestTrexTrafficGenRFC(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'vld_id': 'private_1', - 'dpdk_port_num': '0', + 'vld_id': 'uplink_0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -121,8 +120,8 @@ class TestTrexTrafficGenRFC(unittest.TestCase): 'type': 'PCI-PASSTHROUGH', 'driver': "i40e", 'netmask': '255.255.255.0', - 'vld_id': 'public_1', - 'dpdk_port_num': '1', + 'vld_id': 'downlink_0', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', @@ -252,6 +251,8 @@ class TestTrexTrafficGenRFC(unittest.TestCase): trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0) trex_traffic_gen._start_server = mock.Mock(return_value=0) trex_traffic_gen.resource_helper = mock.MagicMock() + trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock() + scenario_cfg = { "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B", "topology": 'nsb_test_case.yaml', @@ -286,6 +287,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0) trex_traffic_gen.resource_helper = mock.MagicMock() + trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock() scenario_cfg = { "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B", "nodes": [ 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 65370dfa5..eb9f0525b 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 @@ -20,10 +20,11 @@ from __future__ import absolute_import import unittest import mock +SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' + from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh from tests.unit import STL_MOCKS - NAME = 'vnf_1' STLClient = mock.MagicMock() @@ -32,77 +33,77 @@ stl_patch.start() if stl_patch: from yardstick.network_services.vnf_generic.vnf.tg_trex import \ - TrexTrafficGen, TrexResourceHelper + TrexTrafficGen, TrexResourceHelper from yardstick.network_services.traffic_profile.base import TrafficProfile class TestTrexTrafficGen(unittest.TestCase): VNFD = {'vnfd:vnfd-catalog': - {'vnfd': - [{'short-name': 'VpeVnf', - 'vdu': - [{'routing_table': - [{'network': '152.16.100.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.100.20', - 'if': 'xe0'}, - {'network': '152.16.40.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.40.20', - 'if': 'xe1'}], - 'description': 'VPE approximation using DPDK', - 'name': 'vpevnf-baremetal', - 'nd_route_tbl': - [{'network': '0064:ff9b:0:0:0:0:9810:6414', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:6414', - 'if': 'xe0'}, - {'network': '0064:ff9b:0:0:0:0:9810:2814', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:2814', - 'if': 'xe1'}], - 'id': 'vpevnf-baremetal', - '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': '0', - 'bandwidth': '10 Gbps', - 'driver': "i40e", - 'dst_ip': '152.16.100.20', - 'local_iface_name': '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:05:00.1', - 'local_ip': '152.16.40.19', - 'type': 'PCI-PASSTHROUGH', - 'driver': "i40e", - 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', - 'bandwidth': '10 Gbps', - 'dst_ip': '152.16.40.20', - 'local_iface_name': 'xe1', - 'local_mac': '00:00:00:00:00:01'}, - 'vnfd-connection-point-ref': 'xe1', - 'name': 'xe1'}]}], - 'description': 'Vpe approximation using DPDK', - 'mgmt-interface': - {'vdu-id': 'vpevnf-baremetal', - 'host': '1.1.1.1', - 'password': 'r00t', - 'user': 'root', - 'ip': '1.1.1.1'}, - 'benchmark': - {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']}, - 'connection-point': [{'type': 'VPORT', 'name': 'xe0'}, - {'type': 'VPORT', 'name': 'xe1'}], - 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}} + {'vnfd': + [{'short-name': 'VpeVnf', + 'vdu': + [{'routing_table': + [{'network': '152.16.100.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'if': 'xe0'}, + {'network': '152.16.40.20', + 'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'if': 'xe1'}], + 'description': 'VPE approximation using DPDK', + 'name': 'vpevnf-baremetal', + 'nd_route_tbl': + [{'network': '0064:ff9b:0:0:0:0:9810:6414', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0'}, + {'network': '0064:ff9b:0:0:0:0:9810:2814', + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1'}], + 'id': 'vpevnf-baremetal', + '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': 0, + 'bandwidth': '10 Gbps', + 'driver': "i40e", + 'dst_ip': '152.16.100.20', + 'local_iface_name': '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:05:00.1', + 'local_ip': '152.16.40.19', + 'type': 'PCI-PASSTHROUGH', + 'driver': "i40e", + 'netmask': '255.255.255.0', + 'dpdk_port_num': 1, + 'bandwidth': '10 Gbps', + 'dst_ip': '152.16.40.20', + 'local_iface_name': 'xe1', + 'local_mac': '00:00:00:00:00:01'}, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1'}]}], + 'description': 'Vpe approximation using DPDK', + 'mgmt-interface': + {'vdu-id': 'vpevnf-baremetal', + 'host': '1.1.1.1', + 'password': 'r00t', + 'user': 'root', + 'ip': '1.1.1.1'}, + 'benchmark': + {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']}, + 'connection-point': [{'type': 'VPORT', 'name': 'xe0'}, + {'type': 'VPORT', 'name': 'xe1'}], + 'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}} TRAFFIC_PROFILE = { "schema": "isb:traffic_profile:0.1", @@ -112,16 +113,195 @@ class TestTrexTrafficGen(unittest.TestCase): "traffic_type": "FixedTraffic", "frame_rate": 100, # pps "flow_number": 10, - "frame_size": 64}} + "frame_size": 64 + }, + } + + SCENARIO_CFG = { + "options": { + "packetsize": 64, + "traffic_type": 4, + "rfc2544": { + "allowed_drop_rate": "0.8 - 1", + }, + "vnf__1": { + "rules": "acl_1rule.yaml", + "vnf_config": { + "lb_config": "SW", + "lb_count": 1, + "worker_config": "1C/1T", + "worker_threads": 1, + } + } + }, + "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7", + "tc": "tc_ipv4_1Mflow_64B_packetsize", + "runner": { + "object": "NetworkServiceTestCase", + "interval": 35, + "output_filename": "/tmp/yardstick.out", + "runner_id": 74476, "duration": 400, + "type": "Duration" + }, + "traffic_profile": "ipv4_throughput_acl.yaml", + "traffic_options": { + "flow": "ipv4_Packets_acl.yaml", + "imix": "imix_voice.yaml" + }, + "type": "ISB", + "nodes": { + "tg__2": "trafficgen_2.yardstick", + "tg__1": "trafficgen_1.yardstick", + "vnf__1": "vnf.yardstick" + }, + "topology": "udpreplay-tg-topology-baremetal.yaml" + } - @mock.patch("yardstick.ssh.SSH") + CONTEXT_CFG = { + "nodes": { + "vnf__1": { + "vnfd-id-ref": "vnf__1", + "ip": "1.2.1.1", + "interfaces": { + "xe0": { + "local_iface_name": "ens786f0", + "vld_id": TrafficProfile.UPLINK, + "netmask": "255.255.255.0", + "vpci": "0000:05:00.0", + "local_ip": "152.16.100.19", + "driver": "i40e", + "dst_ip": "152.16.100.20", + "local_mac": "00:00:00:00:00:02", + "dst_mac": "00:00:00:00:00:04", + "dpdk_port_num": 0 + }, + "xe1": { + "local_iface_name": "ens786f1", + "vld_id": TrafficProfile.DOWNLINK, + "netmask": "255.255.255.0", + "vpci": "0000:05:00.1", + "local_ip": "152.16.40.19", + "driver": "i40e", + "dst_ip": "152.16.40.20", + "local_mac": "00:00:00:00:00:01", + "dst_mac": "00:00:00:00:00:03", + "dpdk_port_num": 1 + } + }, + "host": "1.2.1.1", + "user": "root", + "nd_route_tbl": [ + { + "netmask": "112", + "if": "xe0", + "gateway": "0064:ff9b:0:0:0:0:9810:6414", + "network": "0064:ff9b:0:0:0:0:9810:6414" + }, + { + "netmask": "112", + "if": "xe1", + "gateway": "0064:ff9b:0:0:0:0:9810:2814", + "network": "0064:ff9b:0:0:0:0:9810:2814" + } + ], + "password": "r00t", + "VNF model": "udp_replay.yaml", + "name": "vnf.yardstick", + "member-vnf-index": "2", + "routing_table": [ + { + "netmask": "255.255.255.0", + "if": "xe0", + "gateway": "152.16.100.20", + "network": "152.16.100.20" + }, + { + "netmask": "255.255.255.0", + "if": "xe1", + "gateway": "152.16.40.20", + "network": "152.16.40.20" + } + ], + "role": "vnf" + }, + "trafficgen_2.yardstick": { + "member-vnf-index": "3", + "role": "TrafficGen", + "name": "trafficgen_2.yardstick", + "vnfd-id-ref": "tg__2", + "ip": "1.2.1.1", + "interfaces": { + "xe0": { + "local_iface_name": "ens513f0", + "vld_id": TrafficProfile.DOWNLINK, + "netmask": "255.255.255.0", + "vpci": "0000:02:00.0", + "local_ip": "152.16.40.20", + "driver": "ixgbe", + "dst_ip": "152.16.40.19", + "local_mac": "00:00:00:00:00:03", + "dst_mac": "00:00:00:00:00:01", + "dpdk_port_num": 0 + }, + "xe1": { + "local_iface_name": "ens513f1", + "netmask": "255.255.255.0", + "network": "202.16.100.0", + "local_ip": "202.16.100.20", + "driver": "ixgbe", + "local_mac": "00:1e:67:d0:60:5d", + "vpci": "0000:02:00.1", + "dpdk_port_num": 1 + } + }, + "password": "r00t", + "VNF model": "l3fwd_vnf.yaml", + "user": "root" + }, + "trafficgen_1.yardstick": { + "member-vnf-index": "1", + "role": "TrafficGen", + "name": "trafficgen_1.yardstick", + "vnfd-id-ref": "tg__1", + "ip": "1.2.1.1", + "interfaces": { + "xe0": { + "local_iface_name": "ens785f0", + "vld_id": TrafficProfile.UPLINK, + "netmask": "255.255.255.0", + "vpci": "0000:05:00.0", + "local_ip": "152.16.100.20", + "driver": "i40e", + "dst_ip": "152.16.100.19", + "local_mac": "00:00:00:00:00:04", + "dst_mac": "00:00:00:00:00:02", + "dpdk_port_num": 0 + }, + "xe1": { + "local_ip": "152.16.100.21", + "driver": "i40e", + "vpci": "0000:05:00.1", + "dpdk_port_num": 1, + "local_iface_name": "ens785f1", + "netmask": "255.255.255.0", + "local_mac": "00:00:00:00:00:01" + } + }, + "password": "r00t", + "VNF model": "tg_rfc2544_tpl.yaml", + "user": "root" + } + } + } + + @mock.patch(SSH_HELPER) def test___init__(self, ssh): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(NAME, vnfd) self.assertIsInstance(trex_traffic_gen.resource_helper, TrexResourceHelper) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test_collect_kpi(self, ssh): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -130,14 +310,14 @@ class TestTrexTrafficGen(unittest.TestCase): result = trex_traffic_gen.collect_kpi() self.assertEqual({}, result) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test_listen_traffic(self, ssh): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(NAME, vnfd) self.assertIsNone(trex_traffic_gen.listen_traffic({})) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test_instantiate(self, ssh): mock_ssh(ssh) @@ -150,9 +330,11 @@ class TestTrexTrafficGen(unittest.TestCase): trex_traffic_gen._tg_process._is_alive = mock.Mock(return_value=1) trex_traffic_gen.ssh_helper = mock.MagicMock() trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock() - self.assertIsNone(trex_traffic_gen.instantiate({}, {})) + trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock() + + self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test_instantiate_error(self, ssh): mock_ssh(ssh, exec_result=(1, "", "")) @@ -164,9 +346,10 @@ class TestTrexTrafficGen(unittest.TestCase): trex_traffic_gen._tg_process._is_alive = mock.Mock(return_value=0) trex_traffic_gen.ssh_helper = mock.MagicMock() trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock() - self.assertIsNone(trex_traffic_gen.instantiate({}, {})) + trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock() + self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test__start_server(self, ssh): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -175,13 +358,13 @@ class TestTrexTrafficGen(unittest.TestCase): trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock() self.assertIsNone(trex_traffic_gen._start_server()) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test__traffic_runner(self, ssh): mock_ssh(ssh) mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" - mock_traffic_profile.execute.return_value = "64" + mock_traffic_profile.execute_traffic.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -195,7 +378,7 @@ class TestTrexTrafficGen(unittest.TestCase): self.sut.resource_helper.QUEUE_WAIT_TIME = 0 self.sut._traffic_runner(mock_traffic_profile) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test__generate_trex_cfg(self, ssh): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -203,7 +386,7 @@ class TestTrexTrafficGen(unittest.TestCase): trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock() self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg()) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test_run_traffic(self, ssh): mock_ssh(ssh) @@ -221,21 +404,14 @@ class TestTrexTrafficGen(unittest.TestCase): self.sut._traffic_process.terminate() self.assertIsNotNone(result) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test_scale(self, ssh): mock_ssh(ssh, exec_result=(1, "", "")) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(NAME, vnfd) trex_traffic_gen.scale('') - @mock.patch("yardstick.ssh.SSH") - def test_setup_vnf_environment(self, ssh): - mock_ssh(ssh, exec_result=(1, "", "")) - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - trex_traffic_gen = TrexTrafficGen(NAME, vnfd) - self.assertIsNone(trex_traffic_gen.setup_helper.setup_vnf_environment()) - - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test_terminate(self, ssh): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -244,7 +420,7 @@ class TestTrexTrafficGen(unittest.TestCase): trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock() self.assertIsNone(trex_traffic_gen.terminate()) - @mock.patch("yardstick.ssh.SSH") + @mock.patch(SSH_HELPER) def test__connect_client(self, ssh): mock_ssh(ssh) vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] @@ -253,5 +429,6 @@ class TestTrexTrafficGen(unittest.TestCase): client.connect = mock.Mock(return_value=0) self.assertIsNotNone(trex_traffic_gen.resource_helper._connect(client)) + if __name__ == '__main__': unittest.main() diff --git a/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py b/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py index f0d75d57b..b75ed6764 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py @@ -22,6 +22,7 @@ import mock import os from tests.unit import STL_MOCKS +SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper' STLClient = mock.MagicMock() @@ -30,381 +31,455 @@ stl_patch.start() if stl_patch: from yardstick.network_services.vnf_generic.vnf.udp_replay import UdpReplayApproxVnf - from yardstick.network_services.vnf_generic.vnf import udp_replay + from yardstick.network_services.nfvi.resource import ResourceProfile + from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper + +from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh TEST_FILE_YAML = 'nsb_test_case.yaml' -NAME = "tg__1" +NAME = "vnf__1" @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process") -class TestAclApproxVnf(unittest.TestCase): - VNFD = {'vnfd:vnfd-catalog': - {'vnfd': - [{'short-name': 'VpeVnf', - 'vdu': - [{'routing_table': - [{'network': '152.16.100.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.100.20', - 'if': 'xe0'}, - {'network': '152.16.40.20', - 'netmask': '255.255.255.0', - 'gateway': '152.16.40.20', - 'if': 'xe1'}], - 'description': 'VPE approximation using DPDK', - 'name': 'vpevnf-baremetal', - 'nd_route_tbl': - [{'network': '0064:ff9b:0:0:0:0:9810:6414', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:6414', - 'if': 'xe0'}, - {'network': '0064:ff9b:0:0:0:0:9810:2814', - 'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:2814', - 'if': 'xe1'}], - 'id': 'vpevnf-baremetal', - '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': '0', - 'bandwidth': '10 Gbps', - 'driver': "i40e", - 'dst_ip': '152.16.100.20', - 'local_iface_name': '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:05:00.1', - 'local_ip': '152.16.40.19', - 'type': 'PCI-PASSTHROUGH', - 'driver': "i40e", - 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', - 'bandwidth': '10 Gbps', - 'dst_ip': '152.16.40.20', - 'local_iface_name': 'xe1', - 'local_mac': '00:00:00:00:00:01'}, - 'vnfd-connection-point-ref': 'xe1', - 'name': 'xe1'}]}], - 'description': 'Vpe approximation using DPDK', - 'mgmt-interface': - {'vdu-id': 'vpevnf-baremetal', - 'host': '1.2.1.1', - 'password': 'r00t', - 'user': 'root', - 'ip': '1.2.1.1'}, - 'benchmark': - {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']}, - 'connection-point': [{'type': 'VPORT', 'name': 'xe0'}, - {'type': 'VPORT', 'name': 'xe1'}], - 'id': 'UdpReplayApproxVnf', 'name': 'VPEVnfSsh'}]}} - - scenario_cfg = {'options': {'packetsize': 64, 'traffic_type': 4, - 'rfc2544': {'allowed_drop_rate': '0.8 - 1'}, - 'vnf__1': {'rules': 'acl_1rule.yaml', - 'vnf_config': {'lb_config': 'SW', - 'lb_count': 1, - 'worker_config': - '1C/1T', - 'worker_threads': 1}} - }, - 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7', - 'tc': 'tc_ipv4_1Mflow_64B_packetsize', - 'runner': {'object': 'NetworkServiceTestCase', - 'interval': 35, - 'output_filename': '/tmp/yardstick.out', - 'runner_id': 74476, 'duration': 400, - 'type': 'Duration'}, - 'traffic_profile': 'ipv4_throughput_acl.yaml', - 'traffic_options': {'flow': 'ipv4_Packets_acl.yaml', - 'imix': 'imix_voice.yaml'}, - 'type': 'ISB', - 'nodes': {'tg__2': 'trafficgen_2.yardstick', - 'tg__1': 'trafficgen_1.yardstick', - 'vnf__1': 'vnf.yardstick'}, - 'topology': 'vpe-tg-topology-baremetal.yaml'} - - context_cfg = {'nodes': {'trafficgen_2.yardstick': - {'member-vnf-index': '3', - 'role': 'TrafficGen', - 'name': 'trafficgen_2.yardstick', - 'vnfd-id-ref': 'tg__2', - 'ip': '1.2.1.1', - 'interfaces': - {'xe0': {'local_iface_name': 'ens513f0', - 'vld_id': 'public', - 'netmask': '255.255.255.0', - 'local_ip': '152.16.40.20', - 'dst_mac': '00:00:00:00:00:01', - 'local_mac': '00:00:00:00:00:03', - 'dst_ip': '152.16.40.19', - 'driver': 'ixgbe', - 'vpci': '0000:02:00.0', - 'dpdk_port_num': 0}, - 'xe1': {'local_iface_name': 'ens513f1', - 'netmask': '255.255.255.0', - 'network': '202.16.100.0', - 'local_ip': '202.16.100.20', - 'local_mac': '00:1e:67:d0:60:5d', - 'driver': 'ixgbe', - 'vpci': '0000:02:00.1', - 'dpdk_port_num': 1}}, - 'password': 'r00t', - 'VNF model': 'l3fwd_vnf.yaml', - 'user': 'root'}, - 'trafficgen_1.yardstick': - {'member-vnf-index': '1', - 'role': 'TrafficGen', - 'name': 'trafficgen_1.yardstick', - 'vnfd-id-ref': 'tg__1', - 'ip': '1.2.1.1', - 'interfaces': - {'xe0': {'local_iface_name': 'ens785f0', - 'vld_id': 'private', - 'netmask': '255.255.255.0', - 'local_ip': '152.16.100.20', - 'dst_mac': '00:00:00:00:00:02', - 'local_mac': '00:00:00:00:00:04', - 'dst_ip': '152.16.100.19', - 'driver': 'i40e', - 'vpci': '0000:05:00.0', - 'dpdk_port_num': 0}, - 'xe1': {'local_iface_name': 'ens785f1', - 'netmask': '255.255.255.0', - 'local_ip': '152.16.100.21', - 'local_mac': '00:00:00:00:00:01', - 'driver': 'i40e', - 'vpci': '0000:05:00.1', - 'dpdk_port_num': 1}}, - 'password': 'r00t', - 'VNF model': 'tg_rfc2544_tpl.yaml', - 'user': 'root'}, - 'vnf__1': - {'name': 'vnf.yardstick', - 'vnfd-id-ref': 'vnf__1', - 'ip': '1.2.1.1', - 'interfaces': - {'xe0': {'local_iface_name': 'ens786f0', - 'vld_id': 'private', - 'netmask': '255.255.255.0', - 'local_ip': '152.16.100.19', - 'dst_mac': '00:00:00:00:00:04', - 'local_mac': '00:00:00:00:00:02', - 'dst_ip': '152.16.100.20', - 'driver': 'i40e', - 'vpci': '0000:05:00.0', - 'dpdk_port_num': 0}, - 'xe1': {'local_iface_name': 'ens786f1', - 'vld_id': 'public', - 'netmask': '255.255.255.0', - 'local_ip': '152.16.40.19', - 'dst_mac': '00:00:00:00:00:03', - 'local_mac': '00:00:00:00:00:01', - 'dst_ip': '152.16.40.20', - 'driver': 'i40e', - 'vpci': '0000:05:00.1', - 'dpdk_port_num': 1}}, - 'routing_table': - [{'netmask': '255.255.255.0', - 'gateway': '152.16.100.20', - 'network': '152.16.100.20', - 'if': 'xe0'}, - {'netmask': '255.255.255.0', - 'gateway': '152.16.40.20', - 'network': '152.16.40.20', - 'if': 'xe1'}], - 'member-vnf-index': '2', - 'host': '1.2.1.1', - 'role': 'vnf', - 'user': 'root', - 'nd_route_tbl': - [{'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:6414', - 'network': '0064:ff9b:0:0:0:0:9810:6414', - 'if': 'xe0'}, - {'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:2814', - 'network': '0064:ff9b:0:0:0:0:9810:2814', - 'if': 'xe1'}], - 'password': 'r00t', - 'VNF model': 'udp_replay.yaml'}}} - - def test___init__(self, mock_process): - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) - self.assertIsNone(udp_approx_vnf._vnf_process) +class TestUdpReplayApproxVnf(unittest.TestCase): - @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") - def test_collect_kpi(self, mock_time, mock_process): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - result = "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \ - "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\ - "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \ - "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>" - udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) - udp_approx_vnf.q_in = mock.MagicMock() - udp_approx_vnf.q_out = mock.MagicMock() - udp_approx_vnf.q_out.qsize = mock.Mock(return_value=0) - udp_approx_vnf.all_ports = [0, 1] - udp_approx_vnf.interfaces = vnfd["vdu"][0]['external-interface'] - udp_approx_vnf.get_stats = mock.Mock(return_value=result) - result = {'collect_stats': {}, 'packets_dropped': 0, - 'packets_fwd': 14748451, 'packets_in': 14748472} - self.assertEqual(result, udp_approx_vnf.collect_kpi()) + VNFD_0 = { + 'short-name': 'UdpReplayVnf', + 'vdu': [ + { + 'description': 'UDPReplay approximation using DPDK', + 'routing_table': [ + { + 'netmask': '255.255.255.0', + 'if': 'xe0', + 'network': '152.16.100.20', + 'gateway': '152.16.100.20', + }, + { + 'netmask': '255.255.255.0', + 'if': 'xe1', + 'network': '152.16.40.20', + 'gateway': '152.16.40.20', + } + ], + 'external-interface': [ + { + 'virtual-interface': { + 'dst_mac': '00:00:00:00:00:04', + 'driver': 'i40e', + 'local_iface_name': 'xe0', + 'bandwidth': '10 Gbps', + 'local_ip': '152.16.100.19', + 'local_mac': '00:00:00:00:00:02', + 'vpci': '0000:05:00.0', + 'dpdk_port_num': 0, + 'netmask': '255.255.255.0', + 'dst_ip': '152.16.100.20', + 'type': 'PCI-PASSTHROUGH', + 'vld_id': 'uplink_0', + 'ifname': 'xe0', + }, + 'vnfd-connection-point-ref': 'xe0', + 'name': 'xe0', + }, + { + 'virtual-interface': { + 'dst_mac': '00:00:00:00:00:03', + 'driver': 'i40e', + 'local_iface_name': 'xe1', + 'bandwidth': '10 Gbps', + 'local_ip': '152.16.40.19', + 'local_mac': '00:00:00:00:00:01', + 'vpci': '0000:05:00.1', + 'dpdk_port_num': 1, + 'netmask': '255.255.255.0', + 'dst_ip': '152.16.40.20', + 'type': 'PCI-PASSTHROUGH', + 'vld_id': 'downlink_0', + 'ifname': 'xe1', + }, + 'vnfd-connection-point-ref': 'xe1', + 'name': 'xe1', + } + ], + 'nd_route_tbl': [ + { + 'netmask': '112', + 'if': 'xe0', + 'network': '0064:ff9b:0:0:0:0:9810:6414', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + }, + { + 'netmask': '112', + 'if': 'xe1', + 'network': '0064:ff9b:0:0:0:0:9810:2814', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + } + ], + 'id': 'udpreplayvnf-baremetal', + 'name': 'udpreplayvnf-baremetal', + } + ], + 'description': 'UDPReplay approximation using DPDK', + 'name': 'VPEVnfSsh', + 'mgmt-interface': { + 'vdu-id': 'udpreplay-baremetal', + 'host': '1.2.1.1', + 'password': 'r00t', + 'user': 'root', + 'ip': '1.2.1.1', + }, + 'benchmark': { + 'kpi': [ + 'packets_in', + 'packets_fwd', + 'packets_dropped', + ] + }, + 'connection-point': [ + { + 'type': 'VPORT', + 'name': 'xe0', + }, + { + 'type': 'VPORT', + 'name': 'xe1', + } + ], + 'id': 'UdpReplayApproxVnf', + } + + SCENARIO_CFG = { + "options": { + "packetsize": 64, + "traffic_type": 4, + "rfc2544": { + "allowed_drop_rate": "0.8 - 1", + }, + "vnf__1": { + "rules": "acl_1rule.yaml", + "vnf_config": { + "lb_config": "SW", + "lb_count": 1, + "worker_config": "1C/1T", + "worker_threads": 1, + }, + "hw_csum": "false", + } + }, + "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7", + "tc": "tc_ipv4_1Mflow_64B_packetsize", + "runner": { + "object": "NetworkServiceTestCase", + "interval": 35, + "output_filename": "/tmp/yardstick.out", + "runner_id": 74476, "duration": 400, + "type": "Duration" + }, + "traffic_profile": "ipv4_throughput_acl.yaml", + "traffic_options": { + "flow": "ipv4_Packets_acl.yaml", + "imix": "imix_voice.yaml" + }, + "type": "ISB", + "nodes": { + "tg__2": "trafficgen_2.yardstick", + "tg__1": "trafficgen_1.yardstick", + "vnf__1": "vnf.yardstick" + }, + "topology": "udpreplay-tg-topology-baremetal.yaml" + } + + CONTEXT_CFG = { + "nodes": { + "vnf__1": { + "vnfd-id-ref": "vnf__1", + "ip": "1.2.1.1", + "interfaces": { + "xe0": { + "local_iface_name": "ens786f0", + "vld_id": UdpReplayApproxVnf.UPLINK, + "netmask": "255.255.255.0", + "vpci": "0000:05:00.0", + "local_ip": "152.16.100.19", + "driver": "i40e", + "dst_ip": "152.16.100.20", + "local_mac": "00:00:00:00:00:02", + "dst_mac": "00:00:00:00:00:04", + "dpdk_port_num": 0 + }, + "xe1": { + "local_iface_name": "ens786f1", + "vld_id": UdpReplayApproxVnf.DOWNLINK, + "netmask": "255.255.255.0", + "vpci": "0000:05:00.1", + "local_ip": "152.16.40.19", + "driver": "i40e", + "dst_ip": "152.16.40.20", + "local_mac": "00:00:00:00:00:01", + "dst_mac": "00:00:00:00:00:03", + "dpdk_port_num": 1 + } + }, + "host": "1.2.1.1", + "user": "root", + "nd_route_tbl": [ + { + "netmask": "112", + "if": "xe0", + "gateway": "0064:ff9b:0:0:0:0:9810:6414", + "network": "0064:ff9b:0:0:0:0:9810:6414" + }, + { + "netmask": "112", + "if": "xe1", + "gateway": "0064:ff9b:0:0:0:0:9810:2814", + "network": "0064:ff9b:0:0:0:0:9810:2814" + } + ], + "password": "r00t", + "VNF model": "udp_replay.yaml", + "name": "vnf.yardstick", + "member-vnf-index": "2", + "routing_table": [ + { + "netmask": "255.255.255.0", + "if": "xe0", + "gateway": "152.16.100.20", + "network": "152.16.100.20" + }, + { + "netmask": "255.255.255.0", + "if": "xe1", + "gateway": "152.16.40.20", + "network": "152.16.40.20" + } + ], + "role": "vnf" + }, + "trafficgen_2.yardstick": { + "member-vnf-index": "3", + "role": "TrafficGen", + "name": "trafficgen_2.yardstick", + "vnfd-id-ref": "tg__2", + "ip": "1.2.1.1", + "interfaces": { + "xe0": { + "local_iface_name": "ens513f0", + "vld_id": UdpReplayApproxVnf.DOWNLINK, + "netmask": "255.255.255.0", + "vpci": "0000:02:00.0", + "local_ip": "152.16.40.20", + "driver": "ixgbe", + "dst_ip": "152.16.40.19", + "local_mac": "00:00:00:00:00:03", + "dst_mac": "00:00:00:00:00:01", + "dpdk_port_num": 0 + }, + "xe1": { + "local_iface_name": "ens513f1", + "netmask": "255.255.255.0", + "network": "202.16.100.0", + "local_ip": "202.16.100.20", + "driver": "ixgbe", + "local_mac": "00:1e:67:d0:60:5d", + "vpci": "0000:02:00.1", + "dpdk_port_num": 1 + } + }, + "password": "r00t", + "VNF model": "l3fwd_vnf.yaml", + "user": "root" + }, + "trafficgen_1.yardstick": { + "member-vnf-index": "1", + "role": "TrafficGen", + "name": "trafficgen_1.yardstick", + "vnfd-id-ref": "tg__1", + "ip": "1.2.1.1", + "interfaces": { + "xe0": { + "local_iface_name": "ens785f0", + "vld_id": UdpReplayApproxVnf.UPLINK, + "netmask": "255.255.255.0", + "vpci": "0000:05:00.0", + "local_ip": "152.16.100.20", + "driver": "i40e", + "dst_ip": "152.16.100.19", + "local_mac": "00:00:00:00:00:04", + "dst_mac": "00:00:00:00:00:02", + "dpdk_port_num": 0 + }, + "xe1": { + "local_ip": "152.16.100.21", + "driver": "i40e", + "vpci": "0000:05:00.1", + "dpdk_port_num": 1, + "local_iface_name": "ens785f1", + "netmask": "255.255.255.0", + "local_mac": "00:00:00:00:00:01" + } + }, + "password": "r00t", + "VNF model": "tg_rfc2544_tpl.yaml", + "user": "root" + } + } + } + + def test___init__(self, _): + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0) + self.assertIsNone(udp_replay_approx_vnf._vnf_process) @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") - def test_vnf_execute_command(self, mock_time, mock_process): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) - cmd = "quit" - self.assertEqual("", udp_approx_vnf.vnf_execute(cmd)) - - def test_get_stats(self, mock_process): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) - udp_approx_vnf.q_in = mock.MagicMock() - udp_approx_vnf.q_out = mock.MagicMock() - udp_approx_vnf.q_out.qsize = mock.Mock(return_value=0) - mock_result = \ - "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress" - udp_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result) - self.assertEqual(mock_result, - udp_approx_vnf.get_stats()) + @mock.patch(SSH_HELPER) + def test_collect_kpi(self, ssh, mock_time, _): + mock_ssh(ssh) + + vnfd = self.VNFD_0 + result = "stats\r\r\n\r\nUDP_Replay stats:\r\n--------------\r\n" \ + "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\ + "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \ + "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>" + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) + udp_replay_approx_vnf.q_in = mock.MagicMock() + udp_replay_approx_vnf.q_out = mock.MagicMock() + udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0) + udp_replay_approx_vnf.all_ports = ["xe0", "xe1"] + udp_replay_approx_vnf.get_stats = mock.Mock(return_value=result) + result = {'collect_stats': {}, 'packets_dropped': 0, + 'packets_fwd': 14748451, 'packets_in': 14748472} + self.assertEqual(result, udp_replay_approx_vnf.collect_kpi()) + + @mock.patch(SSH_HELPER) + def test_get_stats(self, ssh, _): + mock_ssh(ssh) + + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0) + udp_replay_approx_vnf.q_in = mock.MagicMock() + udp_replay_approx_vnf.q_out = mock.MagicMock() + udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0) + mock_result = \ + "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress" + + udp_replay_approx_vnf.vnf_execute = mock.Mock(return_value=mock_result) + + self.assertEqual(mock_result, + udp_replay_approx_vnf.get_stats()) def _get_file_abspath(self, filename): curr_path = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(curr_path, filename) return file_path + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch(SSH_HELPER) + def test__build_config(self, ssh, mock_context, *_): + mock_ssh(ssh) + + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0) + udp_replay_approx_vnf.queue_wrapper = mock.MagicMock() + udp_replay_approx_vnf.nfvi_context = mock_context + udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'} + udp_replay_approx_vnf.setup_helper.bound_pci = [] + udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path") + udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1') + udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG + + cmd_line = udp_replay_approx_vnf._build_config() + + expected = \ + "sudo tool_path --log-level=5 -c 0x7 -n 4 -w -- -p 0x3 --config='(0,0,1),(1,0,2)'" + self.assertEqual(cmd_line, expected) + @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open') - def test__build_pipeline_kwargs(self, mock_open, mock_process): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh.from_node.return_value = ssh_mock - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) - udp_approx_vnf._build_config = mock.MagicMock() - udp_approx_vnf.queue_wrapper = mock.MagicMock() - udp_approx_vnf.nfvi_type = "baremetal" - udp_approx_vnf.bound_pci = [] - udp_approx_vnf.all_ports = [0, 1] - udp_approx_vnf.ssh_helper = mock.MagicMock( - **{"provision_tool.return_value": "tool_path"}) - udp_approx_vnf.vnf_cfg = {'lb_config': 'SW', - 'lb_count': 1, - 'worker_config': '1C/1T', - 'worker_threads': 1} - udp_approx_vnf.options = {'traffic_type': '4', - 'topology': 'nsb_test_case.yaml'} - - udp_approx_vnf._build_pipeline_kwargs() - self.assertEqual(udp_approx_vnf.pipeline_kwargs, { - 'config': '(0, 0, 1)(1, 0, 2)', - 'cpu_mask_hex': '0x6', - 'hw_csum': '', - 'ports_len_hex': '0x3', - 'tool_path': 'tool_path', - 'whitelist': '' - }) - - @mock.patch("yardstick.network_services.vnf_generic.vnf.udp_replay.hex") - @mock.patch("yardstick.network_services.vnf_generic.vnf.udp_replay.eval") - @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open') - def test_run_udp_replay(self, mock_open, eval, hex, mock_process): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh_mock.run = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) - udp_approx_vnf._build_config = mock.MagicMock() - udp_approx_vnf.queue_wrapper = mock.MagicMock() - udp_approx_vnf.ssh_helper = mock.MagicMock() - udp_approx_vnf.ssh_helper.run = mock.MagicMock() - udp_approx_vnf.vnf_cfg = {'lb_config': 'SW', - 'lb_count': 1, - 'worker_config': '1C/1T', - 'worker_threads': 1} - udp_approx_vnf.options = {'traffic_type': '4', - 'topology': 'nsb_test_case.yaml'} - - udp_approx_vnf._run() - udp_approx_vnf.ssh_helper.run.assert_called_once() + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch(SSH_HELPER) + def test__build_pipeline_kwargs(self, ssh, mock_context, *_): + mock_ssh(ssh) + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0) + udp_replay_approx_vnf.nfvi_context = mock_context + udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'} + udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3'] + udp_replay_approx_vnf.all_ports = ["xe0", "xe1"] + udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path") + udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1') + udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG + + udp_replay_approx_vnf._build_pipeline_kwargs() + + self.assertEqual(udp_replay_approx_vnf.pipeline_kwargs, { + 'config': '(0,0,1),(1,0,2)', + 'cpu_mask_hex': '0x7', + 'hw_csum': '', + 'port_mask_hex': '0x3', + 'tool_path': 'tool_path', + 'whitelist': '0000:00:0.1 -w 0000:00:0.3' + }) + + @mock.patch(SSH_HELPER) + def test_run_udp_replay(self, ssh, _): + mock_ssh(ssh) + + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0) + udp_replay_approx_vnf._build_config = mock.MagicMock() + udp_replay_approx_vnf.queue_wrapper = mock.MagicMock() + + udp_replay_approx_vnf._run() + + udp_replay_approx_vnf.ssh_helper.run.assert_called_once() @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") - def test_instantiate(self, Context, mock_process): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) - self.scenario_cfg['vnf_options'] = {'cgnapt': {'cfg': "", - 'rules': ""}} - udp_approx_vnf._run_udp_replay = mock.Mock(return_value=0) - udp_approx_vnf._parse_rule_file = mock.Mock(return_value={}) - udp_approx_vnf.deploy_udp_replay_vnf = mock.Mock(return_value=1) - udp_approx_vnf.q_out.put("Replay>") - udp_approx_vnf.get_my_ports = mock.Mock(return_value=[0, 1]) - udp_replay.WAIT_TIME = 3 - udp_approx_vnf.get_nfvi_type = mock.Mock(return_value="baremetal") - - udp_approx_vnf._vnf_process = mock.MagicMock() - udp_approx_vnf._vnf_process.is_alive = \ - mock.Mock(return_value=1) - self.assertIsNone(udp_approx_vnf.instantiate(self.scenario_cfg, - self.context_cfg)) - - def test_scale(self, mock_process): - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) + @mock.patch(SSH_HELPER) + def test_instantiate(self, ssh, *_): + mock_ssh(ssh) + + resource = mock.Mock(autospec=ResourceProfile) + + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0) + udp_replay_approx_vnf.q_out.put("Replay>") + udp_replay_approx_vnf.WAIT_TIME = 0 + udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock() + + self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)) + + udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1) + udp_replay_approx_vnf._vnf_process.exitcode = 0 + + self.assertEquals(udp_replay_approx_vnf.wait_for_instantiate(), 0) + + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch('yardstick.ssh.SSH') + @mock.patch(SSH_HELPER) + def test_instantiate_panic(self, ssh, resource_ssh, *_): + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0) + udp_replay_approx_vnf.WAIT_TIME = 0 + udp_replay_approx_vnf.q_out.put("some text PANIC some text") + udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock() + + self.assertIsNone(udp_replay_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)) + with self.assertRaises(RuntimeError): + udp_replay_approx_vnf.wait_for_instantiate() + + def test_scale(self, _): + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0) flavor = "" - self.assertRaises(NotImplementedError, udp_approx_vnf.scale, flavor) + + self.assertRaises(NotImplementedError, udp_replay_approx_vnf.scale, flavor) @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time") - def test_terminate(self, mock_time, mock_process): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "", "")) - ssh.from_node.return_value = ssh_mock - vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] - udp_approx_vnf = UdpReplayApproxVnf(NAME, vnfd) - udp_approx_vnf._vnf_process = mock.MagicMock() - udp_approx_vnf._vnf_process.terminate = mock.Mock() - udp_approx_vnf.used_drivers = {"01:01.0": "i40e", - "01:01.1": "i40e"} - udp_approx_vnf.execute_command = mock.Mock() - udp_approx_vnf.ssh_helper = ssh_mock - udp_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py" - self.assertEqual(None, udp_approx_vnf.terminate()) + @mock.patch(SSH_HELPER) + def test_terminate(self, ssh, mock_time, _): + mock_ssh(ssh) + + udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0) + udp_replay_approx_vnf._vnf_process = mock.MagicMock() + udp_replay_approx_vnf._vnf_process.terminate = mock.Mock() + udp_replay_approx_vnf.used_drivers = {"01:01.0": "i40e", "01:01.1": "i40e"} + udp_replay_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py" + self.assertEqual(None, udp_replay_approx_vnf.terminate()) if __name__ == '__main__': unittest.main() diff --git a/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py index c3d53ff03..958099a03 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py @@ -73,7 +73,7 @@ class TestFWApproxVnf(unittest.TestCase): 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', @@ -88,7 +88,7 @@ class TestFWApproxVnf(unittest.TestCase): 'type': 'PCI-PASSTHROUGH', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', @@ -142,7 +142,7 @@ class TestFWApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens513f0', - 'vld_id': 'public', + 'vld_id': FWApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -170,7 +170,7 @@ class TestFWApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens785f0', - 'vld_id': 'private', + 'vld_id': FWApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -195,7 +195,7 @@ class TestFWApproxVnf(unittest.TestCase): 'ip': '1.2.1.1', 'interfaces': {'xe0': {'local_iface_name': 'ens786f0', - 'vld_id': 'private', + 'vld_id': FWApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -205,7 +205,7 @@ class TestFWApproxVnf(unittest.TestCase): 'vpci': '0000:05:00.0', 'dpdk_port_num': 0}, 'xe1': {'local_iface_name': 'ens786f1', - 'vld_id': 'public', + 'vld_id': FWApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', diff --git a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py index ffd0d539b..757109d11 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py @@ -36,8 +36,8 @@ stl_patch.start() if stl_patch: from yardstick.network_services.vnf_generic.vnf.vpe_vnf import ConfigCreate from yardstick.network_services.nfvi.resource import ResourceProfile - from yardstick.network_services.vnf_generic.vnf import vpe_vnf - from yardstick.network_services.vnf_generic.vnf.vpe_vnf import VpeApproxVnf + from yardstick.network_services.vnf_generic.vnf.vpe_vnf import \ + VpeApproxVnf, VpeApproxSetupEnvHelper from tests.unit.network_services.vnf_generic.vnf.test_base import FileAbsPath from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh @@ -57,8 +57,8 @@ class TestConfigCreate(unittest.TestCase): def test___init__(self): config_create = ConfigCreate([0], [1], 2) - self.assertEqual(config_create.priv_ports, [0]) - self.assertEqual(config_create.pub_ports, [1]) + self.assertEqual(config_create.uplink_ports, [0]) + self.assertEqual(config_create.downlink_ports, [1]) self.assertEqual(config_create.socket, 2) def test_vpe_initialize(self): @@ -110,7 +110,7 @@ class TestConfigCreate(unittest.TestCase): self.assertNotEqual(result, '') def test_create_vpe_config(self): - priv_ports = [ + uplink_ports = [ { 'index': 0, 'dpdk_port_num': 1, @@ -121,7 +121,7 @@ class TestConfigCreate(unittest.TestCase): }, ] - pub_ports = [ + downlink_ports = [ { 'index': 2, 'dpdk_port_num': 3, @@ -132,7 +132,7 @@ class TestConfigCreate(unittest.TestCase): }, ] - config_create = ConfigCreate(priv_ports, pub_ports, 23) + config_create = ConfigCreate(uplink_ports, downlink_ports, 23) curr_path = os.path.dirname(os.path.abspath(__file__)) vpe_cfg = "samples/vnf_samples/nsut/vpe/vpe_config" vnf_cfg = os.path.join(curr_path, "../../../../..", vpe_cfg) @@ -185,14 +185,15 @@ class TestVpeApproxVnf(unittest.TestCase): 'vpci': '0000:05:00.0', 'local_ip': '152.16.100.19', 'type': 'PCI-PASSTHROUGH', - 'vld_id': '', 'netmask': '255.255.255.0', - 'dpdk_port_num': '0', + 'dpdk_port_num': 0, 'bandwidth': '10 Gbps', 'driver': "i40e", 'dst_ip': '152.16.100.20', 'local_iface_name': 'xe0', 'local_mac': '00:00:00:00:00:02', + 'vld_id': 'uplink_0', + 'ifname': 'xe0', }, 'vnfd-connection-point-ref': 'xe0', 'name': 'xe0', @@ -203,14 +204,15 @@ class TestVpeApproxVnf(unittest.TestCase): 'vpci': '0000:05:00.1', 'local_ip': '152.16.40.19', 'type': 'PCI-PASSTHROUGH', - 'vld_id': '', 'driver': "i40e", 'netmask': '255.255.255.0', - 'dpdk_port_num': '1', + 'dpdk_port_num': 1, 'bandwidth': '10 Gbps', 'dst_ip': '152.16.40.20', 'local_iface_name': 'xe1', 'local_mac': '00:00:00:00:00:01', + 'vld_id': 'downlink_0', + 'ifname': 'xe1', }, 'vnfd-connection-point-ref': 'xe1', 'name': 'xe1', @@ -258,7 +260,7 @@ class TestVpeApproxVnf(unittest.TestCase): SCENARIO_CFG = { 'options': { 'packetsize': 64, - 'traffic_type': 4 , + 'traffic_type': 4, 'rfc2544': { 'allowed_drop_rate': '0.8 - 1', }, @@ -308,7 +310,7 @@ class TestVpeApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens513f0', - 'vld_id': 'public', + 'vld_id': VpeApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.20', 'dst_mac': '00:00:00:00:00:01', @@ -342,7 +344,7 @@ class TestVpeApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens785f0', - 'vld_id': 'private', + 'vld_id': VpeApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.20', 'dst_mac': '00:00:00:00:00:02', @@ -373,7 +375,7 @@ class TestVpeApproxVnf(unittest.TestCase): 'interfaces': { 'xe0': { 'local_iface_name': 'ens786f0', - 'vld_id': 'private', + 'vld_id': VpeApproxVnf.UPLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.100.19', 'dst_mac': '00:00:00:00:00:04', @@ -385,7 +387,7 @@ class TestVpeApproxVnf(unittest.TestCase): }, 'xe1': { 'local_iface_name': 'ens786f1', - 'vld_id': 'public', + 'vld_id': VpeApproxVnf.DOWNLINK, 'netmask': '255.255.255.0', 'local_ip': '152.16.40.19', 'dst_mac': '00:00:00:00:00:03', @@ -499,9 +501,6 @@ class TestVpeApproxVnf(unittest.TestCase): vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0) vpe_approx_vnf.tc_file_name = get_file_abspath(TEST_FILE_YAML) - vpe_approx_vnf.generate_port_pairs = mock.Mock() - vpe_approx_vnf.tg_port_pairs = [[[0], [1]]] - vpe_approx_vnf.vnf_port_pairs = [[[0], [1]]] vpe_approx_vnf.vnf_cfg = { 'lb_config': 'SW', 'lb_count': 1, @@ -513,16 +512,56 @@ class TestVpeApproxVnf(unittest.TestCase): NAME: { 'traffic_type': '4', 'topology': 'nsb_test_case.yaml', + 'vnf_config': 'vpe_config', } } } vpe_approx_vnf.topology = "nsb_test_case.yaml" vpe_approx_vnf.nfvi_type = "baremetal" vpe_approx_vnf._provide_config_file = mock.Mock() + vpe_approx_vnf._build_config = mock.MagicMock() self.assertIsInstance(vpe_approx_vnf.ssh_helper, mock.Mock) + self.assertIsInstance(vpe_approx_vnf.ssh_helper, mock.Mock) self.assertIsNone(vpe_approx_vnf._run()) + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig") + @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context") + @mock.patch("yardstick.network_services.vnf_generic.vnf.vpe_vnf.ConfigCreate") + @mock.patch("yardstick.network_services.vnf_generic.vnf.vpe_vnf.open") + @mock.patch(SSH_HELPER) + def test_build_config(self, mock_mul, mock_context, mock_config, mock_open, ssh, _): + mock_ssh(ssh) + vpe_approx_vnf = VpeApproxSetupEnvHelper(mock.MagicMock(), + mock.MagicMock, mock.MagicMock) + vpe_approx_vnf.tc_file_name = get_file_abspath(TEST_FILE_YAML) + vpe_approx_vnf.generate_port_pairs = mock.Mock() + vpe_approx_vnf.vnf_cfg = { + 'lb_config': 'SW', + 'lb_count': 1, + 'worker_config': '1C/1T', + 'worker_threads': 1, + } + vpe_approx_vnf.scenario_helper.scenario_cfg = { + 'options': { + NAME: { + 'traffic_type': '4', + 'topology': 'nsb_test_case.yaml', + 'vnf_config': 'vpe_config', + } + } + } + vpe_approx_vnf.topology = "nsb_test_case.yaml" + vpe_approx_vnf.nfvi_type = "baremetal" + vpe_approx_vnf._provide_config_file = mock.Mock() + + vpe_approx_vnf.ssh_helper = mock.MagicMock() + vpe_approx_vnf.scenario_helper = mock.MagicMock() + vpe_approx_vnf.ssh_helper.bin_path = mock.Mock() + vpe_approx_vnf.ssh_helper.upload_config_file = mock.MagicMock() + self.assertIsNone(vpe_approx_vnf._build_vnf_ports()) + self.assertIsNotNone(vpe_approx_vnf.build_config()) + @mock.patch(SSH_HELPER) def test_wait_for_instantiate(self, ssh, _): mock_ssh(ssh) diff --git a/tests/unit/test_ssh.py b/tests/unit/test_ssh.py index 27ed68c7b..b298c745b 100644 --- a/tests/unit/test_ssh.py +++ b/tests/unit/test_ssh.py @@ -527,7 +527,7 @@ class TestAutoConnectSSH(unittest.TestCase): 'key_filename': None, 'password': None, 'name': None, - 'wait': False, + 'wait': True, } result = auto_connect_ssh._make_dict() self.assertDictEqual(result, expected) |