From patchwork Tue Jan 25 07:08:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Dong X-Patchwork-Id: 106471 Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5A564A04A9; Tue, 25 Jan 2022 08:08:32 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 32EAA4282D; Tue, 25 Jan 2022 08:08:32 +0100 (CET) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mails.dpdk.org (Postfix) with ESMTP id 040E14013F for ; Tue, 25 Jan 2022 08:08:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643094510; x=1674630510; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=xMhRfM1hW93pFAI++z02sdiWpRxr557AUiJIW+QE4ms=; b=MYrBWmNbiJnPun6FFGEn94PuAU0lVz8eVW8ApsOwO+Gx3EGDr49e8S1V Ia4gCeLgeYruFSKIwEiezFbcE3YDVH0LYytwljN5LnxW0VL2+GelwzXoM uPHuR68NuI9rK39jmMtmcaSU2vZSOUlvgz9pz3QwBf7bg0UDYeXPGOZXX WIm4vNFFyxOlOboX0G9nnPdEs5lgfRzra21JrRU+HUGdaPzQhhTFQpft+ iROX46nRGKB4xmn+1ts8lCMwRp1rZohj/vqjoNreYgEwf6VoQxv+ysPZE WCr9gyuy708BhI9A9jrspqOm7O9+DVjSAgPuSmywFWZsps0iXCog/vTvY g==; X-IronPort-AV: E=McAfee;i="6200,9189,10237"; a="229812955" X-IronPort-AV: E=Sophos;i="5.88,314,1635231600"; d="scan'208";a="229812955" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 23:08:28 -0800 X-IronPort-AV: E=Sophos;i="5.88,314,1635231600"; d="scan'208";a="617519050" Received: from shwdenpg197.ccr.corp.intel.com ([10.253.109.35]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2022 23:08:18 -0800 From: DongJunX To: dts@dpdk.org Cc: lijuan.tu@intel.com, qingx.sun@intel.com, junx.dong@intel.com Subject: [DTS][V2] framework/crb: Add functions of check and wait specified link status Date: Tue, 25 Jan 2022 15:08:09 +0800 Message-Id: <20220125070809.1810-1-junx.dong@intel.com> X-Mailer: git-send-email 2.33.1.windows.1 MIME-Version: 1.0 X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.29 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 Signed-off-by: DongJunX Tested-by: Yu Jiang --- framework/crb.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/framework/crb.py b/framework/crb.py index bd4f565d..7875510f 100755 --- a/framework/crb.py +++ b/framework/crb.py @@ -907,3 +907,33 @@ class Crb(object): else: self.logger.info("NIC %s may be not find %s" % (intf, flag)) return False + + def is_interface_up(self, intf, timeout=15): + """ + check and wait port link status up until timeout + """ + for i in range(timeout): + link_status = self.get_interface_link_status(intf) + if link_status == 'Up': + return True + time.sleep(1) + self.logger.error(f"check and wait {intf} link up timeout") + return False + + def is_interface_down(self, intf, timeout=15): + """ + check and wait port link status down until timeout + """ + for i in range(timeout): + link_status = self.get_interface_link_status(intf) + if link_status == 'Down': + return True + time.sleep(1) + self.logger.error(f"check and wait {intf} link down timeout") + return False + + def get_interface_link_status(self, intf): + out = self.send_expect(f"ethtool {intf}", "#") + link_status_matcher = r'Link detected: (\w+)' + link_status = re.search(link_status_matcher, out).groups()[0] + return 'Up' if link_status == 'yes' else 'Down'