summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/client/trex_stateless_client.py
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-02-01 17:16:38 +0200
committerHanoh Haim <hhaim@cisco.com>2016-02-01 17:16:38 +0200
commit37ea6af93798ef5e2a877b755ff6dc6cb2cde33a (patch)
tree038bd751a2b5904125769b5192101aa49ef728a7 /scripts/automation/trex_control_plane/client/trex_stateless_client.py
parent00d74df1d05ce2b47d37574fda8806d71841d3e9 (diff)
parent11bcf4ca8fed5259e321c535bf90d0442e9b9746 (diff)
Merge from origin
Diffstat (limited to 'scripts/automation/trex_control_plane/client/trex_stateless_client.py')
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_stateless_client.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
index 4a2cc436..506decfe 100755
--- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
@@ -25,6 +25,7 @@ from trex_port import Port
from common.trex_types import *
from common.trex_stl_exceptions import *
from trex_async_client import CTRexAsyncClient
+from yaml import YAMLError
############################ logger #############################
@@ -436,9 +437,6 @@ class STLClient(object):
self.stats_generator = trex_stats.CTRexInfoGenerator(self.global_stats,
self.ports)
- # stream DB
- self.streams_db = CStreamsDB()
-
############# private functions - used by the class itself ###########
@@ -932,6 +930,8 @@ class STLClient(object):
# by default use all ports
if ports == None:
ports = self.get_all_ports()
+ else:
+ ports = self.__ports(ports)
# verify valid port id list
rc = self._validate_port_list(ports)
@@ -1299,17 +1299,28 @@ class STLClient(object):
if not rc:
raise STLArgumentError('ports', ports, valid_values = self.get_all_ports())
- # load the YAML
+
+ streams = None
+
+ # try YAML
try:
- streams_pack = self.streams_db.load_yaml_file(filename)
- except Exception as e:
- raise STLError(str(e))
+ streams_db = CStreamsDB()
+ stream_list = streams_db.load_yaml_file(filename)
- # HACK - convert the stream pack to simple streams
- streams = []
- for stream in streams_pack.compiled:
- s = HACKSTLStream(stream)
- streams.append(s)
+ # convert to new style stream object
+ streams = [HACKSTLStream(stream) for stream in stream_list.compiled]
+ except YAMLError:
+ # try python
+ try:
+ basedir = os.path.dirname(filename)
+ sys.path.append(basedir)
+ file = os.path.basename(filename).split('.')[0]
+ module = __import__(file, globals(), locals(), [], -1)
+
+ streams = module.register().get_streams()
+
+ except (AttributeError, ImportError):
+ raise STLError("bad format input file '{0}'".format(filename))
self.add_streams(streams, ports)
@@ -1632,6 +1643,8 @@ class STLClient(object):
# by default use all ports
if ports == None:
ports = self.get_all_ports()
+ else:
+ ports = self.__ports(ports)
# verify valid port id list
rc = self._validate_port_list(ports)