summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yardstick/benchmark/contexts/base.py3
-rw-r--r--yardstick/benchmark/scenarios/networking/vnf_generic.py4
-rw-r--r--yardstick/network_services/collector/subscriber.py31
-rw-r--r--yardstick/network_services/nfvi/resource.py73
-rw-r--r--yardstick/network_services/vnf_generic/vnf/prox_vnf.py16
-rw-r--r--yardstick/network_services/vnf_generic/vnf/router_vnf.py4
-rw-r--r--yardstick/network_services/vnf_generic/vnf/sample_vnf.py58
-rw-r--r--yardstick/network_services/vnf_generic/vnf/udp_replay.py11
-rw-r--r--yardstick/network_services/vnf_generic/vnf/vpe_vnf.py5
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_base.py2
-rw-r--r--yardstick/tests/unit/network_services/collector/test_subscriber.py33
-rw-r--r--yardstick/tests/unit/network_services/nfvi/test_resource.py42
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py36
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py205
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py46
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py19
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py40
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py43
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py18
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py12
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py16
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py29
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py21
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py40
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py10
-rw-r--r--yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py16
26 files changed, 553 insertions, 280 deletions
diff --git a/yardstick/benchmark/contexts/base.py b/yardstick/benchmark/contexts/base.py
index 022e365e4..1c798fbb3 100644
--- a/yardstick/benchmark/contexts/base.py
+++ b/yardstick/benchmark/contexts/base.py
@@ -81,6 +81,9 @@ class Context(object):
self.file_path = os.path.join(YARDSTICK_ROOT_PATH, file_path)
cfg = utils.read_yaml_file(self.file_path)
+ for node in cfg["nodes"]:
+ node["ctx_type"] = self.__context_type__
+
self.nodes.extend(cfg["nodes"])
self.controllers.extend([node for node in cfg["nodes"]
if node.get("role") == "Controller"])
diff --git a/yardstick/benchmark/scenarios/networking/vnf_generic.py b/yardstick/benchmark/scenarios/networking/vnf_generic.py
index 4d7c4f9be..eb62d6222 100644
--- a/yardstick/benchmark/scenarios/networking/vnf_generic.py
+++ b/yardstick/benchmark/scenarios/networking/vnf_generic.py
@@ -23,6 +23,7 @@ import time
import six
import yaml
+from yardstick.benchmark.contexts import base as context_base
from yardstick.benchmark.scenarios import base as scenario_base
from yardstick.common.constants import LOG_DIR
from yardstick.common import exceptions
@@ -36,6 +37,7 @@ from yardstick.network_services.traffic_profile import base as tprofile_base
from yardstick.network_services.utils import get_nsb_option
from yardstick import ssh
+
traffic_profile.register_modules()
@@ -448,7 +450,7 @@ class NetworkServiceTestCase(scenario_base.Scenario):
traffic_gen.listen_traffic(self.traffic_profile)
# register collector with yardstick for KPI collection.
- self.collector = Collector(self.vnfs)
+ self.collector = Collector(self.vnfs, context_base.Context.get_physical_nodes())
self.collector.start()
# Start the actual traffic
diff --git a/yardstick/network_services/collector/subscriber.py b/yardstick/network_services/collector/subscriber.py
index 322b3f5a2..937c266a6 100644
--- a/yardstick/network_services/collector/subscriber.py
+++ b/yardstick/network_services/collector/subscriber.py
@@ -14,17 +14,36 @@
"""This module implements stub for publishing results in yardstick format."""
import logging
+from yardstick.network_services.nfvi.resource import ResourceProfile
+from yardstick.network_services.utils import get_nsb_option
+
+
LOG = logging.getLogger(__name__)
class Collector(object):
"""Class that handles dictionary of results in yardstick-plot format."""
- def __init__(self, vnfs):
+ def __init__(self, vnfs, contexts_nodes, timeout=3600):
super(Collector, self).__init__()
self.vnfs = vnfs
+ self.nodes = contexts_nodes
+ self.bin_path = get_nsb_option('bin_path', '')
+ self.resource_profiles = {}
+
+ for ctx_name, nodes in contexts_nodes.items():
+ for node in (node for node in nodes if node.get('collectd')):
+ name = ".".join([node['name'], ctx_name])
+ self.resource_profiles.update(
+ {name: ResourceProfile.make_from_node(node, timeout)}
+ )
def start(self):
+ for resource in self.resource_profiles.values():
+ resource.initiate_systemagent(self.bin_path)
+ resource.start()
+ resource.amqp_process_for_nfvi_kpi()
+
for vnf in self.vnfs:
vnf.start_collect()
@@ -32,6 +51,9 @@ class Collector(object):
for vnf in self.vnfs:
vnf.stop_collect()
+ for resource in self.resource_profiles.values():
+ resource.stop()
+
def get_kpi(self):
"""Returns dictionary of results in yardstick-plot format
@@ -42,7 +64,12 @@ class Collector(object):
for vnf in self.vnfs:
# Result example:
# {"VNF1: { "tput" : [1000, 999] }, "VNF2": { "latency": 100 }}
- LOG.debug("collect KPI for %s", vnf.name)
+ LOG.debug("collect KPI for vnf %s", vnf.name)
results[vnf.name] = vnf.collect_kpi()
+ for node_name, resource in self.resource_profiles.items():
+ LOG.debug("collect KPI for nfvi_node %s", node_name)
+ results[node_name] = {"core": resource.amqp_collect_nfvi_kpi()}
+ LOG.debug("%s collect KPIs %s", node_name, results[node_name]['core'])
+
return results
diff --git a/yardstick/network_services/nfvi/resource.py b/yardstick/network_services/nfvi/resource.py
index 0c0bf223a..5922bd3b9 100644
--- a/yardstick/network_services/nfvi/resource.py
+++ b/yardstick/network_services/nfvi/resource.py
@@ -31,6 +31,7 @@ from yardstick.common.exceptions import ResourceCommandError
from yardstick.common.task_template import finalize_for_yaml
from yardstick.common.utils import validate_non_string_sequence
from yardstick.network_services.nfvi.collectd import AmqpConsumer
+from yardstick.benchmark.contexts import heat
LOG = logging.getLogger(__name__)
@@ -52,7 +53,8 @@ class ResourceProfile(object):
DEFAULT_TIMEOUT = 3600
OVS_SOCKET_PATH = "/usr/local/var/run/openvswitch/db.sock"
- def __init__(self, mgmt, port_names=None, plugins=None, interval=None, timeout=None):
+ def __init__(self, mgmt, port_names=None, plugins=None,
+ interval=None, timeout=None, reset_mq_flag=True):
if plugins is None:
self.plugins = {}
@@ -77,6 +79,7 @@ class ResourceProfile(object):
# we need to save mgmt so we can connect to port 5672
self.mgmt = mgmt
self.connection = ssh.AutoConnectSSH.from_node(mgmt)
+ self._reset_mq_flag = reset_mq_flag
@classmethod
def make_from_node(cls, node, timeout):
@@ -87,7 +90,10 @@ class ResourceProfile(object):
plugins = collectd_options.get("plugins", {})
interval = collectd_options.get("interval")
- return cls(node, plugins=plugins, interval=interval, timeout=timeout)
+ reset_mq_flag = (False if node.get("ctx_type") == heat.HeatContext.__context_type__
+ else True)
+ return cls(node, plugins=plugins, interval=interval,
+ timeout=timeout, reset_mq_flag=reset_mq_flag)
def check_if_system_agent_running(self, process):
""" verify if system agent is running """
@@ -210,11 +216,14 @@ class ResourceProfile(object):
if not self.enable:
return {}
+ if self.check_if_system_agent_running("collectd")[0] != 0:
+ return {}
+
metric = {}
while not self._queue.empty():
metric.update(self._queue.get())
- msg = self.parse_collectd_result(metric)
- return msg
+
+ return self.parse_collectd_result(metric)
def _provide_config_file(self, config_file_path, nfvi_cfg, template_kwargs):
template = pkg_resources.resource_string("yardstick.network_services.nfvi",
@@ -250,7 +259,7 @@ class ResourceProfile(object):
if status != 0:
LOG.error("cannot find OVS socket %s", socket_path)
- def _start_rabbitmq(self, connection):
+ def _reset_rabbitmq(self, connection):
# Reset amqp queue
LOG.debug("reset and setup amqp to collect data from collectd")
# ensure collectd.conf.d exists to avoid error/warning
@@ -263,10 +272,37 @@ class ResourceProfile(object):
"sudo rabbitmqctl authenticate_user admin admin",
"sudo rabbitmqctl set_permissions -p / admin '.*' '.*' '.*'"
]
+
for cmd in cmd_list:
- exit_status, stdout, stderr = connection.execute(cmd)
- if exit_status != 0:
- raise ResourceCommandError(command=cmd, stderr=stderr)
+ exit_status, _, stderr = connection.execute(cmd)
+ if exit_status != 0:
+ raise ResourceCommandError(command=cmd, stderr=stderr)
+
+ def _check_rabbitmq_user(self, connection, user='admin'):
+ exit_status, stdout, _ = connection.execute("sudo rabbitmqctl list_users")
+ if exit_status == 0:
+ for line in stdout.split('\n')[1:]:
+ if line.split('\t')[0] == user:
+ return True
+
+ def _set_rabbitmq_admin_user(self, connection):
+ LOG.debug("add admin user to amqp")
+ cmd_list = ["sudo rabbitmqctl add_user admin admin",
+ "sudo rabbitmqctl authenticate_user admin admin",
+ "sudo rabbitmqctl set_permissions -p / admin '.*' '.*' '.*'"
+ ]
+
+ for cmd in cmd_list:
+ exit_status, stdout, stderr = connection.execute(cmd)
+ if exit_status != 0:
+ raise ResourceCommandError(command=cmd, stdout=stdout, stderr=stderr)
+
+ def _start_rabbitmq(self, connection):
+ if self._reset_mq_flag:
+ self._reset_rabbitmq(connection)
+ else:
+ if not self._check_rabbitmq_user(connection):
+ self._set_rabbitmq_admin_user(connection)
# check stdout for "sudo rabbitmqctl status" command
cmd = "sudo rabbitmqctl status"
@@ -282,10 +318,11 @@ class ResourceProfile(object):
self._prepare_collectd_conf(config_file_path)
connection.execute('sudo pkill -x -9 collectd')
- exit_status = connection.execute("which %s > /dev/null 2>&1" % collectd_path)[0]
+ cmd = "which %s > /dev/null 2>&1" % collectd_path
+ exit_status, _, stderr = connection.execute(cmd)
if exit_status != 0:
- LOG.warning("%s is not present disabling", collectd_path)
- return
+ raise ResourceCommandError(command=cmd, stderr=stderr)
+
if "ovs_stats" in self.plugins:
self._setup_ovs_stats(connection)
@@ -293,8 +330,12 @@ class ResourceProfile(object):
LOG.debug("Start collectd service..... %s second timeout", self.timeout)
# intel_pmu plug requires large numbers of files open, so try to set
# ulimit -n to a large value
- connection.execute("sudo bash -c 'ulimit -n 1000000 ; %s'" % collectd_path,
- timeout=self.timeout)
+
+ cmd = "sudo bash -c 'ulimit -n 1000000 ; %s'" % collectd_path
+ exit_status, _, stderr = connection.execute(cmd, timeout=self.timeout)
+ if exit_status != 0:
+ raise ResourceCommandError(command=cmd, stderr=stderr)
+
LOG.debug("Done")
def initiate_systemagent(self, bin_path):
@@ -334,5 +375,7 @@ class ResourceProfile(object):
if pid:
self.connection.execute('sudo kill -9 "%s"' % pid)
self.connection.execute('sudo pkill -9 "%s"' % agent)
- self.connection.execute('sudo service rabbitmq-server stop')
- self.connection.execute("sudo rabbitmqctl stop_app")
+
+ if self._reset_mq_flag:
+ self.connection.execute('sudo service rabbitmq-server stop')
+ self.connection.execute("sudo rabbitmqctl stop_app")
diff --git a/yardstick/network_services/vnf_generic/vnf/prox_vnf.py b/yardstick/network_services/vnf_generic/vnf/prox_vnf.py
index cb97f7711..9d90ddb47 100644
--- a/yardstick/network_services/vnf_generic/vnf/prox_vnf.py
+++ b/yardstick/network_services/vnf_generic/vnf/prox_vnf.py
@@ -23,6 +23,7 @@ from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxDpdkVnfS
from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper
from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
from yardstick.network_services import constants
+from yardstick.benchmark.contexts import base as context_base
LOG = logging.getLogger(__name__)
@@ -68,15 +69,20 @@ class ProxApproxVnf(SampleVNF):
def collect_kpi(self):
# we can't get KPIs if the VNF is down
- check_if_process_failed(self._vnf_process)
+ check_if_process_failed(self._vnf_process, 0.01)
+
+ physical_node = context_base.Context.get_physical_node_from_server(
+ self.scenario_helper.nodes[self.name])
+
+ result = {"physical_node": physical_node}
if self.resource_helper is None:
- result = {
+ result.update({
"packets_in": 0,
"packets_dropped": 0,
"packets_fwd": 0,
"collect_stats": {"core": {}},
- }
+ })
return result
# use all_ports so we only use ports matched in topology
@@ -96,14 +102,14 @@ class ProxApproxVnf(SampleVNF):
LOG.error("Invalid data ...")
return {}
- result = {
+ result.update({
"packets_in": rx_total,
"packets_dropped": max((tx_total - rx_total), 0),
"packets_fwd": tx_total,
# we share ProxResourceHelper with TG, but we want to collect
# collectd KPIs here and not TG KPIs, so use a different method name
"collect_stats": self.resource_helper.collect_collectd_kpi(),
- }
+ })
try:
curr_packets_in = int((rx_total - self.prev_packets_in)
/ (curr_time - self.prev_time))
diff --git a/yardstick/network_services/vnf_generic/vnf/router_vnf.py b/yardstick/network_services/vnf_generic/vnf/router_vnf.py
index aea27ffa6..90b7b215e 100644
--- a/yardstick/network_services/vnf_generic/vnf/router_vnf.py
+++ b/yardstick/network_services/vnf_generic/vnf/router_vnf.py
@@ -47,7 +47,6 @@ class RouterVNF(SampleVNF):
def instantiate(self, scenario_cfg, context_cfg):
self.scenario_helper.scenario_cfg = scenario_cfg
self.context_cfg = context_cfg
- self.nfvi_context = Context.get_context_from_server(self.scenario_helper.nodes[self.name])
self.configure_routes(self.name, scenario_cfg, context_cfg)
def wait_for_instantiate(self):
@@ -107,8 +106,11 @@ class RouterVNF(SampleVNF):
stdout = self.ssh_helper.execute(ip_link_stats)[1]
link_stats = self.get_stats(stdout)
# get RX/TX from link_stats and assign to results
+ physical_node = Context.get_physical_node_from_server(
+ self.scenario_helper.nodes[self.name])
result = {
+ "physical_node": physical_node,
"packets_in": 0,
"packets_dropped": 0,
"packets_fwd": 0,
diff --git a/yardstick/network_services/vnf_generic/vnf/sample_vnf.py b/yardstick/network_services/vnf_generic/vnf/sample_vnf.py
index 9ff2e7d1a..3fe3f8b75 100644
--- a/yardstick/network_services/vnf_generic/vnf/sample_vnf.py
+++ b/yardstick/network_services/vnf_generic/vnf/sample_vnf.py
@@ -39,7 +39,7 @@ from yardstick.network_services.vnf_generic.vnf.base import GenericTrafficGen
from yardstick.network_services.vnf_generic.vnf.base import GenericVNF
from yardstick.network_services.vnf_generic.vnf.base import QueueFileWrapper
from yardstick.network_services.vnf_generic.vnf.vnf_ssh_helper import VnfSshHelper
-
+from yardstick.benchmark.contexts.node import NodeContext
LOG = logging.getLogger(__name__)
@@ -319,6 +319,7 @@ class ResourceHelper(object):
self.resource = None
self.setup_helper = setup_helper
self.ssh_helper = setup_helper.ssh_helper
+ self._enable = True
def setup(self):
self.resource = self.setup_helper.setup_vnf_environment()
@@ -326,22 +327,33 @@ class ResourceHelper(object):
def generate_cfg(self):
pass
+ def update_from_context(self, context, attr_name):
+ """Disable resource helper in case of baremetal context.
+
+ And update appropriate node collectd options in context
+ """
+ if isinstance(context, NodeContext):
+ self._enable = False
+ context.update_collectd_options_for_node(self.setup_helper.collectd_options,
+ attr_name)
+
def _collect_resource_kpi(self):
result = {}
status = self.resource.check_if_system_agent_running("collectd")[0]
- if status == 0:
+ if status == 0 and self._enable:
result = self.resource.amqp_collect_nfvi_kpi()
result = {"core": result}
return result
def start_collect(self):
- self.resource.initiate_systemagent(self.ssh_helper.bin_path)
- self.resource.start()
- self.resource.amqp_process_for_nfvi_kpi()
+ if self._enable:
+ self.resource.initiate_systemagent(self.ssh_helper.bin_path)
+ self.resource.start()
+ self.resource.amqp_process_for_nfvi_kpi()
def stop_collect(self):
- if self.resource:
+ if self.resource and self._enable:
self.resource.stop()
def collect_kpi(self):
@@ -631,7 +643,6 @@ class SampleVNF(GenericVNF):
self.resource_helper = resource_helper_type(self.setup_helper)
self.context_cfg = None
- self.nfvi_context = None
self.pipeline_kwargs = {}
self.uplink_ports = None
self.downlink_ports = None
@@ -658,8 +669,10 @@ class SampleVNF(GenericVNF):
self._update_collectd_options(scenario_cfg, context_cfg)
self.scenario_helper.scenario_cfg = scenario_cfg
self.context_cfg = context_cfg
- self.nfvi_context = Context.get_context_from_server(self.scenario_helper.nodes[self.name])
- # self.nfvi_context = None
+ self.resource_helper.update_from_context(
+ Context.get_context_from_server(self.scenario_helper.nodes[self.name]),
+ self.scenario_helper.nodes[self.name]
+ )
# vnf deploy is unsupported, use ansible playbooks
if self.scenario_helper.options.get("vnf_deploy", False):
@@ -813,15 +826,18 @@ class SampleVNF(GenericVNF):
check_if_process_failed(self._vnf_process)
stats = self.get_stats()
m = re.search(self.COLLECT_KPI, stats, re.MULTILINE)
+ physical_node = Context.get_physical_node_from_server(
+ self.scenario_helper.nodes[self.name])
+
+ result = {"physical_node": physical_node}
if m:
- result = {k: int(m.group(v)) for k, v in self.COLLECT_MAP.items()}
+ result.update({k: int(m.group(v)) for k, v in self.COLLECT_MAP.items()})
result["collect_stats"] = self.resource_helper.collect_kpi()
else:
- result = {
- "packets_in": 0,
- "packets_fwd": 0,
- "packets_dropped": 0,
- }
+ result.update({"packets_in": 0,
+ "packets_fwd": 0,
+ "packets_dropped": 0})
+
LOG.debug("%s collect KPIs %s", self.APP_NAME, result)
return result
@@ -867,6 +883,11 @@ class SampleVNFTrafficGen(GenericTrafficGen):
def instantiate(self, scenario_cfg, context_cfg):
self.scenario_helper.scenario_cfg = scenario_cfg
+ self.resource_helper.update_from_context(
+ Context.get_context_from_server(self.scenario_helper.nodes[self.name]),
+ self.scenario_helper.nodes[self.name]
+ )
+
self.resource_helper.setup()
# must generate_cfg after DPDK bind because we need port number
self.resource_helper.generate_cfg()
@@ -921,9 +942,14 @@ class SampleVNFTrafficGen(GenericTrafficGen):
def collect_kpi(self):
# check if the tg processes have exited
+ physical_node = Context.get_physical_node_from_server(
+ self.scenario_helper.nodes[self.name])
+
+ result = {"physical_node": physical_node}
for proc in (self._tg_process, self._traffic_process):
check_if_process_failed(proc)
- result = self.resource_helper.collect_kpi()
+
+ result["collect_stats"] = self.resource_helper.collect_kpi()
LOG.debug("%s collect KPIs %s", self.APP_NAME, result)
return result
diff --git a/yardstick/network_services/vnf_generic/vnf/udp_replay.py b/yardstick/network_services/vnf_generic/vnf/udp_replay.py
index a57f53bc7..fa92744d8 100644
--- a/yardstick/network_services/vnf_generic/vnf/udp_replay.py
+++ b/yardstick/network_services/vnf_generic/vnf/udp_replay.py
@@ -19,7 +19,7 @@ from yardstick.common.process import check_if_process_failed
from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
from yardstick.network_services.vnf_generic.vnf.sample_vnf import DpdkVnfSetupEnvHelper
from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper
-
+from yardstick.benchmark.contexts import base as ctx_base
LOG = logging.getLogger(__name__)
@@ -79,9 +79,11 @@ class UdpReplayApproxVnf(SampleVNF):
ports_mask_hex = hex(sum(2 ** num for num in port_nums))
# one core extra for master
cpu_mask_hex = hex(2 ** (number_of_ports + 1) - 1)
+ nfvi_context = ctx_base.Context.get_context_from_server(
+ self.scenario_helper.nodes[self.name])
hw_csum = ""
if (not self.scenario_helper.options.get('hw_csum', False) or
- self.nfvi_context.attrs.get('nfvi_type') not in self.HW_OFFLOADING_NFVI_TYPES):
+ nfvi_context.attrs.get('nfvi_type') not in self.HW_OFFLOADING_NFVI_TYPES):
hw_csum = '--no-hw-csum'
# tuples of (FLD_PORT, FLD_QUEUE, FLD_LCORE)
@@ -116,7 +118,12 @@ class UdpReplayApproxVnf(SampleVNF):
stats = self.get_stats()
stats_words = stats.split()
split_stats = stats_words[stats_words.index('0'):][:number_of_ports * 5]
+
+ physical_node = ctx_base.Context.get_physical_node_from_server(
+ self.scenario_helper.nodes[self.name])
+
result = {
+ "physical_node": physical_node,
"packets_in": get_sum(1),
"packets_fwd": get_sum(2),
"packets_dropped": get_sum(3) + get_sum(4),
diff --git a/yardstick/network_services/vnf_generic/vnf/vpe_vnf.py b/yardstick/network_services/vnf_generic/vnf/vpe_vnf.py
index 9deef5cfa..bfff45c67 100644
--- a/yardstick/network_services/vnf_generic/vnf/vpe_vnf.py
+++ b/yardstick/network_services/vnf_generic/vnf/vpe_vnf.py
@@ -28,6 +28,7 @@ from yardstick.common.process import check_if_process_failed
from yardstick.network_services.helpers.samplevnf_helper import PortPairs
from yardstick.network_services.pipeline import PipelineRules
from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF, DpdkVnfSetupEnvHelper
+from yardstick.benchmark.contexts import base as ctx_base
LOG = logging.getLogger(__name__)
@@ -302,7 +303,11 @@ class VpeApproxVnf(SampleVNF):
def collect_kpi(self):
# we can't get KPIs if the VNF is down
check_if_process_failed(self._vnf_process)
+ physical_node = ctx_base.Context.get_physical_node_from_server(
+ self.scenario_helper.nodes[self.name])
+
result = {
+ "physical_node": physical_node,
'pkt_in_up_stream': 0,
'pkt_drop_up_stream': 0,
'pkt_in_down_stream': 0,
diff --git a/yardstick/tests/unit/benchmark/contexts/test_base.py b/yardstick/tests/unit/benchmark/contexts/test_base.py
index 8f1cbcc55..1e63b4831 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_base.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_base.py
@@ -25,6 +25,8 @@ from yardstick.common.constants import YARDSTICK_ROOT_PATH
class DummyContextClass(Context):
+ __context_type__ = "Dummy"
+
def __init__(self, host_name_separator='.'):
super(DummyContextClass, self).__init__\
(host_name_separator=host_name_separator)
diff --git a/yardstick/tests/unit/network_services/collector/test_subscriber.py b/yardstick/tests/unit/network_services/collector/test_subscriber.py
index 4ec2ea7a2..4271f852c 100644
--- a/yardstick/tests/unit/network_services/collector/test_subscriber.py
+++ b/yardstick/tests/unit/network_services/collector/test_subscriber.py
@@ -38,6 +38,15 @@ class MockVnfAprrox(object):
class CollectorTestCase(unittest.TestCase):
+ NODES = {'context1': [{'name': 'node1',
+ 'ip': '1.2.3.4',
+ 'collectd': {
+ 'plugins': {'abc': 12, 'def': 34},
+ 'interval': 987
+ },
+ }]
+ }
+
def setUp(self):
vnf = MockVnfAprrox()
vnf.start_collect = mock.Mock()
@@ -47,30 +56,46 @@ class CollectorTestCase(unittest.TestCase):
mock_instance = mock.Mock()
mock_instance.execute.return_value = 0, '', ''
mock_ssh.from_node.return_value = mock_instance
- self.collector = subscriber.Collector([vnf])
+ self.collector = subscriber.Collector([vnf], self.NODES)
def tearDown(self):
self.ssh_patch.stop()
def test___init__(self, *_):
vnf = MockVnfAprrox()
- collector = subscriber.Collector([vnf])
+ collector = subscriber.Collector([vnf], self.NODES)
self.assertEqual(len(collector.vnfs), 1)
+ self.assertEqual(len(collector.nodes), 1)
def test_start(self, *_):
- self.collector.start()
+ resource_profile = mock.MagicMock()
+ self.collector.resource_profiles = {'key': resource_profile}
+ self.collector.bin_path = 'path'
+
+ self.assertIsNone(self.collector.start())
for vnf in self.collector.vnfs:
vnf.start_collect.assert_called_once()
+ for resource_profile in self.collector.resource_profiles.values():
+ resource_profile.initiate_systemagent.assert_called_once_with('path')
+ resource_profile.start.assert_called_once()
+ resource_profile.amqp_process_for_nfvi_kpi.assert_called_once()
+
def test_stop(self, *_):
+ resource_profile = mock.MagicMock()
+ self.collector.resource_profiles = {'key': resource_profile}
+
self.assertIsNone(self.collector.stop())
for vnf in self.collector.vnfs:
vnf.stop_collect.assert_called_once()
+ for resource in self.collector.resource_profiles.values():
+ resource.stop.assert_called_once()
+
def test_get_kpi(self, *_):
result = self.collector.get_kpi()
- self.assertEqual(1, len(result))
+ self.assertEqual(2, len(result))
self.assertEqual(4, len(result["vnf__1"]))
self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100)
self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5)
diff --git a/yardstick/tests/unit/network_services/nfvi/test_resource.py b/yardstick/tests/unit/network_services/nfvi/test_resource.py
index 741f9a6cc..c06658218 100644
--- a/yardstick/tests/unit/network_services/nfvi/test_resource.py
+++ b/yardstick/tests/unit/network_services/nfvi/test_resource.py
@@ -17,10 +17,10 @@ import errno
import mock
import unittest
+from yardstick.common import exceptions
+from yardstick.common.exceptions import ResourceCommandError
from yardstick.network_services.nfvi.resource import ResourceProfile
from yardstick.network_services.nfvi import resource, collectd
-from yardstick.common.exceptions import ResourceCommandError
-from yardstick.common.exceptions import SSHError
class TestResourceProfile(unittest.TestCase):
@@ -135,25 +135,45 @@ class TestResourceProfile(unittest.TestCase):
self.assertIsNone(self.resource_profile._start_collectd(ssh_mock,
"/opt/nsb_bin"))
- ssh_mock.execute = mock.Mock(side_effect=SSHError)
- with self.assertRaises(SSHError):
+ ssh_mock.execute = mock.Mock(side_effect=exceptions.SSHError)
+ with self.assertRaises(exceptions.SSHError):
self.resource_profile._start_collectd(ssh_mock, "/opt/nsb_bin")
ssh_mock.execute = mock.Mock(return_value=(1, "", ""))
- self.assertIsNone(self.resource_profile._start_collectd(ssh_mock,
- "/opt/nsb_bin"))
+ with self.assertRaises(ResourceCommandError):
+ self.resource_profile._start_collectd(ssh_mock, "/opt/nsb_bin")
+
+ def test__reset_rabbitmq(self):
+ ssh_mock = mock.Mock()
+ ssh_mock.execute = mock.Mock(return_value=(1, "", ""))
+ with self.assertRaises(exceptions.ResourceCommandError):
+ self.resource_profile._reset_rabbitmq(ssh_mock)
+
+ def test__check_rabbitmq_user(self):
+ ssh_mock = mock.Mock()
+ ssh_mock.execute = mock.Mock(return_value=(0, "title\nadmin\t[]", ""))
+ self.assertTrue(self.resource_profile._check_rabbitmq_user(ssh_mock))
+
+ def test__set_rabbitmq_admin_user(self):
+ ssh_mock = mock.Mock()
+ ssh_mock.execute = mock.Mock(return_value=(1, "", ""))
+ with self.assertRaises(exceptions.ResourceCommandError):
+ self.resource_profile._set_rabbitmq_admin_user(ssh_mock)
def test__start_rabbitmq(self):
ssh_mock = mock.Mock()
- ssh_mock.execute = mock.Mock(return_value=(0, "RabbitMQ", ""))
- self.assertIsNone(self.resource_profile._start_rabbitmq(ssh_mock))
+ self.resource_profile._reset_rabbitmq = mock.Mock()
+ self.resource_profile._set_rabbitmq_admin_user = mock.Mock()
- ssh_mock.execute = mock.Mock(return_value=(0, "", ""))
- with self.assertRaises(ResourceCommandError):
+ self.resource_profile._reset_mq_flag = True
+ ssh_mock.execute = mock.Mock(return_value=(1, "", ""))
+ with self.assertRaises(exceptions.ResourceCommandError):
self.resource_profile._start_rabbitmq(ssh_mock)
+ self.resource_profile._reset_mq_flag = False
+ self.resource_profile._check_rabbitmq_user = mock.Mock(return_value=False)
ssh_mock.execute = mock.Mock(return_value=(1, "", ""))
- with self.assertRaises(ResourceCommandError):
+ with self.assertRaises(exceptions.ResourceCommandError):
self.resource_profile._start_rabbitmq(ssh_mock)
def test__prepare_collectd_conf(self):
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py
index ce32a31e2..f04d2c617 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_acl_vnf.py
@@ -23,6 +23,7 @@ from yardstick.tests import STL_MOCKS
from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from yardstick.common import utils
from yardstick.common import exceptions
+from yardstick.benchmark.contexts import base as ctx_base
STLClient = mock.MagicMock()
@@ -30,7 +31,7 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
if stl_patch:
- from yardstick.network_services.vnf_generic.vnf.acl_vnf import AclApproxVnf
+ from yardstick.network_services.vnf_generic.vnf import acl_vnf
from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
from yardstick.network_services.nfvi.resource import ResourceProfile
from yardstick.network_services.vnf_generic.vnf.acl_vnf import AclApproxSetupEnvSetupEnvHelper
@@ -146,7 +147,7 @@ class TestAclApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens513f0',
- 'vld_id': AclApproxVnf.DOWNLINK,
+ 'vld_id': acl_vnf.AclApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.20',
'dst_mac': '00:00:00:00:00:01',
@@ -174,7 +175,7 @@ class TestAclApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens785f0',
- 'vld_id': AclApproxVnf.UPLINK,
+ 'vld_id': acl_vnf.AclApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.20',
'dst_mac': '00:00:00:00:00:02',
@@ -199,7 +200,7 @@ class TestAclApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens786f0',
- 'vld_id': AclApproxVnf.UPLINK,
+ 'vld_id': acl_vnf.AclApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.19',
'dst_mac': '00:00:00:00:00:04',
@@ -209,7 +210,7 @@ class TestAclApproxVnf(unittest.TestCase):
'vpci': '0000:05:00.0',
'dpdk_port_num': 0},
'xe1': {'local_iface_name': 'ens786f1',
- 'vld_id': AclApproxVnf.DOWNLINK,
+ 'vld_id': acl_vnf.AclApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.19',
'dst_mac': '00:00:00:00:00:03',
@@ -245,22 +246,31 @@ class TestAclApproxVnf(unittest.TestCase):
def test___init__(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf = acl_vnf.AclApproxVnf(name, vnfd)
self.assertIsNone(acl_approx_vnf._vnf_process)
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch(SSH_HELPER)
def test_collect_kpi(self, ssh, *args):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf = acl_vnf.AclApproxVnf(name, vnfd)
+ acl_approx_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {acl_approx_vnf.name: "mock"}
+ }
acl_approx_vnf.q_in = mock.MagicMock()
acl_approx_vnf.q_out = mock.MagicMock()
acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
acl_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
acl_approx_vnf.vnf_execute = mock.Mock(return_value="")
- result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0}
+ result = {
+ 'physical_node': 'mock_node',
+ 'packets_dropped': 0,
+ 'packets_fwd': 0,
+ 'packets_in': 0
+ }
self.assertEqual(result, acl_approx_vnf.collect_kpi())
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
@@ -269,7 +279,7 @@ class TestAclApproxVnf(unittest.TestCase):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf = acl_vnf.AclApproxVnf(name, vnfd)
acl_approx_vnf.q_in = mock.MagicMock()
acl_approx_vnf.q_out = mock.MagicMock()
acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
@@ -281,7 +291,7 @@ class TestAclApproxVnf(unittest.TestCase):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf = acl_vnf.AclApproxVnf(name, vnfd)
acl_approx_vnf.q_in = mock.MagicMock()
acl_approx_vnf.q_out = mock.MagicMock()
acl_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
@@ -302,7 +312,7 @@ class TestAclApproxVnf(unittest.TestCase):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf = acl_vnf.AclApproxVnf(name, vnfd)
acl_approx_vnf._build_config = mock.MagicMock()
acl_approx_vnf.queue_wrapper = mock.MagicMock()
acl_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
@@ -322,7 +332,7 @@ class TestAclApproxVnf(unittest.TestCase):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf = acl_vnf.AclApproxVnf(name, vnfd)
acl_approx_vnf.deploy_helper = mock.MagicMock()
acl_approx_vnf.resource_helper = mock.MagicMock()
acl_approx_vnf._build_config = mock.MagicMock()
@@ -340,7 +350,7 @@ class TestAclApproxVnf(unittest.TestCase):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- acl_approx_vnf = AclApproxVnf(name, vnfd)
+ acl_approx_vnf = acl_vnf.AclApproxVnf(name, vnfd)
acl_approx_vnf._vnf_process = mock.MagicMock()
acl_approx_vnf._vnf_process.terminate = mock.Mock()
acl_approx_vnf.used_drivers = {"01:01.0": "i40e",
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py
index 82376a4eb..635ca41a2 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_cgnapt_vnf.py
@@ -11,25 +11,22 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-#
from copy import deepcopy
-import os
-import unittest
+import time
+
import mock
+import unittest
-from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
+from yardstick.benchmark.contexts import base as ctx_base
from yardstick.common import utils
-
-from yardstick.network_services.vnf_generic.vnf.cgnapt_vnf import CgnaptApproxVnf, \
- CgnaptApproxSetupEnvHelper
+from yardstick.common import process
from yardstick.network_services.vnf_generic.vnf import cgnapt_vnf
-from yardstick.network_services.nfvi.resource import ResourceProfile
-
-TEST_FILE_YAML = 'nsb_test_case.yaml'
-SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
+from yardstick.network_services.vnf_generic.vnf import sample_vnf
+from yardstick.network_services.nfvi import resource
+TEST_FILE_YAML = 'nsb_test_case.yaml'
name = 'vnf__0'
@@ -37,8 +34,9 @@ class TestCgnaptApproxSetupEnvHelper(unittest.TestCase):
def test__generate_ip_from_pool(self):
- ip = CgnaptApproxSetupEnvHelper._generate_ip_from_pool("1.2.3.4")
- self.assertEqual(next(ip), '1.2.3.4')
+ _ip = '1.2.3.4'
+ ip = cgnapt_vnf.CgnaptApproxSetupEnvHelper._generate_ip_from_pool(_ip)
+ self.assertEqual(next(ip), _ip)
self.assertEqual(next(ip), '1.2.4.4')
self.assertEqual(next(ip), '1.2.5.4')
@@ -57,19 +55,22 @@ link 1 up
"""
header = "This is a header"
- out = CgnaptApproxSetupEnvHelper._update_cgnat_script_file(header, sample.splitlines())
+ out = cgnapt_vnf.CgnaptApproxSetupEnvHelper._update_cgnat_script_file(
+ header, sample.splitlines())
self.assertNotIn("This is a header", out)
def test__get_cgnapt_config(self):
vnfd_helper = mock.MagicMock()
vnfd_helper.port_pairs.uplink_ports = [{"name": 'a'}, {"name": "b"}, {"name": "c"}]
- helper = CgnaptApproxSetupEnvHelper(vnfd_helper, mock.Mock(), mock.Mock())
+ helper = cgnapt_vnf.CgnaptApproxSetupEnvHelper(
+ vnfd_helper, mock.Mock(), mock.Mock())
result = helper._get_cgnapt_config()
self.assertIsNotNone(result)
def test_scale(self):
- helper = CgnaptApproxSetupEnvHelper(mock.Mock(), mock.Mock(), mock.Mock())
+ helper = cgnapt_vnf.CgnaptApproxSetupEnvHelper(
+ mock.Mock(), mock.Mock(), mock.Mock())
with self.assertRaises(NotImplementedError):
helper.scale()
@@ -85,9 +86,8 @@ link 1 up
scenario_helper.options = {}
scenario_helper.all_options = {}
- cgnat_approx_setup_helper = CgnaptApproxSetupEnvHelper(vnfd_helper,
- ssh_helper,
- scenario_helper)
+ cgnat_approx_setup_helper = cgnapt_vnf.CgnaptApproxSetupEnvHelper(
+ vnfd_helper, ssh_helper, scenario_helper)
cgnat_approx_setup_helper.ssh_helper.provision_tool = mock.Mock(return_value='tool_path')
cgnat_approx_setup_helper.ssh_helper.all_ports = mock.Mock()
@@ -96,7 +96,7 @@ link 1 up
self.assertEqual(cgnat_approx_setup_helper.build_config(), expected)
-@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Process")
+@mock.patch.object(sample_vnf, 'Process')
class TestCgnaptApproxVnf(unittest.TestCase):
VNFD = {'vnfd:vnfd-catalog':
{'vnfd':
@@ -216,7 +216,7 @@ class TestCgnaptApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens513f0',
- 'vld_id': CgnaptApproxVnf.DOWNLINK,
+ 'vld_id': cgnapt_vnf.CgnaptApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.20',
'dst_mac': '00:00:00:00:00:01',
@@ -244,7 +244,7 @@ class TestCgnaptApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens785f0',
- 'vld_id': CgnaptApproxVnf.UPLINK,
+ 'vld_id': cgnapt_vnf.CgnaptApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.20',
'dst_mac': '00:00:00:00:00:02',
@@ -269,7 +269,7 @@ class TestCgnaptApproxVnf(unittest.TestCase):
'ip': '1.2.1.1',
'interfaces':
{'xe0': {'local_iface_name': 'ens786f0',
- 'vld_id': CgnaptApproxVnf.UPLINK,
+ 'vld_id': cgnapt_vnf.CgnaptApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.19',
'dst_mac': '00:00:00:00:00:04',
@@ -279,7 +279,7 @@ class TestCgnaptApproxVnf(unittest.TestCase):
'vpci': '0000:05:00.0',
'dpdk_port_num': 0},
'xe1': {'local_iface_name': 'ens786f1',
- 'vld_id': CgnaptApproxVnf.DOWNLINK,
+ 'vld_id': cgnapt_vnf.CgnaptApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.19',
'dst_mac': '00:00:00:00:00:03',
@@ -318,81 +318,68 @@ class TestCgnaptApproxVnf(unittest.TestCase):
def test___init__(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
+ cgnapt_approx_vnf = cgnapt_vnf.CgnaptApproxVnf(name, vnfd)
self.assertIsNone(cgnapt_approx_vnf._vnf_process)
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
- @mock.patch(SSH_HELPER)
- def test_collect_kpi(self, ssh, *args):
- mock_ssh(ssh)
-
+ @mock.patch.object(process, 'check_if_process_failed')
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
+ def test_collect_kpi(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
+ cgnapt_approx_vnf = cgnapt_vnf.CgnaptApproxVnf(name, vnfd)
+ cgnapt_approx_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {cgnapt_approx_vnf.name: "mock"}
+ }
cgnapt_approx_vnf._vnf_process = mock.MagicMock(
**{"is_alive.return_value": True, "exitcode": None})
cgnapt_approx_vnf.q_in = mock.MagicMock()
cgnapt_approx_vnf.q_out = mock.MagicMock()
cgnapt_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- cgnapt_approx_vnf.resource = mock.Mock(autospec=ResourceProfile)
- result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0}
- self.assertEqual(result, cgnapt_approx_vnf.collect_kpi())
-
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.time')
- @mock.patch(SSH_HELPER)
- def test_vnf_execute_command(self, ssh, *args):
- mock_ssh(ssh)
-
+ cgnapt_approx_vnf.resource = mock.Mock(
+ autospec=resource.ResourceProfile)
+ result = {
+ 'physical_node': 'mock_node',
+ 'packets_dropped': 0,
+ 'packets_fwd': 0,
+ 'packets_in': 0
+ }
+ with mock.patch.object(cgnapt_approx_vnf, 'get_stats',
+ return_value=''):
+ self.assertEqual(result, cgnapt_approx_vnf.collect_kpi())
+
+ @mock.patch.object(time, 'sleep')
+ def test_vnf_execute_command(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- cgnapt_approx_vnf.q_in = mock.MagicMock()
- cgnapt_approx_vnf.q_out = mock.MagicMock()
+ cgnapt_approx_vnf = cgnapt_vnf.CgnaptApproxVnf(name, vnfd)
+ cgnapt_approx_vnf.q_in = mock.Mock()
+ cgnapt_approx_vnf.q_out = mock.Mock()
cgnapt_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- cmd = "quit"
- self.assertEqual("", cgnapt_approx_vnf.vnf_execute(cmd))
-
- @mock.patch(SSH_HELPER)
- def test_get_stats(self, ssh, *args):
- mock_ssh(ssh)
+ self.assertEqual("", cgnapt_approx_vnf.vnf_execute('quit'))
+ def test_get_stats(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- cgnapt_approx_vnf.q_in = mock.MagicMock()
- cgnapt_approx_vnf.q_out = mock.MagicMock()
- cgnapt_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
- result = \
- "CG-NAPT(.*\n)*Received 100, Missed 0, Dropped 0,Translated 100,ingress"
- cgnapt_approx_vnf.vnf_execute = mock.Mock(return_value=result)
- self.assertListEqual(list(result), list(cgnapt_approx_vnf.get_stats()))
-
- def _get_file_abspath(self, filename):
- curr_path = os.path.dirname(os.path.abspath(__file__))
- file_path = os.path.join(curr_path, filename)
- return file_path
-
- @mock.patch("yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.hex")
- @mock.patch("yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.eval")
- @mock.patch('yardstick.network_services.vnf_generic.vnf.cgnapt_vnf.open')
- @mock.patch(SSH_HELPER)
- def test_run_vcgnapt(self, ssh, *args):
- mock_ssh(ssh)
+ cgnapt_approx_vnf = cgnapt_vnf.CgnaptApproxVnf(name, vnfd)
+ with mock.patch.object(cgnapt_approx_vnf, 'vnf_execute') as mock_exec:
+ mock_exec.return_value = 'output'
+ self.assertEqual('output', cgnapt_approx_vnf.get_stats())
+
+ mock_exec.assert_called_once_with('p cgnapt stats')
+ def test_run_vcgnapt(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- cgnapt_approx_vnf._build_config = mock.MagicMock()
- cgnapt_approx_vnf.queue_wrapper = mock.MagicMock()
- cgnapt_approx_vnf.ssh_helper = mock.MagicMock()
- cgnapt_approx_vnf.ssh_helper.run = mock.MagicMock()
- cgnapt_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
- cgnapt_approx_vnf._run()
- cgnapt_approx_vnf.ssh_helper.run.assert_called_once()
+ cgnapt_approx_vnf = cgnapt_vnf.CgnaptApproxVnf(name, vnfd)
+ cgnapt_approx_vnf.ssh_helper = mock.Mock()
+ cgnapt_approx_vnf.setup_helper = mock.Mock()
+ with mock.patch.object(cgnapt_approx_vnf, '_build_config'), \
+ mock.patch.object(cgnapt_approx_vnf, '_build_run_kwargs'):
+ cgnapt_approx_vnf._run()
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
- @mock.patch(SSH_HELPER)
- def test_instantiate(self, ssh, *args):
- mock_ssh(ssh)
+ cgnapt_approx_vnf.ssh_helper.run.assert_called_once()
+ cgnapt_approx_vnf.setup_helper.kill_vnf.assert_called_once()
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server')
+ def test_instantiate(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
+ cgnapt_approx_vnf = cgnapt_vnf.CgnaptApproxVnf(name, vnfd)
cgnapt_approx_vnf.deploy_helper = mock.MagicMock()
cgnapt_approx_vnf.resource_helper = mock.MagicMock()
cgnapt_approx_vnf._build_config = mock.MagicMock()
@@ -401,51 +388,25 @@ class TestCgnaptApproxVnf(unittest.TestCase):
cgnapt_approx_vnf.q_out.put("pipeline>")
cgnapt_vnf.WAIT_TIME = 3
self.scenario_cfg.update({"nodes": {"vnf__0": ""}})
- self.assertIsNone(cgnapt_approx_vnf.instantiate(self.scenario_cfg,
- self.context_cfg))
-
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- @mock.patch(SSH_HELPER)
- def test_terminate(self, ssh, *args):
- mock_ssh(ssh)
-
- vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- cgnapt_approx_vnf._vnf_process = mock.MagicMock()
- cgnapt_approx_vnf._vnf_process.terminate = mock.Mock()
- cgnapt_approx_vnf.used_drivers = {"01:01.0": "i40e",
- "01:01.1": "i40e"}
- cgnapt_approx_vnf.vnf_execute = mock.MagicMock()
- cgnapt_approx_vnf.dpdk_nic_bind = "dpdk_nic_bind.py"
- cgnapt_approx_vnf._resource_collect_stop = mock.Mock()
- self.assertIsNone(cgnapt_approx_vnf.terminate())
-
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- @mock.patch(SSH_HELPER)
- def test__vnf_up_post(self, ssh, *args):
- mock_ssh(ssh)
+ with mock.patch.object(cgnapt_approx_vnf, '_start_vnf'):
+ self.assertIsNone(cgnapt_approx_vnf.instantiate(
+ self.scenario_cfg, self.context_cfg))
+ @mock.patch.object(time, 'sleep')
+ def test__vnf_up_post(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
self.scenario_cfg['options'][name]['napt'] = 'static'
-
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- cgnapt_approx_vnf._vnf_process = mock.MagicMock()
- cgnapt_approx_vnf._vnf_process.terminate = mock.Mock()
- cgnapt_approx_vnf.vnf_execute = mock.MagicMock()
+ cgnapt_approx_vnf = cgnapt_vnf.CgnaptApproxVnf(name, vnfd)
+ cgnapt_approx_vnf.vnf_execute = mock.Mock()
cgnapt_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
- cgnapt_approx_vnf._resource_collect_stop = mock.Mock()
- cgnapt_approx_vnf._vnf_up_post()
-
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
- @mock.patch(SSH_HELPER)
- def test__vnf_up_post_short(self, ssh, *args):
- mock_ssh(ssh)
+ with mock.patch.object(cgnapt_approx_vnf, 'setup_helper') as \
+ mock_setup_helper:
+ mock_setup_helper._generate_ip_from_pool.return_value = ['ip1']
+ mock_setup_helper._get_cgnapt_config.return_value = ['gw_ip1']
+ cgnapt_approx_vnf._vnf_up_post()
+ def test__vnf_up_post_short(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
- cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
- cgnapt_approx_vnf._vnf_process = mock.MagicMock()
- cgnapt_approx_vnf._vnf_process.terminate = mock.Mock()
- cgnapt_approx_vnf.vnf_execute = mock.MagicMock()
+ cgnapt_approx_vnf = cgnapt_vnf.CgnaptApproxVnf(name, vnfd)
cgnapt_approx_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
- cgnapt_approx_vnf._resource_collect_stop = mock.Mock()
cgnapt_approx_vnf._vnf_up_post()
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py
index 351607fb5..d9227e7d5 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_prox_vnf.py
@@ -20,6 +20,7 @@ import mock
from copy import deepcopy
from yardstick.tests import STL_MOCKS
+from yardstick.benchmark.contexts import base as ctx_base
SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
@@ -29,7 +30,7 @@ stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
if stl_patch:
- from yardstick.network_services.vnf_generic.vnf.prox_vnf import ProxApproxVnf
+ from yardstick.network_services.vnf_generic.vnf import prox_vnf
from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
@@ -187,7 +188,7 @@ class TestProxApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens513f0',
- 'vld_id': ProxApproxVnf.DOWNLINK,
+ 'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.20',
'dst_mac': '00:00:00:00:00:01',
@@ -221,7 +222,7 @@ class TestProxApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens785f0',
- 'vld_id': ProxApproxVnf.UPLINK,
+ 'vld_id': prox_vnf.ProxApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.20',
'dst_mac': '00:00:00:00:00:02',
@@ -252,7 +253,7 @@ class TestProxApproxVnf(unittest.TestCase):
'interfaces': {
'xe0': {
'local_iface_name': 'ens786f0',
- 'vld_id': ProxApproxVnf.UPLINK,
+ 'vld_id': prox_vnf.ProxApproxVnf.UPLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.100.19',
'dst_mac': '00:00:00:00:00:04',
@@ -264,7 +265,7 @@ class TestProxApproxVnf(unittest.TestCase):
},
'xe1': {
'local_iface_name': 'ens786f1',
- 'vld_id': ProxApproxVnf.DOWNLINK,
+ 'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK,
'netmask': '255.255.255.0',
'local_ip': '152.16.40.19',
'dst_mac': '00:00:00:00:00:03',
@@ -316,16 +317,21 @@ class TestProxApproxVnf(unittest.TestCase):
@mock.patch(SSH_HELPER)
def test___init__(self, ssh, *args):
mock_ssh(ssh)
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
self.assertIsNone(prox_approx_vnf._vnf_process)
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch(SSH_HELPER)
def test_collect_kpi_no_client(self, ssh, *args):
mock_ssh(ssh)
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {prox_approx_vnf.name: "mock"}
+ }
prox_approx_vnf.resource_helper = None
expected = {
+ 'physical_node': 'mock_node',
'packets_in': 0,
'packets_dropped': 0,
'packets_fwd': 0,
@@ -334,6 +340,7 @@ class TestProxApproxVnf(unittest.TestCase):
result = prox_approx_vnf.collect_kpi()
self.assertEqual(result, expected)
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch(SSH_HELPER)
def test_collect_kpi(self, ssh, *args):
mock_ssh(ssh)
@@ -343,10 +350,14 @@ class TestProxApproxVnf(unittest.TestCase):
[2, 1, 2, 3, 4, 5], [3, 1, 2, 3, 4, 5]]
resource_helper.collect_collectd_kpi.return_value = {'core': {'result': 234}}
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {prox_approx_vnf.name: "mock"}
+ }
prox_approx_vnf.resource_helper = resource_helper
expected = {
+ 'physical_node': 'mock_node',
'packets_in': 4,
'packets_dropped': 4,
'packets_fwd': 8,
@@ -359,13 +370,16 @@ class TestProxApproxVnf(unittest.TestCase):
self.assertNotEqual(result['packets_fwd'], 0)
self.assertNotEqual(result['packets_fwd'], 0)
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch(SSH_HELPER)
def test_collect_kpi_error(self, ssh, *args):
mock_ssh(ssh)
resource_helper = mock.MagicMock()
-
- prox_approx_vnf = ProxApproxVnf(NAME, deepcopy(self.VNFD0))
+ prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, deepcopy(self.VNFD0))
+ prox_approx_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {prox_approx_vnf.name: "mock"}
+ }
prox_approx_vnf.resource_helper = resource_helper
prox_approx_vnf.vnfd_helper['vdu'][0]['external-interface'] = []
prox_approx_vnf.vnfd_helper.port_pairs.interfaces = []
@@ -385,7 +399,7 @@ class TestProxApproxVnf(unittest.TestCase):
def test_run_prox(self, ssh, *_):
mock_ssh(ssh)
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf = prox_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'
@@ -399,7 +413,7 @@ class TestProxApproxVnf(unittest.TestCase):
@mock.patch(SSH_HELPER)
def bad_test_instantiate(self, *args):
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
prox_approx_vnf.scenario_helper = mock.MagicMock()
prox_approx_vnf.setup_helper = mock.MagicMock()
# we can't mock super
@@ -409,7 +423,7 @@ class TestProxApproxVnf(unittest.TestCase):
@mock.patch(SSH_HELPER)
def test_wait_for_instantiate_panic(self, ssh, *args):
mock_ssh(ssh, exec_result=(1, "", ""))
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
prox_approx_vnf._vnf_process = mock.MagicMock(**{"is_alive.return_value": True})
prox_approx_vnf._run_prox = mock.Mock(return_value=0)
prox_approx_vnf.WAIT_TIME = 0
@@ -421,7 +435,7 @@ class TestProxApproxVnf(unittest.TestCase):
@mock.patch(SSH_HELPER)
def test_terminate(self, ssh, *args):
mock_ssh(ssh)
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
prox_approx_vnf._vnf_process = mock.MagicMock()
prox_approx_vnf._vnf_process.terminate = mock.Mock()
prox_approx_vnf.ssh_helper = mock.MagicMock()
@@ -433,7 +447,7 @@ class TestProxApproxVnf(unittest.TestCase):
@mock.patch(SSH_HELPER)
def test__vnf_up_post(self, ssh, *args):
mock_ssh(ssh)
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
prox_approx_vnf.resource_helper = resource_helper = mock.Mock()
prox_approx_vnf._vnf_up_post()
@@ -442,7 +456,7 @@ class TestProxApproxVnf(unittest.TestCase):
@mock.patch(SSH_HELPER)
def test_vnf_execute_oserror(self, ssh, *args):
mock_ssh(ssh)
- prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
+ prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
prox_approx_vnf.resource_helper = resource_helper = mock.Mock()
resource_helper.execute.side_effect = OSError(errno.EPIPE, "")
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py
index 5574c6770..edd0ff796 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_router_vnf.py
@@ -18,6 +18,7 @@ import mock
from yardstick.tests import STL_MOCKS
from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
+from yardstick.benchmark.contexts import base as ctx_base
STLClient = mock.MagicMock()
@@ -214,15 +215,25 @@ class TestRouterVNF(unittest.TestCase):
stats = RouterVNF.get_stats(self.IP_SHOW_STATS_OUTPUT)
self.assertDictEqual(stats, self.STATS)
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
@mock.patch(SSH_HELPER)
- def test_collect_kpi(self, ssh, _):
+ def test_collect_kpi(self, ssh, *args):
m = mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
router_vnf = RouterVNF(name, vnfd)
+ router_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {router_vnf.name: "mock"}
+ }
router_vnf.ssh_helper = m
- result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0, 'link_stats': {}}
+ result = {
+ 'physical_node': 'mock_node',
+ 'packets_dropped': 0,
+ 'packets_fwd': 0,
+ 'packets_in': 0,
+ 'link_stats': {}
+ }
self.assertEqual(result, router_vnf.collect_kpi())
@mock.patch(SSH_HELPER)
@@ -235,9 +246,9 @@ class TestRouterVNF(unittest.TestCase):
router_vnf._run()
router_vnf.ssh_helper.drop_connection.assert_called_once()
- @mock.patch("yardstick.network_services.vnf_generic.vnf.router_vnf.Context")
+ @mock.patch.object(ctx_base, 'Context')
@mock.patch(SSH_HELPER)
- def test_instantiate(self, ssh, _):
+ def test_instantiate(self, ssh, *args):
mock_ssh(ssh)
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
index 45e06689b..03e499510 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
@@ -18,7 +18,6 @@ import unittest
import mock
import six
-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
@@ -35,6 +34,7 @@ from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTrafficGen
from yardstick.network_services.vnf_generic.vnf.sample_vnf import DpdkVnfSetupEnvHelper
from yardstick.tests.unit.network_services.vnf_generic.vnf import test_base
+from yardstick.benchmark.contexts import base as ctx_base
class MockError(Exception):
@@ -1532,33 +1532,20 @@ class TestSampleVnf(unittest.TestCase):
self.assertIsNotNone(sample_vnf.queue_wrapper)
self.assertIsNotNone(sample_vnf._vnf_process)
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
@mock.patch("yardstick.ssh.SSH")
- def test_instantiate(self, ssh):
+ def test_instantiate(self, ssh, *args):
test_base.mock_ssh(ssh)
-
nodes = {
'vnf1': 'name1',
'vnf2': 'name2',
}
- context1 = mock.Mock()
- context1._get_server.return_value = None
- context2 = mock.Mock()
- context2._get_server.return_value = context2
-
- try:
- Context.list.clear()
- except AttributeError:
- # clear() but works in Py2.7
- Context.list[:] = []
-
- Context.list.extend([
- context1,
- context2,
- ])
-
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
sample_vnf = SampleVNF('vnf1', vnfd)
+ sample_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {sample_vnf.name: 'mock'}
+ }
sample_vnf.APP_NAME = 'sample1'
sample_vnf._start_server = mock.Mock(return_value=0)
sample_vnf._vnf_process = mock.MagicMock()
@@ -1571,7 +1558,6 @@ class TestSampleVnf(unittest.TestCase):
}
self.assertIsNone(sample_vnf.instantiate(scenario_cfg, {}))
- self.assertEqual(sample_vnf.nfvi_context, context2)
def test__update_collectd_options(self):
scenario_cfg = {'options':
@@ -1708,9 +1694,13 @@ class TestSampleVnf(unittest.TestCase):
self.assertEqual(sample_vnf.get_stats(), 'the stats')
- def test_collect_kpi(self):
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
+ def test_collect_kpi(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
sample_vnf = SampleVNF('vnf1', vnfd)
+ sample_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {sample_vnf.name: "mock"}
+ }
sample_vnf.APP_NAME = 'sample1'
sample_vnf.COLLECT_KPI = r'\s(\d+)\D*(\d+)\D*(\d+)'
sample_vnf.COLLECT_MAP = {
@@ -1727,18 +1717,24 @@ class TestSampleVnf(unittest.TestCase):
'k2': 34,
'k3': 91,
'collect_stats': {},
+ 'physical_node': 'mock_node'
}
result = sample_vnf.collect_kpi()
self.assertDictEqual(result, expected)
- def test_collect_kpi_default(self):
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
+ def test_collect_kpi_default(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
sample_vnf = SampleVNF('vnf1', vnfd)
+ sample_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {sample_vnf.name: "mock"}
+ }
sample_vnf.APP_NAME = 'sample1'
sample_vnf.COLLECT_KPI = r'\s(\d+)\D*(\d+)\D*(\d+)'
sample_vnf.get_stats = mock.Mock(return_value='')
expected = {
+ 'physical_node': 'mock_node',
'packets_in': 0,
'packets_fwd': 0,
'packets_dropped': 0,
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py
index 59594a3c3..6858cf70a 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ixload.py
@@ -22,6 +22,7 @@ import unittest
from yardstick import ssh
from yardstick.common import utils
from yardstick.tests import STL_MOCKS
+from yardstick.benchmark.contexts import base as ctx_base
STLClient = mock.MagicMock()
@@ -137,17 +138,26 @@ class TestIxLoadTrafficGen(unittest.TestCase):
ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd)
self.assertIsNone(ixload_traffic_gen.resource_helper.data)
- def test_collect_kpi(self):
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
+ def test_collect_kpi(self, *args):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "", ""))
ssh.from_node.return_value = ssh_mock
+
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd)
+ ixload_traffic_gen.scenario_helper.scenario_cfg = {
+ 'nodes': {ixload_traffic_gen.name: "mock"}
+ }
ixload_traffic_gen.data = {}
restult = ixload_traffic_gen.collect_kpi()
- self.assertEqual({}, restult)
+ expected = {
+ 'physical_node': 'mock_node',
+ 'collect_stats': {},
+ }
+ self.assertEqual(expected, restult)
def test_listen_traffic(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
@@ -161,8 +171,10 @@ class TestIxLoadTrafficGen(unittest.TestCase):
@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.object(ctx_base.Context, 'get_context_from_server')
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
- def test_instantiate(self, *args):
+ def test_instantiate(self, shutil, *args):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
@@ -176,6 +188,7 @@ class TestIxLoadTrafficGen(unittest.TestCase):
'ixia_profile': "ixload.cfg",
'task_path': "/path/to/task"}
ixload_traffic_gen.RESULTS_MOUNT = "/tmp/result"
+ shutil.copy = mock.Mock()
scenario_cfg.update({'options': {'packetsize': 64, 'traffic_type': 4,
'rfc2544': {'allowed_drop_rate': '0.8 - 1'},
'vnf__1': {'rules': 'acl_1rule.yaml',
@@ -185,17 +198,21 @@ class TestIxLoadTrafficGen(unittest.TestCase):
'1C/1T',
'worker_threads': 1}}
}})
+ scenario_cfg.update({
+ 'nodes': {ixload_traffic_gen.name: "mock"}
+ })
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.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")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
- def test_run_traffic(self, *args):
+ 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
@@ -216,15 +233,17 @@ class TestIxLoadTrafficGen(unittest.TestCase):
sut.connection = mock.Mock()
sut.connection.run = mock.Mock()
sut._traffic_runner = mock.Mock(return_value=0)
+ shutil.copy = mock.Mock()
result = sut.run_traffic(mock_traffic_profile)
self.assertIsNone(result)
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
@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")
@mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.shutil")
- def test_run_traffic_csv(self, *args):
+ 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
@@ -245,6 +264,7 @@ class TestIxLoadTrafficGen(unittest.TestCase):
sut.connection = mock.Mock()
sut.connection.run = mock.Mock()
sut._traffic_runner = mock.Mock(return_value=0)
+ shutil.copy = mock.Mock()
subprocess.call(["touch", "/tmp/1.csv"])
sut.rel_bin_path = mock.Mock(return_value="/tmp/*.csv")
result = sut.run_traffic(mock_traffic_profile)
@@ -257,8 +277,9 @@ class TestIxLoadTrafficGen(unittest.TestCase):
ixload_traffic_gen = IxLoadTrafficGen(NAME, vnfd)
self.assertIsNone(ixload_traffic_gen.terminate())
- @mock.patch("yardstick.ssh.SSH")
- def test_parse_csv_read(self, mock_ssh):
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
+ @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,
@@ -280,8 +301,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")
- def test_parse_csv_read_value_error(self, mock_ssh):
+ @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ixload.call")
+ @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,
@@ -301,8 +323,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.network_services.vnf_generic.vnf.tg_ixload.call")
@mock.patch.object(ssh, 'SSH')
- def test_parse_csv_read_error(self, mock_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/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py
index 14e0db788..d774bb9f7 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py
@@ -21,6 +21,7 @@ import unittest
from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from yardstick.tests import STL_MOCKS
+from yardstick.benchmark.contexts import base as ctx_base
SSH_HELPER = "yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper"
@@ -253,14 +254,25 @@ class TestPingTrafficGen(unittest.TestCase):
self.assertNotEqual(ext_ifs[0]['virtual-interface']['local_iface_name'], 'if_name_1')
self.assertNotEqual(ext_ifs[1]['virtual-interface']['local_iface_name'], 'if_name_2')
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch("yardstick.ssh.SSH")
- def test_collect_kpi(self, ssh):
+ def test_collect_kpi(self, ssh, *args):
mock_ssh(ssh, exec_result=(0, "success", ""))
+
ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0)
+ ping_traffic_gen.scenario_helper.scenario_cfg = {
+ 'nodes': {ping_traffic_gen.name: "mock"}
+ }
ping_traffic_gen._queue = Queue()
ping_traffic_gen._queue.put({})
- ping_traffic_gen.collect_kpi()
- self.assertEqual(ping_traffic_gen._result, {})
+ expected = {
+ 'physical_node': 'mock_node',
+ 'collect_stats': {}
+ }
+ # NOTE: Why we check _result but not collect_kpi() return value
+ # self.assertEqual(ping_traffic_gen._result, {})
+ self.assertEqual(ping_traffic_gen.collect_kpi(), expected)
+
@mock.patch(SSH_HELPER)
def test_instantiate(self, ssh):
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
index f581ec8d9..050aa4aa0 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
@@ -18,6 +18,7 @@ import mock
from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from yardstick.tests import STL_MOCKS
+from yardstick.benchmark.contexts import base as ctx_base
SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
@@ -324,15 +325,22 @@ class TestProxTrafficGen(unittest.TestCase):
self.assertIsNone(prox_traffic_gen._tg_process)
self.assertIsNone(prox_traffic_gen._traffic_process)
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch(SSH_HELPER)
def test_collect_kpi(self, ssh, *args):
mock_ssh(ssh)
-
prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0)
+ prox_traffic_gen.scenario_helper.scenario_cfg = {
+ 'nodes': {prox_traffic_gen.name: "mock"}
+ }
prox_traffic_gen._vnf_wrapper.resource_helper.resource = mock.MagicMock(
**{"self.check_if_system_agent_running.return_value": [False]})
prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="")
- self.assertEqual({}, prox_traffic_gen.collect_kpi())
+ expected = {
+ 'collect_stats': {},
+ 'physical_node': 'mock_node'
+ }
+ self.assertEqual(prox_traffic_gen.collect_kpi(), expected)
@mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.find_relative_file')
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py
index dca8098fa..42ac40b50 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_ixia.py
@@ -21,6 +21,7 @@ import unittest
from yardstick.network_services.libs.ixia_libs.ixnet import ixnet_api
from yardstick.network_services.traffic_profile import base as tp_base
from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_ixia
+from yardstick.benchmark.contexts import base as ctx_base
TEST_FILE_YAML = 'nsb_test_case.yaml'
@@ -186,6 +187,7 @@ class TestIXIATrafficGen(unittest.TestCase):
ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
self.assertIsNone(ixnet_traffic_gen.listen_traffic({}))
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
def test_instantiate(self, *args):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
@@ -212,6 +214,9 @@ class TestIXIATrafficGen(unittest.TestCase):
'lb_count': 1,
'worker_config': '1C/1T',
'worker_threads': 1}}}})
+ scenario_cfg.update({
+ 'nodes': {ixnet_traffic_gen.name: "mock"}
+ })
ixnet_traffic_gen.topology = ""
ixnet_traffic_gen.get_ixobj = mock.MagicMock()
ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
@@ -220,17 +225,26 @@ class TestIXIATrafficGen(unittest.TestCase):
IOError,
ixnet_traffic_gen.instantiate(scenario_cfg, {}))
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
def test_collect_kpi(self, *args):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "", ""))
ssh.from_node.return_value = ssh_mock
+
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
ixnet_traffic_gen = tg_rfc2544_ixia.IxiaTrafficGen(NAME, vnfd)
+ ixnet_traffic_gen.scenario_helper.scenario_cfg = {
+ 'nodes': {ixnet_traffic_gen.name: "mock"}
+ }
ixnet_traffic_gen.data = {}
restult = ixnet_traffic_gen.collect_kpi()
- self.assertEqual({}, restult)
+
+ expected = {'collect_stats': {},
+ 'physical_node': 'mock_node'}
+
+ self.assertEqual(expected, restult)
def test_terminate(self, *args):
with mock.patch("yardstick.ssh.SSH") as ssh:
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py
index a463fa0de..b52d2d0c3 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py
@@ -20,6 +20,7 @@ import unittest
from yardstick.network_services.traffic_profile import base as tp_base
from yardstick.network_services.vnf_generic.vnf import sample_vnf
from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
+from yardstick.benchmark.contexts import base as ctx_base
class TestTrexRfcResouceHelper(unittest.TestCase):
@@ -226,7 +227,20 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0)
self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value)
- def test_instantiate(self):
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
+ def test_collect_kpi(self, *args):
+ trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0)
+ trex_traffic_gen.scenario_helper.scenario_cfg = {
+ 'nodes': {trex_traffic_gen.name: "mock"}
+ }
+ expected = {
+ 'physical_node': 'mock_node',
+ 'collect_stats': {},
+ }
+ self.assertEqual(trex_traffic_gen.collect_kpi(), expected)
+
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
+ def test_instantiate(self, *args):
mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
mock_traffic_profile.get_traffic_definition.return_value = "64"
mock_traffic_profile.params = self.TRAFFIC_PROFILE
@@ -257,10 +271,11 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
},
}
tg_rfc2544_trex.WAIT_TIME = 3
- scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]})
+ scenario_cfg.update({"nodes": {"tg_1": {}, "vnf1": {}}})
self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
- def test_instantiate_error(self):
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
+ def test_instantiate_error(self, *args):
mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
mock_traffic_profile.get_traffic_definition.return_value = "64"
mock_traffic_profile.params = self.TRAFFIC_PROFILE
@@ -270,10 +285,10 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
scenario_cfg = {
"tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
- "nodes": [
- "tg_1",
- "vnf_1",
- ],
+ "nodes": {
+ "tg_1": {},
+ "vnf1": {}
+ },
"topology": 'nsb_test_case.yaml',
'options': {
'packetsize': 64,
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py
index 4f8742477..350ba8448 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py
@@ -21,9 +21,10 @@ from yardstick.network_services.traffic_profile import base as tp_base
from yardstick.network_services.traffic_profile import rfc2544
from yardstick.network_services.vnf_generic.vnf import sample_vnf
from yardstick.network_services.vnf_generic.vnf import tg_trex
+from yardstick.benchmark.contexts import base as ctx_base
-NAME = 'vnf_1'
+NAME = 'vnf__1'
class TestTrexTrafficGen(unittest.TestCase):
@@ -303,19 +304,28 @@ class TestTrexTrafficGen(unittest.TestCase):
self.assertIsInstance(trex_traffic_gen.resource_helper,
tg_trex.TrexResourceHelper)
- def test_collect_kpi(self):
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
+ def test_collect_kpi(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
trex_traffic_gen = tg_trex.TrexTrafficGen(NAME, vnfd)
+ trex_traffic_gen.scenario_helper.scenario_cfg = {
+ 'nodes': {trex_traffic_gen.name: "mock"}
+ }
trex_traffic_gen.resource_helper._queue.put({})
result = trex_traffic_gen.collect_kpi()
- self.assertEqual({}, result)
+ expected = {
+ 'physical_node': 'mock_node',
+ 'collect_stats': {}
+ }
+ self.assertEqual(expected, result)
def test_listen_traffic(self):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
trex_traffic_gen = tg_trex.TrexTrafficGen(NAME, vnfd)
self.assertIsNone(trex_traffic_gen.listen_traffic({}))
- def test_instantiate(self):
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
+ def test_instantiate(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
trex_traffic_gen = tg_trex.TrexTrafficGen(NAME, vnfd)
trex_traffic_gen._start_server = mock.Mock(return_value=0)
@@ -329,7 +339,8 @@ class TestTrexTrafficGen(unittest.TestCase):
self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG,
self.CONTEXT_CFG))
- def test_instantiate_error(self):
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
+ def test_instantiate_error(self, *args):
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
trex_traffic_gen = tg_trex.TrexTrafficGen(NAME, vnfd)
trex_traffic_gen._start_server = mock.Mock(return_value=0)
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py
index 05a0ead71..1c4ced303 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py
@@ -19,6 +19,7 @@ import os
from yardstick.tests import STL_MOCKS
from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
+from yardstick.benchmark.contexts import base as ctx_base
SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
@@ -330,6 +331,7 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
self.assertIsNone(udp_replay_approx_vnf._vnf_process)
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch(SSH_HELPER)
def test_collect_kpi(self, ssh, *args):
mock_ssh(ssh)
@@ -341,14 +343,21 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
"0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
"1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
+ udp_replay_approx_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {udp_replay_approx_vnf.name: "mock"}
+ }
udp_replay_approx_vnf.q_in = mock.MagicMock()
udp_replay_approx_vnf.q_out = mock.MagicMock()
udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
udp_replay_approx_vnf.get_stats = mock.Mock(return_value=get_stats_ret_val)
-
- result = {'collect_stats': {}, 'packets_dropped': 0,
- 'packets_fwd': 14748451, 'packets_in': 14748472}
+ result = {
+ 'physical_node': 'mock_node',
+ 'collect_stats': {},
+ 'packets_dropped': 0,
+ 'packets_fwd': 14748451,
+ 'packets_in': 14748472
+ }
self.assertEqual(result, udp_replay_approx_vnf.collect_kpi())
@mock.patch(SSH_HELPER)
@@ -372,14 +381,18 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
file_path = os.path.join(curr_path, filename)
return file_path
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server')
@mock.patch(SSH_HELPER)
- def test__build_config(self, ssh, mock_context, *args):
+ def test__build_config(self, ssh, mock_get_ctx, *args):
mock_ssh(ssh)
+ nfvi_context = mock.Mock()
+ nfvi_context.attrs = {'nfvi_type': 'baremetal'}
+ mock_get_ctx.return_value = nfvi_context
+
udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
- udp_replay_approx_vnf.nfvi_context = mock_context
+ udp_replay_approx_vnf.nfvi_context = mock_get_ctx
udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
udp_replay_approx_vnf.setup_helper.bound_pci = []
udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
@@ -393,13 +406,16 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
self.assertEqual(cmd_line, expected)
@mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server')
@mock.patch(SSH_HELPER)
- def test__build_pipeline_kwargs(self, ssh, mock_context, *args):
+ def test__build_pipeline_kwargs(self, ssh, mock_get_ctx, *args):
mock_ssh(ssh)
+
+ nfvi_context = mock.Mock()
+ nfvi_context.attrs = {'nfvi_type': "baremetal"}
+ mock_get_ctx.return_value = nfvi_context
+
udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
- udp_replay_approx_vnf.nfvi_context = mock_context
- udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3']
udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
@@ -430,7 +446,7 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server')
@mock.patch(SSH_HELPER)
def test_instantiate(self, ssh, *args):
mock_ssh(ssh)
@@ -449,7 +465,7 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
self.assertEqual(udp_replay_approx_vnf.wait_for_instantiate(), 0)
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server')
@mock.patch('yardstick.ssh.SSH')
@mock.patch(SSH_HELPER)
def test_instantiate_panic(self, *args):
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py
index a0a0794ea..b67a3cdee 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vfw_vnf.py
@@ -21,7 +21,7 @@ from yardstick.tests import STL_MOCKS
from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from yardstick.common import utils
-
+from yardstick.benchmark.contexts import base as ctx_base
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
@@ -259,12 +259,15 @@ pipeline>
""" # noqa
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch(SSH_HELPER)
def test_collect_kpi(self, ssh, *args):
mock_ssh(ssh)
-
vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
vfw_approx_vnf = FWApproxVnf(name, vnfd)
+ vfw_approx_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {vfw_approx_vnf.name: "mock"}
+ }
vfw_approx_vnf.q_in = mock.MagicMock()
vfw_approx_vnf.q_out = mock.MagicMock()
vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
@@ -273,6 +276,7 @@ pipeline>
**{'collect_kpi.return_value': {"core": {}}})
vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
result = {
+ 'physical_node': 'mock_node',
'packets_dropped': 0,
'packets_fwd': 6007180,
'packets_in': 6007180,
@@ -334,7 +338,7 @@ pipeline>
vfw_approx_vnf.ssh_helper.run.assert_called_once()
@mock.patch.object(utils, 'find_relative_file')
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+ @mock.patch.object(ctx_base.Context, 'get_context_from_server')
@mock.patch(SSH_HELPER)
def test_instantiate(self, ssh, *args):
mock_ssh(ssh)
diff --git a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
index 73f91d1b1..f91852f74 100644
--- a/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
+++ b/yardstick/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
@@ -26,6 +26,7 @@ from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import File
from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
from yardstick.network_services.vnf_generic.vnf.base import QueueFileWrapper
from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
+from yardstick.benchmark.contexts import base as ctx_base
SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
@@ -547,8 +548,9 @@ class TestVpeApproxVnf(unittest.TestCase):
vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
self.assertIsNone(vpe_approx_vnf._vnf_process)
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch(SSH_HELPER)
- def test_collect_kpi_sa_not_running(self, ssh):
+ def test_collect_kpi_sa_not_running(self, ssh, *args):
mock_ssh(ssh)
resource = mock.Mock(autospec=ResourceProfile)
@@ -557,12 +559,16 @@ class TestVpeApproxVnf(unittest.TestCase):
resource.check_if_system_agent_running.return_value = (1, None)
vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {vpe_approx_vnf.name: "mock"}
+ }
vpe_approx_vnf.q_in = mock.MagicMock()
vpe_approx_vnf.q_out = mock.MagicMock()
vpe_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
vpe_approx_vnf.resource_helper.resource = resource
expected = {
+ 'physical_node': 'mock_node',
'pkt_in_down_stream': 0,
'pkt_in_up_stream': 0,
'pkt_drop_down_stream': 0,
@@ -571,8 +577,9 @@ class TestVpeApproxVnf(unittest.TestCase):
}
self.assertEqual(vpe_approx_vnf.collect_kpi(), expected)
+ @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
@mock.patch(SSH_HELPER)
- def test_collect_kpi_sa_running(self, ssh):
+ def test_collect_kpi_sa_running(self, ssh, *args):
mock_ssh(ssh)
resource = mock.Mock(autospec=ResourceProfile)
@@ -580,12 +587,16 @@ class TestVpeApproxVnf(unittest.TestCase):
resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234}
vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
+ vpe_approx_vnf.scenario_helper.scenario_cfg = {
+ 'nodes': {vpe_approx_vnf.name: "mock"}
+ }
vpe_approx_vnf.q_in = mock.MagicMock()
vpe_approx_vnf.q_out = mock.MagicMock()
vpe_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
vpe_approx_vnf.resource_helper.resource = resource
expected = {
+ 'physical_node': 'mock_node',
'pkt_in_down_stream': 0,
'pkt_in_up_stream': 0,
'pkt_drop_down_stream': 0,
@@ -634,7 +645,6 @@ class TestVpeApproxVnf(unittest.TestCase):
self.assertIsNone(vpe_approx_vnf._run())
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.MultiPortConfig")
- @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
@mock.patch("yardstick.network_services.vnf_generic.vnf.vpe_vnf.ConfigCreate")
@mock.patch("six.moves.builtins.open")
@mock.patch(SSH_HELPER)