test suite reviews and discussions
 help / color / mirror / Atom feed
From: Marvin Liu <yong.liu@intel.com>
To: dts@dpdk.org
Cc: Marvin Liu <yong.liu@intel.com>
Subject: [dts] [PATCH v1 13/16] framework/virt_dut: support multiple VMs module
Date: Sun,  7 Jan 2018 21:49:26 -0500	[thread overview]
Message-ID: <1515379769-11553-14-git-send-email-yong.liu@intel.com> (raw)
In-Reply-To: <1515379769-11553-1-git-send-email-yong.liu@intel.com>

1. Added 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 locked, 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 <yong.liu@intel.com>

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

  parent reply	other threads:[~2018-01-08  9:56 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-08  2:49 [dts] [PATCH v1 00/16] Support parallel multiple virtual machine management Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 01/16] framework: add external thread pool library Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 02/16] framework/multiple_vm: add multiple VM management module Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 03/16] framework/utils: support locks function in parallel model Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 04/16] framework: add DUT index support Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 05/16] framework/logger: optimize output format for child threads Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 06/16] framework/dts: support multiple VMs module Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 07/16] framework/debugger: " Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 08/16] framework/ssh_pexpect: " Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 09/16] framework/ssh_connection: support DUT index argument Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 10/16] framework/settings: add parallel related settings Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 11/16] framework/virt_resource: support multiple VMs module Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 12/16] framework/virt_base: add attach/quick start/quit function for VM management Marvin Liu
2018-01-08  2:49 ` Marvin Liu [this message]
2018-01-08  2:49 ` [dts] [PATCH v1 14/16] framework/qemu_kvm: support multiple VMs module Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 15/16] conf/virt_global: add vm management related configuration Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 16/16] doc: add descriptions for multiple virtual machine module Marvin Liu
2018-01-10  0:10 ` [dts] [PATCH v2 00/16] Support parallel multiple virtual machines management Marvin Liu
2018-01-10  0:10   ` [dts] [PATCH v2 01/16] framework: add external thread pool library Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 02/16] framework/multiple_vm: add multiple VM management module Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 03/16] framework/utils: support locks for parallel model Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 04/16] framework: add DUT index support Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 05/16] framework/logger: optimize output format for threads Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 06/16] framework/dts: support multiple VMs module Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 07/16] framework/debugger: " Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH 08/16] framework/ssh_pexpect: " Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 09/16] framework/ssh_connection: " Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 10/16] framework/settings: add parallel related settings Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 11/16] framework/virt_resource: support multiple VMs module Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 12/16] framework/virt_base: add attach/quick start/quit function for VM management Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 13/16] framework/virt_dut: support multiple VMs module Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 14/16] framework/qemu_kvm: " Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 15/16] conf/virt_global: add vm management related configuration Marvin Liu
2018-01-10  0:11   ` [dts] [PATCH v2 16/16] doc: add descriptions for multiple virtual machines module Marvin Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1515379769-11553-14-git-send-email-yong.liu@intel.com \
    --to=yong.liu@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).