Update logmgmt to use python3

This reverts commit 115332ef6b.

Change python to python3 about script and spec
fix log runtime errors in python3 env
1. layer build OK
2. logmgmt.service running and stop ok
3. log rotate and force rotate ok
4. logmgmt manage and delete monitored or unmonitored log ok
5. logmgmgt.log back up ok

Story: 2007106
Task: 39288
Depends-on: https://review.opendev.org/#/c/728323/
Depends-on: https://review.opendev.org/#/c/728325/
Signed-off-by: Long Li <lilong-neu@neusoft.com>
Signed-off-by: SidneyAn <ran1.an@intel.com>
Change-Id: I08d6396922cea2d8d4d485f3cc66f522f6579f2e
This commit is contained in:
Ran An 2020-05-15 01:34:37 +00:00 committed by Long Li
parent 36420bc00d
commit 7552f4a0f5
7 changed files with 31 additions and 18 deletions

View File

@ -1,4 +1,4 @@
SRC_DIR="logmgmt"
COPY_LIST_TO_TAR="scripts"
COPY_LIST="$SRC_DIR/LICENSE"
TIS_PATCH_VER=4
TIS_PATCH_VER=5

View File

@ -9,12 +9,13 @@ URL: unknown
Source0: %{name}-%{version}.tar.gz
Source1: LICENSE
BuildRequires: python-setuptools
BuildRequires: python2-pip
BuildRequires: python2-wheel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
BuildRequires: python3-wheel
BuildRequires: systemd-devel
BuildRequires: python3-devel
Requires: systemd
Requires: python-daemon
Requires: python3-daemon
%description
Management of /var/log filesystem
@ -22,7 +23,7 @@ Management of /var/log filesystem
%define local_bindir /usr/bin/
%define local_etc_initd /etc/init.d/
%define local_etc_pmond /etc/pmon.d/
%define pythonroot /usr/lib64/python2.7/site-packages
%define pythonroot %{python3_sitearch}
%define debug_package %{nil}
@ -33,11 +34,11 @@ Management of /var/log filesystem
rm -rf *.egg-info
%build
%{__python} setup.py build
%py2_build_wheel
%{__python3} setup.py build
%{__python3} setup.py bdist_wheel
%install
%{__python} setup.py install --root=$RPM_BUILD_ROOT \
%{__python3} setup.py install --root=$RPM_BUILD_ROOT \
--install-lib=%{pythonroot} \
--prefix=/usr \
--install-data=/usr/share \
@ -74,8 +75,8 @@ rm -rf $RPM_BUILD_ROOT
%{_unitdir}/logmgmt.service
%dir %{pythonroot}/%{name}
%{pythonroot}/%{name}/*
%dir %{pythonroot}/%{name}-%{version}.0-py2.7.egg-info
%{pythonroot}/%{name}-%{version}.0-py2.7.egg-info/*
%dir %{pythonroot}/%{name}-%{version}.0-py3.6.egg-info
%{pythonroot}/%{name}-%{version}.0-py3.6.egg-info/*
%package wheels
Summary: %{name} wheels

View File

@ -42,7 +42,7 @@ LOGROTATE_PERIOD = 600 # Every ten minutes
###################
def start_polling():
logmgmt_daemon = LogMgmtDaemon()
logmgmt_runner = runner.DaemonRunner(logmgmt_daemon)
logmgmt_runner = MyDaemonRunner(logmgmt_daemon)
logmgmt_runner.daemon_context.umask = 0o022
logmgmt_runner.do_action()
@ -57,6 +57,18 @@ def handle_exception(exc_type, exc_value, exc_traceback):
###################
# CLASSES
###################
class MyDaemonRunner(runner.DaemonRunner):
# Workaround: fix the "unbuffered bytes I/O for py3" runtime
# error in pyhon3 env.
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:
self.daemon_context.stderr = open(app.stderr_path, 'wb+', buffering=0)
class LogMgmtDaemon():
"""Daemon process representation of the /var/log monitoring program"""
def __init__(self):
@ -122,7 +134,7 @@ class LogMgmtDaemon():
output = subprocess.check_output(['/usr/sbin/logrotate', '-d', '/etc/logrotate.conf'],
stderr=subprocess.STDOUT)
for line in output.split('\n'):
for line in output.decode().split('\n'):
fields = line.split()
if len(fields) > 0 and fields[0] == "considering":
self.monitored_files.extend(glob.glob(fields[2]))
@ -140,7 +152,7 @@ class LogMgmtDaemon():
try:
output = subprocess.check_output(['find', '/var/log', '-type', 'f'])
for fname in output.split('\n'):
for fname in output.decode().split('\n'):
if fname in self.monitored_files:
continue

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Copyright (c) 2014 Wind River Systems, Inc.

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Copyright (c) 2014 Wind River Systems, Inc.

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Copyright (c) 2014 Wind River Systems, Inc.

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Copyright (c) 2014 Wind River Systems, Inc.