Merge "bugfix: tc023 miss description and tc050-58 wrong description"
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / sample_vnf.py
index 92f78c2..20e5895 100644 (file)
@@ -22,7 +22,6 @@ import os
 import re
 import subprocess
 from collections import Mapping
-
 from multiprocessing import Queue, Value, Process
 
 from six.moves import cStringIO
@@ -30,7 +29,6 @@ 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.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
@@ -97,7 +95,6 @@ class SetupEnvHelper(object):
 
     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"
@@ -108,13 +105,6 @@ class SetupEnvHelper(object):
         self.ssh_helper = ssh_helper
         self.scenario_helper = scenario_helper
 
-    def _get_ports_gateway(self, name):
-        routing_table = self.vnfd_helper.vdu0.get('routing_table', [])
-        for route in routing_table:
-            if name == route['if']:
-                return route['gateway']
-        return None
-
     def build_config(self):
         raise NotImplementedError
 
@@ -133,9 +123,6 @@ class DpdkVnfSetupEnvHelper(SetupEnvHelper):
     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'
@@ -248,41 +235,6 @@ class DpdkVnfSetupEnvHelper(SetupEnvHelper):
             '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]
@@ -330,7 +282,6 @@ class DpdkVnfSetupEnvHelper(SetupEnvHelper):
         else:
             self.socket = 1
 
-        cores = self._validate_cpu_cfg()
         # implicit ordering, presumably by DPDK port num, so pre-sort by port_num
         # this won't work because we don't have DPDK port numbers yet
         ports = sorted(self.vnfd_helper.interfaces, key=self.vnfd_helper.port_num)
@@ -338,7 +289,7 @@ class DpdkVnfSetupEnvHelper(SetupEnvHelper):
         collectd_options = self.get_collectd_options()
         plugins = collectd_options.get("plugins", {})
         # we must set timeout to be the same as the VNF otherwise KPIs will die before VNF
-        return ResourceProfile(self.vnfd_helper.mgmt_interface, port_names=port_names, cores=cores,
+        return ResourceProfile(self.vnfd_helper.mgmt_interface, port_names=port_names,
                                plugins=plugins, interval=collectd_options.get("interval"),
                                timeout=self.scenario_helper.timeout)
 
@@ -440,6 +391,10 @@ class ClientResourceHelper(ResourceHelper):
             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)
@@ -685,6 +640,7 @@ class SampleVNF(GenericVNF):
 
     VNF_PROMPT = "pipeline>"
     WAIT_TIME = 1
+    WAIT_TIME_FOR_SCRIPT = 10
     APP_NAME = "SampleVNF"
     # we run the VNF interactively, so the ssh command will timeout after this long
 
@@ -811,7 +767,7 @@ class SampleVNF(GenericVNF):
                                        self.APP_NAME)
 
             LOG.info("Waiting for %s VNF to start.. ", self.APP_NAME)
-            time.sleep(1)
+            time.sleep(self.WAIT_TIME_FOR_SCRIPT)
             # Send ENTER to display a new prompt in case the prompt text was corrupted
             # by other VNF output
             self.q_in.put('\r\n')
@@ -930,18 +886,15 @@ class SampleVNFTrafficGen(GenericTrafficGen):
 
     def instantiate(self, scenario_cfg, context_cfg):
         self.scenario_helper.scenario_cfg = scenario_cfg
-        self.resource_helper.generate_cfg()
         self.resource_helper.setup()
+        # must generate_cfg after DPDK bind because we need port number
+        self.resource_helper.generate_cfg()
 
         LOG.info("Starting %s server...", self.APP_NAME)
         name = "{}-{}-{}".format(self.name, self.APP_NAME, os.getpid())
         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
 
@@ -985,24 +938,6 @@ class SampleVNFTrafficGen(GenericTrafficGen):
 
         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):