test suite reviews and discussions
 help / color / mirror / Atom feed
* [dts] [PATCH V2] framework/*: add dependent module Dot1BR of scapy
@ 2021-11-05  8:26 Dong, JunX
  2021-11-05 14:35 ` Tu, Lijuan
  0 siblings, 1 reply; 2+ messages in thread
From: Dong, JunX @ 2021-11-05  8:26 UTC (permalink / raw)
  To: dts; +Cc: PingX.Yu, weix.ling, junx.dong

Signed-off-by: Dong, JunX <junx.dong@intel.com>
---
 framework/packet.py | 11 ++++++-----
 framework/tester.py | 26 ++++++++++++++------------
 framework/utils.py  |  7 +++++++
 3 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/framework/packet.py b/framework/packet.py
index 633dd36..adfa985 100644
--- a/framework/packet.py
+++ b/framework/packet.py
@@ -32,11 +32,12 @@
 Generic packet create, transmit and analyze module
 Base on scapy(python program for packet manipulation)
 """
+import shutil
 
 from importlib import import_module
 from socket import AF_INET6
 from scapy.all import *
-from .utils import convert_int2ip, convert_ip2int
+from .utils import convert_int2ip, convert_ip2int, get_module_path
 
 # load extension layers
 exec_file = os.path.realpath(__file__)
@@ -47,12 +48,13 @@ TMP_PATH = DTS_PATH[:-1] + '/output/tmp/pcap/' if exec_file.endswith('.pyc') els
 if not os.path.exists(TMP_PATH):
     os.system('mkdir -p %s' % TMP_PATH)
 
-# add /tmp/dep to sys.path
-sys.path.append('/tmp/dep')
+# copy dep/Dot1BR to scapy
+_contrib_module_path = get_module_path('scapy.contrib')
+shutil.copy(DTS_PATH + '/dep/scapy_modules/Dot1BR.py', _contrib_module_path)
 
 scapy_modules_required = {'scapy.contrib.gtp': ['GTP_U_Header', 'GTPPDUSessionContainer'],
                           'scapy.contrib.lldp': ['LLDPDU', 'LLDPDUManagementAddress'],
-                          'Dot1BR': ['Dot1BR'],
+                          'scapy.contrib.Dot1BR': ['Dot1BR'],
                           'scapy.contrib.pfcp': ['PFCP'],
                           'scapy.contrib.nsh': ['NSH'],
                           'scapy.contrib.igmp': ['IGMP'],
@@ -73,7 +75,6 @@ def get_scapy_module_impcmd():
         cmd_li.append(f'from {m} import {",".join(scapy_modules_required[m])}')
     return ';'.join(cmd_li)
 
-SCAPY_IMP_CMD = get_scapy_module_impcmd()
 
 # packet generator type should be configured later
 PACKETGEN = "scapy"
diff --git a/framework/tester.py b/framework/tester.py
index 9dba4e4..9b764e8 100644
--- a/framework/tester.py
+++ b/framework/tester.py
@@ -46,9 +46,9 @@ from .config import PktgenConf
 from .crb import Crb
 from .exception import ParameterInvalidException
 from .packet import (
-    SCAPY_IMP_CMD,
-    Packet,
     compare_pktload,
+    get_scapy_module_impcmd,
+    Packet,
     start_tcpdump,
     stop_and_load_tcpdump_packets,
     strip_pktload,
@@ -92,7 +92,6 @@ class Tester(Crb):
         self.bgItf = ''
         self.re_run_time = 0
         self.pktgen = None
-        self.tmp_scapy_module_dir = '/tmp/dep'
         # prepare for scapy env
         self.scapy_sessions_li = list()
         self.scapy_session = self.prepare_scapy_env()
@@ -109,17 +108,20 @@ class Tester(Crb):
         session.send_expect('scapy', '>>> ')
         file_dir = os.path.dirname(__file__).split(os.path.sep)
         lib_path = os.path.sep.join(file_dir[:-1]) + '/dep/scapy_modules/'
-        exists_flag = self.alt_session.session.send_expect(f'ls {self.tmp_scapy_module_dir}', '# ', verify=True)
-        if exists_flag == 2:
-            self.alt_session.session.send_expect(f'mkdir -p {self.tmp_scapy_module_dir}', '# ', verify=True)
-        scapy_modules_path = [lib_path+i for i in os.listdir(lib_path) if i.endswith('.py')]
-        path = ' '.join(scapy_modules_path)
-        session.copy_file_to(src=path, dst=self.tmp_scapy_module_dir)
-        session.session.send_expect(f"sys.path.append('{self.tmp_scapy_module_dir}')", ">>> ")
-
-        out = session.session.send_expect(SCAPY_IMP_CMD, '>>> ')
+
+        # get contrib module path on tester
+        scapy_module_path = session.session.send_expect("os.path.dirname(sys.modules['scapy'].__file__)", '>>>')
+        contrib_module_path = scapy_module_path.replace("'", "") + '/contrib'
+
+        # copy scapy module to tester
+        scapy_dep_module_path = lib_path + 'Dot1BR.py'
+        session.copy_file_to(src=scapy_dep_module_path, dst=contrib_module_path)
+
+        # import scapy moudle to scapy APP
+        out = session.session.send_expect(get_scapy_module_impcmd(), '>>> ')
         if 'ImportError' in out:
             session.logger.warning(f'entering import error: {out}')
+
         return session
 
     def check_scapy_version(self):
diff --git a/framework/utils.py b/framework/utils.py
index 7075919..269bfbb 100644
--- a/framework/utils.py
+++ b/framework/utils.py
@@ -308,3 +308,10 @@ def check_dts_python_version():
              "it is deprecated for use in DTS, "
              "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)
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dts] [PATCH V2] framework/*: add dependent module Dot1BR of scapy
  2021-11-05  8:26 [dts] [PATCH V2] framework/*: add dependent module Dot1BR of scapy Dong, JunX
@ 2021-11-05 14:35 ` Tu, Lijuan
  0 siblings, 0 replies; 2+ messages in thread
From: Tu, Lijuan @ 2021-11-05 14:35 UTC (permalink / raw)
  To: Dong, JunX, dts; +Cc: Yu, PingX, Ling, WeiX, Dong, JunX

> -----Original Message-----
> From: dts <dts-bounces@dpdk.org> On Behalf Of Dong, JunX
> Sent: 2021年11月5日 16:26
> To: dts@dpdk.org
> Cc: Yu, PingX <pingx.yu@intel.com>; Ling, WeiX <weix.ling@intel.com>; Dong,
> JunX <junx.dong@intel.com>
> Subject: [dts] [PATCH V2] framework/*: add dependent module Dot1BR of scapy
> 
> Signed-off-by: Dong, JunX <junx.dong@intel.com>

Applied

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-05 14:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05  8:26 [dts] [PATCH V2] framework/*: add dependent module Dot1BR of scapy Dong, JunX
2021-11-05 14:35 ` Tu, Lijuan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).