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 v2 04/16] framework: add DUT index support
Date: Tue,  9 Jan 2018 19:11:02 -0500	[thread overview]
Message-ID: <1515543074-81373-5-git-send-email-yong.liu@intel.com> (raw)
In-Reply-To: <1515543074-81373-1-git-send-email-yong.liu@intel.com>

1. All CRBs will have index concept, the index value is assigned when
CRB instantiating.
2. Alternative session is not must for virtual DUT. Thus can save lots
of system resource when starting many vitual machines.
3. Virtual environment setup will remove all related ssh rsa keys.

Signed-off-by: Marvin Liu <yong.liu@intel.com>

diff --git a/framework/crb.py b/framework/crb.py
index dd29a8b..7affce7 100644
--- a/framework/crb.py
+++ b/framework/crb.py
@@ -49,7 +49,8 @@ class Crb(object):
     CPU/PCI/NIC on the board and setup running environment for DPDK.
     """
 
-    def __init__(self, crb, serializer, name):
+    def __init__(self, crb, serializer, name, alt_session=True, dut_id=0):
+        self.dut_id = dut_id
         self.crb = crb
         self.read_cache = False
         self.skip_setup = False
@@ -62,14 +63,18 @@ class Crb(object):
         self.logger = getLogger(name)
         self.session = SSHConnection(self.get_ip_address(), name,
                                      self.get_username(),
-                                     self.get_password())
+                                     self.get_password(), dut_id)
         self.session.init_log(self.logger)
-        self.alt_session = SSHConnection(
-            self.get_ip_address(),
-            name + '_alt',
-            self.get_username(),
-            self.get_password())
-        self.alt_session.init_log(self.logger)
+        if alt_session:
+            self.alt_session = SSHConnection(
+                self.get_ip_address(),
+                name + '_alt',
+                self.get_username(),
+                self.get_password(),
+                dut_id)
+            self.alt_session.init_log(self.logger)
+        else:
+            self.alt_session = None
 
     def send_expect(self, cmds, expected, timeout=TIMEOUT,
                     alt_session=False, verify=False):
@@ -78,8 +83,8 @@ class Crb(object):
         there's no expected string found before timeout, TimeoutException will
         be raised.
         """
-
-        if alt_session:
+        # sometimes there will be no alt_session like VM dut
+        if alt_session and self.alt_session:
             return self.alt_session.session.send_expect(cmds, expected,
                                                         timeout, verify)
 
@@ -93,7 +98,8 @@ class Crb(object):
         session = SSHConnection(self.get_ip_address(),
                                 name,
                                 self.get_username(),
-                                self.get_password())
+                                self.get_password(),
+                                dut_id = self.dut_id)
         session.init_log(logger)
         self.sessions.append(session)
         return session
@@ -104,7 +110,7 @@ class Crb(object):
         """
         for save_session in self.sessions:
             if save_session == session:
-                save_session.close()
+                save_session.close(force=True)
                 logger = getLogger(save_session.name)
                 logger.logger_exit()
                 self.sessions.remove(save_session)
@@ -141,7 +147,7 @@ class Crb(object):
         Send commands to crb and return string before timeout.
         """
 
-        if alt_session:
+        if alt_session and self.alt_session:
             return self.alt_session.session.send_command(cmds, timeout)
 
         return self.session.send_command(cmds, timeout)
@@ -167,7 +173,7 @@ class Crb(object):
             "awk '/HugePages_Total/ { print $2 }' /proc/meminfo",
             "# ", alt_session=True)
         if huge_pages != "":
-            return int(huge_pages)
+            return int(huge_pages.split()[0])
         return 0
 
     def mount_huge_pages(self):
@@ -220,9 +226,6 @@ class Crb(object):
         """
         self.base_dir = base_dir
 
-    def set_virttype(self, virttype):
-        self.virttype = virttype
-
     def admin_ports(self, port, status):
         """
         Force set port's interface status.
diff --git a/framework/dut.py b/framework/dut.py
index 22ff0bb..9c2a5a8 100644
--- a/framework/dut.py
+++ b/framework/dut.py
@@ -39,7 +39,7 @@ from ssh_connection import SSHConnection
 from crb import Crb
 from net_device import GetNicObj
 from virt_resource import VirtResource
-from utils import RED
+from utils import RED, remove_old_rsa_key
 from uuid import uuid4
 
 
@@ -60,9 +60,9 @@ class Dut(Crb):
     CORE_LIST_CACHE_KEY = 'dut_core_list'
     PCI_DEV_CACHE_KEY = 'dut_pci_dev_info'
 
