[V1] framework/*: changed method of import Dot1BR

Message ID 1638423721-75428-1-git-send-email-junx.dong@intel.com (mailing list archive)
State Superseded
Headers
Series [V1] framework/*: changed method of import Dot1BR |

Checks

Context Check Description
ci/Intel-dts-suite-test fail Testing issues

Commit Message

Jun Dong Dec. 2, 2021, 5:42 a.m. UTC
  Signed-off-by: Dong JunX <junx.dong@intel.com>
---
 framework/packet.py | 8 ++++++--
 framework/utils.py  | 6 ------
 2 files changed, 6 insertions(+), 8 deletions(-)
  

Patch

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)