diff options
author | 2015-08-24 18:44:56 +0300 | |
---|---|---|
committer | 2015-08-24 18:44:56 +0300 | |
commit | 98bc71b1c21452c3d868c4a4d418a8aeaa5a43af (patch) | |
tree | 2e66b9a775f0a5c545caa76f62890f5a5546e231 /scripts/automation/trex_control_plane/server | |
parent | 20eb7d362f9bce1951bd61ad3f78cf8f4267d1d5 (diff) | |
parent | 36c6c87fe4380b214f8ff8a45dc0213fa109821c (diff) |
Merge branch 'master' into dan_stateless
Diffstat (limited to 'scripts/automation/trex_control_plane/server')
3 files changed, 40 insertions, 75 deletions
diff --git a/scripts/automation/trex_control_plane/server/extended_daemon_runner.py b/scripts/automation/trex_control_plane/server/extended_daemon_runner.py index a9b36e22..1813ed48 100755 --- a/scripts/automation/trex_control_plane/server/extended_daemon_runner.py +++ b/scripts/automation/trex_control_plane/server/extended_daemon_runner.py @@ -8,18 +8,17 @@ import os, sys from argparse import ArgumentParser
from trex_server import trex_parser
try:
- from python_lib.termstyle import termstyle
+ from termstyle import termstyle
except ImportError:
import termstyle
-
-def daemonize_parser (parser_obj, action_funcs, help_menu):
+def daemonize_parser(parser_obj, action_funcs, help_menu):
"""Update the regular process parser to deal with daemon process options"""
parser_obj.description += " (as a daemon process)"
parser_obj.usage = None
- parser_obj.add_argument("action", choices = action_funcs,
- action="store", help = help_menu )
+ parser_obj.add_argument("action", choices=action_funcs,
+ action="store", help=help_menu)
return
@@ -42,7 +41,7 @@ class ExtendedDaemonRunner(runner.DaemonRunner): (*) start-live : start the application in live mode (no daemon process).
"""
- def __init__ (self, app, parser_obj):
+ def __init__(self, app, parser_obj):
""" Set up the parameters of a new runner.
THIS METHOD INTENTIONALLY DO NOT INVOKE SUPER __init__() METHOD
@@ -78,8 +77,8 @@ class ExtendedDaemonRunner(runner.DaemonRunner): self.daemon_context = daemon.DaemonContext()
self.daemon_context.stdin = open(app.stdin_path, 'rt')
self.daemon_context.stdout = open(app.stdout_path, 'w+t')
- self.daemon_context.stderr = open(
- app.stderr_path, 'a+t', buffering=0)
+ self.daemon_context.stderr = open(app.stderr_path,
+ 'a+t', buffering=0)
self.pidfile = None
if app.pidfile_path is not None:
@@ -87,23 +86,22 @@ class ExtendedDaemonRunner(runner.DaemonRunner): self.daemon_context.pidfile = self.pidfile
# mask out all arguments that aren't relevant to main app script
-
- def update_action_funcs (self):
+ def update_action_funcs(self):
self.action_funcs.update({u'start-live': self._start_live, u'show': self._show}) # add key (=action), value (=desired func)
@staticmethod
- def _start_live (self):
+ def _start_live(self):
self.app.run()
@staticmethod
- def _show (self):
+ def _show(self):
if self.pidfile.is_locked():
print termstyle.red("T-Rex server daemon is running")
else:
print termstyle.red("T-Rex server daemon is NOT running")
- def do_action (self):
+ def do_action(self):
self.__prevent_duplicate_runs()
self.__prompt_init_msg()
try:
@@ -117,7 +115,7 @@ class ExtendedDaemonRunner(runner.DaemonRunner): self.do_action()
- def __prevent_duplicate_runs (self):
+ def __prevent_duplicate_runs(self):
if self.action == 'start' and self.pidfile.is_locked():
print termstyle.green("Server daemon is already running")
exit(1)
@@ -125,13 +123,13 @@ class ExtendedDaemonRunner(runner.DaemonRunner): print termstyle.green("Server daemon is not running")
exit(1)
- def __prompt_init_msg (self):
+ def __prompt_init_msg(self):
if self.action == 'start':
print termstyle.green("Starting daemon server...")
elif self.action == 'stop':
print termstyle.green("Stopping daemon server...")
- def __verify_termination (self):
+ def __verify_termination(self):
pass
# import time
# while self.pidfile.is_locked():
diff --git a/scripts/automation/trex_control_plane/server/outer_packages.py b/scripts/automation/trex_control_plane/server/outer_packages.py index ab25ea68..f07ed59a 100755 --- a/scripts/automation/trex_control_plane/server/outer_packages.py +++ b/scripts/automation/trex_control_plane/server/outer_packages.py @@ -1,66 +1,35 @@ #!/router/bin/python -import sys,site -import platform,os -import tarfile -import errno -import pwd +import sys +import site +import os CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) -ROOT_PATH = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir)) # path to trex_control_plane directory -PATH_TO_PYTHON_LIB = os.path.abspath(os.path.join(ROOT_PATH, 'python_lib')) +ROOT_PATH = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir)) # path to trex_control_plane directory +PATH_TO_PYTHON_LIB = os.path.abspath(os.path.join(ROOT_PATH, os.pardir, os.pardir, + os.pardir, 'external_libs', 'python')) SERVER_MODULES = ['enum34-1.0.4', - # 'jsonrpclib-0.1.3', - 'jsonrpclib-pelix-0.2.5', - 'zmq', - 'python-daemon-2.0.5', - 'lockfile-0.10.2', - 'termstyle' - ] + 'jsonrpclib-pelix-0.2.5', + 'zmq', + 'python-daemon-2.0.5', + 'lockfile-0.10.2', + 'termstyle' + ] -def extract_zmq_package (): - """make sure zmq package is available""" - os.chdir(PATH_TO_PYTHON_LIB) - if not os.path.exists('zmq'): - if os.path.exists('zmq_fedora.tar.gz'): # make sure tar file is available for extraction - try: - tar = tarfile.open("zmq_fedora.tar.gz") - # finally, extract the tarfile locally - tar.extractall() - except OSError as err: - if err.errno == errno.EACCES: - # fall back. try extracting using currently logged in user - stat_info = os.stat(PATH_TO_PYTHON_LIB) - uid = stat_info.st_uid - logged_user = pwd.getpwuid(uid).pw_name - if logged_user != 'root': - try: - os.system("sudo -u {user} tar -zxvf zmq_fedora.tar.gz".format(user = logged_user)) - except: - raise OSError(13, 'Permission denied: Please make sure that logged user have sudo access and writing privileges to `python_lib` directory.') - else: - raise OSError(13, 'Permission denied: Please make sure that logged user have sudo access and writing privileges to `python_lib` directory.') - finally: - tar.close() - else: - raise IOError("File 'zmq_fedora.tar.gz' couldn't be located at python_lib directory.") - os.chdir(CURRENT_PATH) - -def import_server_modules (): +def import_server_modules(): # must be in a higher priority sys.path.insert(0, PATH_TO_PYTHON_LIB) sys.path.append(ROOT_PATH) - extract_zmq_package() import_module_list(SERVER_MODULES) -def import_module_list (modules_list): + +def import_module_list(modules_list): assert(isinstance(modules_list, list)) for p in modules_list: - full_path = os.path.join(PATH_TO_PYTHON_LIB, p) - fix_path = os.path.normcase(full_path) + full_path = os.path.join(PATH_TO_PYTHON_LIB, p) + fix_path = os.path.normcase(full_path) site.addsitedir(full_path) - import_server_modules() diff --git a/scripts/automation/trex_control_plane/server/zmq_monitor_thread.py b/scripts/automation/trex_control_plane/server/zmq_monitor_thread.py index 28e154ee..7a278af8 100755 --- a/scripts/automation/trex_control_plane/server/zmq_monitor_thread.py +++ b/scripts/automation/trex_control_plane/server/zmq_monitor_thread.py @@ -13,25 +13,23 @@ from common.trex_status_e import TRexStatus CCustomLogger.setup_custom_logger('TRexServer')
logger = logging.getLogger('TRexServer')
+
class ZmqMonitorSession(threading.Thread):
def __init__(self, trexObj , zmq_port):
super(ZmqMonitorSession, self).__init__()
self.stoprequest = threading.Event()
-# self.terminateFlag = False
self.first_dump = True
self.zmq_port = zmq_port
- self.zmq_publisher = "tcp://localhost:{port}".format( port = self.zmq_port )
-# self.context = zmq.Context()
-# self.socket = self.context.socket(zmq.SUB)
+ self.zmq_publisher = "tcp://localhost:{port}".format(port=self.zmq_port)
self.trexObj = trexObj
self.expect_trex = self.trexObj.expect_trex # used to signal if T-Rex is expected to run and if data should be considered
self.decoder = JSONDecoder()
logger.info("ZMQ monitor initialization finished")
- def run (self):
+ def run(self):
self.context = zmq.Context()
self.socket = self.context.socket(zmq.SUB)
- logger.info("ZMQ monitor started listening @ {pub}".format( pub = self.zmq_publisher ) )
+ logger.info("ZMQ monitor started listening @ {pub}".format(pub=self.zmq_publisher))
self.socket.connect(self.zmq_publisher)
self.socket.setsockopt(zmq.SUBSCRIBE, '')
@@ -46,10 +44,10 @@ class ZmqMonitorSession(threading.Thread): # allow this exception since it comes from ZMQ monitor termination
pass
else:
- logger.error("ZMQ monitor thrown an exception. Received exception: {ex}".format(ex = e))
+ logger.error("ZMQ monitor thrown an exception. Received exception: {ex}".format(ex=e))
raise
- def join (self, timeout = None):
+ def join(self, timeout=None):
self.stoprequest.set()
logger.debug("Handling termination of ZMQ monitor thread")
self.socket.close()
@@ -57,15 +55,15 @@ class ZmqMonitorSession(threading.Thread): logger.info("ZMQ monitor resources has been freed.")
super(ZmqMonitorSession, self).join(timeout)
- def parse_and_update_zmq_dump (self, zmq_dump):
+ def parse_and_update_zmq_dump(self, zmq_dump):
try:
dict_obj = self.decoder.decode(zmq_dump)
except ValueError:
- logger.error("ZMQ dump failed JSON-RPC decode. Ignoring. Bad dump was: {dump}".format(dump = zmq_dump))
+ logger.error("ZMQ dump failed JSON-RPC decode. Ignoring. Bad dump was: {dump}".format(dump=zmq_dump))
dict_obj = None
# add to trex_obj zmq latest dump, based on its 'name' header
- if dict_obj is not None and dict_obj!={}:
+ if dict_obj is not None and dict_obj != {}:
self.trexObj.zmq_dump[dict_obj['name']] = dict_obj
if self.first_dump:
# change TRexStatus from starting to Running once the first ZMQ dump is obtained and parsed successfully
|