From patchwork Thu Dec 2 05:42:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Dong X-Patchwork-Id: 104819 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 2C55FA0C41; Thu, 2 Dec 2021 06:41:24 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E7EC3406FF; Thu, 2 Dec 2021 06:41:23 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id E20B840692 for ; Thu, 2 Dec 2021 06:41:22 +0100 (CET) X-IronPort-AV: E=McAfee;i="6200,9189,10185"; a="235363923" X-IronPort-AV: E=Sophos;i="5.87,281,1631602800"; d="scan'208";a="235363923" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2021 21:41:21 -0800 X-IronPort-AV: E=Sophos;i="5.87,281,1631602800"; d="scan'208";a="460317553" Received: from unknown (HELO dpdk-zhaohy-t.sh.intel.com) ([10.240.183.68]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2021 21:41:16 -0800 From: Dong JunX To: dts@dpdk.org Cc: lijuan.tu@intel.com, weix.ling@intel.com, junx.dong@intel.com Subject: [dts] [PATCH V1] framework/*: changed method of import Dot1BR Date: Thu, 2 Dec 2021 13:42:01 +0800 Message-Id: <1638423721-75428-1-git-send-email-junx.dong@intel.com> X-Mailer: git-send-email 1.8.3.1 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: Dong JunX --- framework/packet.py | 8 ++++++-- framework/utils.py | 6 ------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/framework/packet.py b/framework/packet.py index adfa985..dac3ea5 100644 --- a/framework/packet.py +++ b/framework/packet.py @@ -32,12 +32,14 @@ Generic packet create, transmit and analyze module Base on scapy(python program for packet manipulation) """ +import os +import subprocess import shutil from importlib import import_module from socket import AF_INET6 from scapy.all import * -from .utils import convert_int2ip, convert_ip2int, get_module_path +from .utils import convert_int2ip, convert_ip2int # load extension layers exec_file = os.path.realpath(__file__) @@ -49,7 +51,9 @@ if not os.path.exists(TMP_PATH): os.system('mkdir -p %s' % TMP_PATH) # copy dep/Dot1BR to scapy -_contrib_module_path = get_module_path('scapy.contrib') +_scapy_module_path = subprocess.check_output("python3 -m pip show scapy |grep Location |awk -F': ' '{print $2}'", + encoding='utf-8', stderr=subprocess.STDOUT, shell=True) +_contrib_module_path = os.path.join(_scapy_module_path.strip(), 'scapy', 'contrib') shutil.copy(DTS_PATH + '/dep/scapy_modules/Dot1BR.py', _contrib_module_path) scapy_modules_required = {'scapy.contrib.gtp': ['GTP_U_Header', 'GTPPDUSessionContainer'], diff --git a/framework/utils.py b/framework/utils.py index 269bfbb..5eefd0a 100644 --- a/framework/utils.py +++ b/framework/utils.py @@ -309,9 +309,3 @@ def check_dts_python_version(): "and will not work in future releases.")), file=sys.stderr) print(RED("Please use Python >= 3.6.9 instead"), file=sys.stderr) -def get_module_path(module_name): - from importlib import import_module - _module = import_module(module_name) - _module_file_path = _module.__file__ - del _module - return os.path.dirname(_module_file_path)