summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openstack/common/cfg.py6
-rw-r--r--openstack/common/eventlet_backdoor.py2
-rw-r--r--openstack/common/importutils.py2
-rw-r--r--openstack/common/jsonutils.py2
-rw-r--r--openstack/common/lockutils.py1
-rw-r--r--openstack/common/notifier/api.py7
-rw-r--r--openstack/common/notifier/rpc_notifier.py2
-rw-r--r--openstack/common/periodic_task.py12
-rw-r--r--openstack/common/plugin/pluginmanager.py1
-rw-r--r--openstack/common/rpc/amqp.py9
-rw-r--r--openstack/common/rpc/common.py6
-rw-r--r--openstack/common/rpc/impl_qpid.py2
-rw-r--r--openstack/common/rpc/matchmaker.py2
-rw-r--r--openstack/common/service.py12
-rw-r--r--openstack/common/threadgroup.py1
-rw-r--r--openstack/common/utils.py9
-rw-r--r--tests/unit/test_cfg.py14
-rw-r--r--tools/pip-requires1
-rw-r--r--tox.ini4
-rw-r--r--update.py28
20 files changed, 68 insertions, 55 deletions
diff --git a/openstack/common/cfg.py b/openstack/common/cfg.py
index 673675b..767ba1a 100644
--- a/openstack/common/cfg.py
+++ b/openstack/common/cfg.py
@@ -1656,12 +1656,12 @@ class CommonConfigOpts(ConfigOpts):
metavar='FORMAT',
help='A logging.Formatter log message format string which may '
'use any of the available logging.LogRecord attributes. '
- 'Default: %default'),
+ 'Default: %(default)s'),
StrOpt('log-date-format',
default=DEFAULT_LOG_DATE_FORMAT,
metavar='DATE_FORMAT',
- help='Format string for %(asctime)s in log records. '
- 'Default: %default'),
+ help='Format string for %%(asctime)s in log records. '
+ 'Default: %(default)s'),
StrOpt('log-file',
metavar='PATH',
help='(Optional) Name of log file to output to. '
diff --git a/openstack/common/eventlet_backdoor.py b/openstack/common/eventlet_backdoor.py
index b28a2c6..035d282 100644
--- a/openstack/common/eventlet_backdoor.py
+++ b/openstack/common/eventlet_backdoor.py
@@ -46,7 +46,7 @@ def _find_objects(t):
def _print_greenthreads():
- for i, gt in enumerate(find_objects(greenlet.greenlet)):
+ for i, gt in enumerate(_find_objects(greenlet.greenlet)):
print i, gt
traceback.print_stack(gt.gr_frame)
print
diff --git a/openstack/common/importutils.py b/openstack/common/importutils.py
index f45372b..2a28b45 100644
--- a/openstack/common/importutils.py
+++ b/openstack/common/importutils.py
@@ -29,7 +29,7 @@ def import_class(import_str):
try:
__import__(mod_str)
return getattr(sys.modules[mod_str], class_str)
- except (ValueError, AttributeError), exc:
+ except (ValueError, AttributeError):
raise ImportError('Class %s cannot be found (%s)' %
(class_str,
traceback.format_exception(*sys.exc_info())))
diff --git a/openstack/common/jsonutils.py b/openstack/common/jsonutils.py
index f96e727..efc8324 100644
--- a/openstack/common/jsonutils.py
+++ b/openstack/common/jsonutils.py
@@ -120,7 +120,7 @@ def to_primitive(value, convert_instances=False, level=0):
level=level + 1)
else:
return value
- except TypeError, e:
+ except TypeError:
# Class objects are tricky since they may define something like
# __iter__ defined but it isn't callable as list().
return unicode(value)
diff --git a/openstack/common/lockutils.py b/openstack/common/lockutils.py
index d98ce8b..a342938 100644
--- a/openstack/common/lockutils.py
+++ b/openstack/common/lockutils.py
@@ -27,6 +27,7 @@ import weakref
from eventlet import semaphore
from openstack.common import cfg
+from openstack.common.gettextutils import _
from openstack.common import fileutils
from openstack.common import log as logging
diff --git a/openstack/common/notifier/api.py b/openstack/common/notifier/api.py
index 470eacb..5714306 100644
--- a/openstack/common/notifier/api.py
+++ b/openstack/common/notifier/api.py
@@ -137,10 +137,11 @@ def notify(context, publisher_id, event_type, priority, payload):
for driver in _get_drivers():
try:
driver.notify(context, msg)
- except Exception, e:
+ except Exception as e:
LOG.exception(_("Problem '%(e)s' attempting to "
"send to notification system. "
- "Payload=%(payload)s") % locals())
+ "Payload=%(payload)s")
+ % dict(e=e, payload=payload))
_drivers = None
@@ -166,7 +167,7 @@ def add_driver(notification_driver):
try:
driver = importutils.import_module(notification_driver)
_drivers[notification_driver] = driver
- except ImportError as e:
+ except ImportError:
LOG.exception(_("Failed to load notifier %s. "
"These notifications will not be sent.") %
notification_driver)
diff --git a/openstack/common/notifier/rpc_notifier.py b/openstack/common/notifier/rpc_notifier.py
index 604af86..7e25f47 100644
--- a/openstack/common/notifier/rpc_notifier.py
+++ b/openstack/common/notifier/rpc_notifier.py
@@ -41,6 +41,6 @@ def notify(context, message):
topic = '%s.%s' % (topic, priority)
try:
rpc.notify(context, topic, message)
- except Exception, e:
+ except Exception:
LOG.exception(_("Could not send notification to %(topic)s. "
"Payload=%(message)s"), locals())
diff --git a/openstack/common/periodic_task.py b/openstack/common/periodic_task.py
index 8a32162..28ab22e 100644
--- a/openstack/common/periodic_task.py
+++ b/openstack/common/periodic_task.py
@@ -95,17 +95,21 @@ class PeriodicTasks(object):
ticks_to_skip = self._ticks_to_skip[task_name]
if ticks_to_skip > 0:
LOG.debug(_("Skipping %(full_task_name)s, %(ticks_to_skip)s"
- " ticks left until next run"), locals())
+ " ticks left until next run"),
+ dict(full_task_name=full_task_name,
+ ticks_to_skip=ticks_to_skip))
self._ticks_to_skip[task_name] -= 1
continue
self._ticks_to_skip[task_name] = task._ticks_between_runs
- LOG.debug(_("Running periodic task %(full_task_name)s"), locals())
+ LOG.debug(_("Running periodic task %(full_task_name)s"),
+ dict(full_task_name=full_task_name))
try:
task(self, context)
except Exception as e:
if raise_on_error:
raise
- LOG.exception(_("Error during %(full_task_name)s: %(e)s"),
- locals())
+ LOG.exception(_("Error during %(full_task_name)s:"
+ " %(e)s"),
+ dict(e=e, full_task_name=full_task_name))
diff --git a/openstack/common/plugin/pluginmanager.py b/openstack/common/plugin/pluginmanager.py
index 38e05ae..f7891cd 100644
--- a/openstack/common/plugin/pluginmanager.py
+++ b/openstack/common/plugin/pluginmanager.py
@@ -16,6 +16,7 @@
import pkg_resources
from openstack.common import cfg
+from openstack.common.gettextutils import _
from openstack.common import log as logging
from openstack.common.notifier import api as notifier_api
diff --git a/openstack/common/rpc/amqp.py b/openstack/common/rpc/amqp.py
index 79eda39..2ea506a 100644
--- a/openstack/common/rpc/amqp.py
+++ b/openstack/common/rpc/amqp.py
@@ -26,7 +26,6 @@ AMQP, but is deprecated and predates this code.
"""
import inspect
-import logging
import sys
import uuid
@@ -38,6 +37,7 @@ from openstack.common import cfg
from openstack.common import excutils
from openstack.common.gettextutils import _
from openstack.common import local
+from openstack.common import log as logging
from openstack.common.rpc import common as rpc_common
@@ -282,7 +282,7 @@ class ProxyCallback(object):
ctxt.reply(rval, None, connection_pool=self.connection_pool)
# This final None tells multicall that it is done.
ctxt.reply(ending=True, connection_pool=self.connection_pool)
- except Exception as e:
+ except Exception:
LOG.exception('Exception during message handling')
ctxt.reply(None, sys.exc_info(),
connection_pool=self.connection_pool)
@@ -407,8 +407,9 @@ def fanout_cast_to_server(conf, context, server_params, topic, msg,
def notify(conf, context, topic, msg, connection_pool):
"""Sends a notification event on a topic."""
- event_type = msg.get('event_type')
- LOG.debug(_('Sending %(event_type)s on %(topic)s'), locals())
+ LOG.debug(_('Sending %(event_type)s on %(topic)s'),
+ dict(event_type=msg.get('event_type'),
+ topic=topic))
pack_context(msg, context)
with ConnectionContext(conf, connection_pool) as conn:
conn.notify_send(topic, msg)
diff --git a/openstack/common/rpc/common.py b/openstack/common/rpc/common.py
index 58f958f..c56c9a6 100644
--- a/openstack/common/rpc/common.py
+++ b/openstack/common/rpc/common.py
@@ -18,13 +18,13 @@
# under the License.
import copy
-import logging
import traceback
from openstack.common.gettextutils import _
from openstack.common import importutils
from openstack.common import jsonutils
from openstack.common import local
+from openstack.common import log as logging
LOG = logging.getLogger(__name__)
@@ -40,7 +40,7 @@ class RPCException(Exception):
try:
message = self.message % kwargs
- except Exception as e:
+ except Exception:
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
LOG.exception(_('Exception in string format operation'))
@@ -258,7 +258,7 @@ def deserialize_remote_exception(conf, data):
# we cannot necessarily change an exception message so we must override
# the __str__ method.
failure.__class__ = new_ex_type
- except TypeError as e:
+ except TypeError:
# NOTE(ameade): If a core exception then just add the traceback to the
# first exception argument.
failure.args = (message,) + failure.args[1:]
diff --git a/openstack/common/rpc/impl_qpid.py b/openstack/common/rpc/impl_qpid.py
index 887a54e..fcf2508 100644
--- a/openstack/common/rpc/impl_qpid.py
+++ b/openstack/common/rpc/impl_qpid.py
@@ -17,7 +17,6 @@
import functools
import itertools
-import logging
import time
import uuid
@@ -29,6 +28,7 @@ import qpid.messaging.exceptions
from openstack.common import cfg
from openstack.common.gettextutils import _
from openstack.common import jsonutils
+from openstack.common import log as logging
from openstack.common.rpc import amqp as rpc_amqp
from openstack.common.rpc import common as rpc_common
diff --git a/openstack/common/rpc/matchmaker.py b/openstack/common/rpc/matchmaker.py
index 2791ac2..48270ba 100644
--- a/openstack/common/rpc/matchmaker.py
+++ b/openstack/common/rpc/matchmaker.py
@@ -21,10 +21,10 @@ return keys for direct exchanges, per (approximate) AMQP parlance.
import contextlib
import itertools
import json
-import logging
from openstack.common import cfg
from openstack.common.gettextutils import _
+from openstack.common import log as logging
matchmaker_opts = [
diff --git a/openstack/common/service.py b/openstack/common/service.py
index 0c355f7..3186d56 100644
--- a/openstack/common/service.py
+++ b/openstack/common/service.py
@@ -27,6 +27,7 @@ import sys
import time
import eventlet
+import extras
import logging as std_logging
from openstack.common import cfg
@@ -35,11 +36,8 @@ from openstack.common.gettextutils import _
from openstack.common import log as logging
from openstack.common import threadgroup
-try:
- from openstack.common import rpc
-except ImportError:
- rpc = None
+rpc = extras.try_import('openstack.common.rpc')
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
@@ -253,10 +251,12 @@ class ProcessLauncher(object):
if os.WIFSIGNALED(status):
sig = os.WTERMSIG(status)
- LOG.info(_('Child %(pid)d killed by signal %(sig)d'), locals())
+ LOG.info(_('Child %(pid)d killed by signal %(sig)d'),
+ dict(pid=pid, sig=sig))
else:
code = os.WEXITSTATUS(status)
- LOG.info(_('Child %(pid)d exited with status %(code)d'), locals())
+ LOG.info(_('Child %(pid)s exited with status %(code)d'),
+ dict(pid=pid, code=code))
if pid not in self.children:
LOG.warning(_('pid %d not in child list'), pid)
diff --git a/openstack/common/threadgroup.py b/openstack/common/threadgroup.py
index 27b3c4c..1f80fef 100644
--- a/openstack/common/threadgroup.py
+++ b/openstack/common/threadgroup.py
@@ -18,7 +18,6 @@ from eventlet import greenlet
from eventlet import greenpool
from eventlet import greenthread
-from openstack.common.gettextutils import _
from openstack.common import log as logging
from openstack.common import loopingcall
diff --git a/openstack/common/utils.py b/openstack/common/utils.py
index e5e04ba..05f0e9f 100644
--- a/openstack/common/utils.py
+++ b/openstack/common/utils.py
@@ -20,15 +20,6 @@ System-level utilities and helper functions.
"""
import logging
-import random
-import shlex
-
-from eventlet.green import subprocess
-from eventlet import greenthread
-
-from openstack.common import exception
-from openstack.common.gettextutils import _
-
LOG = logging.getLogger(__name__)
diff --git a/tests/unit/test_cfg.py b/tests/unit/test_cfg.py
index bff7c2d..feb0da1 100644
--- a/tests/unit/test_cfg.py
+++ b/tests/unit/test_cfg.py
@@ -1335,6 +1335,11 @@ class SadPathTestCase(BaseTestCase):
self.assertTrue(hasattr(self.conf, 'foo'))
self.assertEquals(self.conf.foo, None)
+ def test_error_duplicate(self):
+ self.conf.register_cli_opt(StrOpt('foo', help='bar'))
+ self.assertRaises(DuplicateOptError,
+ self.conf.register_cli_opt, StrOpt('foo'))
+
def test_error_duplicate_with_different_dest(self):
self.conf.register_cli_opt(StrOpt('foo', dest='f'))
self.conf.register_cli_opt(StrOpt('foo'))
@@ -1534,6 +1539,15 @@ class CommonOptsTestCase(BaseTestCase):
super(CommonOptsTestCase, self).setUp()
self.conf = CommonConfigOpts()
+ def test_print_help(self):
+ f = StringIO.StringIO()
+ self.conf([])
+ self.conf.print_help(file=f)
+ self.assertTrue('debug' in f.getvalue())
+ self.assertTrue('verbose' in f.getvalue())
+ self.assertTrue('log-config' in f.getvalue())
+ self.assertTrue('log-format' in f.getvalue())
+
def test_debug_verbose(self):
self.conf(['--debug', '--verbose'])
diff --git a/tools/pip-requires b/tools/pip-requires
index 5040d73..2403294 100644
--- a/tools/pip-requires
+++ b/tools/pip-requires
@@ -1,6 +1,7 @@
PasteDeploy==1.5.0
WebOb==1.0.8
eventlet
+extras
greenlet>=0.3.1
lxml
routes==1.12.3
diff --git a/tox.ini b/tox.ini
index 7f97a91..d7ecb96 100644
--- a/tox.ini
+++ b/tox.ini
@@ -27,3 +27,7 @@ commands = {posargs}
deps = -r{toxinidir}/tools/pip-requires
-r{toxinidir}/tools/test-requires
-r{toxinidir}/tools/test-options
+
+[testenv:pyflakes]
+deps = pyflakes
+commands = pyflakes openstack setup.py update.py
diff --git a/update.py b/update.py
index 624143e..d7b0c18 100644
--- a/update.py
+++ b/update.py
@@ -55,7 +55,6 @@ the modules to copy and the base destination module
Obviously, the first way is the easiest!
"""
-import imp
import os
import os.path
import re
@@ -78,34 +77,31 @@ opts = [
cfg.StrOpt('dest-dir',
default=None,
help='Destination project directory'),
+ cfg.StrOpt('configfile_or_destdir',
+ default=None,
+ help='A config file or destination project directory',
+ positional=True),
]
def _parse_args(argv):
conf = cfg.ConfigOpts()
conf.register_cli_opts(opts)
- args = conf(argv, usage='Usage: %(prog)s [config-file|dest-dir]')
+ conf(argv, usage='Usage: %(prog)s [config-file|dest-dir]')
- if len(args) == 1:
+ if conf.configfile_or_destdir:
def def_config_file(dest_dir):
return os.path.join(dest_dir, 'openstack-common.conf')
- i = argv.index(args[0])
-
config_file = None
- if os.path.isfile(argv[i]):
- config_file = argv[i]
- elif (os.path.isdir(argv[i])
- and os.path.isfile(def_config_file(argv[i]))):
- config_file = def_config_file(argv[i])
+ if os.path.isfile(conf.configfile_or_destdir):
+ config_file = conf.configfile_or_destdir
+ elif (os.path.isdir(conf.configfile_or_destdir)
+ and os.path.isfile(def_config_file(conf.configfile_or_destdir))):
+ config_file = def_config_file(conf.configfile_or_destdir)
if config_file:
- argv[i:i + 1] = ['--config-file', config_file]
- args = conf(argv)
-
- if args:
- conf.print_usage(file=sys.stderr)
- sys.exit(1)
+ conf(argv + ['--config-file', config_file])
return conf