Alon Bar-Lev has uploaded a new change for review. Change subject: packaging: service: logger is part of the interface, remove _ ......................................................................
packaging: service: logger is part of the interface, remove _ Change-Id: I433b6a0d926c5afca8c905841c7543c273ebb235 Signed-off-by: Alon Bar-Lev <alo...@redhat.com> --- M packaging/services/ovirt-engine.py M packaging/services/service.py 2 files changed, 41 insertions(+), 35 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/91/15491/1 diff --git a/packaging/services/ovirt-engine.py b/packaging/services/ovirt-engine.py index bfb1d12..0a1c607 100755 --- a/packaging/services/ovirt-engine.py +++ b/packaging/services/ovirt-engine.py @@ -159,7 +159,7 @@ engineApp, ) if not os.path.exists(engineAppDir): - self._logger.warning( + self.logger.warning( _( "Application '{application}' directory '{directory}' " "does not exist, it will be ignored" @@ -181,7 +181,7 @@ try: os.symlink(engineAppDir, engineAppLink) except OSError as e: - self._logger.debug('exception', exc_info=True) + self.logger.debug('exception', exc_info=True) raise RuntimeError( _( "Cannot create symbolic link '{file}': " @@ -197,7 +197,7 @@ try: os.remove(markerFile) except OSError as e: - self._logger.debug('exception', exc_info=True) + self.logger.debug('exception', exc_info=True) raise RuntimeError( _( "Cannot remove deployment marker file '{file}': " @@ -215,7 +215,7 @@ with open(markerFile, "w"): pass except IOError as e: - self._logger.debug('exception', exc_info=True) + self.logger.debug('exception', exc_info=True) raise RuntimeError( _( "Cannot create deployment marker file '{file}': " diff --git a/packaging/services/service.py b/packaging/services/service.py index b4b2a2f..ae14dae 100755 --- a/packaging/services/service.py +++ b/packaging/services/service.py @@ -74,6 +74,12 @@ """ Base class for logging. """ + + @property + def logger(self): + """Logger.""" + return self._logger + def __init__(self): self._logger = logging.getLogger( 'ovirt.service.%s' % self.__class__.__name__ @@ -118,7 +124,7 @@ def loadFile(self, file): if os.path.exists(file): - self._logger.debug("loading config '%s'", file) + self.logger.debug("loading config '%s'", file) index = 0 try: with open(file, 'r') as f: @@ -126,7 +132,7 @@ index += 1 self._loadLine(line) except Exception as e: - self._logger.debug( + self.logger.debug( "File '%s' index %d error" % (file, index), exc_info=True, ) @@ -210,7 +216,7 @@ """ def _clear(self): - self._logger.debug("removing directory '%s'", self._dir) + self.logger.debug("removing directory '%s'", self._dir) if os.path.exists(self._dir): shutil.rmtree(self._dir) @@ -226,13 +232,13 @@ try: self._clear() except Exception as e: - self._logger.warning( + self.logger.warning( _("Cannot remove directory '{directory}': {error}").format( directory=self._dir, error=e, ), ) - self._logger.debug('exception', exc_info=True) + self.logger.debug('exception', exc_info=True) def __enter__(self): self.create() @@ -256,7 +262,7 @@ def __enter__(self): if self._file is not None: - self._logger.debug( + self.logger.debug( "creating pidfile '%s' pid=%s", self._file, os.getpid() @@ -266,7 +272,7 @@ def __exit__(self, exc_type, exc_value, traceback): if self._file is not None: - self._logger.debug("removing pidfile '%s'", self._file) + self.logger.debug("removing pidfile '%s'", self._file) try: os.remove(self._file) except OSError: @@ -276,13 +282,13 @@ with open(self._file, 'w'): pass except IOError as e: - self._logger.error( + self.logger.error( _("Cannot remove pidfile '{file}': {error}").format( file=self._file, error=e, ), ) - self._logger.debug('exception', exc_info=True) + self.logger.debug('exception', exc_info=True) class Daemon(Base): @@ -394,7 +400,7 @@ stopTime=30, stopInterval=1, ): - self._logger.debug( + self.logger.debug( 'executing daemon: exe=%s, args=%s, env=%s', executable, args, @@ -402,7 +408,7 @@ ) try: - self._logger.debug('creating process') + self.logger.debug('creating process') p = subprocess.Popen( args=args, executable=executable, @@ -410,12 +416,12 @@ close_fds=True, ) - self._logger.debug( + self.logger.debug( 'waiting for termination of pid=%s', p.pid, ) p.wait() - self._logger.debug( + self.logger.debug( 'terminated pid=%s rc=%s', p.pid, p.returncode, @@ -432,36 +438,36 @@ ) except self.TerminateException: - self._logger.debug('got stop signal') + self.logger.debug('got stop signal') # avoid recursive signals for sig in (signal.SIGTERM, signal.SIGINT): signal.signal(sig, signal.SIG_IGN) try: - self._logger.debug('terminating pid=%s', p.pid) + self.logger.debug('terminating pid=%s', p.pid) p.terminate() for i in range(stopTime // stopInterval): if p.poll() is not None: - self._logger.debug('terminated pid=%s', p.pid) + self.logger.debug('terminated pid=%s', p.pid) break - self._logger.debug( + self.logger.debug( 'waiting for termination of pid=%s', p.pid, ) time.sleep(stopInterval) except OSError as e: - self._logger.warning( + self.logger.warning( _('Cannot terminate pid {pid}: {error}').format( pid=p.pid, error=e, ) ) - self._logger.debug('exception', exc_info=True) + self.logger.debug('exception', exc_info=True) try: if p.poll() is None: - self._logger.debug('killing pid=%s', p.pid) + self.logger.debug('killing pid=%s', p.pid) p.kill() raise RuntimeError( _('Had to kill process {pid}').format( @@ -469,21 +475,21 @@ ) ) except OSError as e: - self._logger.warning( + self.logger.warning( _('Cannot kill pid {pid}: {error}').format( pid=p.pid, error=e ) ) - self._logger.debug('exception', exc_info=True) + self.logger.debug('exception', exc_info=True) raise raise def _daemon(self): - self._logger.debug('daemon entry pid=%s', os.getpid()) - self._logger.debug('background=%s', self._options.background) + self.logger.debug('daemon entry pid=%s', os.getpid()) + self.logger.debug('background=%s', self._options.background) os.umask(self._umask) @@ -507,21 +513,21 @@ stderr=stderr, umask=0o022, ): - self._logger.debug('I am a daemon %s', os.getpid()) + self.logger.debug('I am a daemon %s', os.getpid()) try: with PidFile(self._options.pidfile): self.daemonContext() - self._logger.debug('Returned normally %s', os.getpid()) + self.logger.debug('Returned normally %s', os.getpid()) except self.TerminateException: - self._logger.debug('Terminated normally %s', os.getpid()) + self.logger.debug('Terminated normally %s', os.getpid()) finally: self.daemonCleanup() - self._logger.debug('daemon return') + self.logger.debug('daemon return') def run(self): - self._logger.debug('startup args=%s', sys.argv) + self.logger.debug('startup args=%s', sys.argv) parser = optparse.OptionParser( usage=_('usage: %prog [options] start'), @@ -588,12 +594,12 @@ try: self._daemon() except Exception as e: - self._logger.error( + self.logger.error( _('Error: {error}').format( error=e, ) ) - self._logger.debug('exception', exc_info=True) + self.logger.debug('exception', exc_info=True) sys.exit(1) else: sys.exit(0) -- To view, visit http://gerrit.ovirt.org/15491 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I433b6a0d926c5afca8c905841c7543c273ebb235 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches