From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 5E451301 for ; Fri, 5 Aug 2016 05:20:09 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP; 04 Aug 2016 20:20:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,472,1464678000"; d="scan'208";a="1035455654" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga002.fm.intel.com with ESMTP; 04 Aug 2016 20:20:07 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id u753K5BV014968; Fri, 5 Aug 2016 11:20:05 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id u753K3dh018282; Fri, 5 Aug 2016 11:20:05 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id u753K3VB018278; Fri, 5 Aug 2016 11:20:03 +0800 From: Marvin Liu To: dts@dpdk.org Cc: Marvin Liu Date: Fri, 5 Aug 2016 11:20:02 +0800 Message-Id: <1470367202-18244-1-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dts] [PATCH] framework: support reconnect session when unavailable 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: Fri, 05 Aug 2016 03:20:09 -0000 Suite will check session status before running any case. When found session is not available for useage, will create new one for replace. Signed-off-by: Marvin Liu diff --git a/framework/crb.py b/framework/crb.py index 44ddc42..bc8b24a 100644 --- a/framework/crb.py +++ b/framework/crb.py @@ -57,6 +57,7 @@ class Crb(object): self.ports_info = None self.sessions = [] self.stage = 'pre-init' + self.name = name self.logger = getLogger(name) self.session = SSHConnection(self.get_ip_address(), name, @@ -88,7 +89,7 @@ class Crb(object): """ logger = getLogger(name) session = SSHConnection(self.get_ip_address(), name, - self.get_password()) + self.get_password()) session.init_log(logger) self.sessions.append(session) return session @@ -104,6 +105,31 @@ class Crb(object): logger.logger_exit() self.sessions.remove(save_session) + def reconnect_session(self, alt_session=False): + """ + When session can't used anymore, recreate another one for replace + """ + try: + if alt_session: + self.alt_session.close(force=True) + else: + self.session.close(force=True) + except Exception as e: + self.loggger.error("Session close failed for [%s]" % e) + + if alt_session: + session = SSHConnection( + self.get_ip_address(), + self.name + '_alt', + self.get_password()) + self.alt_session = session + else: + session = SSHConnection(self.get_ip_address(), self.name, + self.get_password()) + self.session = session + + session.init_log(self.logger) + def send_command(self, cmds, timeout=TIMEOUT, alt_session=False): """ Send commands to crb and return string before timeout. @@ -166,10 +192,9 @@ class Crb(object): if numa == -1: self.send_expect('echo %d > /sys/kernel/mm/hugepages/hugepages-%skB/nr_hugepages' % (huge_pages, page_size), '# ', 5) else: - #sometimes we set hugepage on kernel cmdline, so we need clear default hugepage + # sometimes we set hugepage on kernel cmdline, so we need clear default hugepage self.send_expect('echo 0 > /sys/kernel/mm/hugepages/hugepages-%skB/nr_hugepages' % (page_size), '# ', 5) - - #some platform not support numa, example vm dut + # some platform not support numa, example vm dut try: self.send_expect('echo %d > /sys/devices/system/node/node%d/hugepages/hugepages-%skB/nr_hugepages' % (huge_pages, numa, page_size), '# ', 5) except: @@ -687,7 +712,7 @@ class Crb(object): for port_info in self.ports_info: if port_info['pci'] == pci: return port_info - - def enable_promisc(self,intf): - if intf !='N/A': - self.send_expect("ifconfig %s promisc" %intf, "# ",alt_session=True) + + def enable_promisc(self, intf): + if intf != 'N/A': + self.send_expect("ifconfig %s promisc" % intf, "# ", alt_session=True) diff --git a/framework/test_case.py b/framework/test_case.py index 7ace75c..85fdb70 100644 --- a/framework/test_case.py +++ b/framework/test_case.py @@ -54,13 +54,6 @@ class TestCase(object): self.tester = tester self.target = target - # make sure session workable - for dutobj in duts: - self.verify(dutobj.session.check_available(), "DUT session can't work") - self.verify(dutobj.alt_session.check_available(), "DUT alt_session can't work") - self.verify(tester.session.check_available(), "Tester session can't work!!!") - self.verify(tester.alt_session.check_available(), "Tester alt_session can't work!!!") - # get log handler class_name = self.__class__.__name__ self.logger = getLogger(class_name) @@ -68,6 +61,11 @@ class TestCase(object): # local variable self._requested_tests = None + # check session and reconnect if possible + for dutobj in self.duts: + self._check_and_reconnect(crb=dutobj) + self._check_and_reconnect(crb=self.tester) + # covert netdevice to codename self.nics = [] for portid in range(len(self.dut.ports_info)): @@ -114,6 +112,23 @@ class TestCase(object): # create rst format report for this suite self._rst_obj = RstReport('rst_report', target, self.nic, self.suite_name, self._enable_perf) + def _check_and_reconnect(self, crb=None): + try: + result = crb.session.check_available() + except: + result = False + + if result is False: + crb.reconnect_session() + + try: + result = crb.alt_session.check_available() + except: + result = False + + if result is False: + crb.reconnect_session(alt_session=True) + def set_up_all(self): pass -- 1.9.3