From a977504e53b6aaa212fc293064464656bfee709e Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Thu, 11 Jun 2015 06:12:54 -0400 Subject: [PATCH] Sync with latest oslo-incubator Commits are as follows: 16eb642 Clean up logging to conform to guidelines 14874b8 Guru Meditation Reports broken without version_string 289f909 Remove timeutils.strtime() usage 97ba6db Port service to Python 3 Change-Id: Ia5f3204a23fe262315ec2c58a521b870bfe228bf --- nova/openstack/common/eventlet_backdoor.py | 2 +- nova/openstack/common/fileutils.py | 2 +- nova/openstack/common/local.py | 45 ------------------- nova/openstack/common/loopingcall.py | 6 +-- nova/openstack/common/periodic_task.py | 6 +-- .../common/report/generators/version.py | 22 +++++++-- .../common/report/guru_meditation_report.py | 3 +- nova/openstack/common/service.py | 17 +++---- nova/openstack/common/threadgroup.py | 13 +++--- openstack-common.conf | 5 --- 10 files changed, 40 insertions(+), 81 deletions(-) delete mode 100644 nova/openstack/common/local.py diff --git a/nova/openstack/common/eventlet_backdoor.py b/nova/openstack/common/eventlet_backdoor.py index 2b9bf5097e8e..bf79feba4603 100644 --- a/nova/openstack/common/eventlet_backdoor.py +++ b/nova/openstack/common/eventlet_backdoor.py @@ -143,7 +143,7 @@ def initialize_if_enabled(): # listen(). In any case, pull the port number out here. port = sock.getsockname()[1] LOG.info( - _LI('Eventlet backdoor listening on %(port)s for process %(pid)d') % + _LI('Eventlet backdoor listening on %(port)s for process %(pid)d'), {'port': port, 'pid': os.getpid()} ) eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock, diff --git a/nova/openstack/common/fileutils.py b/nova/openstack/common/fileutils.py index 9097c35d4595..1191ce8f461b 100644 --- a/nova/openstack/common/fileutils.py +++ b/nova/openstack/common/fileutils.py @@ -61,7 +61,7 @@ def read_cached_file(filename, force_reload=False): cache_info = _FILE_CACHE.setdefault(filename, {}) if not cache_info or mtime > cache_info.get('mtime', 0): - LOG.debug("Reloading cached file %s" % filename) + LOG.debug("Reloading cached file %s", filename) with open(filename) as fap: cache_info['data'] = fap.read() cache_info['mtime'] = mtime diff --git a/nova/openstack/common/local.py b/nova/openstack/common/local.py deleted file mode 100644 index 0819d5b97cbb..000000000000 --- a/nova/openstack/common/local.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2011 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -"""Local storage of variables using weak references""" - -import threading -import weakref - - -class WeakLocal(threading.local): - def __getattribute__(self, attr): - rval = super(WeakLocal, self).__getattribute__(attr) - if rval: - # NOTE(mikal): this bit is confusing. What is stored is a weak - # reference, not the value itself. We therefore need to lookup - # the weak reference and return the inner value here. - rval = rval() - return rval - - def __setattr__(self, attr, value): - value = weakref.ref(value) - return super(WeakLocal, self).__setattr__(attr, value) - - -# NOTE(mikal): the name "store" should be deprecated in the future -store = WeakLocal() - -# A "weak" store uses weak references and allows an object to fall out of scope -# when it falls out of scope in the code that uses the thread local storage. A -# "strong" store will hold a reference to the object so that it never falls out -# of scope. -weak_store = WeakLocal() -strong_store = threading.local() diff --git a/nova/openstack/common/loopingcall.py b/nova/openstack/common/loopingcall.py index 29628b7c3036..15f5405ffadf 100644 --- a/nova/openstack/common/loopingcall.py +++ b/nova/openstack/common/loopingcall.py @@ -84,9 +84,9 @@ class FixedIntervalLoopingCall(LoopingCallBase): break delay = end - start - interval if delay > 0: - LOG.warn(_LW('task %(func_name)r run outlasted ' - 'interval by %(delay).2f sec'), - {'func_name': self.f, 'delay': delay}) + LOG.warning(_LW('task %(func_name)r run outlasted ' + 'interval by %(delay).2f sec'), + {'func_name': self.f, 'delay': delay}) greenthread.sleep(-delay if delay < 0 else 0) except LoopingCallDone as e: self.stop() diff --git a/nova/openstack/common/periodic_task.py b/nova/openstack/common/periodic_task.py index 419098bde9d1..14f9fefcc8f0 100644 --- a/nova/openstack/common/periodic_task.py +++ b/nova/openstack/common/periodic_task.py @@ -222,11 +222,11 @@ class PeriodicTasks(object): try: task(self, context) - except Exception as e: + except Exception: if raise_on_error: raise - LOG.exception(_LE("Error during %(full_task_name)s: %(e)s"), - {"full_task_name": full_task_name, "e": e}) + LOG.exception(_LE("Error during %(full_task_name)s"), + {"full_task_name": full_task_name}) time.sleep(0) return idle_for diff --git a/nova/openstack/common/report/generators/version.py b/nova/openstack/common/report/generators/version.py index 65302d5b1237..f79e0a5aeb68 100644 --- a/nova/openstack/common/report/generators/version.py +++ b/nova/openstack/common/report/generators/version.py @@ -40,7 +40,21 @@ class PackageReportGenerator(object): self.version_obj = version_obj def __call__(self): - return vm.PackageModel( - self.version_obj.vendor_string(), - self.version_obj.product_string(), - self.version_obj.version_string_with_package()) + if hasattr(self.version_obj, "vendor_string"): + vendor_string = self.version_obj.vendor_string() + else: + vendor_string = None + + if hasattr(self.version_obj, "product_string"): + product_string = self.version_obj.product_string() + else: + product_string = None + + if hasattr(self.version_obj, "version_string_with_package"): + version_string_with_package = self.version_obj.\ + version_string_with_package() + else: + version_string_with_package = None + + return vm.PackageModel(vendor_string, product_string, + version_string_with_package) diff --git a/nova/openstack/common/report/guru_meditation_report.py b/nova/openstack/common/report/guru_meditation_report.py index 6d1f2e759c8b..ee383a5afe8a 100644 --- a/nova/openstack/common/report/guru_meditation_report.py +++ b/nova/openstack/common/report/guru_meditation_report.py @@ -157,7 +157,8 @@ class GuruMeditation(object): service_name = service_name or os.path.basename( inspect.stack()[-1][1]) filename = "%s_gurumeditation_%s" % ( - service_name, timeutils.strtime(fmt=cls.timestamp_fmt)) + service_name, timeutils.utcnow().strftime( + cls.timestamp_fmt)) filepath = os.path.join(log_dir, filename) try: with open(filepath, "w") as dumpfile: diff --git a/nova/openstack/common/service.py b/nova/openstack/common/service.py index ea94f9e2dd83..126ac6c215a4 100644 --- a/nova/openstack/common/service.py +++ b/nova/openstack/common/service.py @@ -18,6 +18,7 @@ """Generic Node base class for all workers that run on hosts.""" import errno +import io import logging import os import random @@ -25,14 +26,6 @@ import signal import sys import time -try: - # Importing just the symbol here because the io module does not - # exist in Python 2.6. - from io import UnsupportedOperation # noqa -except ImportError: - # Python 2.6 - UnsupportedOperation = None - import eventlet from eventlet import event from oslo_config import cfg @@ -59,15 +52,15 @@ def _is_daemon(): # http://www.gnu.org/software/bash/manual/bashref.html#Job-Control-Basics try: is_daemon = os.getpgrp() != os.tcgetpgrp(sys.stdout.fileno()) + except io.UnsupportedOperation: + # Could not get the fileno for stdout, so we must be a daemon. + is_daemon = True except OSError as err: if err.errno == errno.ENOTTY: # Assume we are a daemon because there is no terminal. is_daemon = True else: raise - except UnsupportedOperation: - # Could not get the fileno for stdout, so we must be a daemon. - is_daemon = True return is_daemon @@ -234,7 +227,7 @@ class ProcessLauncher(object): def _pipe_watcher(self): # This will block until the write end is closed when the parent # dies unexpectedly - self.readpipe.read() + self.readpipe.read(1) LOG.info(_LI('Parent process has died unexpectedly, exiting')) diff --git a/nova/openstack/common/threadgroup.py b/nova/openstack/common/threadgroup.py index 687996572f31..a2119f9a769a 100644 --- a/nova/openstack/common/threadgroup.py +++ b/nova/openstack/common/threadgroup.py @@ -17,6 +17,7 @@ import threading import eventlet from eventlet import greenpool +from nova.openstack.common._i18n import _LE from nova.openstack.common import loopingcall @@ -98,15 +99,15 @@ class ThreadGroup(object): x.stop() except eventlet.greenlet.GreenletExit: pass - except Exception as ex: - LOG.exception(ex) + except Exception: + LOG.exception(_LE('Error stopping thread.')) def stop_timers(self): for x in self.timers: try: x.stop() - except Exception as ex: - LOG.exception(ex) + except Exception: + LOG.exception(_LE('Error stopping timer.')) self.timers = [] def stop(self, graceful=False): @@ -132,8 +133,8 @@ class ThreadGroup(object): x.wait() except eventlet.greenlet.GreenletExit: pass - except Exception as ex: - LOG.exception(ex) + except Exception: + LOG.exception(_LE('Error waiting on ThreadGroup.')) current = threading.current_thread() # Iterate over a copy of self.threads so thread_done doesn't diff --git a/openstack-common.conf b/openstack-common.conf index 5eb437b68313..a586529190dc 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -2,10 +2,8 @@ # The list of modules to copy from oslo-incubator module=cliutils -module=eventlet_backdoor module=fileutils module=imageutils -module=local module=loopingcall module=memorycache module=periodic_task @@ -18,9 +16,6 @@ module=report.views.text module=report.views.xml module=service module=sslutils -module=systemd -module=threadgroup -module=versionutils # The base module to hold the copy of openstack.common base=nova