summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/server/trex_server.py
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2017-02-05 10:03:25 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2017-02-05 10:03:25 +0200
commit78c0502f5935ae575d0d89d201c1de83afd05fae (patch)
tree9dc22c0e0800ea8401389b20805eff11db8f81cf /scripts/automation/trex_control_plane/server/trex_server.py
parent9808fce2b0b3b5b7c9b28303e99486501a1cc10d (diff)
trex_daemon_server: check ZMQ port matches between the server and TRex platform config file.
Change-Id: I1a6d6dc45513e4ba5f7c50f11f4730c8996c7731 Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/server/trex_server.py')
-rwxr-xr-xscripts/automation/trex_control_plane/server/trex_server.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/server/trex_server.py b/scripts/automation/trex_control_plane/server/trex_server.py
index 2b718a69..8abd8838 100755
--- a/scripts/automation/trex_control_plane/server/trex_server.py
+++ b/scripts/automation/trex_control_plane/server/trex_server.py
@@ -7,6 +7,7 @@ import sys
import time
import outer_packages
import zmq
+import yaml
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
import jsonrpclib
from jsonrpclib import Fault
@@ -471,6 +472,8 @@ class CTRexServer(object):
if trex_args:
trex_cmd_options += ' %s' % trex_args
+ self._check_zmq_port(trex_cmd_options)
+
if not stateless:
if 'f' not in kwargs:
raise Exception('Argument -f should be specified in stateful command')
@@ -489,6 +492,28 @@ class CTRexServer(object):
return (cmd, export_path, kwargs.get('d', 0))
+ def _check_zmq_port(self, trex_cmd_options):
+ zmq_cfg_port = 4500 # default
+ parser = ArgumentParser()
+ parser.add_argument('--cfg', default = '/etc/trex_cfg.yaml')
+ args, _ = parser.parse_known_args(shlex.split(trex_cmd_options))
+ if not os.path.exists(args.cfg):
+ raise Exception('Platform config file "%s" does not exist!' % args.cfg)
+ with open(args.cfg) as f:
+ trex_cfg = yaml.safe_load(f.read())
+ if type(trex_cfg) is not list:
+ raise Exception('Platform config file "%s" content should be array.' % args.cfg)
+ if not len(trex_cfg):
+ raise Exception('Platform config file "%s" content should be array with one element.' % args.cfg)
+ trex_cfg = trex_cfg[0]
+ if 'enable_zmq_pub' in trex_cfg and trex_cfg['enable_zmq_pub'] == False:
+ raise Exception('TRex daemon expects ZMQ publisher to be enabled. Please change "enable_zmq_pub" to true.')
+ if 'zmq_pub_port' in trex_cfg:
+ zmq_cfg_port = trex_cfg['zmq_pub_port']
+ if zmq_cfg_port != self.trex_zmq_port:
+ raise Exception('ZMQ port does not match: platform config file is configured to: %s, daemon server to: %s' % (zmq_cfg_port, self.trex_zmq_port))
+
+
def __check_trex_path_validity(self):
# check for executable existance
if not os.path.exists(self.TREX_PATH+'/t-rex-64'):