import re
import subprocess
from collections import Mapping
-
from multiprocessing import Queue, Value, Process
from six.moves import cStringIO
from yardstick.benchmark.contexts.base import Context
from yardstick.benchmark.scenarios.networking.vnf_generic import find_relative_file
+from yardstick.common import exceptions as y_exceptions
from yardstick.common.process import check_if_process_failed
-from yardstick.network_services.helpers.cpu import CpuSysCores
from yardstick.network_services.helpers.samplevnf_helper import PortPairs
from yardstick.network_services.helpers.samplevnf_helper import MultiPortConfig
from yardstick.network_services.helpers.dpdkbindnic_helper import DpdkBindHelper
CFG_CONFIG = os.path.join(REMOTE_TMP, "sample_config")
CFG_SCRIPT = os.path.join(REMOTE_TMP, "sample_script")
- CORES = []
DEFAULT_CONFIG_TPL_CFG = "sample.cfg"
PIPELINE_COMMAND = ''
VNF_TYPE = "SAMPLE"
APP_NAME = 'DpdkVnf'
FIND_NET_CMD = "find /sys/class/net -lname '*{}*' -printf '%f'"
- HW_DEFAULT_CORE = 3
- SW_DEFAULT_CORE = 2
-
@staticmethod
def _update_packet_type(ip_pipeline_cfg, traffic_options):
match_str = 'pkt_type = ipv4'
'tool_path': tool_path,
}
- def _get_app_cpu(self):
- if self.CORES:
- return self.CORES
-
- vnf_cfg = self.scenario_helper.vnf_cfg
- sys_obj = CpuSysCores(self.ssh_helper)
- self.sys_cpu = sys_obj.get_core_socket()
- num_core = int(vnf_cfg["worker_threads"])
- if vnf_cfg.get("lb_config", "SW") == 'HW':
- num_core += self.HW_DEFAULT_CORE
- else:
- num_core += self.SW_DEFAULT_CORE
- app_cpu = self.sys_cpu[str(self.socket)][:num_core]
- return app_cpu
-
- def _get_cpu_sibling_list(self, cores=None):
- if cores is None:
- cores = self._get_app_cpu()
- sys_cmd_template = "%s/cpu%s/topology/thread_siblings_list"
- awk_template = "awk -F: '{ print $1 }' < %s"
- sys_path = "/sys/devices/system/cpu/"
- cpu_topology = []
- try:
- for core in cores:
- sys_cmd = sys_cmd_template % (sys_path, core)
- cpu_id = self.ssh_helper.execute(awk_template % sys_cmd)[1]
- cpu_topology.extend(cpu.strip() for cpu in cpu_id.split(','))
-
- return cpu_topology
- except Exception:
- return []
-
- def _validate_cpu_cfg(self):
- return self._get_cpu_sibling_list()
-
def setup_vnf_environment(self):
self._setup_dpdk()
self.bound_pci = [v['virtual-interface']["vpci"] for v in self.vnfd_helper.interfaces]
if vpci == v['virtual-interface']['vpci'])
# force to int
intf['virtual-interface']['dpdk_port_num'] = int(dpdk_port_num)
- except:
+ except: # pylint: disable=bare-except
pass
time.sleep(2)
self.vnfd_helper.port_nums(self.vnfd_helper.port_pairs.downlink_ports)
self.all_ports = self.vnfd_helper.port_nums(self.vnfd_helper.port_pairs.all_ports)
+ def port_num(self, intf):
+ # by default return port num
+ return self.vnfd_helper.port_num(intf)
+
def get_stats(self, *args, **kwargs):
try:
return self.client.get_stats(*args, **kwargs)
self.client.clear_stats(ports=ports)
def start(self, ports=None, *args, **kwargs):
+ # pylint: disable=keyword-arg-before-vararg
+ # NOTE(ralonsoh): defining keyworded arguments before variable
+ # positional arguments is a bug. This function definition doesn't work
+ # in Python 2, although it works in Python 3. Reference:
+ # https://www.python.org/dev/peps/pep-3102/
if ports is None:
ports = self.all_ports
self.client.start(ports=ports, *args, **kwargs)
if not self._queue.empty():
kpi = self._queue.get()
self._result.update(kpi)
- LOG.debug("Got KPIs from _queue for {0} {1}".format(
- self.scenario_helper.name, self.RESOURCE_WORD))
+ LOG.debug('Got KPIs from _queue for %s %s',
+ self.scenario_helper.name, self.RESOURCE_WORD)
return self._result
def _connect(self, client=None):
self.pipeline_kwargs = {}
self.uplink_ports = None
self.downlink_ports = None
- # TODO(esm): make QueueFileWrapper invert-able so that we
+ # NOTE(esm): make QueueFileWrapper invert-able so that we
# never have to manage the queues
self.q_in = Queue()
self.q_out = Queue()
if not self._vnf_process.is_alive():
raise RuntimeError("%s VNF process died." % self.APP_NAME)
- # TODO(esm): move to QueueFileWrapper
+ # NOTE(esm): move to QueueFileWrapper
while self.q_out.qsize() > 0:
buf.append(self.q_out.get())
message = ''.join(buf)
self._vnf_process.terminate()
# no terminate children here because we share processes with tg
- def get_stats(self, *args, **kwargs):
- """
- Method for checking the statistics
+ def get_stats(self, *args, **kwargs): # pylint: disable=unused-argument
+ """Method for checking the statistics
- :return:
- VNF statistics
+ This method could be overridden in children classes.
+
+ :return: VNF statistics
"""
cmd = 'p {0} stats'.format(self.APP_WORD)
out = self.vnf_execute(cmd)
LOG.debug("%s collect KPIs %s", self.APP_NAME, result)
return result
+ def scale(self, flavor=""):
+ """The SampleVNF base class doesn't provide the 'scale' feature"""
+ raise y_exceptions.FunctionNotImplemented(
+ function_name='scale', class_name='SampleVNFTrafficGen')
+
class SampleVNFTrafficGen(GenericTrafficGen):
""" Class providing file-like API for generic traffic generator """
self._tg_process = Process(name=name, target=self._start_server)
self._tg_process.start()
- def wait_for_instantiate(self):
- # overridden by subclasses
- return self._wait_for_process()
-
def _check_status(self):
raise NotImplementedError
return self._traffic_process.is_alive()
- def listen_traffic(self, traffic_profile):
- """ Listen to traffic with the given parameters.
- Method is non-blocking, returns immediately when traffic process
- is running. Optional.
-
- :param traffic_profile:
- :return: True/False
- """
- pass
-
- def verify_traffic(self, traffic_profile):
- """ Verify captured traffic after it has ended. Optional.
-
- :param traffic_profile:
- :return: dict
- """
- pass
-
def collect_kpi(self):
# check if the tg processes have exited
for proc in (self._tg_process, self._traffic_process):
self._tg_process.join(PROCESS_JOIN_TIMEOUT)
self._tg_process.terminate()
# no terminate children here because we share processes with vnf
+
+ def scale(self, flavor=""):
+ """A traffic generator VFN doesn't provide the 'scale' feature"""
+ raise y_exceptions.FunctionNotImplemented(
+ function_name='scale', class_name='SampleVNFTrafficGen')