From 508703e11a3fad3e44535c5433f803d77f28e245 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Wed, 14 Oct 2015 02:56:40 +0300 Subject: Fixed trex bugs in Ubuntu disctribution (Firing trex-daemon server) and unresolved domain name handling. --- .../trex_control_plane/client/outer_packages.py | 3 +-- .../client_utils/external_packages.py | 3 +-- .../trex_control_plane/server/outer_packages.py | 3 +-- .../trex_control_plane/server/trex_server.py | 28 +++++++++++++++------- 4 files changed, 23 insertions(+), 14 deletions(-) (limited to 'scripts') diff --git a/scripts/automation/trex_control_plane/client/outer_packages.py b/scripts/automation/trex_control_plane/client/outer_packages.py index 5facad20..206d4b4c 100755 --- a/scripts/automation/trex_control_plane/client/outer_packages.py +++ b/scripts/automation/trex_control_plane/client/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__)) @@ -25,6 +24,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) # (CURRENT_PATH+p) - site.addsitedir(full_path) + sys.path.insert(1, full_path) import_client_modules() diff --git a/scripts/automation/trex_control_plane/client_utils/external_packages.py b/scripts/automation/trex_control_plane/client_utils/external_packages.py index f8de0323..4b10609b 100755 --- a/scripts/automation/trex_control_plane/client_utils/external_packages.py +++ b/scripts/automation/trex_control_plane/client_utils/external_packages.py @@ -1,7 +1,6 @@ #!/router/bin/python import sys -import site import os CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) @@ -24,7 +23,7 @@ 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_client_utils_modules() 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() -- cgit 1.2.3-korg