-    def __init__(self, crb, serializer):
+    def __init__(self, crb, serializer, dut_id):
         self.NAME = 'dut' + LOG_NAME_SEP + '%s' % crb['My IP']
-        super(Dut, self).__init__(crb, serializer, self.NAME)
+        super(Dut, self).__init__(crb, serializer, self.NAME, alt_session=True, dut_id=dut_id)
 
         self.host_init_flag = False
         self.number_of_cores = 0
@@ -76,29 +76,35 @@ class Dut(Crb):
         # hypervisor pid list, used for cleanup
         self.virt_pids = []
 
-    def init_host_session(self):
-        if self.host_init_flag:
-            pass
-        else:
-            self.host_session = SSHConnection(
-                self.get_ip_address(),
-                self.NAME + '_host',
-                self.get_username(),
-                self.get_password())
-            self.host_session.init_log(self.logger)
-            self.host_init_flag = True
+    def init_host_session(self, vm_name):
+        """
+        Create session for each VM, session will be handled by VM instance
+        """
+        self.host_session = SSHConnection(
+            self.get_ip_address(),
+            vm_name + '_host',
+            self.get_username(),
+            self.get_password())
+        self.host_session.init_log(self.logger)
+        self.logger.info("[%s] create new session for VM" % (threading.current_thread().name))
 
     def new_session(self, suite=""):
         """
         Create new session for dut instance. Session name will be unique.
         """
-        session_name = self.NAME + '_' + str(uuid4())
+        if len(suite):
+            session_name = self.NAME + '_' + suite
+        else:
+            session_name = self.NAME + '_' + str(uuid4())
         session = self.create_session(name=session_name)
         if suite != "":
             session.logger.config_suite(suite, self.NAME)
         else:
             session.logger.config_execution(self.NAME)
-        session.send_expect("cd %s" % self.base_dir, "# ")
+
+        if getattr(self, "base_dir", None):
+            session.send_expect("cd %s" % self.base_dir, "# ")
+
         return session
 
     def close_session(self, session):
@@ -366,11 +372,11 @@ class Dut(Crb):
             return False
 
     def get_dpdk_bind_script(self):
-        op = self.send_command("ls")
+        op = self.send_expect("ls", "#")
         if "usertools" in op:
             res = 'usertools/dpdk-devbind.py'
         else:
-            op = self.send_command("ls tools")
+            op = self.send_expect("ls tools", "#")
             if "dpdk_nic_bind.py" in op:
                 res = 'tools/dpdk_nic_bind.py'
             else:
@@ -788,6 +794,14 @@ class Dut(Crb):
             self.ports_info.append({'port': port, 'pci': pci_str, 'type': pci_id, 'intf':
                                     intf, 'mac': macaddr, 'ipv6': ipv6, 'numa': -1})
 
+    def setup_virtenv(self, virttype):
+        """
+        Setup current virtualization hypervisor type and remove elder VM ssh keys
+        """
+        self.virttype = virttype
+        # remove VM ras keys from tester
+        remove_old_rsa_key(self.tester, self.crb['My IP'])
+
     def generate_sriov_vfs_by_port(self, port_id, vf_num, driver='default'):
         """
         Generate SRIOV VFs with default driver it is bound now or specifid driver.
diff --git a/framework/project_dpdk.py b/framework/project_dpdk.py
index 1f673c9..40c862a 100644
--- a/framework/project_dpdk.py
+++ b/framework/project_dpdk.py
@@ -49,8 +49,8 @@ class DPDKdut(Dut):
     build, memory and kernel module.
     """
 
-    def __init__(self, crb, serializer):
-        super(DPDKdut, self).__init__(crb, serializer)
+    def __init__(self, crb, serializer, dut_id):
+        super(DPDKdut, self).__init__(crb, serializer, dut_id)
         self.testpmd = None
 
     def set_target(self, target, bind_dev=True):
@@ -447,7 +447,7 @@ class DPDKtester(Tester):
     interface and generate port map.
     """
 
-    def __init__(self, crb, serializer):
+    def __init__(self, crb, serializer, dut_id):
         self.NAME = "tester"
         super(DPDKtester, self).__init__(crb, serializer)
 
-- 
1.9.3

  parent reply	other threads:[~2018-01-10  7:18 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 ` [dts] [PATCH v1 13/16] framework/virt_dut: support multiple VMs module Marvin Liu
2018-01-08  2:49 ` [dts] [PATCH v1 14/16] framework/qemu_kvm: " 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   ` Marvin Liu [this message]
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=1515543074-81373-5-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).