From fd1717baee8d4047e8175853184cc40c65eb714e Mon Sep 17 00:00:00 2001 From: Andrei Grosu Date: Wed, 7 Jul 2021 07:25:17 +0000 Subject: [PATCH] Fix python3 issue in patch-alarm-manager. Wrap DaemonRunner class from 3rd party python-daemon library which is not compatible with python3. The solution was lifted from: https://review.opendev.org/c/starlingx/utilities/+/786837 as it was the acceptable way to work around python-daemon limitations. Patching python-daemon was not accepted as per: https://review.opendev.org/c/starlingx/integ/+/785523 Story: 2008454 Task: 42789 Depends-On: I3c68322603eaaf9a78d101b5b1198e9582497105 Signed-off-by: Andrei Grosu Change-Id: I66b2ac6825b78228a40869a3721e6853f2bbe83f --- .../patch_alarm/patch_alarm_manager.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py b/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py index 356553ca..1cab2455 100644 --- a/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py +++ b/patch-alarm/patch-alarm/patch_alarm/patch_alarm_manager.py @@ -28,13 +28,27 @@ LOG_FILE = '/var/log/patch-alarms.log' PID_FILE = '/var/run/patch-alarm-manager.pid' +class DaemonRunnerWrapper(runner.DaemonRunner): + # Workaround: fix the "unbuffered bytes I/O for py3" runtime + # error in pyhon3 env. + # Picked from [starlingx/utilities]:utilities/logmgmt/logmgmt/logmgmt/logmgmt.py + # If there will be a saner approach, it must be changed also in utilities repo. + def _open_streams_from_app_stream_paths(self, app): + self.daemon_context.stdin = open(app.stdin_path, 'rt') + self.daemon_context.stdout = open(app.stdout_path, 'w+t') + try: + self.daemon_context.stderr = open(app.stderr_path, 'w+t', buffering=0) + except Exception: + self.daemon_context.stderr = open(app.stderr_path, 'wb+', buffering=0) + + ################### # METHODS ################### def start_polling(): cfg.read_config() patch_alarm_daemon = PatchAlarmDaemon() - alarm_runner = runner.DaemonRunner(patch_alarm_daemon) + alarm_runner = DaemonRunnerWrapper(patch_alarm_daemon) alarm_runner.daemon_context.umask = 0o022 alarm_runner.do_action()