From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 56DB41B168 for ; Wed, 10 Jan 2018 08:18:18 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2018 23:18:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,339,1511856000"; d="scan'208";a="19775238" Received: from dpdk-test38.sh.intel.com ([10.67.119.87]) by fmsmga004.fm.intel.com with ESMTP; 09 Jan 2018 23:18:17 -0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Tue, 9 Jan 2018 19:11:11 -0500 Message-Id: <1515543074-81373-14-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1515543074-81373-1-git-send-email-yong.liu@intel.com> References: <1515379769-11553-1-git-send-email-yong.liu@intel.com> <1515543074-81373-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH v2 13/16] framework/virt_dut: support multiple VMs module X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jan 2018 07:18:18 -0000 1. Add DUT index argument and protect tester interactive process by lock. 2. Only create one ssh connection to virtual machine. 3. Support disable auto-detect function which must be protected, thus can save virtual machine instantiate time. 4. Without alternative session, kill_all function should be handled by control session. Signed-off-by: Marvin Liu diff --git a/framework/virt_dut.py b/framework/virt_dut.py index 348279d..83f661d 100644 --- a/framework/virt_dut.py +++ b/framework/virt_dut.py @@ -32,8 +32,8 @@ import os import re import time -import utils import settings +from utils import RED, parallel_lock from config import PortConf from settings import NICS, LOG_NAME_SEP, get_netdev from project_dpdk import DPDKdut @@ -53,14 +53,16 @@ class VirtDut(DPDKdut): or CRBBareMetal. """ - def __init__(self, hyper, crb, serializer, virttype, vm_name, suite, cpu_topo): + def __init__(self, hyper, crb, serializer, virttype, vm_name, suite, cpu_topo, dut_id): self.vm_name = vm_name self.hyper = hyper self.cpu_topo = cpu_topo + self.dut_id = dut_id self.vm_ip = crb['IP'] self.NAME = 'virtdut' + LOG_NAME_SEP + '%s' % self.vm_ip - super(Dut, self).__init__(crb, serializer, self.NAME) + # do not create addition alt_session + super(Dut, self).__init__(crb, serializer, self.NAME, alt_session=False, dut_id=self.dut_id) # load port config from suite cfg self.suite = suite @@ -73,15 +75,13 @@ class VirtDut(DPDKdut): self.virttype = virttype def init_log(self): - self.logger.config_suite(self.host_dut.test_classname, 'virtdut') + if hasattr(self.host_dut, "test_classname"): + self.logger.config_suite(self.host_dut.test_classname, 'virtdut') def close(self, force=False): if self.session: self.session.close(force) self.session = None - if self.alt_session: - self.alt_session.close(force) - self.alt_session = None RemoveNicObj(self) def set_nic_type(self, nic_type): @@ -91,6 +91,7 @@ class VirtDut(DPDKdut): self.nic_type = nic_type # vm_dut config will load from vm configuration file + @parallel_lock() def load_portconf(self): """ Load port config for this virtual machine @@ -99,12 +100,24 @@ class VirtDut(DPDKdut): self.conf.load_ports_config(self.vm_name) self.ports_cfg = self.conf.get_ports_config() - return + @parallel_lock() + def detect_portmap(self, dut_id): + """ + Detect port mapping with ping6 message, should be locked for protect + tester operations. + """ + # enable tester port ipv6 + self.host_dut.enable_tester_ipv6() + + self.map_available_ports() - def create_portmap(self): - # if not config ports in vm port config file, used ping6 get portmap - if not self.ports_cfg: - self.map_available_ports() + # disable tester port ipv6 + self.host_dut.disable_tester_ipv6() + + def load_portmap(self): + """ + Generate port mapping base on loaded port configuration + """ port_num = len(self.ports_info) self.ports_map = [-1] * port_num for key in self.ports_cfg.keys(): @@ -142,7 +155,7 @@ class VirtDut(DPDKdut): if bind_dev: self.bind_interfaces_linux('igb_uio') - def prerequisites(self, pkgName, patch): + def prerequisites(self, pkgName, patch, autodetect_topo): """ Prerequest function should be called before execute any test case. Will call function to scan all lcore's information which on DUT. @@ -152,7 +165,10 @@ class VirtDut(DPDKdut): if not self.skip_setup: self.prepare_package() - self.send_expect("cd %s" % self.base_dir, "# ") + out = self.send_expect("cd %s" % self.base_dir, "# ") + if 'No such file or directory' in out: + self.logger.error("Can't switch to dpdk folder!!!") + self.send_expect("alias ls='ls --color=none'", "#") if self.get_os_type() == 'freebsd': @@ -180,14 +196,14 @@ class VirtDut(DPDKdut): # load port infor from config file self.load_portconf() - # enable tester port ipv6 - self.host_dut.enable_tester_ipv6() self.mount_procfs() - self.create_portmap() - - # disable tester port ipv6 - self.host_dut.disable_tester_ipv6() + if self.ports_cfg: + self.load_portmap() + else: + # if no config ports in port config file, will auto-detect portmap + if autodetect_topo: + self.detect_portmap(dut_id=self.dut_id) # print latest ports_info for port_info in self.ports_info: @@ -196,7 +212,7 @@ class VirtDut(DPDKdut): def init_core_list(self): self.cores = [] cpuinfo = self.send_expect("grep --color=never \"processor\"" - " /proc/cpuinfo", "#", alt_session=False) + " /proc/cpuinfo", "#") cpuinfo = cpuinfo.split('\r\n') if self.cpu_topo != '': topo_reg = r"(\d)S/(\d)C/(\d)T" @@ -394,3 +410,21 @@ class VirtDut(DPDKdut): self.ports_map[vmPort] = remotePort hits[remotePort] = True continue + + def kill_all(self, alt_session=False): + """ + Kill all dpdk applications on VM + """ + control = getattr(self.hyper, 'control_session', None) + if callable(control): + out = control("lsof -Fp /var/run/.rte_config") + pids = [] + pid_reg = r'p(\d+)' + if len(out): + lines = out.split('\r\n') + for line in lines: + m = re.match(pid_reg, line) + if m: + pids.append(m.group(1)) + for pid in pids: + control('kill -9 %s' % pid) -- 1.9.3