summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/ci/prepare_env.sh57
-rwxr-xr-xtests/ci/prepare_storperf_admin-rc.sh5
-rw-r--r--tests/opnfv/test_suites/opnfv_k8-nosdn-lb_ceph-noha_daily.yaml18
-rw-r--r--tests/opnfv/test_suites/opnfv_os-odl-bgpvpn-noha_daily.yaml23
-rw-r--r--tests/unit/__init__.py64
-rw-r--r--tests/unit/network_services/collector/test_publisher.py2
-rw-r--r--tests/unit/network_services/collector/test_subscriber.py2
-rw-r--r--tests/unit/network_services/helpers/test_cpu.py2
-rw-r--r--tests/unit/network_services/helpers/test_dpdkbindnic_helper.py404
-rw-r--r--tests/unit/network_services/helpers/test_samplevnf_helper.py405
-rw-r--r--tests/unit/network_services/libs/ixia_libs/test_IxNet.py4
-rw-r--r--tests/unit/network_services/nfvi/test_collectd.py54
-rw-r--r--tests/unit/network_services/nfvi/test_resource.py5
-rw-r--r--tests/unit/network_services/traffic_profile/test_base.py43
-rw-r--r--tests/unit/network_services/traffic_profile/test_fixed.py4
-rw-r--r--tests/unit/network_services/traffic_profile/test_http.py10
-rw-r--r--tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py13
-rw-r--r--tests/unit/network_services/traffic_profile/test_prox_binsearch.py94
-rw-r--r--tests/unit/network_services/traffic_profile/test_prox_profile.py21
-rw-r--r--tests/unit/network_services/traffic_profile/test_rfc2544.py80
-rw-r--r--tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py (renamed from tests/unit/network_services/traffic_profile/test_traffic_profile.py)34
-rw-r--r--tests/unit/network_services/vnf_generic/test_vnfdgen.py2
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py7
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_base.py4
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py2
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py35
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py31
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py7
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py105
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py59
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py4
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py2
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py12
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py2
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py6
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py2
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py7
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py2
38 files changed, 974 insertions, 659 deletions
diff --git a/tests/ci/prepare_env.sh b/tests/ci/prepare_env.sh
index caef8acce..886e50e21 100755
--- a/tests/ci/prepare_env.sh
+++ b/tests/ci/prepare_env.sh
@@ -19,7 +19,8 @@
# Extract network name from EXTERNAL_NETWORK
# e.g. EXTERNAL_NETWORK='ext-net;flat;192.168.0.2;192.168.0.253;192.168.0.1;192.168.0.0/24'
-export EXTERNAL_NETWORK=$(echo $EXTERNAL_NETWORK | cut -f1 -d \;)
+EXTERNAL_NETWORK=$(echo ${EXTERNAL_NETWORK} | cut -f1 -d \;)
+export EXTERNAL_NETWORK
# Create openstack credentials
echo "INFO: Creating openstack credentials .."
@@ -28,44 +29,22 @@ OPENRC=/etc/yardstick/openstack.creds
INSTALLERS=(apex compass fuel joid)
RC_VAR_EXIST=false
-if [ "${OS_AUTH_URL}" -a "${OS_USERNAME}" -a "${OS_PASSWORD}" -a "${EXTERNAL_NETWORK}" ];then
+if [[ "${OS_AUTH_URL}" && "${OS_USERNAME}" && "${OS_PASSWORD}" && "${EXTERNAL_NETWORK}" ]];then
RC_VAR_EXIST=true
fi
-if [ "${RC_VAR_EXIST}" = false ]; then
- if [ ! -f $OPENRC ];then
- # credentials file is not given, check if environment variables are set
- # to get the creds using fetch_os_creds.sh later on
- echo "INFO: Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
- if [ -z ${INSTALLER_TYPE} ]; then
- echo "environment variable 'INSTALLER_TYPE' is not defined."
- exit 1
- elif [[ ${INSTALLERS[@]} =~ ${INSTALLER_TYPE} ]]; then
- echo "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
- else
- echo "Invalid env variable INSTALLER_TYPE=${INSTALLER_TYPE}"
- exit 1
- fi
-
- if [ "$DEPLOY_TYPE" == "virt" ]; then
- FETCH_CRED_ARG="-v -d $OPENRC -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}"
- else
- FETCH_CRED_ARG="-d $OPENRC -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}"
- fi
-
- $RELENG_REPO_DIR/utils/fetch_os_creds.sh $FETCH_CRED_ARG
- fi
- source $OPENRC
+if [[ "${RC_VAR_EXIST}" = false && -f ${OPENRC} ]]; then
+ . ${OPENRC}
fi
export EXTERNAL_NETWORK INSTALLER_TYPE DEPLOY_TYPE NODE_NAME
# Prepare a admin-rc file for StorPerf integration
-$YARDSTICK_REPO_DIR/tests/ci/prepare_storperf_admin-rc.sh
+"${YARDSTICK_REPO_DIR}"/tests/ci/prepare_storperf_admin-rc.sh
# copy Storperf related files to the deployment location
if [ "$INSTALLER_TYPE" == "compass" ]; then
- source $YARDSTICK_REPO_DIR/tests/ci/scp_storperf_files.sh
+ . "${YARDSTICK_REPO_DIR}"/tests/ci/scp_storperf_files.sh
fi
# Fetching id_rsa file from jump_server..."
@@ -73,7 +52,7 @@ verify_connectivity() {
local ip=$1
echo "Verifying connectivity to $ip..."
for i in $(seq 0 10); do
- if ping -c 1 -W 1 $ip > /dev/null; then
+ if ping -c 1 -W 1 "${ip}" > /dev/null; then
echo "$ip is reachable!"
return 0
fi
@@ -87,34 +66,34 @@ ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
if [ "$INSTALLER_TYPE" == "fuel" ]; then
# check the connection
- verify_connectivity $INSTALLER_IP
+ verify_connectivity "${INSTALLER_IP}"
pod_yaml="$YARDSTICK_REPO_DIR/etc/yardstick/nodes/fuel_baremetal/pod.yaml"
# update "ip" according to the CI env
- ssh -l ubuntu ${INSTALLER_IP} -i ${SSH_KEY} ${ssh_options} \
+ ssh -l ubuntu "${INSTALLER_IP}" -i ${SSH_KEY} ${ssh_options} \
"sudo salt -C 'ctl* or cmp*' grains.get fqdn_ip4 --out yaml">node_info
- controller_ips=($(cat node_info|awk '/ctl/{getline; print $2}'))
- compute_ips=($(cat node_info|awk '/cmp/{getline; print $2}'))
+ controller_ips=($(awk '/ctl/{getline; print $2} < node_info'))
+ compute_ips=($(awk '/cmp/{getline; print $2} < node_info'))
if [[ ${controller_ips[0]} ]]; then
- sed -i "s|ip1|${controller_ips[0]}|" $pod_yaml;
+ sed -i "s|ip1|${controller_ips[0]}|" "${pod_yaml}"
fi
if [[ ${controller_ips[1]} ]]; then
- sed -i "s|ip2|${controller_ips[1]}|" $pod_yaml;
+ sed -i "s|ip2|${controller_ips[1]}|" "${pod_yaml}"
fi
if [[ ${controller_ips[2]} ]]; then
- sed -i "s|ip3|${controller_ips[2]}|" $pod_yaml;
+ sed -i "s|ip3|${controller_ips[2]}|" "${pod_yaml}"
fi
if [[ ${compute_ips[0]} ]]; then
- sed -i "s|ip4|${compute_ips[0]}|" $pod_yaml;
+ sed -i "s|ip4|${compute_ips[0]}|" "${pod_yaml}"
fi
if [[ ${compute_ips[1]} ]]; then
- sed -i "s|ip5|${compute_ips[1]}|" $pod_yaml;
+ sed -i "s|ip5|${compute_ips[1]}|" "${pod_yaml}"
fi
# update 'user' and 'key_filename' according to the CI env
- sed -i "s|node_username|${USER_NAME}|;s|node_keyfile|${SSH_KEY}|" $pod_yaml;
+ sed -i "s|node_username|${USER_NAME}|;s|node_keyfile|${SSH_KEY}|" "${pod_yaml}"
fi
diff --git a/tests/ci/prepare_storperf_admin-rc.sh b/tests/ci/prepare_storperf_admin-rc.sh
index 558375e62..ef7c2297e 100755
--- a/tests/ci/prepare_storperf_admin-rc.sh
+++ b/tests/ci/prepare_storperf_admin-rc.sh
@@ -15,8 +15,9 @@ AUTH_URL=${OS_AUTH_URL}
USERNAME=${OS_USERNAME:-admin}
PASSWORD=${OS_PASSWORD:-console}
+# OS_TENANT_NAME is still present to keep backward compatibility with legacy
+# deployments, but should be replaced by OS_PROJECT_NAME.
TENANT_NAME=${OS_TENANT_NAME:-admin}
-TENANT_ID=`openstack project show admin|grep '\bid\b' |awk -F '|' '{print $3}'|sed -e 's/^[[:space:]]*//'`
PROJECT_NAME=${OS_PROJECT_NAME:-$TENANT_NAME}
PROJECT_ID=`openstack project show admin|grep '\bid\b' |awk -F '|' '{print $3}'|sed -e 's/^[[:space:]]*//'`
@@ -30,8 +31,6 @@ echo "OS_USERNAME="$USERNAME >> ~/storperf_admin-rc
echo "OS_PASSWORD="$PASSWORD >> ~/storperf_admin-rc
echo "OS_PROJECT_NAME="$PROJECT_NAME >> ~/storperf_admin-rc
echo "OS_PROJECT_ID="$PROJECT_ID >> ~/storperf_admin-rc
-echo "OS_TENANT_NAME="$TENANT_NAME >> ~/storperf_admin-rc
-echo "OS_TENANT_ID="$TENANT_ID >> ~/storperf_admin-rc
echo "OS_USER_DOMAIN_ID="$USER_DOMAIN_ID >> ~/storperf_admin-rc
echo "OS_PROJECT_DOMAIN_NAME="$OS_PROJECT_DOMAIN_NAME >> ~/storperf_admin-rc
echo "OS_USER_DOMAIN_NAME="$OS_USER_DOMAIN_NAME >> ~/storperf_admin-rc
diff --git a/tests/opnfv/test_suites/opnfv_k8-nosdn-lb_ceph-noha_daily.yaml b/tests/opnfv/test_suites/opnfv_k8-nosdn-lb_ceph-noha_daily.yaml
new file mode 100644
index 000000000..ebb21b5c7
--- /dev/null
+++ b/tests/opnfv/test_suites/opnfv_k8-nosdn-lb_ceph-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 nosdn lb ceph noha daily task suite
+
+schema: "yardstick:suite:0.1"
+
+name: "k8-nosdn-lb_ceph-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-odl-bgpvpn-noha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-odl-bgpvpn-noha_daily.yaml
new file mode 100644
index 000000000..e55b83301
--- /dev/null
+++ b/tests/opnfv/test_suites/opnfv_os-odl-bgpvpn-noha_daily.yaml
@@ -0,0 +1,23 @@
+##############################################################################
+# 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-bgpvpn-noha daily task suite
+
+schema: "yardstick:suite:0.1"
+
+name: "os-odl-bgpvpn-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_tc012.yaml
diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py
index a468b272b..5935abbac 100644
--- a/tests/unit/__init__.py
+++ b/tests/unit/__init__.py
@@ -12,65 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import absolute_import
-import mock
+from yardstick import tests
-STL_MOCKS = {
- 'trex_stl_lib': mock.MagicMock(),
- 'trex_stl_lib.base64': mock.MagicMock(),
- 'trex_stl_lib.binascii': mock.MagicMock(),
- 'trex_stl_lib.collections': mock.MagicMock(),
- 'trex_stl_lib.copy': mock.MagicMock(),
- 'trex_stl_lib.datetime': mock.MagicMock(),
- 'trex_stl_lib.functools': mock.MagicMock(),
- 'trex_stl_lib.imp': mock.MagicMock(),
- 'trex_stl_lib.inspect': mock.MagicMock(),
- 'trex_stl_lib.json': mock.MagicMock(),
- 'trex_stl_lib.linecache': mock.MagicMock(),
- 'trex_stl_lib.math': mock.MagicMock(),
- 'trex_stl_lib.os': mock.MagicMock(),
- 'trex_stl_lib.platform': mock.MagicMock(),
- 'trex_stl_lib.pprint': mock.MagicMock(),
- 'trex_stl_lib.random': mock.MagicMock(),
- 'trex_stl_lib.re': mock.MagicMock(),
- 'trex_stl_lib.scapy': mock.MagicMock(),
- 'trex_stl_lib.socket': mock.MagicMock(),
- 'trex_stl_lib.string': mock.MagicMock(),
- 'trex_stl_lib.struct': mock.MagicMock(),
- 'trex_stl_lib.sys': mock.MagicMock(),
- 'trex_stl_lib.threading': mock.MagicMock(),
- 'trex_stl_lib.time': mock.MagicMock(),
- 'trex_stl_lib.traceback': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_async_client': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_client': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_exceptions': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_ext': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_port': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_stats': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_streams': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_types': mock.MagicMock(),
- 'trex_stl_lib.types': mock.MagicMock(),
- 'trex_stl_lib.utils': mock.MagicMock(),
- 'trex_stl_lib.utils.argparse': mock.MagicMock(),
- 'trex_stl_lib.utils.collections': mock.MagicMock(),
- 'trex_stl_lib.utils.common': mock.MagicMock(),
- 'trex_stl_lib.utils.json': mock.MagicMock(),
- 'trex_stl_lib.utils.os': mock.MagicMock(),
- 'trex_stl_lib.utils.parsing_opts': mock.MagicMock(),
- 'trex_stl_lib.utils.pwd': mock.MagicMock(),
- 'trex_stl_lib.utils.random': mock.MagicMock(),
- 'trex_stl_lib.utils.re': mock.MagicMock(),
- 'trex_stl_lib.utils.string': mock.MagicMock(),
- 'trex_stl_lib.utils.sys': mock.MagicMock(),
- 'trex_stl_lib.utils.text_opts': mock.MagicMock(),
- 'trex_stl_lib.utils.text_tables': mock.MagicMock(),
- 'trex_stl_lib.utils.texttable': mock.MagicMock(),
- 'trex_stl_lib.warnings': mock.MagicMock(),
- 'trex_stl_lib.yaml': mock.MagicMock(),
- 'trex_stl_lib.zlib': mock.MagicMock(),
- 'trex_stl_lib.zmq': mock.MagicMock(),
-}
+# NOTE(ralonsoh): to be removed. Replace all occurrences of
+# tests.unit.STL_MOCKS with yardstick.tests.STL_MOCKS
+STL_MOCKS = tests.STL_MOCKS
diff --git a/tests/unit/network_services/collector/test_publisher.py b/tests/unit/network_services/collector/test_publisher.py
index d1e56e114..4a175841d 100644
--- a/tests/unit/network_services/collector/test_publisher.py
+++ b/tests/unit/network_services/collector/test_publisher.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/tests/unit/network_services/collector/test_subscriber.py b/tests/unit/network_services/collector/test_subscriber.py
index f324f627d..d4b4ecf7a 100644
--- a/tests/unit/network_services/collector/test_subscriber.py
+++ b/tests/unit/network_services/collector/test_subscriber.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/tests/unit/network_services/helpers/test_cpu.py b/tests/unit/network_services/helpers/test_cpu.py
index 7ea6bd0fc..1f9d3f219 100644
--- a/tests/unit/network_services/helpers/test_cpu.py
+++ b/tests/unit/network_services/helpers/test_cpu.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py b/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py
index e30aee854..367072e84 100644
--- a/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py
+++ b/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +14,14 @@
import mock
import unittest
+
+import os
+
+from yardstick.error import IncorrectConfig, SSHError
+from yardstick.error import IncorrectNodeSetup
+from yardstick.error import IncorrectSetup
+from yardstick.network_services.helpers.dpdkbindnic_helper import DpdkInterface
+from yardstick.network_services.helpers.dpdkbindnic_helper import DpdkNode
from yardstick.network_services.helpers.dpdkbindnic_helper import DpdkBindHelper
from yardstick.network_services.helpers.dpdkbindnic_helper import DpdkBindHelperException
from yardstick.network_services.helpers.dpdkbindnic_helper import NETWORK_KERNEL
@@ -26,7 +32,269 @@ from yardstick.network_services.helpers.dpdkbindnic_helper import NETWORK_OTHER
from yardstick.network_services.helpers.dpdkbindnic_helper import CRYPTO_OTHER
+NAME = "tg_0"
+
+
+class TestDpdkInterface(unittest.TestCase):
+
+ SAMPLE_NETDEVS = {
+ 'enp11s0': {
+ 'address': '0a:de:ad:be:ef:f5',
+ 'device': '0x1533',
+ 'driver': 'igb',
+ 'ifindex': '2',
+ 'interface_name': 'enp11s0',
+ 'operstate': 'down',
+ 'pci_bus_id': '0000:0b:00.0',
+ 'subsystem_device': '0x1533',
+ 'subsystem_vendor': '0x15d9',
+ 'vendor': '0x8086'
+ },
+ 'lan': {
+ 'address': '0a:de:ad:be:ef:f4',
+ 'device': '0x153a',
+ 'driver': 'e1000e',
+ 'ifindex': '3',
+ 'interface_name': 'lan',
+ 'operstate': 'up',
+ 'pci_bus_id': '0000:00:19.0',
+ 'subsystem_device': '0x153a',
+ 'subsystem_vendor': '0x15d9',
+ 'vendor': '0x8086'
+ }
+ }
+
+ SAMPLE_VM_NETDEVS = {
+ 'eth1': {
+ 'address': 'fa:de:ad:be:ef:5b',
+ 'device': '0x0001',
+ 'driver': 'virtio_net',
+ 'ifindex': '3',
+ 'interface_name': 'eth1',
+ 'operstate': 'down',
+ 'pci_bus_id': '0000:00:04.0',
+ 'vendor': '0x1af4'
+ }
+ }
+
+ def test_parse_netdev_info(self):
+ output = """\
+/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/ifindex:2
+/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/address:0a:de:ad:be:ef:f5
+/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/operstate:down
+/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/vendor:0x8086
+/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/device:0x1533
+/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/subsystem_vendor:0x15d9
+/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/subsystem_device:0x1533
+/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/driver:igb
+/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/pci_bus_id:0000:0b:00.0
+/sys/devices/pci0000:00/0000:00:19.0/net/lan/ifindex:3
+/sys/devices/pci0000:00/0000:00:19.0/net/lan/address:0a:de:ad:be:ef:f4
+/sys/devices/pci0000:00/0000:00:19.0/net/lan/operstate:up
+/sys/devices/pci0000:00/0000:00:19.0/net/lan/device/vendor:0x8086
+/sys/devices/pci0000:00/0000:00:19.0/net/lan/device/device:0x153a
+/sys/devices/pci0000:00/0000:00:19.0/net/lan/device/subsystem_vendor:0x15d9
+/sys/devices/pci0000:00/0000:00:19.0/net/lan/device/subsystem_device:0x153a
+/sys/devices/pci0000:00/0000:00:19.0/net/lan/driver:e1000e
+/sys/devices/pci0000:00/0000:00:19.0/net/lan/pci_bus_id:0000:00:19.0
+"""
+ res = DpdkBindHelper.parse_netdev_info(output)
+ self.assertDictEqual(res, self.SAMPLE_NETDEVS)
+
+ def test_parse_netdev_info_virtio(self):
+ output = """\
+/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/ifindex:3
+/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/address:fa:de:ad:be:ef:5b
+/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/operstate:down
+/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/device/vendor:0x1af4
+/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/device/device:0x0001
+/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/driver:virtio_net
+"""
+ res = DpdkBindHelper.parse_netdev_info(output)
+ self.assertDictEqual(res, self.SAMPLE_VM_NETDEVS)
+
+ def test_probe_missing_values(self):
+ mock_dpdk_node = mock.Mock()
+ mock_dpdk_node.netdevs = self.SAMPLE_NETDEVS.copy()
+
+ interface = {'local_mac': '0a:de:ad:be:ef:f5'}
+ dpdk_intf = DpdkInterface(mock_dpdk_node, interface)
+
+ dpdk_intf.probe_missing_values()
+ self.assertEqual(interface['vpci'], '0000:0b:00.0')
+
+ interface['local_mac'] = '0a:de:ad:be:ef:f4'
+ dpdk_intf.probe_missing_values()
+ self.assertEqual(interface['vpci'], '0000:00:19.0')
+
+ def test_probe_missing_values_no_update(self):
+ mock_dpdk_node = mock.Mock()
+ mock_dpdk_node.netdevs = self.SAMPLE_NETDEVS.copy()
+ del mock_dpdk_node.netdevs['enp11s0']['driver']
+ del mock_dpdk_node.netdevs['lan']['driver']
+
+ interface = {'local_mac': '0a:de:ad:be:ef:f5'}
+ dpdk_intf = DpdkInterface(mock_dpdk_node, interface)
+
+ dpdk_intf.probe_missing_values()
+ self.assertNotIn('vpci', interface)
+ self.assertNotIn('driver', interface)
+
+ def test_probe_missing_values_negative(self):
+ mock_dpdk_node = mock.Mock()
+ mock_dpdk_node.netdevs.values.side_effect = IncorrectNodeSetup
+
+ interface = {'local_mac': '0a:de:ad:be:ef:f5'}
+ dpdk_intf = DpdkInterface(mock_dpdk_node, interface)
+
+ with self.assertRaises(IncorrectConfig):
+ dpdk_intf.probe_missing_values()
+
+
+class TestDpdkNode(unittest.TestCase):
+
+ INTERFACES = [
+ {'name': 'name1',
+ 'virtual-interface': {
+ 'local_mac': 404,
+ 'vpci': 'pci10',
+ }},
+ {'name': 'name2',
+ 'virtual-interface': {
+ 'local_mac': 404,
+ 'vpci': 'pci2',
+ }},
+ {'name': 'name3',
+ 'virtual-interface': {
+ 'local_mac': 404,
+ 'vpci': 'some-pci1',
+ }},
+ ]
+
+ def test_probe_dpdk_drivers(self):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 0, '', ''
+
+ interfaces = [
+ {'name': 'name1',
+ 'virtual-interface': {
+ 'local_mac': 404,
+ 'vpci': 'pci10',
+ }},
+ {'name': 'name2',
+ 'virtual-interface': {
+ 'local_mac': 404,
+ 'vpci': 'pci2',
+ }},
+ {'name': 'name3',
+ 'virtual-interface': {
+ 'local_mac': 404,
+ 'vpci': 'some-pci1',
+ }},
+ ]
+
+ dpdk_node = DpdkNode(NAME, interfaces, mock_ssh_helper)
+ dpdk_helper = dpdk_node.dpdk_helper
+
+ dpdk_helper.probe_real_kernel_drivers = mock.Mock()
+ dpdk_helper.real_kernel_interface_driver_map = {
+ 'pci1': 'driver1',
+ 'pci2': 'driver2',
+ 'pci3': 'driver3',
+ 'pci4': 'driver1',
+ 'pci6': 'driver3',
+ }
+
+ dpdk_node._probe_dpdk_drivers()
+ self.assertNotIn('driver', interfaces[0]['virtual-interface'])
+ self.assertEqual(interfaces[1]['virtual-interface']['driver'], 'driver2')
+ self.assertEqual(interfaces[2]['virtual-interface']['driver'], 'driver1')
+
+ def test_check(self):
+ def update():
+ if not mock_force_rebind.called:
+ raise IncorrectConfig
+
+ interfaces[0]['virtual-interface'].update({
+ 'vpci': '0000:01:02.1',
+ 'local_ip': '10.20.30.40',
+ 'netmask': '255.255.0.0',
+ 'driver': 'ixgbe',
+ })
+
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 0, '', ''
+
+ interfaces = [
+ {'name': 'name1',
+ 'virtual-interface': {
+ 'local_mac': 404,
+ }},
+ ]
+
+ dpdk_node = DpdkNode(NAME, interfaces, mock_ssh_helper)
+ dpdk_node._probe_missing_values = mock_probe_missing = mock.Mock(side_effect=update)
+ dpdk_node._force_rebind = mock_force_rebind = mock.Mock()
+
+ self.assertIsNone(dpdk_node.check())
+ self.assertEqual(mock_probe_missing.call_count, 2)
+
+ @mock.patch('yardstick.network_services.helpers.dpdkbindnic_helper.DpdkInterface')
+ def test_check_negative(self, mock_intf_type):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 0, '', ''
+
+ mock_intf_type().check.side_effect = SSHError
+
+ dpdk_node = DpdkNode(NAME, self.INTERFACES, mock_ssh_helper)
+
+ with self.assertRaises(IncorrectSetup):
+ dpdk_node.check()
+
+ def test_probe_netdevs(self):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 0, '', ''
+
+ expected = {'key1': 500, 'key2': 'hello world'}
+ update = {'key1': 1000, 'key3': []}
+
+ dpdk_node = DpdkNode(NAME, self.INTERFACES, mock_ssh_helper)
+ dpdk_helper = dpdk_node.dpdk_helper
+ dpdk_helper.find_net_devices = mock.Mock(side_effect=[expected, update])
+
+ self.assertDictEqual(dpdk_node.netdevs, {})
+ dpdk_node._probe_netdevs()
+ self.assertDictEqual(dpdk_node.netdevs, expected)
+
+ expected = {'key1': 1000, 'key2': 'hello world', 'key3': []}
+ dpdk_node._probe_netdevs()
+ self.assertDictEqual(dpdk_node.netdevs, expected)
+
+ def test_probe_netdevs_setup_negative(self):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 0, '', ''
+
+ dpdk_node = DpdkNode(NAME, self.INTERFACES, mock_ssh_helper)
+ dpdk_helper = dpdk_node.dpdk_helper
+ dpdk_helper.find_net_devices = mock.Mock(side_effect=DpdkBindHelperException)
+
+ with self.assertRaises(DpdkBindHelperException):
+ dpdk_node._probe_netdevs()
+
+ def test_force_rebind(self):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 0, '', ''
+
+ dpdk_node = DpdkNode(NAME, self.INTERFACES, mock_ssh_helper)
+ dpdk_helper = dpdk_node.dpdk_helper
+ dpdk_helper.force_dpdk_rebind = mock_helper_func = mock.Mock()
+
+ dpdk_node._force_rebind()
+ self.assertEqual(mock_helper_func.call_count, 1)
+
+
class TestDpdkBindHelper(unittest.TestCase):
+ bin_path = "/opt/nsb_bin"
EXAMPLE_OUTPUT = """
Network devices using DPDK-compatible driver
@@ -111,13 +379,15 @@ Other crypto devices
def test___init__(self):
conn = mock.Mock()
conn.provision_tool = mock.Mock(return_value='path_to_tool')
+ conn.join_bin_path.return_value = os.path.join(self.bin_path, DpdkBindHelper.DPDK_DEVBIND)
dpdk_bind_helper = DpdkBindHelper(conn)
self.assertEqual(conn, dpdk_bind_helper.ssh_helper)
self.assertEqual(self.CLEAN_STATUS, dpdk_bind_helper.dpdk_status)
self.assertIsNone(dpdk_bind_helper.status_nic_row_re)
- self.assertIsNone(dpdk_bind_helper._dpdk_devbind)
+ self.assertEqual(dpdk_bind_helper.dpdk_devbind,
+ os.path.join(self.bin_path, dpdk_bind_helper.DPDK_DEVBIND))
self.assertIsNone(dpdk_bind_helper._status_cmd_attr)
def test__dpdk_execute(self):
@@ -125,8 +395,7 @@ Other crypto devices
conn.execute = mock.Mock(return_value=(0, 'output', 'error'))
conn.provision_tool = mock.Mock(return_value='tool_path')
dpdk_bind_helper = DpdkBindHelper(conn)
- self.assertEqual((0, 'output', 'error'),
- dpdk_bind_helper._dpdk_execute('command'))
+ self.assertEqual((0, 'output', 'error'), dpdk_bind_helper._dpdk_execute('command'))
def test__dpdk_execute_failure(self):
conn = mock.Mock()
@@ -141,7 +410,7 @@ Other crypto devices
dpdk_bind_helper = DpdkBindHelper(conn)
- dpdk_bind_helper._addline(NETWORK_KERNEL, self.ONE_INPUT_LINE)
+ dpdk_bind_helper._add_line(NETWORK_KERNEL, self.ONE_INPUT_LINE)
self.assertIsNotNone(dpdk_bind_helper.dpdk_status)
self.assertEqual(self.ONE_INPUT_LINE_PARSED, dpdk_bind_helper.dpdk_status[NETWORK_KERNEL])
@@ -161,11 +430,35 @@ Other crypto devices
dpdk_bind_helper = DpdkBindHelper(conn)
- dpdk_bind_helper.parse_dpdk_status_output(self.EXAMPLE_OUTPUT)
+ dpdk_bind_helper._parse_dpdk_status_output(self.EXAMPLE_OUTPUT)
self.maxDiff = None
self.assertEqual(self.PARSED_EXAMPLE, dpdk_bind_helper.dpdk_status)
+ def test_kernel_bound_pci_addresses(self):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 0, '', ''
+
+ expected = ['a', 'b', 3]
+
+ dpdk_helper = DpdkBindHelper(mock_ssh_helper)
+ dpdk_helper.dpdk_status = {
+ NETWORK_DPDK: [{'vpci': 4}, {'vpci': 5}, {'vpci': 'g'}],
+ NETWORK_KERNEL: [{'vpci': 'a'}, {'vpci': 'b'}, {'vpci': 3}],
+ CRYPTO_DPDK: [],
+ }
+
+ result = dpdk_helper.kernel_bound_pci_addresses
+ self.assertEqual(result, expected)
+
+ def test_find_net_devices_negative(self):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 1, 'error', 'debug'
+
+ dpdk_helper = DpdkBindHelper(mock_ssh_helper)
+
+ self.assertDictEqual(dpdk_helper.find_net_devices(), {})
+
def test_read_status(self):
conn = mock.Mock()
conn.execute = mock.Mock(return_value=(0, self.EXAMPLE_OUTPUT, ''))
@@ -180,7 +473,7 @@ Other crypto devices
dpdk_bind_helper = DpdkBindHelper(conn)
- dpdk_bind_helper.parse_dpdk_status_output(self.EXAMPLE_OUTPUT)
+ dpdk_bind_helper._parse_dpdk_status_output(self.EXAMPLE_OUTPUT)
self.assertEqual(['0000:00:04.0', '0000:00:05.0'],
dpdk_bind_helper._get_bound_pci_addresses(NETWORK_DPDK))
@@ -192,18 +485,18 @@ Other crypto devices
dpdk_bind_helper = DpdkBindHelper(conn)
- dpdk_bind_helper.parse_dpdk_status_output(self.EXAMPLE_OUTPUT)
+ dpdk_bind_helper._parse_dpdk_status_output(self.EXAMPLE_OUTPUT)
self.assertEqual({'0000:00:04.0': 'igb_uio',
- '0000:00:03.0': 'virtio-pci',
- '0000:00:05.0': 'igb_uio',
- },
- dpdk_bind_helper.interface_driver_map)
+ '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-devbind.py')
+ conn.join_bin_path.return_value = os.path.join(self.bin_path, DpdkBindHelper.DPDK_DEVBIND)
dpdk_bind_helper = DpdkBindHelper(conn)
dpdk_bind_helper.read_status = mock.Mock()
@@ -217,7 +510,7 @@ Other crypto devices
def test_bind_single_pci(self):
conn = mock.Mock()
conn.execute = mock.Mock(return_value=(0, '', ''))
- conn.provision_tool = mock.Mock(return_value='/opt/nsb_bin/dpdk-devbind.py')
+ conn.join_bin_path.return_value = os.path.join(self.bin_path, DpdkBindHelper.DPDK_DEVBIND)
dpdk_bind_helper = DpdkBindHelper(conn)
dpdk_bind_helper.read_status = mock.Mock()
@@ -257,3 +550,84 @@ Other crypto devices
}
self.assertDictEqual(expected, dpdk_bind_helper.used_drivers)
+
+ def test_force_dpdk_rebind(self):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 0, '', ''
+
+ dpdk_helper = DpdkBindHelper(mock_ssh_helper, 'driver2')
+ dpdk_helper.dpdk_status = {
+ NETWORK_DPDK: [
+ {
+ 'vpci': 'pci1',
+ },
+ {
+ 'vpci': 'pci3',
+ },
+ {
+ 'vpci': 'pci6',
+ },
+ {
+ 'vpci': 'pci3',
+ },
+ ]
+ }
+ dpdk_helper.real_kernel_interface_driver_map = {
+ 'pci1': 'real_driver1',
+ 'pci2': 'real_driver2',
+ 'pci3': 'real_driver1',
+ 'pci4': 'real_driver4',
+ 'pci6': 'real_driver6',
+ }
+ dpdk_helper.load_dpdk_driver = mock.Mock()
+ dpdk_helper.read_status = mock.Mock()
+ dpdk_helper.save_real_kernel_interface_driver_map = mock.Mock()
+ dpdk_helper.save_used_drivers = mock.Mock()
+ dpdk_helper.bind = mock_bind = mock.Mock()
+
+ dpdk_helper.force_dpdk_rebind()
+ self.assertEqual(mock_bind.call_count, 2)
+
+ def test_save_real_kernel_drivers(self):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.return_value = 0, '', ''
+
+ dpdk_helper = DpdkBindHelper(mock_ssh_helper)
+ dpdk_helper.real_kernel_drivers = {
+ 'abc': '123',
+ }
+ dpdk_helper.real_kernel_interface_driver_map = {
+ 'abc': 'AAA',
+ 'def': 'DDD',
+ 'abs': 'AAA',
+ 'ghi': 'GGG',
+ }
+
+ # save_used_drivers must be called before save_real_kernel_drivers can be
+ with self.assertRaises(AttributeError):
+ dpdk_helper.save_real_kernel_drivers()
+
+ dpdk_helper.save_used_drivers()
+
+ expected_used_drivers = {
+ 'AAA': ['abc', 'abs'],
+ 'DDD': ['def'],
+ 'GGG': ['ghi'],
+ }
+ dpdk_helper.save_real_kernel_drivers()
+ self.assertDictEqual(dpdk_helper.used_drivers, expected_used_drivers)
+ self.assertDictEqual(dpdk_helper.real_kernel_drivers, {})
+
+ def test_get_real_kernel_driver(self):
+ mock_ssh_helper = mock.Mock()
+ mock_ssh_helper.execute.side_effect = [
+ (0, 'non-matching text', ''),
+ (0, 'pre Kernel modules: real_driver1', ''),
+ (0, 'before Ethernet middle Virtio network device after', ''),
+ ]
+
+ dpdk_helper = DpdkBindHelper(mock_ssh_helper)
+
+ self.assertIsNone(dpdk_helper.get_real_kernel_driver('abc'))
+ self.assertEqual(dpdk_helper.get_real_kernel_driver('abc'), 'real_driver1')
+ self.assertEqual(dpdk_helper.get_real_kernel_driver('abc'), DpdkBindHelper.VIRTIO_DRIVER)
diff --git a/tests/unit/network_services/helpers/test_samplevnf_helper.py b/tests/unit/network_services/helpers/test_samplevnf_helper.py
index 05acdfaa9..3b6c89d3a 100644
--- a/tests/unit/network_services/helpers/test_samplevnf_helper.py
+++ b/tests/unit/network_services/helpers/test_samplevnf_helper.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,14 +13,12 @@
# limitations under the License.
#
-from __future__ import absolute_import
-from __future__ import division
-
-import unittest
-
import mock
+import os
+import six
+import unittest
-from yardstick.network_services.helpers.samplevnf_helper import MultiPortConfig, PortPairs
+from yardstick.network_services.helpers import samplevnf_helper
from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
@@ -30,31 +26,32 @@ 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)
+ port_pairs = samplevnf_helper.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")])
+ port_pairs = samplevnf_helper.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)
+ port_pairs = samplevnf_helper.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)
+ port_pairs = samplevnf_helper.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)
+ port_pairs = samplevnf_helper.PortPairs(interfaces)
self.assertEqual(port_pairs.downlink_ports, ["xe1"])
@@ -63,14 +60,14 @@ class TestMultiPortConfig(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'}],
+ [{'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':
@@ -121,7 +118,7 @@ class TestMultiPortConfig(unittest.TestCase):
},
'vnfd-connection-point-ref': 'xe1',
'name': 'xe1'}
- ]}],
+ ]}],
'description': 'Vpe approximation using DPDK',
'mgmt-interface':
{'vdu-id': 'vpevnf-baremetal',
@@ -143,67 +140,85 @@ class TestMultiPortConfig(unittest.TestCase):
}
}
+ def setUp(self):
+ self._mock_open = mock.patch.object(six.moves.builtins, 'open')
+ self.mock_open = self._mock_open.start()
+ self._mock_os = mock.patch.object(os, 'path')
+ self.mock_os = self._mock_os.start()
+ self._mock_config_parser = mock.patch.object(
+ samplevnf_helper, 'ConfigParser')
+ self.mock_config_parser = self._mock_config_parser.start()
+
+ self.addCleanup(self._cleanup)
+
+ def _cleanup(self):
+ self._mock_open.stop()
+ self._mock_os.stop()
+ self._mock_config_parser.stop()
+
def test_validate_ip_and_prefixlen(self):
- ip_addr, prefix_len = MultiPortConfig.validate_ip_and_prefixlen('10.20.30.40', '16')
+ ip_addr, prefix_len = (
+ samplevnf_helper.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')
+ ip_addr, prefix_len = (
+ samplevnf_helper.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('', '')
+ samplevnf_helper.MultiPortConfig.validate_ip_and_prefixlen('', '')
with self.assertRaises(AttributeError):
- MultiPortConfig.validate_ip_and_prefixlen('10.20.30.400', '16')
+ samplevnf_helper.MultiPortConfig.validate_ip_and_prefixlen(
+ '10.20.30.400', '16')
with self.assertRaises(AttributeError):
- MultiPortConfig.validate_ip_and_prefixlen('10.20.30.40', '33')
+ samplevnf_helper.MultiPortConfig.validate_ip_and_prefixlen(
+ '10.20.30.40', '33')
with self.assertRaises(AttributeError):
- MultiPortConfig.validate_ip_and_prefixlen('::1', '129')
+ samplevnf_helper.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')
- @mock.patch('yardstick.network_services.helpers.samplevnf_helper.ConfigParser')
- def test___init__(self, mock_open, mock_os, ConfigParser):
+ def test___init__(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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, vnfd_mock)
+ self.mock_os.path = mock.MagicMock()
+ self.mock_os.path.isfile = mock.Mock(return_value=False)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
self.assertEqual(0, opnfv_vnf.swq)
- @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')
- def test_update_timer(self, mock_open, mock_os, ConfigParser):
+ def test_update_timer(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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()
- self.assertEqual(None, opnfv_vnf.update_timer())
+ self.assertIsNone(opnfv_vnf.update_timer())
- @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')
- def test_generate_script(self, mock_open, mock_os, ConfigParser):
+ def test_generate_script(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = VnfdHelper(self.VNFD_0)
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -218,15 +233,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.lb_config = 'HW'
self.assertIsNotNone(opnfv_vnf.generate_script(self.VNFD))
- @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')
- def test_generate_script_data(self, mock_open, mock_os, ConfigParser):
+ def test_generate_script_data(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -240,15 +253,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.generate_rule_config = mock.Mock()
self.assertIsNotNone(opnfv_vnf.generate_script_data())
- @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')
- def test_generate_rule_config(self, mock_open, mock_os, ConfigParser):
+ def test_generate_rule_config(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -261,9 +272,11 @@ class TestMultiPortConfig(unittest.TestCase):
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')
- opnfv_vnf.get_netmask_gateway = mock.Mock(return_value=u'255.255.255.0')
+ opnfv_vnf.get_netmask_gateway = mock.Mock(
+ return_value=u'255.255.255.0')
opnfv_vnf.get_ports_gateway6 = mock.Mock(return_value=u'1.1.1.1')
- opnfv_vnf.get_netmask_gateway6 = mock.Mock(return_value=u'255.255.255.0')
+ opnfv_vnf.get_netmask_gateway6 = mock.Mock(
+ return_value=u'255.255.255.0')
opnfv_vnf.txrx_pipeline = ''
opnfv_vnf.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
opnfv_vnf.interfaces = opnfv_vnf.vnfd['vdu'][0]['external-interface']
@@ -272,15 +285,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.rules = 'new'
self.assertIsNotNone(opnfv_vnf.generate_rule_config())
- @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')
- def test_generate_action_config(self, mock_open, mock_os, ConfigParser):
+ def test_generate_action_config(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -293,22 +304,22 @@ class TestMultiPortConfig(unittest.TestCase):
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')
- opnfv_vnf.get_netmask_gateway = mock.Mock(return_value=u'255.255.255.0')
+ opnfv_vnf.get_netmask_gateway = mock.Mock(
+ return_value=u'255.255.255.0')
opnfv_vnf.get_ports_gateway6 = mock.Mock(return_value=u'1.1.1.1')
- opnfv_vnf.get_netmask_gateway6 = mock.Mock(return_value=u'255.255.255.0')
+ opnfv_vnf.get_netmask_gateway6 = mock.Mock(
+ return_value=u'255.255.255.0')
opnfv_vnf.txrx_pipeline = ''
opnfv_vnf.rules = ''
self.assertIsNotNone(opnfv_vnf.generate_action_config())
- @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')
- def test_generate_arp_config6(self, mock_open, mock_os, ConfigParser):
+ def test_generate_arp_config6(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -321,24 +332,24 @@ class TestMultiPortConfig(unittest.TestCase):
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')
- opnfv_vnf.get_netmask_gateway = mock.Mock(return_value=u'255.255.255.0')
+ opnfv_vnf.get_netmask_gateway = mock.Mock(
+ return_value=u'255.255.255.0')
opnfv_vnf.get_ports_gateway6 = mock.Mock(return_value=u'1.1.1.1')
- opnfv_vnf.get_netmask_gateway6 = mock.Mock(return_value=u'255.255.255.0')
+ opnfv_vnf.get_netmask_gateway6 = mock.Mock(
+ return_value=u'255.255.255.0')
opnfv_vnf.txrx_pipeline = ''
opnfv_vnf.rules = ''
opnfv_vnf.interfaces = mock.MagicMock()
opnfv_vnf.get_ports_gateway6 = mock.Mock()
self.assertIsNotNone(opnfv_vnf.generate_arp_config6())
- @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')
- def test_generate_arp_config(self, mock_open, mock_os, ConfigParser):
+ def test_generate_arp_config(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -351,24 +362,24 @@ class TestMultiPortConfig(unittest.TestCase):
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')
- opnfv_vnf.get_netmask_gateway = mock.Mock(return_value=u'255.255.255.0')
+ opnfv_vnf.get_netmask_gateway = mock.Mock(
+ return_value=u'255.255.255.0')
opnfv_vnf.get_ports_gateway6 = mock.Mock(return_value=u'1.1.1.1')
- opnfv_vnf.get_netmask_gateway6 = mock.Mock(return_value=u'255.255.255.0')
+ opnfv_vnf.get_netmask_gateway6 = mock.Mock(
+ return_value=u'255.255.255.0')
opnfv_vnf.txrx_pipeline = ''
opnfv_vnf.rules = ''
opnfv_vnf.interfaces = mock.MagicMock()
opnfv_vnf.get_ports_gateway6 = mock.Mock()
self.assertIsNotNone(opnfv_vnf.generate_arp_config())
- @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')
- def test_get_ports_gateway(self, mock_open, mock_os, ConfigParser):
+ def test_get_ports_gateway(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -387,15 +398,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
self.assertIsNotNone(opnfv_vnf.get_ports_gateway('xe0'))
- @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')
- def test_get_ports_gateway6(self, mock_open, mock_os, ConfigParser):
+ def test_get_ports_gateway6(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -414,15 +423,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
self.assertIsNotNone(opnfv_vnf.get_ports_gateway6('xe0'))
- @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')
- def test_get_netmask_gateway(self, mock_open, mock_os, ConfigParser):
+ def test_get_netmask_gateway(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -441,15 +448,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
self.assertIsNotNone(opnfv_vnf.get_netmask_gateway('xe0'))
- @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')
- def test_get_netmask_gateway6(self, mock_open, mock_os, ConfigParser):
+ def test_get_netmask_gateway6(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -468,16 +473,14 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
self.assertIsNotNone(opnfv_vnf.get_netmask_gateway6('xe0'))
- @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')
- def test_generate_link_config(self, mock_open, mock_os, ConfigParser):
+ def test_generate_link_config(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -495,20 +498,19 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
opnfv_vnf.interfaces = opnfv_vnf.vnfd['vdu'][0]['external-interface']
opnfv_vnf.all_ports = ['32', '1', '987']
- opnfv_vnf.validate_ip_and_prefixlen = mock.Mock(return_value=('10.20.30.40', 16))
+ 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')
- @mock.patch('yardstick.network_services.helpers.samplevnf_helper.ConfigParser')
- def test_generate_config(self, mock_open, mock_os, ConfigParser):
+ def test_generate_config(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.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
@@ -531,17 +533,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.is_openstack = False
self.assertIsNone(opnfv_vnf.generate_config())
- @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_get_config_tpl_data(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_get_config_tpl_data(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -555,17 +553,13 @@ class TestMultiPortConfig(unittest.TestCase):
self.assertIsNotNone(opnfv_vnf.get_config_tpl_data('filename'))
- @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_get_txrx_tpl_data(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_get_txrx_tpl_data(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -579,17 +573,13 @@ class TestMultiPortConfig(unittest.TestCase):
self.assertIsNotNone(opnfv_vnf.get_txrx_tpl_data('filename'))
- @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_write_parser_template(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_init_write_parser_template(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -608,17 +598,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.write_parser.set = mock.Mock()
self.assertIsNone(opnfv_vnf.init_write_parser_template('filename'))
- @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_write_parser_template_2(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_init_write_parser_template_2(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -632,17 +618,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.read_parser.items = mock.MagicMock()
self.assertIsNone(opnfv_vnf.init_write_parser_template('filename'))
- @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_update_write_parser(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_update_write_parser(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -658,17 +640,13 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.pipeline_counter = 0
self.assertIsNone(opnfv_vnf.update_write_parser({'filename': 1}))
- @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_get_worker_threads(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_get_worker_threads(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -692,17 +670,14 @@ class TestMultiPortConfig(unittest.TestCase):
result = opnfv_vnf.get_worker_threads(3)
self.assertEqual(2, result)
- @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_generate_next_core_id(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ # TODO(elfoley): Split this test into smaller tests
+ def test_generate_next_core_id(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -719,26 +694,22 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.worker_config = '1t'
opnfv_vnf.start_core = 0
result = opnfv_vnf.generate_next_core_id()
- self.assertEqual(None, result)
+ self.assertIsNone(result)
opnfv_vnf.worker_config = '2t'
opnfv_vnf.start_core = 'a'
self.assertRaises(ValueError, opnfv_vnf.generate_next_core_id)
opnfv_vnf.worker_config = '2t'
opnfv_vnf.start_core = 1
result = opnfv_vnf.generate_next_core_id()
- self.assertEqual(None, result)
+ self.assertIsNone(result)
- @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_generate_lb_to_port_pair_mapping(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_generate_lb_to_port_pair_mapping(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = VnfdHelper(self.VNFD_0)
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.txrx_pipeline = ''
@@ -754,24 +725,20 @@ 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_pairs = samplevnf_helper.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)
+ self.assertIsNone(result)
result = opnfv_vnf.set_priv_to_pub_mapping()
self.assertEqual('(0,1)', result)
- @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_set_priv_que_handler(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_set_priv_que_handler(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = VnfdHelper(self.VNFD_0)
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -790,11 +757,10 @@ class TestMultiPortConfig(unittest.TestCase):
opnfv_vnf.start_core = 0
opnfv_vnf.lb_count = 1
result = opnfv_vnf.set_priv_que_handler()
- self.assertEqual(None, result)
+ self.assertIsNone(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, *_):
+ def test_generate_arp_route_tbl(self):
+ # ELF: could n=do this in setup
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = ""
@@ -821,7 +787,8 @@ class TestMultiPortConfig(unittest.TestCase):
},
]
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.all_ports = [3, 2, 5]
expected = 'routeadd net 32 10.20.30.40 0xfffff000\n' \
@@ -830,17 +797,13 @@ class TestMultiPortConfig(unittest.TestCase):
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')
- def test_generate_arpicmp_data(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_generate_arpicmp_data(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -875,17 +838,13 @@ class TestMultiPortConfig(unittest.TestCase):
result = opnfv_vnf.generate_arpicmp_data()
self.assertIsNotNone(result)
- @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_generate_final_txrx_data(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_generate_final_txrx_data(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -917,17 +876,13 @@ class TestMultiPortConfig(unittest.TestCase):
result = opnfv_vnf.generate_final_txrx_data()
self.assertIsNotNone(result)
- @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_generate_initial_txrx_data(self, mock_open, mock_os,
- ConfigParser, OrderedDict):
+ def test_generate_initial_txrx_data(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -971,17 +926,13 @@ class TestMultiPortConfig(unittest.TestCase):
result = opnfv_vnf.generate_initial_txrx_data()
self.assertIsNotNone(result)
- @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_generate_lb_data(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_generate_lb_data(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -1008,17 +959,13 @@ class TestMultiPortConfig(unittest.TestCase):
result = opnfv_vnf.generate_lb_data()
self.assertIsNotNone(result)
- @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_generate_vnf_data(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_generate_vnf_data(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -1057,17 +1004,13 @@ class TestMultiPortConfig(unittest.TestCase):
result = opnfv_vnf.generate_vnf_data()
self.assertIsNotNone(result)
- @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_generate_config_data(self, mock_open, mock_os, ConfigParser,
- OrderedDict):
+ def test_generate_config_data(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = VnfdHelper(self.VNFD_0)
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
@@ -1123,17 +1066,13 @@ class TestMultiPortConfig(unittest.TestCase):
result = opnfv_vnf.generate_config_data()
self.assertIsNone(result)
- @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):
+ def test_init_eal(self):
topology_file = mock.Mock()
config_tpl = mock.Mock()
tmp_file = mock.Mock()
vnfd_mock = mock.MagicMock()
- opnfv_vnf = MultiPortConfig(topology_file, config_tpl, tmp_file, vnfd_mock)
+ opnfv_vnf = samplevnf_helper.MultiPortConfig(
+ topology_file, config_tpl, tmp_file, vnfd_mock)
opnfv_vnf.socket = 0
opnfv_vnf.start_core = 0
opnfv_vnf.port_pair_list = [("xe0", "xe1")]
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 3f374fb50..2a97048aa 100644
--- a/tests/unit/network_services/libs/ixia_libs/test_IxNet.py
+++ b/tests/unit/network_services/libs/ixia_libs/test_IxNet.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,7 +34,7 @@ class TestIxNextgen(unittest.TestCase):
self.assertIsNone(ixnet_gen._bidir)
@mock.patch("yardstick.network_services.libs.ixia_libs.IxNet.IxNet.sys")
- def test_connect(self, mock_sys):
+ def test_connect(self, *args):
ixnet_gen = IxNextgen()
ixnet_gen.get_config = mock.MagicMock()
diff --git a/tests/unit/network_services/nfvi/test_collectd.py b/tests/unit/network_services/nfvi/test_collectd.py
index 866c31d32..0ae175624 100644
--- a/tests/unit/network_services/nfvi/test_collectd.py
+++ b/tests/unit/network_services/nfvi/test_collectd.py
@@ -34,7 +34,7 @@ class TestAmqpConsumer(unittest.TestCase):
self.amqp_consumer._connection.add_on_close_callback = \
mock.Mock(return_value=0)
self.amqp_consumer._connection.channel = mock.Mock(return_value=0)
- self.assertEqual(None, self.amqp_consumer.on_connection_open(10))
+ self.assertIsNone(self.amqp_consumer.on_connection_open(10))
def test_on_connection_closed(self):
self.amqp_consumer._connection = mock.Mock(autospec=AmqpConsumer)
@@ -42,13 +42,11 @@ class TestAmqpConsumer(unittest.TestCase):
self.amqp_consumer._connection.ioloop.stop = mock.Mock(return_value=0)
self.amqp_consumer._connection.add_timeout = mock.Mock(return_value=0)
self.amqp_consumer._closing = True
- self.assertEqual(None,
- self.amqp_consumer.on_connection_closed("", 404,
- "Not Found"))
+ self.assertIsNone(
+ self.amqp_consumer.on_connection_closed("", 404, "Not Found"))
self.amqp_consumer._closing = False
- self.assertEqual(None,
- self.amqp_consumer.on_connection_closed("", 404,
- "Not Found"))
+ self.assertIsNone(
+ self.amqp_consumer.on_connection_closed("", 404, "Not Found"))
def test_reconnect(self):
self.amqp_consumer._connection = mock.Mock(autospec=AmqpConsumer)
@@ -56,7 +54,7 @@ class TestAmqpConsumer(unittest.TestCase):
self.amqp_consumer._connection.ioloop.stop = mock.Mock(return_value=0)
self.amqp_consumer.connect = mock.Mock(return_value=0)
self.amqp_consumer._closing = True
- self.assertEqual(None, self.amqp_consumer.reconnect())
+ self.assertIsNone(self.amqp_consumer.reconnect())
def test_on_channel_open(self):
self.amqp_consumer._connection = mock.Mock(autospec=AmqpConsumer)
@@ -66,9 +64,8 @@ class TestAmqpConsumer(unittest.TestCase):
self.amqp_consumer.add_on_channel_close_callback = mock.Mock()
self.amqp_consumer._channel.exchange_declare = \
mock.Mock(return_value=0)
- self.assertEqual(None,
- self.amqp_consumer.on_channel_open(
- self.amqp_consumer._channel))
+ self.assertIsNone(
+ self.amqp_consumer.on_channel_open(self.amqp_consumer._channel))
def test_add_on_channel_close_callback(self):
self.amqp_consumer._connection = mock.Mock(autospec=AmqpConsumer)
@@ -76,46 +73,44 @@ class TestAmqpConsumer(unittest.TestCase):
mock.Mock(return_value=0)
self.amqp_consumer._channel = mock.Mock()
self.amqp_consumer._channel.add_on_close_callback = mock.Mock()
- self.assertEqual(None,
- self.amqp_consumer.add_on_channel_close_callback())
+ self.assertIsNone(self.amqp_consumer.add_on_channel_close_callback())
def test_on_channel_closed(self):
self.amqp_consumer._connection = mock.Mock(autospec=AmqpConsumer)
self.amqp_consumer._connection.close = mock.Mock(return_value=0)
_channel = mock.Mock()
- self.assertEqual(None,
- self.amqp_consumer.on_channel_closed(_channel,
- "", ""))
+ self.assertIsNone(
+ self.amqp_consumer.on_channel_closed(_channel, "", ""))
def test_ion_exchange_declareok(self):
self.amqp_consumer.setup_queue = mock.Mock(return_value=0)
- self.assertEqual(None, self.amqp_consumer.on_exchange_declareok(10))
+ self.assertIsNone(self.amqp_consumer.on_exchange_declareok(10))
def test_setup_queue(self):
self.amqp_consumer._channel = mock.Mock()
self.amqp_consumer._channel.add_on_close_callback = mock.Mock()
- self.assertEqual(None, self.amqp_consumer.setup_queue("collectd"))
+ self.assertIsNone(self.amqp_consumer.setup_queue("collectd"))
def test_on_queue_declareok(self):
self.amqp_consumer._channel = mock.Mock()
self.amqp_consumer._channel.queue_bind = mock.Mock()
- self.assertEqual(None, self.amqp_consumer.on_queue_declareok(10))
+ self.assertIsNone(self.amqp_consumer.on_queue_declareok(10))
def test__on_bindok(self):
self.amqp_consumer._channel = mock.Mock()
self.amqp_consumer._channel.basic_consume = mock.Mock()
self.amqp_consumer.add_on_cancel_callback = mock.Mock()
- self.assertEqual(None, self.amqp_consumer._on_bindok(10))
+ self.assertIsNone(self.amqp_consumer._on_bindok(10))
def test_add_on_cancel_callback(self):
self.amqp_consumer._channel = mock.Mock()
self.amqp_consumer._channel.add_on_cancel_callback = mock.Mock()
- self.assertEqual(None, self.amqp_consumer.add_on_cancel_callback())
+ self.assertIsNone(self.amqp_consumer.add_on_cancel_callback())
def test_on_consumer_cancelled(self):
self.amqp_consumer._channel = mock.Mock()
self.amqp_consumer._channel.close = mock.Mock()
- self.assertEqual(None, self.amqp_consumer.on_consumer_cancelled(10))
+ self.assertIsNone(self.amqp_consumer.on_consumer_cancelled(10))
def test_on_message(self):
body = "msg {} cpu/cpu-0/ipc 101010:10"
@@ -123,25 +118,24 @@ class TestAmqpConsumer(unittest.TestCase):
basic_deliver = mock.Mock()
basic_deliver.delivery_tag = mock.Mock(return_value=0)
self.amqp_consumer.ack_message = mock.Mock()
- self.assertEqual(None,
- self.amqp_consumer.on_message(10, basic_deliver,
- properties, body))
+ self.assertIsNone(
+ self.amqp_consumer.on_message(10, basic_deliver, properties, body))
def test_ack_message(self):
self.amqp_consumer._channel = mock.Mock()
self.amqp_consumer._channel.basic_ack = mock.Mock()
- self.assertEqual(None, self.amqp_consumer.ack_message(10))
+ self.assertIsNone(self.amqp_consumer.ack_message(10))
def test_on_cancelok(self):
self.amqp_consumer._channel = mock.Mock()
self.amqp_consumer._channel.close = mock.Mock()
- self.assertEqual(None, self.amqp_consumer.on_cancelok(10))
+ self.assertIsNone(self.amqp_consumer.on_cancelok(10))
def test_run(self):
self.amqp_consumer._connection = mock.Mock(autospec=AmqpConsumer)
self.amqp_consumer.connect = mock.Mock()
self.amqp_consumer._connection.ioloop.start = mock.Mock()
- self.assertEqual(None, self.amqp_consumer.run())
+ self.assertIsNone(self.amqp_consumer.run())
def test_stop(self):
self.amqp_consumer._connection = mock.Mock(autospec=AmqpConsumer)
@@ -149,9 +143,9 @@ class TestAmqpConsumer(unittest.TestCase):
self.amqp_consumer._connection.ioloop.start = mock.Mock()
self.amqp_consumer._channel = mock.Mock()
self.amqp_consumer._channel.basic_cancel = mock.Mock()
- self.assertEqual(None, self.amqp_consumer.stop())
+ self.assertIsNone(self.amqp_consumer.stop())
def test_close_connection(self):
self.amqp_consumer._connection = mock.Mock(autospec=AmqpConsumer)
self.amqp_consumer._connection.close = mock.Mock()
- self.assertEqual(None, self.amqp_consumer.close_connection())
+ self.assertIsNone(self.amqp_consumer.close_connection())
diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py
index 7ad166249..f5f7f0fe7 100644
--- a/tests/unit/network_services/nfvi/test_resource.py
+++ b/tests/unit/network_services/nfvi/test_resource.py
@@ -245,7 +245,7 @@ class TestResourceProfile(unittest.TestCase):
self.resource_profile.run_collectd_amqp = \
mock.Mock(return_value=0)
res = self.resource_profile.amqp_process_for_nfvi_kpi()
- self.assertEqual(None, res)
+ self.assertIsNone(res)
def test_amqp_collect_nfvi_kpi(self):
self.resource_profile.amqp_client = \
@@ -271,6 +271,3 @@ class TestResourceProfile(unittest.TestCase):
# TODO(efoley): Fix this incorrect test.
# Should check that we don't try to stop amqp when it's not running
self.assertIsNone(self.resource_profile.stop())
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/unit/network_services/traffic_profile/test_base.py b/tests/unit/network_services/traffic_profile/test_base.py
index 290610361..3b8804976 100644
--- a/tests/unit/network_services/traffic_profile/test_base.py
+++ b/tests/unit/network_services/traffic_profile/test_base.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,16 +11,16 @@
# 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.
-#
-# Unittest for yardstick.network_services.traffic_profile.test_base
+import sys
-from __future__ import absolute_import
-import unittest
import mock
+import unittest
-from yardstick.network_services.traffic_profile.base import \
- TrafficProfile, DummyProfile
+from yardstick.common import exceptions
+from yardstick.network_services import traffic_profile as tprofile_package
+from yardstick.network_services.traffic_profile import base
+from yardstick import tests as y_tests
class TestTrafficProfile(unittest.TestCase):
@@ -43,20 +41,33 @@ class TestTrafficProfile(unittest.TestCase):
return _mock
def test___init__(self):
- traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE)
+ traffic_profile = base.TrafficProfile(self.TRAFFIC_PROFILE)
self.assertEqual(self.TRAFFIC_PROFILE, traffic_profile.params)
def test_execute(self):
- traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE)
- self.assertRaises(NotImplementedError, traffic_profile.execute_traffic, {})
+ traffic_profile = base.TrafficProfile(self.TRAFFIC_PROFILE)
+ self.assertRaises(NotImplementedError,
+ traffic_profile.execute_traffic, {})
+
+ def test_get_existing_traffic_profile(self):
+ traffic_profile_list = [
+ 'RFC2544Profile', 'FixedProfile', 'TrafficProfileGenericHTTP',
+ 'IXIARFC2544Profile', 'ProxACLProfile', 'ProxBinSearchProfile',
+ 'ProxProfile', 'ProxRampProfile']
+ with mock.patch.dict(sys.modules, y_tests.STL_MOCKS):
+ tprofile_package.register_modules()
+
+ for tp in traffic_profile_list:
+ traffic_profile = base.TrafficProfile.get(
+ {'traffic_profile': {'traffic_type': tp}})
+ self.assertEqual(tp, traffic_profile.__class__.__name__)
- def test_get(self):
- traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE)
- self.assertRaises(RuntimeError, traffic_profile.get,
- self.TRAFFIC_PROFILE)
+ def test_get_non_existing_traffic_profile(self):
+ self.assertRaises(exceptions.TrafficProfileNotImplemented,
+ base.TrafficProfile.get, self.TRAFFIC_PROFILE)
class TestDummyProfile(unittest.TestCase):
def test_execute(self):
- dummy_profile = DummyProfile(TrafficProfile)
+ dummy_profile = base.DummyProfile(base.TrafficProfile)
self.assertIsNone(dummy_profile.execute({}))
diff --git a/tests/unit/network_services/traffic_profile/test_fixed.py b/tests/unit/network_services/traffic_profile/test_fixed.py
index eb182a2fb..dec94964b 100644
--- a/tests/unit/network_services/traffic_profile/test_fixed.py
+++ b/tests/unit/network_services/traffic_profile/test_fixed.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -119,4 +117,4 @@ class TestFixedProfile(unittest.TestCase):
fixed_profile = FixedProfile(self.TRAFFIC_PROFILE)
fixed_profile.params = self.TRAFFIC_PROFILE
fixed_profile.first_run = True
- self.assertEqual(None, fixed_profile.execute(traffic_generator))
+ self.assertIsNone(fixed_profile.execute(traffic_generator))
diff --git a/tests/unit/network_services/traffic_profile/test_http.py b/tests/unit/network_services/traffic_profile/test_http.py
index e818a0528..5d8029ea0 100644
--- a/tests/unit/network_services/traffic_profile/test_http.py
+++ b/tests/unit/network_services/traffic_profile/test_http.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,13 +31,11 @@ class TestTrafficProfileGenericHTTP(unittest.TestCase):
traffic_profile_generic_htt_p = \
TrafficProfileGenericHTTP(TrafficProfile)
traffic_generator = {}
- self.assertEqual(None,
- traffic_profile_generic_htt_p.execute(
- traffic_generator))
+ self.assertIsNone(
+ traffic_profile_generic_htt_p.execute(traffic_generator))
def test__send_http_request(self):
traffic_profile_generic_htt_p = \
TrafficProfileGenericHTTP(TrafficProfile)
- self.assertEqual(None,
- traffic_profile_generic_htt_p._send_http_request(
+ self.assertIsNone(traffic_profile_generic_htt_p._send_http_request(
"10.1.1.1", "250", "/req"))
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 f13945abf..e8910d62b 100644
--- a/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py
+++ b/tests/unit/network_services/traffic_profile/test_ixia_rfc2544.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +27,7 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
if stl_patch:
- from yardstick.network_services.traffic_profile.traffic_profile \
+ from yardstick.network_services.traffic_profile.trex_traffic_profile \
import TrexProfile
from yardstick.network_services.traffic_profile.ixia_rfc2544 import \
IXIARFC2544Profile
@@ -474,7 +472,7 @@ 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(traffic_generator, ixia_obj))
+ self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator, ixia_obj))
def test_update_traffic_profile(self):
traffic_generator = mock.Mock(autospec=TrexProfile)
@@ -609,10 +607,5 @@ class TestIXIARFC2544Profile(unittest.TestCase):
mock.Mock(return_value={})
r_f_c2544_profile.full_profile = {}
r_f_c2544_profile._ixia_traffic_generate = mock.Mock()
- self.assertEqual(
- None,
+ self.assertIsNone(
r_f_c2544_profile.start_ixia_latency(traffic_generator, ixia_obj))
-
-
-if __name__ == '__main__':
- unittest.main()
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 c1f1c825b..1b4189b48 100644
--- a/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
+++ b/tests/unit/network_services/traffic_profile/test_prox_binsearch.py
@@ -32,7 +32,7 @@ if stl_patch:
class TestProxBinSearchProfile(unittest.TestCase):
def test_execute_1(self):
- def target(*args, **kwargs):
+ def target(*args, **_):
runs.append(args[2])
if args[2] < 0 or args[2] > 100:
raise RuntimeError(' '.join([str(args), str(runs)]))
@@ -43,6 +43,8 @@ class TestProxBinSearchProfile(unittest.TestCase):
tp_config = {
'traffic_profile': {
'packet_sizes': [200],
+ 'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
},
}
@@ -61,11 +63,47 @@ class TestProxBinSearchProfile(unittest.TestCase):
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)
+ self.assertEqual(round(profile.current_upper, 2), 76.09)
+ self.assertEqual(len(runs), 7)
+
+ # Result Samples inc theor_max
+ result_tuple = {"Result_Actual_throughput": 7.5e-07,
+ "Result_theor_max_throughput": 0.00012340000000000002,
+ "Result_pktSize": 200}
+ profile.queue.put.assert_called_with(result_tuple)
+
+ success_result_tuple = {"Success_CurrentDropPackets": 0.5,
+ "Success_DropPackets": 0.5,
+ "Success_LatencyAvg": 5.3,
+ "Success_LatencyMax": 5.2,
+ "Success_LatencyMin": 5.1,
+ "Success_PktSize": 200,
+ "Success_RxThroughput": 7.5e-07,
+ "Success_Throughput": 7.5e-07,
+ "Success_TxThroughput": 0.00012340000000000002}
+
+ calls = profile.queue.put(success_result_tuple)
+ profile.queue.put.assert_has_calls(calls)
+
+ success_result_tuple2 = {"Success_CurrentDropPackets": 0.5,
+ "Success_DropPackets": 0.5,
+ "Success_LatencyAvg": 5.3,
+ "Success_LatencyMax": 5.2,
+ "Success_LatencyMin": 5.1,
+ "Success_PktSize": 200,
+ "Success_RxThroughput": 7.5e-07,
+ "Success_Throughput": 7.5e-07,
+ "Success_TxThroughput": 123.4,
+ "Success_can_be_lost": 409600,
+ "Success_drop_total": 20480,
+ "Success_rx_total": 4075520,
+ "Success_tx_total": 4096000}
+
+ calls = profile.queue.put(success_result_tuple2)
+ profile.queue.put.assert_has_calls(calls)
def test_execute_2(self):
- def target(*args, **kwargs):
+ def target(*args, **_):
runs.append(args[2])
if args[2] < 0 or args[2] > 100:
raise RuntimeError(' '.join([str(args), str(runs)]))
@@ -77,6 +115,7 @@ class TestProxBinSearchProfile(unittest.TestCase):
'traffic_profile': {
'packet_sizes': [200],
'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
},
}
@@ -97,3 +136,50 @@ class TestProxBinSearchProfile(unittest.TestCase):
self.assertEqual(round(profile.current_lower, 2), 24.06)
self.assertEqual(round(profile.current_upper, 2), 25.47)
self.assertEqual(len(runs), 7)
+
+ def test_execute_3(self):
+ def target(*args, **_):
+ runs.append(args[2])
+ if args[2] < 0 or args[2] > 100:
+ raise RuntimeError(' '.join([str(args), str(runs)]))
+ if args[2] > 75.0:
+ return fail_tuple, {}
+ return success_tuple, {}
+
+ tp_config = {
+ 'traffic_profile': {
+ 'packet_sizes': [200],
+ 'test_precision': 2.0,
+ 'tolerated_loss': 0.001,
+ },
+ }
+
+ runs = []
+ success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
+ fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
+
+ traffic_generator = mock.MagicMock()
+
+ profile_helper = mock.MagicMock()
+ profile_helper.run_test = target
+
+ profile = ProxBinSearchProfile(tp_config)
+ profile.init(mock.MagicMock())
+ profile._profile_helper = profile_helper
+
+ profile.upper_bound = 100.0
+ profile.lower_bound = 99.0
+ profile.execute_traffic(traffic_generator)
+
+
+ # Result Samples
+ result_tuple = {"Result_theor_max_throughput": 0, "Result_pktSize": 200}
+ profile.queue.put.assert_called_with(result_tuple)
+
+ # Check for success_ tuple (None expected)
+ calls = profile.queue.put.mock_calls
+ for call in calls:
+ for call_detail in call[1]:
+ for k in call_detail:
+ if "Success_" in k:
+ self.assertRaises(AttributeError)
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 078e72b8e..e5b36096f 100644
--- a/tests/unit/network_services/traffic_profile/test_prox_profile.py
+++ b/tests/unit/network_services/traffic_profile/test_prox_profile.py
@@ -31,14 +31,25 @@ if stl_patch:
class TestProxProfile(unittest.TestCase):
+ def test_sort_vpci(self):
+ traffic_generator = mock.Mock()
+ interface_1 = {'virtual-interface': {'vpci': 'id1'}, 'name': 'name1'}
+ interface_2 = {'virtual-interface': {'vpci': 'id2'}, 'name': 'name2'}
+ interface_3 = {'virtual-interface': {'vpci': 'id3'}, 'name': 'name3'}
+ interfaces = [interface_2, interface_3, interface_1]
+ traffic_generator.vnfd_helper = {
+ 'vdu': [{'external-interface': interfaces}]}
+ output = ProxProfile.sort_vpci(traffic_generator)
+ self.assertEqual([interface_1, interface_2, interface_3], output)
+
def test_fill_samples(self):
samples = {}
+
traffic_generator = mock.MagicMock()
- traffic_generator.vpci_if_name_ascending = [
+ interfaces = [
['id1', 'name1'],
- ['id2', 'name2'],
+ ['id2', 'name2']
]
-
traffic_generator.resource_helper.sut.port_stats.side_effect = [
list(range(12)),
list(range(10, 22)),
@@ -54,7 +65,9 @@ class TestProxProfile(unittest.TestCase):
'out_packets': 17,
},
}
- ProxProfile.fill_samples(samples, traffic_generator)
+ with mock.patch.object(ProxProfile, 'sort_vpci', return_value=interfaces):
+ ProxProfile.fill_samples(samples, traffic_generator)
+
self.assertDictEqual(samples, expected)
def test_init(self):
diff --git a/tests/unit/network_services/traffic_profile/test_rfc2544.py b/tests/unit/network_services/traffic_profile/test_rfc2544.py
index 221233710..21c8f6d5b 100644
--- a/tests/unit/network_services/traffic_profile/test_rfc2544.py
+++ b/tests/unit/network_services/traffic_profile/test_rfc2544.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,9 +13,6 @@
# limitations under the License.
#
-from __future__ import absolute_import
-from __future__ import division
-
import unittest
import mock
@@ -29,7 +24,7 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
if stl_patch:
- from yardstick.network_services.traffic_profile.traffic_profile \
+ from yardstick.network_services.traffic_profile.trex_traffic_profile \
import TrexProfile
from yardstick.network_services.traffic_profile.rfc2544 import \
RFC2544Profile
@@ -51,29 +46,29 @@ class TestRFC2544Profile(unittest.TestCase):
'traffic_profile': {'traffic_type': 'RFC2544Profile',
'frame_rate': 100},
'downlink_0': {'ipv4':
- {'outer_l2': {'framesize':
- {'64B': '100', '1518B': '0',
- '128B': '0', '1400B': '0',
- '256B': '0', '373b': '0',
- '570B': '0'}},
- 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
- 'proto': 'udp',
- 'srcip4': '90.90.1.1-90.105.255.255',
- 'dscp': 0, 'ttl': 32, 'count': 1},
- 'outer_l4': {'srcport': '2001',
- 'dsrport': '1234', 'count': 1}}},
+ {'outer_l2': {'framesize':
+ {'64B': '100', '1518B': '0',
+ '128B': '0', '1400B': '0',
+ '256B': '0', '373b': '0',
+ '570B': '0'}},
+ 'outer_l3v4': {'dstip4': '1.1.1.1-1.15.255.255',
+ 'proto': 'udp',
+ 'srcip4': '90.90.1.1-90.105.255.255',
+ 'dscp': 0, 'ttl': 32, 'count': 1},
+ 'outer_l4': {'srcport': '2001',
+ 'dsrport': '1234', 'count': 1}}},
'uplink_0': {'ipv4':
- {'outer_l2': {'framesize':
- {'64B': '100', '1518B': '0',
- '128B': '0', '1400B': '0',
- '256B': '0', '373b': '0',
- '570B': '0'}},
- 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
- 'proto': 'udp',
- 'srcip4': '1.1.1.1-1.15.255.255',
- 'dscp': 0, 'ttl': 32, 'count': 1},
- 'outer_l4': {'dstport': '2001',
- 'srcport': '1234', 'count': 1}}},
+ {'outer_l2': {'framesize':
+ {'64B': '100', '1518B': '0',
+ '128B': '0', '1400B': '0',
+ '256B': '0', '373b': '0',
+ '570B': '0'}},
+ 'outer_l3v4': {'dstip4': '9.9.1.1-90.105.255.255',
+ 'proto': 'udp',
+ 'srcip4': '1.1.1.1-1.15.255.255',
+ 'dscp': 0, 'ttl': 32, 'count': 1},
+ 'outer_l4': {'dstport': '2001',
+ 'srcport': '1234', 'count': 1}}},
'schema': 'isb:traffic_profile:0.1'}
def test___init__(self):
@@ -86,12 +81,11 @@ class TestRFC2544Profile(unittest.TestCase):
"uplink_0": ["xe0"],
"downlink_0": ["xe1"],
}
- traffic_generator.client = \
- mock.Mock(return_value=True)
+ traffic_generator.client.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(traffic_generator))
+ self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator))
def test_get_drop_percentage(self):
traffic_generator = mock.Mock(autospec=TrexProfile)
@@ -99,7 +93,7 @@ class TestRFC2544Profile(unittest.TestCase):
"uplink_0": ["xe0"],
"downlink_0": ["xe1"],
}
- traffic_generator.client = mock.Mock(return_value=True)
+ traffic_generator.client.return_value = True
r_f_c2544_profile = RFC2544Profile(self.TRAFFIC_PROFILE)
r_f_c2544_profile.params = self.PROFILE
@@ -133,7 +127,7 @@ class TestRFC2544Profile(unittest.TestCase):
'rx_throughput_fps': 20,
},
}
- traffic_generator.generate_samples = mock.MagicMock(return_value=samples)
+ traffic_generator.generate_samples.return_value = samples
traffic_generator.RUN_DURATION = 30
traffic_generator.rfc2544_helper.tolerance_low = 0.0001
traffic_generator.rfc2544_helper.tolerance_high = 0.0001
@@ -164,8 +158,6 @@ class TestRFC2544Profile(unittest.TestCase):
"in_packets": 1000,
"out_packets": 1002,
}
- tol_min = 0.0
- tolerance = 1.0
expected = {
'DropPercentage': 0.1996,
'RxThroughput': 33.333333333333336,
@@ -181,7 +173,8 @@ class TestRFC2544Profile(unittest.TestCase):
'rx_throughput_fps': 20,
},
}
- traffic_generator.generate_samples = mock.MagicMock(return_value=samples)
+ traffic_generator.generate_samples = mock.MagicMock(
+ return_value=samples)
traffic_generator.RUN_DURATION = 30
traffic_generator.rfc2544_helper.tolerance_low = 0.0001
traffic_generator.rfc2544_helper.tolerance_high = 0.0001
@@ -198,7 +191,7 @@ class TestRFC2544Profile(unittest.TestCase):
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(traffic_generator))
+ self.assertIsNone(r_f_c2544_profile.execute_traffic(traffic_generator))
samples = {}
for ifname in range(1):
name = "xe{}".format(ifname)
@@ -208,8 +201,6 @@ class TestRFC2544Profile(unittest.TestCase):
"tx_throughput_mbps": 10,
"in_packets": 1000,
"out_packets": 0}
- tol_min = 0.0
- tolerance = 0.0
r_f_c2544_profile.throughput_max = 0
expected = {
'DropPercentage': 100.0, 'RxThroughput': 100 / 3.0,
@@ -221,7 +212,7 @@ class TestRFC2544Profile(unittest.TestCase):
'tx_throughput_mbps': 10, 'rx_throughput_fps': 20
}
}
- traffic_generator.generate_samples = mock.MagicMock(return_value=samples)
+ traffic_generator.generate_samples = mock.Mock(return_value=samples)
traffic_generator.RUN_DURATION = 30
traffic_generator.rfc2544_helper.tolerance_low = 0.0001
traffic_generator.rfc2544_helper.tolerance_high = 0.0001
@@ -281,10 +272,5 @@ class TestRFC2544Profile(unittest.TestCase):
r_f_c2544_profile.calculate_pps = mock.Mock(return_value=[2274546.67,
1.0])
- self.assertEqual(None,
- r_f_c2544_profile.execute_latency(traffic_generator,
- samples))
-
-
-if __name__ == '__main__':
- unittest.main()
+ self.assertIsNone(r_f_c2544_profile.execute_latency(traffic_generator,
+ samples))
diff --git a/tests/unit/network_services/traffic_profile/test_traffic_profile.py b/tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py
index 37b9a08d0..d1009a5e8 100644
--- a/tests/unit/network_services/traffic_profile/test_traffic_profile.py
+++ b/tests/unit/network_services/traffic_profile/test_trex_traffic_profile.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,16 +27,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 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
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import TrexProfile
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import SRC
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import DST
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import ETHERNET
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import IP
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import IPv6
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import UDP
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import SRC_PORT
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import DST_PORT
+ from yardstick.network_services.traffic_profile.trex_traffic_profile import TYPE_OF_SERVICE
class TestTrexProfile(unittest.TestCase):
@@ -153,11 +151,11 @@ class TestTrexProfile(unittest.TestCase):
trex_profile = \
TrexProfile(TrafficProfile)
- self.assertEqual(None, trex_profile.set_qinq(qinq))
+ self.assertIsNone(trex_profile.set_qinq(qinq))
qinq = {"S-VLAN": {"id": "128-130", "priority": 0, "cfi": 0},
"C-VLAN": {"id": "512-515", "priority": 0, "cfi": 0}}
- self.assertEqual(None, trex_profile.set_qinq(qinq))
+ self.assertIsNone(trex_profile.set_qinq(qinq))
def test__set_outer_l2_fields(self):
trex_profile = \
@@ -166,14 +164,14 @@ class TestTrexProfile(unittest.TestCase):
"C-VLAN": {"id": 512, "priority": 0, "cfi": 0}}
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.assertIsNone(trex_profile._set_outer_l2_fields(outer_l2))
def test__set_outer_l3v4_fields(self):
trex_profile = \
TrexProfile(TrafficProfile)
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.assertIsNone(trex_profile._set_outer_l3v4_fields(outer_l3v4))
def test__set_outer_l3v6_fields(self):
trex_profile = \
@@ -182,13 +180,13 @@ class TestTrexProfile(unittest.TestCase):
outer_l3v6['proto'] = 'tcp'
outer_l3v6['tc'] = 1
outer_l3v6['hlim'] = 10
- self.assertEqual(None, trex_profile._set_outer_l3v6_fields(outer_l3v6))
+ self.assertIsNone(trex_profile._set_outer_l3v6_fields(outer_l3v6))
def test__set_outer_l4_fields(self):
trex_profile = \
TrexProfile(TrafficProfile)
outer_l4 = self.PROFILE[TrafficProfile.UPLINK]['ipv4']['outer_l4']
- self.assertEqual(None, trex_profile._set_outer_l4_fields(outer_l4))
+ self.assertIsNone(trex_profile._set_outer_l4_fields(outer_l4))
def test_get_streams(self):
trex_profile = \
diff --git a/tests/unit/network_services/vnf_generic/test_vnfdgen.py b/tests/unit/network_services/vnf_generic/test_vnfdgen.py
index ee881c963..2ab14129b 100644
--- a/tests/unit/network_services/vnf_generic/test_vnfdgen.py
+++ b/tests/unit/network_services/vnf_generic/test_vnfdgen.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
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 f9a10149e..2971b55eb 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,6 +19,7 @@ import os
from tests.unit import STL_MOCKS
from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
+from yardstick.common import utils
STLClient = mock.MagicMock()
@@ -312,7 +311,7 @@ class TestAclApproxVnf(unittest.TestCase):
acl_approx_vnf.ssh_helper.run.assert_called_once()
@mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.YangModel")
- @mock.patch("yardstick.network_services.vnf_generic.vnf.acl_vnf.find_relative_file")
+ @mock.patch.object(utils, 'find_relative_file')
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
@mock.patch(SSH_HELPER)
def test_instantiate(self, ssh, *args):
@@ -345,4 +344,4 @@ class TestAclApproxVnf(unittest.TestCase):
acl_approx_vnf.vnf_execute = mock.MagicMock()
acl_approx_vnf.dpdk_devbind = "dpdk-devbind.py"
acl_approx_vnf._resource_collect_stop = mock.Mock()
- self.assertEqual(None, acl_approx_vnf.terminate())
+ self.assertIsNone(acl_approx_vnf.terminate())
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 e9488f76f..664373f8f 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_base.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_base.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -195,7 +193,7 @@ class TestQueueFileWrapper(unittest.TestCase):
def test_close(self):
queue_file_wrapper = \
base.QueueFileWrapper(self.q_in, self.q_out, self.prompt)
- self.assertEqual(None, queue_file_wrapper.close())
+ self.assertIsNone(queue_file_wrapper.close())
def test_read(self):
queue_file_wrapper = \
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 62b3c7440..edaa0ad7e 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
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 0ac46c632..faceeb695 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +22,7 @@ import mock
import unittest
from tests.unit import STL_MOCKS
+from yardstick.common import utils
from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
@@ -962,7 +961,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
result = setup_helper.prox_config_data
self.assertEqual(result, expected)
- @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
+ @mock.patch.object(utils, 'find_relative_file')
def test_build_config_file_no_additional_file(self, mock_find_path):
vnf1 = {
'prox_args': {'-c': ""},
@@ -996,7 +995,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
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')
+ @mock.patch.object(utils, 'find_relative_file')
def test_build_config_file_additional_file_string(self, mock_find_path):
vnf1 = {
'prox_args': {'-c': ""},
@@ -1028,7 +1027,7 @@ class TestProxDpdkVnfSetupEnvHelper(unittest.TestCase):
helper.build_config_file()
self.assertDictEqual(helper.additional_files, expected)
- @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
+ @mock.patch.object(utils, 'find_relative_file')
def test_build_config_file_additional_file(self, mock_find_path):
vnf1 = {
'prox_args': {'-c': ""},
@@ -1730,7 +1729,7 @@ class TestProxProfileHelper(unittest.TestCase):
}
self.assertIsNone(helper._test_cores)
- expected = [12, 23]
+ expected = [3, 4]
result = helper.test_cores
self.assertEqual(result, expected)
self.assertIs(result, helper._test_cores)
@@ -1787,7 +1786,7 @@ class TestProxProfileHelper(unittest.TestCase):
}
self.assertIsNone(helper._latency_cores)
- expected = [12, 23]
+ expected = [3, 4]
result = helper.latency_cores
self.assertEqual(result, expected)
self.assertIs(result, helper._latency_cores)
@@ -1842,7 +1841,7 @@ class TestProxProfileHelper(unittest.TestCase):
}
}
- expected = [7, 8]
+ expected = [3, 4]
result = helper.get_cores(helper.PROX_CORE_GEN_MODE)
self.assertEqual(result, expected)
@@ -1984,8 +1983,8 @@ class TestProxMplsProfileHelper(unittest.TestCase):
}
}
- expected_tagged = [7]
- expected_plain = [8]
+ expected_tagged = [3]
+ expected_plain = [4]
self.assertIsNone(helper._cores_tuple)
self.assertEqual(helper.tagged_cores, expected_tagged)
self.assertEqual(helper.plain_cores, expected_plain)
@@ -2060,10 +2059,10 @@ class TestProxBngProfileHelper(unittest.TestCase):
}
}
- expected_cpe = [7]
- expected_inet = [8]
- expected_arp = [4, 3]
- expected_arp_task = [0, 4]
+ expected_cpe = [3]
+ expected_inet = [4]
+ expected_arp = [6, 9]
+ expected_arp_task = [0, 6]
expected_combined = (expected_cpe, expected_inet, expected_arp, expected_arp_task)
self.assertIsNone(helper._cores_tuple)
@@ -2131,8 +2130,8 @@ class TestProxVpeProfileHelper(unittest.TestCase):
}
}
- expected_cpe = [7]
- expected_inet = [8]
+ expected_cpe = [3]
+ expected_inet = [4]
expected_combined = (expected_cpe, expected_inet)
self.assertIsNone(helper._cores_tuple)
@@ -2245,8 +2244,8 @@ class TestProxlwAFTRProfileHelper(unittest.TestCase):
}
}
- expected_tun = [7]
- expected_inet = [8]
+ expected_tun = [3]
+ expected_inet = [4]
expected_combined = (expected_tun, expected_inet)
self.assertIsNone(helper._cores_tuple)
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 769279066..159b1f718 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -131,6 +129,8 @@ class TestProxApproxVnf(unittest.TestCase):
'packets_in',
'packets_fwd',
'packets_dropped',
+ 'curr_packets_fwd',
+ 'curr_packets_in'
],
},
'connection-point': [
@@ -329,7 +329,7 @@ class TestProxApproxVnf(unittest.TestCase):
'packets_in': 0,
'packets_dropped': 0,
'packets_fwd': 0,
- 'collect_stats': {'core': {}},
+ 'collect_stats': {'core': {}}
}
result = prox_approx_vnf.collect_kpi()
self.assertEqual(result, expected)
@@ -352,7 +352,11 @@ class TestProxApproxVnf(unittest.TestCase):
'collect_stats': {'core': {'result': 234}},
}
result = prox_approx_vnf.collect_kpi()
- self.assertEqual(result, expected)
+ self.assertEqual(result['packets_in'], expected['packets_in'])
+ self.assertEqual(result['packets_dropped'], expected['packets_dropped'])
+ self.assertEqual(result['packets_fwd'], expected['packets_fwd'])
+ self.assertNotEqual(result['packets_fwd'], 0)
+ self.assertNotEqual(result['packets_fwd'], 0)
@mock.patch(SSH_HELPER)
def test_collect_kpi_error(self, ssh, *args):
@@ -373,6 +377,25 @@ class TestProxApproxVnf(unittest.TestCase):
file_path = os.path.join(curr_path, filename)
return file_path
+ @mock.patch('yardstick.common.utils.open', create=True)
+ @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True)
+ @mock.patch('yardstick.network_services.helpers.iniparser.open', create=True)
+ @mock.patch(SSH_HELPER)
+ def test_run_prox(self, ssh, *_):
+ mock_ssh(ssh)
+
+ prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
+ prox_approx_vnf.ssh_helper.join_bin_path.return_value = '/tool_path12/tool_file34'
+ 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 /tmp/l3-swap-2.cfg '"
+
+ prox_approx_vnf._run()
+ result = prox_approx_vnf.ssh_helper.run.call_args[0][0]
+ self.assertEqual(result, expected)
+
@mock.patch(SSH_HELPER)
def bad_test_instantiate(self, *args):
prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py
index 9ed6fd5b3..c6292f258 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -261,7 +259,4 @@ class TestRouterVNF(unittest.TestCase):
router_vnf = RouterVNF(name, vnfd)
router_vnf._vnf_process = mock.MagicMock()
router_vnf._vnf_process.terminate = mock.Mock()
- self.assertEqual(None, router_vnf.terminate())
-
-if __name__ == '__main__':
- unittest.main()
+ self.assertIsNone(router_vnf.terminate())
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 25633384e..c7d2abcd5 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
@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2017 Intel Corporation
+# Copyright (c) 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,14 +13,17 @@
# limitations under the License.
#
+from copy import deepcopy
+
import unittest
import mock
-from copy import deepcopy
+import six
from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from tests.unit import STL_MOCKS
from yardstick.benchmark.contexts.base import Context
from yardstick.common import exceptions as y_exceptions
+from yardstick.common import utils
from yardstick.network_services.nfvi.resource import ResourceProfile
from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
@@ -36,7 +37,8 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
if stl_patch:
- from yardstick.network_services.vnf_generic.vnf.sample_vnf import VnfSshHelper
+ from yardstick.network_services.vnf_generic.vnf import sample_vnf
+ from yardstick.network_services.vnf_generic.vnf.vnf_ssh_helper import VnfSshHelper
from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFDeployHelper
from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper
from yardstick.network_services.vnf_generic.vnf.sample_vnf import ResourceHelper
@@ -528,46 +530,25 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
result = DpdkVnfSetupEnvHelper._update_traffic_type(ip_pipeline_cfg, traffic_options)
self.assertEqual(result, expected)
- def test__setup_hugepages(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
- ssh_helper = mock.Mock()
- ssh_helper.execute.return_value = 0, '', ''
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
-
- result = dpdk_setup_helper._setup_hugepages()
- expect_start_list = ['awk', 'awk', 'echo']
- expect_in_list = ['meminfo', 'nr_hugepages', '16']
- 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):
- self.assertTrue(arg0.startswith(expect_start))
- self.assertIn(expect_in, arg0)
-
- def test__setup_hugepages_2_mb(self):
- vnfd_helper = VnfdHelper(self.VNFD_0)
+ @mock.patch.object(six, 'BytesIO', return_value=six.BytesIO(b'100\n'))
+ @mock.patch.object(utils, 'read_meminfo',
+ return_value={'Hugepagesize': '2048'})
+ def test__setup_hugepages(self, mock_meminfo, *args):
ssh_helper = mock.Mock()
- ssh_helper.execute.return_value = 0, '2048kB ', ''
- scenario_helper = mock.Mock()
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
-
- result = dpdk_setup_helper._setup_hugepages()
- expect_start_list = ['awk', 'awk', 'echo']
- expect_in_list = ['meminfo', 'nr_hugepages', '8192']
- 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):
- self.assertTrue(arg0.startswith(expect_start))
- self.assertIn(expect_in, arg0)
+ dpdk_setup_helper = DpdkVnfSetupEnvHelper(
+ mock.ANY, ssh_helper, mock.ANY)
+ with mock.patch.object(sample_vnf.LOG, 'info') as mock_info:
+ dpdk_setup_helper._setup_hugepages()
+ mock_info.assert_called_once_with(
+ 'Hugepages size (kB): %s, number claimed: %s, number set: '
+ '%s', 2048, 8192, 100)
+ mock_meminfo.assert_called_once_with(ssh_helper)
@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.object(utils, 'find_relative_file')
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig')
- def test_build_config(self, mock_multi_port_config_class, mock_find, *args):
+ @mock.patch.object(utils, 'open_relative_file')
+ def test_build_config(self, mock_open_rf, mock_multi_port_config_class, mock_find, *args):
mock_multi_port_config = mock_multi_port_config_class()
vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
@@ -584,6 +565,20 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
self.assertGreaterEqual(mock_multi_port_config.generate_config.call_count, 1)
self.assertGreaterEqual(mock_multi_port_config.generate_script.call_count, 1)
+ scenario_helper.vnf_cfg = {'file': 'fake_file'}
+ dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+ mock_open_rf.side_effect = mock.mock_open(read_data='fake_data')
+ dpdk_setup_helper.PIPELINE_COMMAND = expected = 'pipeline command'
+
+ result = dpdk_setup_helper.build_config()
+
+ mock_open_rf.assert_called_once()
+ self.assertEqual(result, expected)
+ self.assertGreaterEqual(ssh_helper.upload_config_file.call_count, 2)
+ self.assertGreaterEqual(mock_find.call_count, 1)
+ self.assertGreaterEqual(mock_multi_port_config.generate_config.call_count, 1)
+ self.assertGreaterEqual(mock_multi_port_config.generate_script.call_count, 1)
+
def test__build_pipeline_kwargs(self):
vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
@@ -619,10 +614,15 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
ssh_helper = mock.Mock()
ssh_helper.execute = execute
- dpdk_vnf_setup_env_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, mock.Mock())
+ scenario_helper = mock.Mock()
+ scenario_helper.nodes = [None, None]
+ dpdk_vnf_setup_env_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
dpdk_vnf_setup_env_helper._validate_cpu_cfg = mock.Mock(return_value=[])
- self.assertIsInstance(dpdk_vnf_setup_env_helper.setup_vnf_environment(), ResourceProfile)
+ with mock.patch.object(dpdk_vnf_setup_env_helper, '_setup_dpdk'):
+ self.assertIsInstance(
+ dpdk_vnf_setup_env_helper.setup_vnf_environment(),
+ ResourceProfile)
def test__setup_dpdk(self):
ssh_helper = mock.Mock()
@@ -638,21 +638,6 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
mock.call('lsmod | grep -i igb_uio')
])
- def test__setup_dpdk_igb_uio_not_loaded(self):
- ssh_helper = mock.Mock()
- ssh_helper.execute = mock.Mock()
- ssh_helper.execute.side_effect = [(0, 0, 0), (1, 0, 0)]
- dpdk_setup_helper = DpdkVnfSetupEnvHelper(mock.ANY, ssh_helper, mock.ANY)
- with mock.patch.object(dpdk_setup_helper, '_setup_hugepages') as \
- mock_setup_hp:
- with self.assertRaises(y_exceptions.DPDKSetupDriverError):
- dpdk_setup_helper._setup_dpdk()
- mock_setup_hp.assert_called_once()
- ssh_helper.execute.assert_has_calls([
- mock.call('sudo modprobe uio && sudo modprobe igb_uio'),
- mock.call('lsmod | grep -i igb_uio')
- ])
-
@mock.patch('yardstick.ssh.SSH')
def test__setup_resources(self, _):
vnfd_helper = VnfdHelper(deepcopy(self.VNFD_0))
@@ -690,6 +675,7 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
# ssh_helper.execute = mock.Mock(return_value = (0, 'text', ''))
# ssh_helper.execute.return_value = 0, 'output', ''
scenario_helper = mock.Mock()
+ scenario_helper.nodes = [None, None]
rv = ['0000:05:00.1', '0000:05:00.0']
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
@@ -708,6 +694,7 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
vnfd_helper = VnfdHelper(self.VNFD_0)
ssh_helper = mock.Mock()
scenario_helper = mock.Mock()
+ scenario_helper.nodes = [None, None]
dpdk_setup_helper = DpdkVnfSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
dpdk_setup_helper.dpdk_bind_helper.bind = mock.Mock()
dpdk_setup_helper.dpdk_bind_helper.used_drivers = {
@@ -1386,7 +1373,7 @@ class TestSampleVNFDeployHelper(unittest.TestCase):
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
@mock.patch('subprocess.check_output')
- def test_deploy_vnfs_disabled(self, *args):
+ def test_deploy_vnfs_disabled(self, *_):
vnfd_helper = mock.Mock()
ssh_helper = mock.Mock()
ssh_helper.join_bin_path.return_value = 'joined_path'
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py
index d77068137..d831ddd3d 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,13 +13,15 @@
# limitations under the License.
#
-from __future__ import absolute_import
+import subprocess
-import unittest
import mock
-import subprocess
+import unittest
+import six
from tests.unit import STL_MOCKS
+from yardstick import ssh
+from yardstick.common import utils
STLClient = mock.MagicMock()
@@ -145,13 +145,13 @@ class TestIxLoadTrafficGen(unittest.TestCase):
ssh.from_node.return_value = ssh_mock
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd)
- self.assertEqual(None, ixload_traffic_gen.listen_traffic({}))
+ self.assertIsNone(ixload_traffic_gen.listen_traffic({}))
- @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.makedirs")
+ @mock.patch.object(utils, 'find_relative_file')
+ @mock.patch.object(utils, 'makedirs')
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
- def test_instantiate(self, call, shutil, mock_makedirs):
- # pylint: disable=unused-argument
+ def test_instantiate(self, shutil, *args):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
@@ -175,19 +175,18 @@ class TestIxLoadTrafficGen(unittest.TestCase):
'1C/1T',
'worker_threads': 1}}
}})
- with mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open',
- create=True) as mock_open:
+ with mock.patch.object(six.moves.builtins, 'open',
+ create=True) as mock_open:
mock_open.return_value = mock.MagicMock()
ixload_traffic_gen.instantiate(scenario_cfg, {})
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
- @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len")
- def test_run_traffic(self, call, shutil, main_open, min, max, len):
- # pylint: disable=unused-argument
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
+ def test_run_traffic(self, shutil, *args):
mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
mock_traffic_profile.get_traffic_definition.return_value = "64"
mock_traffic_profile.params = self.TRAFFIC_PROFILE
@@ -213,13 +212,12 @@ class TestIxLoadTrafficGen(unittest.TestCase):
self.assertIsNone(result)
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
- @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.open")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.min")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.max")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.len")
- def test_run_traffic_csv(self, call, shutil, main_open, min, max, len):
- # pylint: disable=unused-argument
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
+ def test_run_traffic_csv(self, shutil, *args):
mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
mock_traffic_profile.get_traffic_definition.return_value = "64"
mock_traffic_profile.params = self.TRAFFIC_PROFILE
@@ -247,20 +245,15 @@ class TestIxLoadTrafficGen(unittest.TestCase):
self.assertIsNone(result)
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
+ @mock.patch.object(ssh, 'SSH')
def test_terminate(self, *args):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "", ""))
- ssh.from_node.return_value = ssh_mock
- ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd)
- self.assertEqual(None, ixload_traffic_gen.terminate())
+ vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
+ ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd)
+ self.assertIsNone(ixload_traffic_gen.terminate())
- @mock.patch("yardstick.ssh.SSH")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
- def test_parse_csv_read(self, mock_call, mock_ssh):
- # pylint: disable=unused-argument
+ @mock.patch.object(ssh, 'SSH')
+ def test_parse_csv_read(self, mock_ssh, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
kpi_data = {
'HTTP Total Throughput (Kbps)': 1,
@@ -282,10 +275,9 @@ class TestIxLoadTrafficGen(unittest.TestCase):
for key_left, key_right in IxLoadResourceHelper.KPI_LIST.items():
self.assertEqual(result[key_left][-1], int(kpi_data[key_right]))
- @mock.patch("yardstick.ssh.SSH")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
- def test_parse_csv_read_value_error(self, mock_call, mock_ssh):
- # pylint: disable=unused-argument
+ @mock.patch.object(ssh, 'SSH')
+ def test_parse_csv_read_value_error(self, mock_ssh, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
http_reader = [{
'HTTP Total Throughput (Kbps)': 1,
@@ -305,10 +297,9 @@ class TestIxLoadTrafficGen(unittest.TestCase):
ixload_traffic_gen.resource_helper.parse_csv_read(http_reader)
self.assertDictEqual(ixload_traffic_gen.resource_helper.result, init_value)
- @mock.patch("yardstick.ssh.SSH")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
- def test_parse_csv_read_error(self, mock_call, mock_ssh):
- # pylint: disable=unused-argument
+ @mock.patch.object(ssh, 'SSH')
+ def test_parse_csv_read_error(self, mock_ssh, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
http_reader = [{
'HTTP Total Throughput (Kbps)': 1,
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 fb26f20b5..91a353d0d 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,7 +34,7 @@ if stl_patch:
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
+ from yardstick.network_services.vnf_generic.vnf.vnf_ssh_helper import VnfSshHelper
class TestPingResourceHelper(unittest.TestCase):
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 0104e7f63..2151a3284 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
@@ -423,4 +423,4 @@ class TestProxTrafficGen(unittest.TestCase):
prox_traffic_gen._vnf_wrapper.setup_helper = mock.MagicMock()
prox_traffic_gen._vnf_wrapper._vnf_process = mock.MagicMock()
prox_traffic_gen._vnf_wrapper.resource_helper = mock.MagicMock()
- self.assertEqual(None, prox_traffic_gen.terminate())
+ self.assertIsNone(prox_traffic_gen.terminate())
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 e9f718cb7..61fc012bc 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +14,10 @@
#
import os
-import unittest
+
import mock
+import six
+import unittest
from tests.unit import STL_MOCKS
@@ -170,7 +170,7 @@ class TestIXIATrafficGen(unittest.TestCase):
ssh.from_node.return_value = ssh_mock
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
- self.assertEqual(None, ixnet_traffic_gen.listen_traffic({}))
+ self.assertIsNone(ixnet_traffic_gen.listen_traffic({}))
def test_instantiate(self, *args):
with mock.patch("yardstick.ssh.SSH") as ssh:
@@ -228,7 +228,7 @@ class TestIXIATrafficGen(unittest.TestCase):
ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
ixnet_traffic_gen._traffic_process = mock.MagicMock()
ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
- self.assertEqual(None, ixnet_traffic_gen.terminate())
+ self.assertIsNone(ixnet_traffic_gen.terminate())
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
@@ -341,7 +341,7 @@ class TestIXIATrafficGen(unittest.TestCase):
'task_path': '/path/to/task'
}
- @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True)
+ @mock.patch.object(six.moves.builtins, 'open', create=True)
@mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.open',
mock.mock_open(), create=True)
@mock.patch('yardstick.network_services.vnf_generic.vnf.tg_rfc2544_ixia.LOG.exception')
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 7342cfcdc..b9a95a945 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
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 618071507..f80d1f948 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -483,7 +481,3 @@ class TestTrexTrafficGen(unittest.TestCase):
client = mock.Mock(autospec=STLClient)
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 472052b0a..4cf4320f9 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
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 f0a56665c..48fc87ed4 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +20,9 @@ import os
from tests.unit import STL_MOCKS
from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
+from yardstick.common import utils
+
+
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
@@ -331,7 +332,7 @@ pipeline>
vfw_approx_vnf._run()
vfw_approx_vnf.ssh_helper.run.assert_called_once()
- @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.find_relative_file")
+ @mock.patch.object(utils, 'find_relative_file')
@mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.YangModel")
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
@mock.patch(SSH_HELPER)
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 c074dfb4c..8c45d973e 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
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");