summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/server
diff options
context:
space:
mode:
authorDan Klein <danklei@cisco.com>2015-10-14 02:56:40 +0300
committerDan Klein <danklei@cisco.com>2015-10-14 02:56:40 +0300
commit508703e11a3fad3e44535c5433f803d77f28e245 (patch)
treee4efb75e7fa060ec088c9a6b9a5a931e595f1863 /scripts/automation/trex_control_plane/server
parent0951a3e74be22db8726781aae98531668d946656 (diff)
Fixed trex bugs in Ubuntu disctribution (Firing trex-daemon server) and unresolved domain name handling.
Diffstat (limited to 'scripts/automation/trex_control_plane/server')
-rwxr-xr-xscripts/automation/trex_control_plane/server/outer_packages.py3
-rwxr-xr-xscripts/automation/trex_control_plane/server/trex_server.py28
2 files changed, 21 insertions, 10 deletions
diff --git a/scripts/automation/trex_control_plane/server/outer_packages.py b/scripts/automation/trex_control_plane/server/outer_packages.py
index 976e478d..2234c734 100755
--- a/scripts/automation/trex_control_plane/server/outer_packages.py
+++ b/scripts/automation/trex_control_plane/server/outer_packages.py
@@ -1,7 +1,6 @@
#!/router/bin/python
import sys
-import site
import os
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
@@ -29,6 +28,6 @@ def import_module_list(modules_list):
for p in modules_list:
full_path = os.path.join(PATH_TO_PYTHON_LIB, p)
fix_path = os.path.normcase(full_path)
- site.addsitedir(full_path)
+ sys.path.insert(1, full_path)
import_server_modules()
diff --git a/scripts/automation/trex_control_plane/server/trex_server.py b/scripts/automation/trex_control_plane/server/trex_server.py
index fd39b9c4..e48f8963 100755
--- a/scripts/automation/trex_control_plane/server/trex_server.py
+++ b/scripts/automation/trex_control_plane/server/trex_server.py
@@ -19,7 +19,6 @@ from common.trex_status_e import TRexStatus
from common.trex_exceptions import *
import subprocess
from random import randrange
-#import shlex
import logging
import threading
import CCustomLogger
@@ -39,7 +38,7 @@ class CTRexServer(object):
TREX_START_CMD = './t-rex-64'
DEFAULT_FILE_PATH = '/tmp/trex_files/'
- def __init__(self, trex_path, trex_files_path, trex_host = socket.gethostname(), trex_daemon_port = 8090, trex_zmq_port = 4500):
+ def __init__(self, trex_path, trex_files_path, trex_host='0.0.0.0', trex_daemon_port=8090, trex_zmq_port=4500):
"""
Parameters
----------
@@ -92,8 +91,8 @@ class CTRexServer(object):
def start(self):
"""This method fires up the daemon server based on initialized parameters of the class"""
- # initialize the server instance with given reasources
- try:
+ # initialize the server instance with given resources
+ try:
print "Firing up TRex REST daemon @ port {trex_port} ...\n".format( trex_port = self.trex_daemon_port )
logger.info("Firing up TRex REST daemon @ port {trex_port} ...".format( trex_port = self.trex_daemon_port ))
logger.info("current working dir is: {0}".format(self.TREX_PATH) )
@@ -104,7 +103,15 @@ class CTRexServer(object):
if e.errno == errno.EADDRINUSE:
logger.error("TRex server requested address already in use. Aborting server launching.")
print "TRex server requested address already in use. Aborting server launching."
- raise socket.error(errno.EADDRINUSE, "TRex daemon requested address already in use. Server launch aborted. Please make sure no other process is using the desired server properties.")
+ raise socket.error(errno.EADDRINUSE, "TRex daemon requested address already in use. "
+ "Server launch aborted. Please make sure no other process is "
+ "using the desired server properties.")
+ elif isinstance(e, socket.gaierror) and e.errno == -3:
+ # handling Temporary failure in name resolution exception
+ raise socket.gaierror(-3, "Temporary failure in name resolution.\n"
+ "Make sure provided hostname has DNS resolving.")
+ else:
+ raise
# set further functionality and peripherals to server instance
try:
@@ -129,7 +136,7 @@ class CTRexServer(object):
except KeyboardInterrupt:
logger.info("Daemon shutdown request detected." )
finally:
- self.zmq_monitor.join() # close ZMQ monitor thread reasources
+ self.zmq_monitor.join() # close ZMQ monitor thread resources
self.server.shutdown()
pass
@@ -448,6 +455,10 @@ trex_daemon_server [options]
parser.add_argument("-f", "--files-path", dest="files_path",
action="store", help="Specify a path to directory on which pushed files will be saved at.\nDefault path is: {def_path}.".format( def_path = default_files_path ),
metavar="PATH", default = default_files_path )
+ parser.add_argument("--trex-host", dest="trex_host",
+ action="store", help="Specify a hostname to be registered as the TRex server.\n"
+ "Default is to bind all IPs using '0.0.0.0'.",
+ metavar="HOST", default = '0.0.0.0')
return parser
trex_parser = generate_trex_parser()
@@ -455,8 +466,9 @@ trex_parser = generate_trex_parser()
def do_main_program ():
args = trex_parser.parse_args()
-
- server = CTRexServer(trex_daemon_port = args.daemon_port, trex_zmq_port = args.zmq_port, trex_path = args.trex_path, trex_files_path = args.files_path)
+ server = CTRexServer(trex_path = args.trex_path, trex_files_path = args.files_path,
+ trex_host = args.trex_host, trex_daemon_port = args.daemon_port,
+ trex_zmq_port = args.zmq_port)
server.start()