From a8f9eb480739776d2b41303ee70707973db392c1 Mon Sep 17 00:00:00 2001 From: Doron Cohen Date: Mon, 28 Oct 2019 17:34:55 +0200 Subject: [PATCH 1/3] agent: remove weka related code / comments --- talker_agent/talker.py | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/talker_agent/talker.py b/talker_agent/talker.py index 189376b..1c7f5f5 100644 --- a/talker_agent/talker.py +++ b/talker_agent/talker.py @@ -1,23 +1,5 @@ #!/usr/local/bin/python3 - -""" -Talker Agent (Server-Side) -========================== - -* Important: - - keep this free of dependencies (there's only a redis dependency) - - keep this compatible with python2.6+ (no dict comprehension) - -* Packaging: - - update the 'TALKER' version in version_info - - ./teka pack talker - -* Testing: - - See ./wepy/devops/talker.py (client-side) - -""" - import fcntl import json import logging @@ -313,13 +295,7 @@ def start(self): self.job_fn = "%s/job.%s.%s" % (JOBS_DIR, self.job_id, self.popen.pid) with open(self.job_fn, "w") as f: - try: - f.write(repr(self.cmd)) - except IOError: - # to help with WEKAPP-74054 - os.system("df") - os.system("df -i") - raise + f.write(repr(self.cmd)) self.agent.current_processes[self.job_id] = self for channel in self.channels: @@ -940,10 +916,6 @@ def main(*args): config = Config() set_logging_to_file(config.parser.get('logging', 'logpath')) - # to help with WEKAPP-74054 - os.system("df") - os.system("df -i") - open("/var/run/talker.pid", "w").write(str(os.getpid())) atexit.register(os.unlink, "/var/run/talker.pid") From a455c840b745abe5a5cc2591fcbd2c87ac48547d Mon Sep 17 00:00:00 2001 From: Doron Cohen Date: Mon, 28 Oct 2019 17:36:52 +0200 Subject: [PATCH 2/3] agent: remove old ut code --- talker_agent/talker.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/talker_agent/talker.py b/talker_agent/talker.py index 1c7f5f5..df05625 100644 --- a/talker_agent/talker.py +++ b/talker_agent/talker.py @@ -25,6 +25,8 @@ except: # python 2.7 from ConfigParser import ConfigParser +import redis + PY3 = sys.version_info[0] == 3 @@ -817,7 +819,6 @@ def setup(self): health_check_interval = config.parser.getfloat('redis', 'health_check_interval') logger.info("Connecting to redis %s:%s", host, port) - import redis # deferring so that importing talker (for ut) doesn't immediately fail if package not available self.redis = redis.StrictRedis( host=host, port=port, db=0, password=password, socket_timeout=socket_timeout, socket_connect_timeout=socket_connect_timeout, @@ -947,7 +948,4 @@ def main(*args): if __name__ == '__main__': args = sys.argv[1:] - if "--ut" in args: - print("Talker don't need no UT") - else: - sys.exit(main(*args)) + sys.exit(main(*args)) From 06cff98296557ee08d20977665fa5b3aed769bdb Mon Sep 17 00:00:00 2001 From: Doron Cohen Date: Mon, 28 Oct 2019 17:39:22 +0200 Subject: [PATCH 3/3] agent: remove some python 2 compat code --- talker_agent/talker.py | 45 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/talker_agent/talker.py b/talker_agent/talker.py index df05625..24dfc57 100644 --- a/talker_agent/talker.py +++ b/talker_agent/talker.py @@ -16,50 +16,21 @@ import glob import atexit import random -from textwrap import dedent from contextlib import contextmanager from logging import getLogger from logging.handlers import RotatingFileHandler -try: - from configparser import ConfigParser -except: # python 2.7 - from ConfigParser import ConfigParser +from configparser import ConfigParser import redis -PY3 = sys.version_info[0] == 3 - -# =========================================================================================== -# Define a python2/3 compatible 'reraise' function for re-raising exceptions properly -# Since the syntax is different and would not compile between versions, we need to using 'exec' - -if PY3: - def reraise(tp, value, tb=None): - if value is None: - value = tp() - if value.__traceback__ is not tb: - raise value.with_traceback(tb) - raise value -else: - def exec_(_code_, _globs_=None, _locs_=None): - """Execute code in a namespace.""" - if _globs_ is None: - frame = sys._getframe(1) - _globs_ = frame.f_globals - if _locs_ is None: - _locs_ = frame.f_locals - del frame - elif _locs_ is None: - _locs_ = _globs_ - exec("""exec _code_ in _globs_, _locs_""") - - exec_(dedent(""" - def reraise(tp, value, tb=None): - raise tp, value, tb - """)) - -# =========================================================================================== +def reraise(tp, value, tb=None): + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + CONFIG_FILENAME = '/root/talker/config.ini' REBOOT_FILENAME = '/root/talker/reboot.id'