From patchwork Mon Jan 17 10:08:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Dong X-Patchwork-Id: 105917 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 3D8AEA034C; Mon, 17 Jan 2022 11:08:33 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0E22F4118A; Mon, 17 Jan 2022 11:08:33 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 71DAC4067B for ; Mon, 17 Jan 2022 11:08:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642414111; x=1673950111; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=CVG3GOdtAykgItr/TIeTbHY8FiGTlNrri8DbGblbwaA=; b=aoB5IHbbo3HyclmG7+f1d6u9ukXz2DmVBXkXbxiYvxvtceAWqdB5DuL6 7+9vLQp7t/cvhGvJPC3bfn1T2mIeIGZ+n5ci0aitOJQLBL+kB1mVMKqGz 2xjKN2/G1/3xVJyevt9DotVEUnCHXNePhleTjhqI8tZTsdjIT4YJen+oi BMDUCJDFgws0/FVrNwf1MFpOI/rXcldv6kS2IMQfMCwHu3NltkQBs9vAm MfhfvEJYVJVkhAEEiRLwceXrXQ3aEIaihYs4vw9gtAHq/n4eKoYEm1ocl 5JkXLqE8eE+gf+IZ3+bao8LxEpOyah1oa/f2CvDsXwjnx9V41gBx6DOhT A==; X-IronPort-AV: E=McAfee;i="6200,9189,10229"; a="244553227" X-IronPort-AV: E=Sophos;i="5.88,295,1635231600"; d="scan'208";a="244553227" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 02:08:30 -0800 X-IronPort-AV: E=Sophos;i="5.88,295,1635231600"; d="scan'208";a="578001040" Received: from shwdenpg197.ccr.corp.intel.com ([10.253.109.35]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 02:08:28 -0800 From: DongJunX To: dts@dpdk.org Cc: lijuan.tu@intel.com, qingx.sun@intel.com, junx.dong@intel.com Subject: [V1] framework/crb: Add functions of check and wait link status up Date: Mon, 17 Jan 2022 18:08:23 +0800 Message-Id: <20220117100823.4747-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 --- framework/crb.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/framework/crb.py b/framework/crb.py index bd4f565d..c97b01ce 100755 --- a/framework/crb.py +++ b/framework/crb.py @@ -907,3 +907,21 @@ 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 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'