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
This commit is contained in:
Davanum Srinivas
2015-06-11 06:12:54 -04:00
committed by Davanum Srinivas (dims)
parent c9ad954489
commit a977504e53
10 changed files with 40 additions and 81 deletions

View File

@@ -143,7 +143,7 @@ def initialize_if_enabled():
# listen(). In any case, pull the port number out here. # listen(). In any case, pull the port number out here.
port = sock.getsockname()[1] port = sock.getsockname()[1]
LOG.info( 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()} {'port': port, 'pid': os.getpid()}
) )
eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock, eventlet.spawn_n(eventlet.backdoor.backdoor_server, sock,

View File

@@ -61,7 +61,7 @@ def read_cached_file(filename, force_reload=False):
cache_info = _FILE_CACHE.setdefault(filename, {}) cache_info = _FILE_CACHE.setdefault(filename, {})
if not cache_info or mtime > cache_info.get('mtime', 0): 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: with open(filename) as fap:
cache_info['data'] = fap.read() cache_info['data'] = fap.read()
cache_info['mtime'] = mtime cache_info['mtime'] = mtime

View File

@@ -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()

View File

@@ -84,9 +84,9 @@ class FixedIntervalLoopingCall(LoopingCallBase):
break break
delay = end - start - interval delay = end - start - interval
if delay > 0: if delay > 0:
LOG.warn(_LW('task %(func_name)r run outlasted ' LOG.warning(_LW('task %(func_name)r run outlasted '
'interval by %(delay).2f sec'), 'interval by %(delay).2f sec'),
{'func_name': self.f, 'delay': delay}) {'func_name': self.f, 'delay': delay})
greenthread.sleep(-delay if delay < 0 else 0) greenthread.sleep(-delay if delay < 0 else 0)
except LoopingCallDone as e: except LoopingCallDone as e:
self.stop() self.stop()

View File

@@ -222,11 +222,11 @@ class PeriodicTasks(object):
try: try:
task(self, context) task(self, context)
except Exception as e: except Exception:
if raise_on_error: if raise_on_error:
raise raise
LOG.exception(_LE("Error during %(full_task_name)s: %(e)s"), LOG.exception(_LE("Error during %(full_task_name)s"),
{"full_task_name": full_task_name, "e": e}) {"full_task_name": full_task_name})
time.sleep(0) time.sleep(0)
return idle_for return idle_for

View File

@@ -40,7 +40,21 @@ class PackageReportGenerator(object):
self.version_obj = version_obj self.version_obj = version_obj
def __call__(self): def __call__(self):
return vm.PackageModel( if hasattr(self.version_obj, "vendor_string"):
self.version_obj.vendor_string(), vendor_string = self.version_obj.vendor_string()
self.version_obj.product_string(), else:
self.version_obj.version_string_with_package()) 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)

View File

@@ -157,7 +157,8 @@ class GuruMeditation(object):
service_name = service_name or os.path.basename( service_name = service_name or os.path.basename(
inspect.stack()[-1][1]) inspect.stack()[-1][1])
filename = "%s_gurumeditation_%s" % ( 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) filepath = os.path.join(log_dir, filename)
try: try:
with open(filepath, "w") as dumpfile: with open(filepath, "w") as dumpfile:

View File

@@ -18,6 +18,7 @@
"""Generic Node base class for all workers that run on hosts.""" """Generic Node base class for all workers that run on hosts."""
import errno import errno
import io
import logging import logging
import os import os
import random import random
@@ -25,14 +26,6 @@ import signal
import sys import sys
import time 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 import eventlet
from eventlet import event from eventlet import event
from oslo_config import cfg from oslo_config import cfg
@@ -59,15 +52,15 @@ def _is_daemon():
# http://www.gnu.org/software/bash/manual/bashref.html#Job-Control-Basics # http://www.gnu.org/software/bash/manual/bashref.html#Job-Control-Basics
try: try:
is_daemon = os.getpgrp() != os.tcgetpgrp(sys.stdout.fileno()) 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: except OSError as err:
if err.errno == errno.ENOTTY: if err.errno == errno.ENOTTY:
# Assume we are a daemon because there is no terminal. # Assume we are a daemon because there is no terminal.
is_daemon = True is_daemon = True
else: else:
raise raise
except UnsupportedOperation:
# Could not get the fileno for stdout, so we must be a daemon.
is_daemon = True
return is_daemon return is_daemon
@@ -234,7 +227,7 @@ class ProcessLauncher(object):
def _pipe_watcher(self): def _pipe_watcher(self):
# This will block until the write end is closed when the parent # This will block until the write end is closed when the parent
# dies unexpectedly # dies unexpectedly
self.readpipe.read() self.readpipe.read(1)
LOG.info(_LI('Parent process has died unexpectedly, exiting')) LOG.info(_LI('Parent process has died unexpectedly, exiting'))

View File

@@ -17,6 +17,7 @@ import threading
import eventlet import eventlet
from eventlet import greenpool from eventlet import greenpool
from nova.openstack.common._i18n import _LE
from nova.openstack.common import loopingcall from nova.openstack.common import loopingcall
@@ -98,15 +99,15 @@ class ThreadGroup(object):
x.stop() x.stop()
except eventlet.greenlet.GreenletExit: except eventlet.greenlet.GreenletExit:
pass pass
except Exception as ex: except Exception:
LOG.exception(ex) LOG.exception(_LE('Error stopping thread.'))
def stop_timers(self): def stop_timers(self):
for x in self.timers: for x in self.timers:
try: try:
x.stop() x.stop()
except Exception as ex: except Exception:
LOG.exception(ex) LOG.exception(_LE('Error stopping timer.'))
self.timers = [] self.timers = []
def stop(self, graceful=False): def stop(self, graceful=False):
@@ -132,8 +133,8 @@ class ThreadGroup(object):
x.wait() x.wait()
except eventlet.greenlet.GreenletExit: except eventlet.greenlet.GreenletExit:
pass pass
except Exception as ex: except Exception:
LOG.exception(ex) LOG.exception(_LE('Error waiting on ThreadGroup.'))
current = threading.current_thread() current = threading.current_thread()
# Iterate over a copy of self.threads so thread_done doesn't # Iterate over a copy of self.threads so thread_done doesn't

View File

@@ -2,10 +2,8 @@
# The list of modules to copy from oslo-incubator # The list of modules to copy from oslo-incubator
module=cliutils module=cliutils
module=eventlet_backdoor
module=fileutils module=fileutils
module=imageutils module=imageutils
module=local
module=loopingcall module=loopingcall
module=memorycache module=memorycache
module=periodic_task module=periodic_task
@@ -18,9 +16,6 @@ module=report.views.text
module=report.views.xml module=report.views.xml
module=service module=service
module=sslutils module=sslutils
module=systemd
module=threadgroup
module=versionutils
# The base module to hold the copy of openstack.common # The base module to hold the copy of openstack.common
base=nova base=nova