From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 741C5A0350; Tue, 30 Jun 2020 11:55:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6E7051BEE4; Tue, 30 Jun 2020 11:55:08 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id AF7711BEC0 for ; Tue, 30 Jun 2020 11:55:04 +0200 (CEST) IronPort-SDR: M123+nJ/gn7rHfIjn1KmMRJzeZzAHjnlp78/JFBZygcatKOU6DnK9fyXYNTybthyp2h1YYgKCS 8p4cx7+joXIg== X-IronPort-AV: E=McAfee;i="6000,8403,9666"; a="147742014" X-IronPort-AV: E=Sophos;i="5.75,297,1589266800"; d="scan'208";a="147742014" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2020 02:55:04 -0700 IronPort-SDR: co3vmo0RebPntagoftNJyd7Gtsq1N0rjiLFmFxEkK8i8O+YoOx3gRE/d1unwCIt6BMwIdeWYFB EWbMHV+3sbWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,297,1589266800"; d="scan'208";a="355732317" Received: from unknown (HELO xqm-virtio_tester.localdomain) ([10.240.183.52]) by orsmga001.jf.intel.com with ESMTP; 30 Jun 2020 02:55:03 -0700 From: Xiao Qimai To: dts@dpdk.org Cc: Xiao Qimai Date: Tue, 30 Jun 2020 17:46:38 +0800 Message-Id: <1593510398-51509-6-git-send-email-qimaix.xiao@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1593510398-51509-1-git-send-email-qimaix.xiao@intel.com> References: <1593510398-51509-1-git-send-email-qimaix.xiao@intel.com> Subject: [dts] [PATCH V1 5/5]framework/ssh_pexpect: add retry when connect to vm 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: , Errors-To: dts-bounces@dpdk.org Sender: "dts" Signed-off-by: Xiao Qimai --- framework/ssh_pexpect.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py index 0230207..1f839d4 100644 --- a/framework/ssh_pexpect.py +++ b/framework/ssh_pexpect.py @@ -34,15 +34,28 @@ class SSHPexpect: threads number is limited to 8 which less than 10. Lock number can be modified along with MaxStartups value. """ + retry_times = 10 try: - self.session = pxssh.pxssh(encoding='utf-8') if ':' in self.host: - self.ip = self.host.split(':')[0] - self.port = int(self.host.split(':')[1]) - self.session.login(self.ip, self.username, - self.password, original_prompt='[$#>]', - port=self.port, login_timeout=20) + while retry_times: + self.ip = self.host.split(':')[0] + self.port = int(self.host.split(':')[1]) + self.session = pxssh.pxssh(encoding='utf-8') + try: + self.session.login(self.ip, self.username, + self.password, original_prompt='[$#>]', + port=self.port, login_timeout=20) + except Exception as e: + print(e) + time.sleep(2) + retry_times -= 1 + print("retry %d times connecting..." % (10-retry_times)) + else: + break + else: + raise Exception('connect to %s:%s failed' % (self.ip, self.port)) else: + self.session = pxssh.pxssh(encoding='utf-8') self.session.login(self.host, self.username, self.password, original_prompt='[$#>]') self.send_expect('stty -echo', '#') -- 1.8.3.1