aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick')
-rw-r--r--yardstick/benchmark/core/task.py16
-rw-r--r--yardstick/benchmark/runners/duration.py6
-rw-r--r--yardstick/benchmark/runners/iteration.py6
-rw-r--r--yardstick/benchmark/scenarios/base.py30
-rw-r--r--yardstick/benchmark/scenarios/lib/create_floating_ip.py32
-rw-r--r--yardstick/benchmark/scenarios/lib/delete_floating_ip.py26
-rw-r--r--yardstick/benchmark/scenarios/lib/delete_router_interface.py28
-rw-r--r--yardstick/benchmark/scenarios/networking/pktgen_dpdk.py23
-rw-r--r--yardstick/benchmark/scenarios/networking/pktgen_dpdk_latency_benchmark.bash32
-rw-r--r--yardstick/benchmark/scenarios/networking/testpmd_fwd.bash16
-rw-r--r--yardstick/benchmark/scenarios/networking/vnf_generic.py9
-rw-r--r--yardstick/common/exceptions.py12
-rw-r--r--yardstick/common/openstack_utils.py85
-rw-r--r--yardstick/network_services/vnf_generic/vnf/sample_vnf.py4
-rw-r--r--yardstick/tests/unit/apiserver/resources/v1/__init__.py0
-rw-r--r--yardstick/tests/unit/apiserver/resources/v1/test_testsuites.py35
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py33
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py52
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py54
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/test_base.py30
-rw-r--r--yardstick/tests/unit/common/test_openstack_utils.py98
21 files changed, 451 insertions, 176 deletions
diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py
index 4272a6db9..955b8cae2 100644
--- a/yardstick/benchmark/core/task.py
+++ b/yardstick/benchmark/core/task.py
@@ -614,15 +614,25 @@ class TaskParser(object): # pragma: no cover
vnf__0: vnf_0.yardstick
"""
def qualified_name(name):
- node_name, context_name = name.split('.')
+ try:
+ # for openstack
+ node_name, context_name = name.split('.')
+ sep = '.'
+ except ValueError:
+ # for kubernetes, some kubernetes resources don't support
+ # name format like 'xxx.xxx', so we use '-' instead
+ # need unified later
+ node_name, context_name = name.split('-')
+ sep = '-'
+
try:
ctx = next((context for context in contexts
- if context.assigned_name == context_name))
+ if context.assigned_name == context_name))
except StopIteration:
raise y_exc.ScenarioConfigContextNameNotFound(
context_name=context_name)
- return '{}.{}'.format(node_name, ctx.name)
+ return '{}{}{}'.format(node_name, sep, ctx.name)
if 'host' in scenario:
scenario['host'] = qualified_name(scenario['host'])
diff --git a/yardstick/benchmark/runners/duration.py b/yardstick/benchmark/runners/duration.py
index fbf72a74c..60b0348c3 100644
--- a/yardstick/benchmark/runners/duration.py
+++ b/yardstick/benchmark/runners/duration.py
@@ -66,6 +66,8 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
data = {}
errors = ""
+ benchmark.pre_run_wait_time(interval)
+
try:
result = method(data)
except AssertionError as assertion:
@@ -77,7 +79,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
errors = assertion.args
# catch all exceptions because with multiprocessing we can have un-picklable exception
# problems https://bugs.python.org/issue9400
- except Exception:
+ except Exception: # pylint: disable=broad-except
errors = traceback.format_exc()
LOG.exception("")
else:
@@ -86,7 +88,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
# if we do timeout we don't care about dropping individual KPIs
output_queue.put(result, True, QUEUE_PUT_TIMEOUT)
- time.sleep(interval)
+ benchmark.post_run_wait_time(interval)
benchmark_output = {
'timestamp': time.time(),
diff --git a/yardstick/benchmark/runners/iteration.py b/yardstick/benchmark/runners/iteration.py
index cb0424377..20d6da054 100644
--- a/yardstick/benchmark/runners/iteration.py
+++ b/yardstick/benchmark/runners/iteration.py
@@ -71,6 +71,8 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
data = {}
errors = ""
+ benchmark.pre_run_wait_time(interval)
+
try:
result = method(data)
except AssertionError as assertion:
@@ -90,7 +92,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
scenario_cfg['options']['rate'] -= delta
sequence = 1
continue
- except Exception:
+ except Exception: # pylint: disable=broad-except
errors = traceback.format_exc()
LOG.exception("")
else:
@@ -99,7 +101,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
# if we do timeout we don't care about dropping individual KPIs
output_queue.put(result, True, QUEUE_PUT_TIMEOUT)
- time.sleep(interval)
+ benchmark.post_run_wait_time(interval)
benchmark_output = {
'timestamp': time.time(),
diff --git a/yardstick/benchmark/scenarios/base.py b/yardstick/benchmark/scenarios/base.py
index 10a728828..58a02805c 100644
--- a/yardstick/benchmark/scenarios/base.py
+++ b/yardstick/benchmark/scenarios/base.py
@@ -13,9 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
-# yardstick comment: this is a modified copy of
-# rally/rally/benchmark/scenarios/base.py
+import abc
+import time
+import six
from stevedore import extension
import yardstick.common.utils as utils
@@ -37,20 +38,29 @@ def _iter_scenario_classes(scenario_type=None):
yield scenario
+@six.add_metaclass(abc.ABCMeta)
class Scenario(object):
def setup(self):
- """ default impl for scenario setup """
+ """Default setup implementation for Scenario classes"""
pass
+ @abc.abstractmethod
def run(self, *args):
- """ catcher for not implemented run methods in subclasses """
- raise RuntimeError("run method not implemented")
+ """Entry point for scenario classes, called from runner worker"""
def teardown(self):
- """ default impl for scenario teardown """
+ """Default teardown implementation for Scenario classes"""
pass
+ def pre_run_wait_time(self, time_seconds):
+ """Time waited before executing the run method"""
+ pass
+
+ def post_run_wait_time(self, time_seconds):
+ """Time waited after executing the run method"""
+ time.sleep(time_seconds)
+
@staticmethod
def get_types():
"""return a list of known runner type (class) names"""
@@ -88,10 +98,14 @@ class Scenario(object):
"""
return cls.__doc__.splitlines()[0] if cls.__doc__ else str(None)
- def _push_to_outputs(self, keys, values):
+ @staticmethod
+ def _push_to_outputs(keys, values):
+ """Return a dictionary given the keys and the values"""
return dict(zip(keys, values))
- def _change_obj_to_dict(self, obj):
+ @staticmethod
+ def _change_obj_to_dict(obj):
+ """Return a dictionary from the __dict__ attribute of an object"""
dic = {}
for k, v in vars(obj).items():
try:
diff --git a/yardstick/benchmark/scenarios/lib/create_floating_ip.py b/yardstick/benchmark/scenarios/lib/create_floating_ip.py
index 7108722af..e29f9d1fc 100644
--- a/yardstick/benchmark/scenarios/lib/create_floating_ip.py
+++ b/yardstick/benchmark/scenarios/lib/create_floating_ip.py
@@ -11,7 +11,8 @@ import logging
import os
from yardstick.benchmark.scenarios import base
-import yardstick.common.openstack_utils as op_utils
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
LOG = logging.getLogger(__name__)
@@ -26,9 +27,18 @@ class CreateFloatingIp(base.Scenario):
self.scenario_cfg = scenario_cfg
self.context_cfg = context_cfg
self.ext_net_id = os.getenv("EXTERNAL_NETWORK", "external")
+ self.options = self.scenario_cfg["options"]
+
+ self.network_name_or_id = self.options.get("network_name_or_id", self.ext_net_id)
+ self.server = self.options.get("server")
+ self.fixed_address = self.options.get("fixed_address")
+ self.nat_destination = self.options.get("nat_destination")
+ self.port = self.options.get("port")
+ self.wait = self.options.get("wait", False)
+ self.timeout = self.options.get("timeout", 60)
+
+ self.shade_client = openstack_utils.get_shade_client()
- self.neutron_client = op_utils.get_neutron_client()
- self.shade_client = op_utils.get_shade_client()
self.setup_done = False
def setup(self):
@@ -36,21 +46,25 @@ class CreateFloatingIp(base.Scenario):
self.setup_done = True
- def run(self, *args):
+ def run(self, result):
"""execute the test"""
if not self.setup_done:
self.setup()
- net_id = op_utils.get_network_id(self.shade_client, self.ext_net_id)
- floating_info = op_utils.create_floating_ip(self.neutron_client,
- extnet_id=net_id)
+ floating_info = openstack_utils.create_floating_ip(
+ self.shade_client, network_name_or_id=self.network_name_or_id,
+ server=self.server, fixed_address=self.fixed_address,
+ nat_destination=self.nat_destination, port=self.port,
+ wait=self.wait, timeout=self.timeout)
if not floating_info:
+ result.update({"floating_ip_create": 0})
LOG.error("Creating floating ip failed!")
- return
+ raise exceptions.ScenarioCreateFloatingIPError
+ result.update({"floating_ip_create": 1})
LOG.info("Creating floating ip successful!")
- keys = self.scenario_cfg.get('output', '').split()
+ keys = self.scenario_cfg.get("output", '').split()
values = [floating_info["fip_id"], floating_info["fip_addr"]]
return self._push_to_outputs(keys, values)
diff --git a/yardstick/benchmark/scenarios/lib/delete_floating_ip.py b/yardstick/benchmark/scenarios/lib/delete_floating_ip.py
index 4314952fb..a35445f6f 100644
--- a/yardstick/benchmark/scenarios/lib/delete_floating_ip.py
+++ b/yardstick/benchmark/scenarios/lib/delete_floating_ip.py
@@ -7,13 +7,12 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from __future__ import print_function
-from __future__ import absolute_import
-
import logging
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
from yardstick.benchmark.scenarios import base
-import yardstick.common.openstack_utils as op_utils
+
LOG = logging.getLogger(__name__)
@@ -28,9 +27,10 @@ class DeleteFloatingIp(base.Scenario):
self.context_cfg = context_cfg
self.options = self.scenario_cfg['options']
- self.floating_ip_id = self.options.get("floating_ip_id", None)
+ self.floating_ip_id = self.options["floating_ip_id"]
+ self.retry = self.options.get("retry", 1)
- self.nova_client = op_utils.get_nova_client()
+ self.shade_client = openstack_utils.get_shade_client()
self.setup_done = False
def setup(self):
@@ -44,11 +44,13 @@ class DeleteFloatingIp(base.Scenario):
if not self.setup_done:
self.setup()
- status = op_utils.delete_floating_ip(nova_client=self.nova_client,
- floatingip_id=self.floating_ip_id)
- if status:
- result.update({"delete_floating_ip": 1})
- LOG.info("Delete floating ip successful!")
- else:
+ status = openstack_utils.delete_floating_ip(
+ self.shade_client, self.floating_ip_id,
+ retry=self.retry)
+ if not status:
result.update({"delete_floating_ip": 0})
LOG.error("Delete floating ip failed!")
+ raise exceptions.ScenarioDeleteFloatingIPError
+
+ result.update({"delete_floating_ip": 1})
+ LOG.info("Delete floating ip successful!")
diff --git a/yardstick/benchmark/scenarios/lib/delete_router_interface.py b/yardstick/benchmark/scenarios/lib/delete_router_interface.py
index 117c80811..e71aed3ef 100644
--- a/yardstick/benchmark/scenarios/lib/delete_router_interface.py
+++ b/yardstick/benchmark/scenarios/lib/delete_router_interface.py
@@ -7,13 +7,11 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from __future__ import print_function
-from __future__ import absolute_import
-
import logging
from yardstick.benchmark.scenarios import base
-import yardstick.common.openstack_utils as op_utils
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
LOG = logging.getLogger(__name__)
@@ -28,10 +26,11 @@ class DeleteRouterInterface(base.Scenario):
self.context_cfg = context_cfg
self.options = self.scenario_cfg['options']
- self.subnet_id = self.options.get("subnet_id", None)
- self.router_id = self.options.get("router_id", None)
+ self.router = self.options["router"]
+ self.subnet_id = self.options.get("subnet_id")
+ self.port_id = self.options.get("port_id")
- self.neutron_client = op_utils.get_neutron_client()
+ self.shade_client = openstack_utils.get_shade_client()
self.setup_done = False
@@ -46,12 +45,13 @@ class DeleteRouterInterface(base.Scenario):
if not self.setup_done:
self.setup()
- status = op_utils.remove_interface_router(self.neutron_client,
- router_id=self.router_id,
- subnet_id=self.subnet_id)
- if status:
- result.update({"delete_router_interface": 1})
- LOG.info("Delete router interface successful!")
- else:
+ status = openstack_utils.remove_router_interface(
+ self.shade_client, self.router, subnet_id=self.subnet_id,
+ port_id=self.port_id)
+ if not status:
result.update({"delete_router_interface": 0})
LOG.error("Delete router interface failed!")
+ raise exceptions.ScenarioRemoveRouterIntError
+
+ result.update({"delete_router_interface": 1})
+ LOG.info("Delete router interface successful!")
diff --git a/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py b/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py
index ce8a7f497..9a7b975a2 100644
--- a/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py
+++ b/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py
@@ -70,39 +70,42 @@ class PktgenDPDKLatency(base.Scenario):
def run(self, result):
"""execute the benchmark"""
+ options = self.scenario_cfg['options']
+ eth1 = options.get("eth1", "ens4")
+ eth2 = options.get("eth2", "ens5")
if not self.setup_done:
self.setup()
if not self.testpmd_args:
- self.testpmd_args = utils.get_port_mac(self.client, 'eth2')
+ self.testpmd_args = utils.get_port_mac(self.client, eth2)
if not self.pktgen_args:
- server_rev_mac = utils.get_port_mac(self.server, 'eth1')
- server_send_mac = utils.get_port_mac(self.server, 'eth2')
- client_src_ip = utils.get_port_ip(self.client, 'eth1')
- client_dst_ip = utils.get_port_ip(self.client, 'eth2')
+ server_rev_mac = utils.get_port_mac(self.server, eth1)
+ server_send_mac = utils.get_port_mac(self.server, eth2)
+ client_src_ip = utils.get_port_ip(self.client, eth1)
+ client_dst_ip = utils.get_port_ip(self.client, eth2)
self.pktgen_args = [client_src_ip, client_dst_ip,
server_rev_mac, server_send_mac]
- options = self.scenario_cfg['options']
packetsize = options.get("packetsize", 64)
rate = options.get("rate", 100)
- cmd = "screen sudo -E bash ~/testpmd_fwd.sh %s " % (self.testpmd_args)
+ cmd = "screen sudo -E bash ~/testpmd_fwd.sh %s %s %s" % \
+ (self.testpmd_args, eth1, eth2)
LOG.debug("Executing command: %s", cmd)
self.server.send_command(cmd)
time.sleep(1)
- cmd = "screen sudo -E bash ~/pktgen_dpdk.sh %s %s %s %s %s %s" % \
+ cmd = "screen sudo -E bash ~/pktgen_dpdk.sh %s %s %s %s %s %s %s %s" % \
(self.pktgen_args[0], self.pktgen_args[1], self.pktgen_args[2],
- self.pktgen_args[3], rate, packetsize)
+ self.pktgen_args[3], rate, packetsize, eth1, eth2)
LOG.debug("Executing command: %s", cmd)
self.client.send_command(cmd)
# wait for finishing test
- time.sleep(1)
+ time.sleep(60)
cmd = r"""\
cat ~/result.log -vT \
diff --git a/yardstick/benchmark/scenarios/networking/pktgen_dpdk_latency_benchmark.bash b/yardstick/benchmark/scenarios/networking/pktgen_dpdk_latency_benchmark.bash
index b872aa3df..dcd5a9bfb 100644
--- a/yardstick/benchmark/scenarios/networking/pktgen_dpdk_latency_benchmark.bash
+++ b/yardstick/benchmark/scenarios/networking/pktgen_dpdk_latency_benchmark.bash
@@ -7,7 +7,7 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-!/bin/sh
+#!/bin/sh
set -e
@@ -18,6 +18,11 @@ FWD_REV_MAC=$3 # MAC address of forwarding receiver in VM B
FWD_SEND_MAC=$4 # MAC address of forwarding sender in VM B
RATE=$5 # packet rate in percentage
PKT_SIZE=$6 # packet size
+ETH1=$7
+ETH2=$8
+
+DPDK_VERSION="dpdk-17.02"
+PKTGEN_VERSION="pktgen-3.2.12"
load_modules()
@@ -31,13 +36,13 @@ load_modules()
if lsmod | grep "igb_uio" &> /dev/null ; then
echo "igb_uio module is loaded"
else
- insmod /dpdk/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
+ insmod /opt/tempT/$DPDK_VERSION/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
fi
if lsmod | grep "rte_kni" &> /dev/null ; then
echo "rte_kni module is loaded"
else
- insmod /dpdk/x86_64-native-linuxapp-gcc/kmod/rte_kni.ko
+ insmod /opt/tempT/$DPDK_VERSION/x86_64-native-linuxapp-gcc/kmod/rte_kni.ko
fi
}
@@ -48,8 +53,10 @@ change_permissions()
}
add_interface_to_dpdk(){
+ ip link set $ETH1 down
+ ip link set $ETH2 down
interfaces=$(lspci |grep Eth |tail -n +2 |awk '{print $1}')
- /dpdk/tools/dpdk-devbind.py --bind=igb_uio $interfaces
+ /opt/tempT/$DPDK_VERSION/usertools/dpdk-devbind.py --bind=igb_uio $interfaces
}
@@ -106,20 +113,14 @@ spawn ./app/app/x86_64-native-linuxapp-gcc/pktgen -c 0x07 -n 4 -b $blacklist --
expect "Pktgen>"
send "\n"
expect "Pktgen>"
-send "screen on\n"
+send "on\n"
expect "Pktgen>"
set count 10
while { $count } {
send "page latency\n"
- expect {
- timeout { send "\n" }
- -regexp {..*} {
- set result "${result}$expect_out(0,string)"
- set timeout 1
- exp_continue
- }
- "Pktgen>"
- }
+ expect -re "(..*)"
+ set result "${result}$expect_out(0,string)"
+ set timeout 1
set count [expr $count-1]
}
send "stop 0\n"
@@ -136,7 +137,7 @@ EOF
run_pktgen()
{
blacklist=$(lspci |grep Eth |awk '{print $1}'|head -1)
- cd /pktgen-dpdk
+ cd /opt/tempT/$PKTGEN_VERSION
touch /home/ubuntu/result.log
result_log="/home/ubuntu/result.log"
sudo expect /home/ubuntu/pktgen.exp $blacklist $result_log
@@ -153,4 +154,3 @@ main()
}
main
-
diff --git a/yardstick/benchmark/scenarios/networking/testpmd_fwd.bash b/yardstick/benchmark/scenarios/networking/testpmd_fwd.bash
index 247a8a833..30b63a734 100644
--- a/yardstick/benchmark/scenarios/networking/testpmd_fwd.bash
+++ b/yardstick/benchmark/scenarios/networking/testpmd_fwd.bash
@@ -13,6 +13,10 @@ set -e
# Commandline arguments
DST_MAC=$1 # MAC address of the peer port
+ETH1=$2
+ETH2=$3
+
+DPDK_VERSION="dpdk-17.02"
load_modules()
{
@@ -25,13 +29,13 @@ load_modules()
if lsmod | grep "igb_uio" &> /dev/null ; then
echo "igb_uio module is loaded"
else
- insmod /dpdk/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
+ insmod /opt/tempT/$DPDK_VERSION/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
fi
if lsmod | grep "rte_kni" &> /dev/null ; then
echo "rte_kni module is loaded"
else
- insmod /dpdk/x86_64-native-linuxapp-gcc/kmod/rte_kni.ko
+ insmod /opt/tempT/$DPDK_VERSION/x86_64-native-linuxapp-gcc/kmod/rte_kni.ko
fi
}
@@ -42,15 +46,17 @@ change_permissions()
}
add_interface_to_dpdk(){
+ ip link set $ETH1 down
+ ip link set $ETH2 down
interfaces=$(lspci |grep Eth |tail -n +2 |awk '{print $1}')
- /dpdk/tools/dpdk-devbind.py --bind=igb_uio $interfaces
+ /opt/tempT/$DPDK_VERSION/usertools//dpdk-devbind.py --bind=igb_uio $interfaces
}
run_testpmd()
{
blacklist=$(lspci |grep Eth |awk '{print $1}'|head -1)
- cd /dpdk
- sudo ./destdir/bin/testpmd -c 0x07 -n 4 -b $blacklist -- -a --eth-peer=1,$DST_MAC --forward-mode=mac
+ cd /opt/tempT/$DPDK_VERSION/x86_64-native-linuxapp-gcc/app
+ sudo ./testpmd -c 0x07 -n 4 -b $blacklist -- -a --eth-peer=1,$DST_MAC --forward-mode=mac
}
main()
diff --git a/yardstick/benchmark/scenarios/networking/vnf_generic.py b/yardstick/benchmark/scenarios/networking/vnf_generic.py
index 0e4785294..be2fa3f3b 100644
--- a/yardstick/benchmark/scenarios/networking/vnf_generic.py
+++ b/yardstick/benchmark/scenarios/networking/vnf_generic.py
@@ -14,6 +14,7 @@
import copy
import logging
+import time
import ipaddress
from itertools import chain
@@ -484,3 +485,11 @@ class NetworkServiceTestCase(scenario_base.Scenario):
# https://bugs.python.org/issue9400
LOG.exception("")
raise RuntimeError("Error in teardown")
+
+ def pre_run_wait_time(self, time_seconds):
+ """Time waited before executing the run method"""
+ time.sleep(time_seconds)
+
+ def post_run_wait_time(self, time_seconds):
+ """Time waited after executing the run method"""
+ pass
diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py
index e0e5b7e16..9ae2c68cd 100644
--- a/yardstick/common/exceptions.py
+++ b/yardstick/common/exceptions.py
@@ -150,3 +150,15 @@ class UnsupportedPodFormatError(YardstickException):
class ScenarioCreateRouterError(YardstickException):
message = 'Create Neutron Router Scenario failed'
+
+
+class ScenarioRemoveRouterIntError(YardstickException):
+ message = 'Remove Neutron Router Interface Scenario failed'
+
+
+class ScenarioCreateFloatingIPError(YardstickException):
+ message = 'Create Neutron Floating IP Scenario failed'
+
+
+class ScenarioDeleteFloatingIPError(YardstickException):
+ message = 'Delete Neutron Floating IP Scenario failed'
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py
index a4fd4e550..a6b53a607 100644
--- a/yardstick/common/openstack_utils.py
+++ b/yardstick/common/openstack_utils.py
@@ -429,12 +429,6 @@ def delete_keypair(nova_client, key): # pragma: no cover
# *********************************************
# NEUTRON
# *********************************************
-def get_network_id(shade_client, network_name):
- networks = shade_client.list_networks({'name': network_name})
- if networks:
- return networks[0]['id']
-
-
def create_neutron_net(shade_client, network_name, shared=False,
admin_state_up=True, external=False, provider=None,
project_id=None):
@@ -563,38 +557,71 @@ def remove_gateway_router(neutron_client, router_id): # pragma: no cover
return False
-def remove_interface_router(neutron_client, router_id, subnet_id,
- **json_body): # pragma: no cover
- json_body.update({"subnet_id": subnet_id})
+def remove_router_interface(shade_client, router, subnet_id=None,
+ port_id=None):
+ """Detach a subnet from an internal router interface.
+
+ At least one of subnet_id or port_id must be supplied. If you specify both
+ subnet and port ID, the subnet ID must correspond to the subnet ID of the
+ first IP address on the port specified by the port ID.
+ Otherwise an error occurs.
+
+ :param router: The dict object of the router being changed
+ :param subnet_id:(string) The ID of the subnet to use for the interface
+ :param port_id:(string) The ID of the port to use for the interface
+ :returns: True on success
+ """
try:
- neutron_client.remove_interface_router(router=router_id,
- body=json_body)
+ shade_client.remove_router_interface(
+ router, subnet_id=subnet_id, port_id=port_id)
return True
- except Exception: # pylint: disable=broad-except
- log.error("Error [remove_interface_router(neutron_client, '%s', "
- "'%s')]", router_id, subnet_id)
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [remove_interface_router(shade_client)]. "
+ "Exception message: %s", o_exc.orig_message)
return False
-def create_floating_ip(neutron_client, extnet_id): # pragma: no cover
- props = {'floating_network_id': extnet_id}
+def create_floating_ip(shade_client, network_name_or_id=None, server=None,
+ fixed_address=None, nat_destination=None,
+ port=None, wait=False, timeout=60):
+ """Allocate a new floating IP from a network or a pool.
+
+ :param network_name_or_id: Name or ID of the network
+ that the floating IP should come from.
+ :param server: Server dict for the server to create
+ the IP for and to which it should be attached.
+ :param fixed_address: Fixed IP to attach the floating ip to.
+ :param nat_destination: Name or ID of the network
+ that the fixed IP to attach the floating
+ IP to should be on.
+ :param port: The port ID that the floating IP should be
+ attached to. Specifying a port conflicts with specifying a
+ server,fixed_address or nat_destination.
+ :param wait: Whether to wait for the IP to be active.Only applies
+ if a server is provided.
+ :param timeout: How long to wait for the IP to be active.Only
+ applies if a server is provided.
+
+ :returns:Floating IP id and address
+ """
try:
- ip_json = neutron_client.create_floatingip({'floatingip': props})
- fip_addr = ip_json['floatingip']['floating_ip_address']
- fip_id = ip_json['floatingip']['id']
- except Exception: # pylint: disable=broad-except
- log.error("Error [create_floating_ip(neutron_client)]")
- return None
- return {'fip_addr': fip_addr, 'fip_id': fip_id}
+ fip = shade_client.create_floating_ip(
+ network=network_name_or_id, server=server,
+ fixed_address=fixed_address, nat_destination=nat_destination,
+ port=port, wait=wait, timeout=timeout)
+ return {'fip_addr': fip['floating_ip_address'], 'fip_id': fip['id']}
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [create_floating_ip(shade_client)]. "
+ "Exception message: %s", o_exc.orig_message)
-def delete_floating_ip(nova_client, floatingip_id): # pragma: no cover
+def delete_floating_ip(shade_client, floating_ip_id, retry=1):
try:
- nova_client.floating_ips.delete(floatingip_id)
- return True
- except Exception: # pylint: disable=broad-except
- log.error("Error [delete_floating_ip(nova_client, '%s')]",
- floatingip_id)
+ return shade_client.delete_floating_ip(floating_ip_id=floating_ip_id,
+ retry=retry)
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [delete_floating_ip(shade_client,'%s')]. "
+ "Exception message: %s", floating_ip_id, o_exc.orig_message)
return False
diff --git a/yardstick/network_services/vnf_generic/vnf/sample_vnf.py b/yardstick/network_services/vnf_generic/vnf/sample_vnf.py
index addbd9aa4..77488c479 100644
--- a/yardstick/network_services/vnf_generic/vnf/sample_vnf.py
+++ b/yardstick/network_services/vnf_generic/vnf/sample_vnf.py
@@ -79,7 +79,6 @@ class DpdkVnfSetupEnvHelper(SetupEnvHelper):
APP_NAME = 'DpdkVnf'
FIND_NET_CMD = "find /sys/class/net -lname '*{}*' -printf '%f'"
NR_HUGEPAGES_PATH = '/proc/sys/vm/nr_hugepages'
- HUGEPAGES_KB = 1024 * 1024 * 16
@staticmethod
def _update_packet_type(ip_pipeline_cfg, traffic_options):
@@ -118,7 +117,8 @@ class DpdkVnfSetupEnvHelper(SetupEnvHelper):
def _setup_hugepages(self):
meminfo = utils.read_meminfo(self.ssh_helper)
hp_size_kb = int(meminfo['Hugepagesize'])
- nr_hugepages = int(abs(self.HUGEPAGES_KB / hp_size_kb))
+ hugepages_gb = self.scenario_helper.all_options.get('hugepages_gb', 16)
+ nr_hugepages = int(abs(hugepages_gb * 1024 * 1024 / hp_size_kb))
self.ssh_helper.execute('echo %s | sudo tee %s' %
(nr_hugepages, self.NR_HUGEPAGES_PATH))
hp = six.BytesIO()
diff --git a/yardstick/tests/unit/apiserver/resources/v1/__init__.py b/yardstick/tests/unit/apiserver/resources/v1/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/unit/apiserver/resources/v1/__init__.py
diff --git a/yardstick/tests/unit/apiserver/resources/v1/test_testsuites.py b/yardstick/tests/unit/apiserver/resources/v1/test_testsuites.py
new file mode 100644
index 000000000..85c045f44
--- /dev/null
+++ b/yardstick/tests/unit/apiserver/resources/v1/test_testsuites.py
@@ -0,0 +1,35 @@
+##############################################################################
+# Copyright (c) 2018 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
+##############################################################################
+import mock
+
+import unittest
+
+from yardstick.tests.unit.apiserver import APITestCase
+from api.utils.thread import TaskThread
+
+
+class TestsuiteTestCase(APITestCase):
+
+ def test_run_test_suite(self):
+ if self.app is None:
+ unittest.skip('host config error')
+ return
+
+ TaskThread.start = mock.MagicMock()
+
+ url = 'yardstick/testsuites/action'
+ data = {
+ 'action': 'run_test_suite',
+ 'args': {
+ 'opts': {},
+ 'testsuite': 'opnfv_smoke'
+ }
+ }
+ resp = self._post(url, data)
+ self.assertEqual(resp.get('status'), 1)
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py
index a7286f5da..894cc1c2a 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py
@@ -11,48 +11,47 @@ import unittest
import mock
from yardstick.benchmark.scenarios.lib import create_floating_ip
-import yardstick.common.openstack_utils as op_utils
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
class CreateFloatingIpTestCase(unittest.TestCase):
def setUp(self):
- self._mock_get_network_id = mock.patch.object(
- op_utils, 'get_network_id')
- self.mock_get_network_id = self._mock_get_network_id.start()
self._mock_create_floating_ip = mock.patch.object(
- op_utils, 'create_floating_ip')
+ openstack_utils, 'create_floating_ip')
self.mock_create_floating_ip = self._mock_create_floating_ip.start()
- self._mock_get_neutron_client = mock.patch.object(
- op_utils, 'get_neutron_client')
- self.mock_get_neutron_client = self._mock_get_neutron_client.start()
self._mock_get_shade_client = mock.patch.object(
- op_utils, 'get_shade_client')
+ openstack_utils, 'get_shade_client')
self.mock_get_shade_client = self._mock_get_shade_client.start()
self._mock_log = mock.patch.object(create_floating_ip, 'LOG')
self.mock_log = self._mock_log.start()
+ self.args = {'options': {'network_name_or_id': 'yardstick_net'}}
+ self.result = {}
- self._fip_obj = create_floating_ip.CreateFloatingIp(mock.ANY, mock.ANY)
- self._fip_obj.scenario_cfg = {'output': 'key1\nkey2'}
+ self.fip_obj = create_floating_ip.CreateFloatingIp(self.args, mock.ANY)
+ self.fip_obj.scenario_cfg = {'output': 'key1\nkey2'}
self.addCleanup(self._stop_mock)
def _stop_mock(self):
- self._mock_get_network_id.stop()
self._mock_create_floating_ip.stop()
- self._mock_get_neutron_client.stop()
self._mock_get_shade_client.stop()
self._mock_log.stop()
def test_run(self):
self.mock_create_floating_ip.return_value = {'fip_id': 'value1',
'fip_addr': 'value2'}
- output = self._fip_obj.run(mock.ANY)
- self.assertDictEqual({'key1': 'value1', 'key2': 'value2'}, output)
+ output = self.fip_obj.run(self.result)
+ self.assertEqual({'floating_ip_create': 1}, self.result)
+ self.assertEqual({'key1': 'value1', 'key2': 'value2'}, output)
+ self.mock_log.info.asset_called_once_with(
+ 'Creating floating ip successful!')
def test_run_no_fip(self):
self.mock_create_floating_ip.return_value = None
- output = self._fip_obj.run(mock.ANY)
- self.assertIsNone(output)
+ with self.assertRaises(exceptions.ScenarioCreateFloatingIPError):
+ self.fip_obj.run(self.result)
+ self.assertEqual({'floating_ip_create': 0}, self.result)
self.mock_log.error.assert_called_once_with(
'Creating floating ip failed!')
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
index 3185ec59f..45a39eba2 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
@@ -6,22 +6,50 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from oslo_utils import uuidutils
import unittest
import mock
-from yardstick.benchmark.scenarios.lib.delete_floating_ip import DeleteFloatingIp
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
+from yardstick.benchmark.scenarios.lib import delete_floating_ip
class DeleteFloatingIpTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.get_nova_client')
- @mock.patch('yardstick.common.openstack_utils.delete_floating_ip')
- def test_delete_floating_ip(self, mock_get_nova_client, mock_delete_floating_ip):
- options = {
- 'floating_ip_id': '123-123-123'
- }
- args = {"options": options}
- obj = DeleteFloatingIp(args, {})
- obj.run({})
- mock_get_nova_client.assert_called_once()
- mock_delete_floating_ip.assert_called_once()
+ def setUp(self):
+ self._mock_delete_floating_ip = mock.patch.object(
+ openstack_utils, 'delete_floating_ip')
+ self.mock_delete_floating_ip = self._mock_delete_floating_ip.start()
+ self._mock_get_shade_client = mock.patch.object(
+ openstack_utils, 'get_shade_client')
+ self.mock_get_shade_client = self._mock_get_shade_client.start()
+ self._mock_log = mock.patch.object(delete_floating_ip, 'LOG')
+ self.mock_log = self._mock_log.start()
+ self.args = {'options': {'floating_ip_id': uuidutils.generate_uuid()}}
+ self.result = {}
+
+ self.del_obj = delete_floating_ip.DeleteFloatingIp(
+ self.args, mock.ANY)
+
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_delete_floating_ip.stop()
+ self._mock_get_shade_client.stop()
+ self._mock_log.stop()
+
+ def test_run(self):
+ self.mock_delete_floating_ip.return_value = True
+ self.assertIsNone(self.del_obj.run(self.result))
+ self.assertEqual({"delete_floating_ip": 1}, self.result)
+ self.mock_log.info.assert_called_once_with(
+ "Delete floating ip successful!")
+
+ def test_run_fail(self):
+ self.mock_delete_floating_ip.return_value = False
+ with self.assertRaises(exceptions.ScenarioDeleteFloatingIPError):
+ self.del_obj.run(self.result)
+ self.assertEqual({"delete_floating_ip": 0}, self.result)
+ self.mock_log.error.assert_called_once_with(
+ "Delete floating ip failed!")
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
index 9e9c5a5b6..823cb951a 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
@@ -6,23 +6,51 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+from oslo_utils import uuidutils
import unittest
import mock
-from yardstick.benchmark.scenarios.lib.delete_router_interface import DeleteRouterInterface
+from yardstick.benchmark.scenarios.lib import delete_router_interface
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
class DeleteRouterInterfaceTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.get_neutron_client')
- @mock.patch('yardstick.common.openstack_utils.remove_interface_router')
- def test_delete_router_interface(self, mock_get_neutron_client, mock_remove_interface_router):
- options = {
- 'router_id': '123-123-123',
- 'subnet_id': '321-321-321'
- }
- args = {"options": options}
- obj = DeleteRouterInterface(args, {})
- obj.run({})
- mock_get_neutron_client.assert_called_once()
- mock_remove_interface_router.assert_called_once()
+ def setUp(self):
+ self._mock_remove_router_interface = mock.patch.object(
+ openstack_utils, 'remove_router_interface')
+ self.mock_remove_router_interface = (
+ self._mock_remove_router_interface.start())
+ self._mock_get_shade_client = mock.patch.object(
+ openstack_utils, 'get_shade_client')
+ self.mock_get_shade_client = self._mock_get_shade_client.start()
+ self._mock_log = mock.patch.object(delete_router_interface, 'LOG')
+ self.mock_log = self._mock_log.start()
+ self.args = {'options': {'router': uuidutils.generate_uuid()}}
+ self.result = {}
+ self.delrout_obj = delete_router_interface.DeleteRouterInterface(
+ self.args, mock.ANY)
+
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_remove_router_interface.stop()
+ self._mock_get_shade_client.stop()
+ self._mock_log.stop()
+
+ def test_run(self):
+ self.mock_remove_router_interface.return_value = True
+ self.assertIsNone(self.delrout_obj.run(self.result))
+ self.assertEqual({"delete_router_interface": 1}, self.result)
+ self.mock_log.info.assert_called_once_with(
+ "Delete router interface successful!")
+
+ def test_run_fail(self):
+ self.mock_remove_router_interface.return_value = False
+ with self.assertRaises(exceptions.ScenarioRemoveRouterIntError):
+ self.delrout_obj.run(self.result)
+ self.assertEqual({"delete_router_interface": 0}, self.result)
+ self.mock_log.error.assert_called_once_with(
+ "Delete router interface failed!")
diff --git a/yardstick/tests/unit/benchmark/scenarios/test_base.py b/yardstick/tests/unit/benchmark/scenarios/test_base.py
index 985338532..284a71cc8 100644
--- a/yardstick/tests/unit/benchmark/scenarios/test_base.py
+++ b/yardstick/tests/unit/benchmark/scenarios/test_base.py
@@ -13,10 +13,21 @@
# License for the specific language governing permissions and limitations
# under the License.
+import time
+
+import mock
+
from yardstick.benchmark.scenarios import base
from yardstick.tests.unit import base as ut_base
+class _TestScenario(base.Scenario):
+ __scenario_type__ = 'Test Scenario'
+
+ def run(self):
+ pass
+
+
class ScenarioTestCase(ut_base.BaseUnitTestCase):
def test_get_scenario_type(self):
@@ -85,6 +96,25 @@ class ScenarioTestCase(ut_base.BaseUnitTestCase):
self.assertEqual('No such scenario type %s' % wrong_scenario_name,
str(exc.exception))
+ def test_scenario_abstract_class(self):
+ # pylint: disable=abstract-class-instantiated
+ with self.assertRaises(TypeError):
+ base.Scenario()
+
+ @mock.patch.object(time, 'sleep')
+ def test_pre_run_wait_time(self, mock_sleep):
+ """Ensure default behaviour (backwards compatibility): no wait time"""
+ test_scenario = _TestScenario()
+ test_scenario.pre_run_wait_time(mock.ANY)
+ mock_sleep.assert_not_called()
+
+ @mock.patch.object(time, 'sleep')
+ def test_post_run_wait_time(self, mock_sleep):
+ """Ensure default behaviour (backwards compatibility): wait time"""
+ test_scenario = _TestScenario()
+ test_scenario.post_run_wait_time(100)
+ mock_sleep.assert_called_once_with(100)
+
class IterScenarioClassesTestCase(ut_base.BaseUnitTestCase):
diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py
index e39a13f1b..b8f85c083 100644
--- a/yardstick/tests/unit/common/test_openstack_utils.py
+++ b/yardstick/tests/unit/common/test_openstack_utils.py
@@ -35,28 +35,6 @@ class GetHeatApiVersionTestCase(unittest.TestCase):
self.assertEqual(api_version, expected_result)
-class GetNetworkIdTestCase(unittest.TestCase):
-
- def test_get_network_id(self):
- _uuid = uuidutils.generate_uuid()
- mock_shade_client = mock.Mock()
- mock_shade_client.list_networks = mock.Mock()
- mock_shade_client.list_networks.return_value = [{'id': _uuid}]
-
- output = openstack_utils.get_network_id(mock_shade_client,
- 'network_name')
- self.assertEqual(_uuid, output)
-
- def test_get_network_id_no_network(self):
- mock_shade_client = mock.Mock()
- mock_shade_client.list_networks = mock.Mock()
- mock_shade_client.list_networks.return_value = None
-
- output = openstack_utils.get_network_id(mock_shade_client,
- 'network_name')
- self.assertIsNone(output)
-
-
class DeleteNeutronNetTestCase(unittest.TestCase):
def setUp(self):
@@ -185,3 +163,79 @@ class CreateNeutronRouterTestCase(unittest.TestCase):
self.mock_shade_client)
mock_logger.error.assert_called_once()
self.assertIsNone(output)
+
+
+class RemoveRouterInterfaceTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.router = 'router'
+ self.mock_shade_client.remove_router_interface = mock.Mock()
+
+ def test_remove_router_interface(self):
+ self.mock_shade_client.remove_router_interface.return_value = True
+ output = openstack_utils.remove_router_interface(
+ self.mock_shade_client, self.router)
+ self.assertTrue(output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_remove_router_interface_exception(self, mock_logger):
+ self.mock_shade_client.remove_router_interface.side_effect = (
+ exc.OpenStackCloudException('error message'))
+ output = openstack_utils.remove_router_interface(
+ self.mock_shade_client, self.router)
+ mock_logger.error.assert_called_once()
+ self.assertFalse(output)
+
+
+class CreateFloatingIpTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.network_name_or_id = 'name'
+ self.mock_shade_client.create_floating_ip = mock.Mock()
+
+ def test_create_floating_ip(self):
+ self.mock_shade_client.create_floating_ip.return_value = \
+ {'floating_ip_address': 'value1', 'id': 'value2'}
+ output = openstack_utils.create_floating_ip(self.mock_shade_client,
+ self.network_name_or_id)
+ self.assertEqual({'fip_addr': 'value1', 'fip_id': 'value2'}, output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_create_floating_ip_exception(self, mock_logger):
+ self.mock_shade_client.create_floating_ip.side_effect = (
+ exc.OpenStackCloudException('error message'))
+ output = openstack_utils.create_floating_ip(
+ self.mock_shade_client, self.network_name_or_id)
+ mock_logger.error.assert_called_once()
+ self.assertIsNone(output)
+
+
+class DeleteFloatingIpTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.floating_ip_id = 'floating_ip_id'
+ self.mock_shade_client.delete_floating_ip = mock.Mock()
+
+ def test_delete_floating_ip(self):
+ self.mock_shade_client.delete_floating_ip.return_value = True
+ output = openstack_utils.delete_floating_ip(self.mock_shade_client,
+ 'floating_ip_id')
+ self.assertTrue(output)
+
+ def test_delete_floating_ip_fail(self):
+ self.mock_shade_client.delete_floating_ip.return_value = False
+ output = openstack_utils.delete_floating_ip(self.mock_shade_client,
+ 'floating_ip_id')
+ self.assertFalse(output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_delete_floating_ip_exception(self, mock_logger):
+ self.mock_shade_client.delete_floating_ip.side_effect = (
+ exc.OpenStackCloudException('error message'))
+ output = openstack_utils.delete_floating_ip(self.mock_shade_client,
+ 'floating_ip_id')
+ mock_logger.error.assert_called_once()
+ self.assertFalse(output)