diff --git a/openstack/common/log.py b/openstack/common/log.py index 9e0ad7e76..8a368a1aa 100644 --- a/openstack/common/log.py +++ b/openstack/common/log.py @@ -66,13 +66,13 @@ log_opts = [ help='prefix each line of exception output with this format'), cfg.ListOpt('default_log_levels', default=[ - 'amqplib=WARN', - 'sqlalchemy=WARN', - 'boto=WARN', - 'suds=INFO', - 'keystone=INFO', - 'eventlet.wsgi.server=WARN' - ], + 'amqplib=WARN', + 'sqlalchemy=WARN', + 'boto=WARN', + 'suds=INFO', + 'keystone=INFO', + 'eventlet.wsgi.server=WARN' + ], help='list of logger=LEVEL pairs'), cfg.BoolOpt('publish_errors', default=False, @@ -89,7 +89,7 @@ log_opts = [ default='[instance: %(uuid)s] ', help='If an instance UUID is passed with the log message, ' 'format it like this'), - ] +] generic_log_opts = [ @@ -105,7 +105,7 @@ generic_log_opts = [ cfg.StrOpt('logfile_mode', default='0644', help='Default file mode used when creating log files'), - ] +] CONF = cfg.CONF @@ -208,9 +208,9 @@ class JSONFormatter(logging.Formatter): def formatException(self, ei, strip_newlines=True): lines = traceback.format_exception(*ei) if strip_newlines: - lines = [itertools.ifilter(lambda x: x, - line.rstrip().splitlines()) - for line in lines] + lines = [itertools.ifilter( + lambda x: x, + line.rstrip().splitlines()) for line in lines] lines = list(itertools.chain(*lines)) return lines @@ -252,9 +252,9 @@ class PublishErrorsHandler(logging.Handler): CONF.list_notifier_drivers): return notifier.api.notify(None, 'error.publisher', - 'error_notification', - notifier.api.ERROR, - dict(error=record.msg)) + 'error_notification', + notifier.api.ERROR, + dict(error=record.msg)) def handle_exception(type, value, tb): diff --git a/openstack/common/notifier/api.py b/openstack/common/notifier/api.py index f01d11e3d..e699620a5 100644 --- a/openstack/common/notifier/api.py +++ b/openstack/common/notifier/api.py @@ -37,7 +37,7 @@ notifier_opts = [ cfg.StrOpt('default_publisher_id', default='$host', help='Default publisher_id for outgoing notifications'), - ] +] CONF = cfg.CONF CONF.register_opts(notifier_opts) @@ -122,21 +122,21 @@ def notify(context, publisher_id, event_type, priority, payload): """ if priority not in log_levels: raise BadPriorityException( - _('%s not in valid priorities') % priority) + _('%s not in valid priorities') % priority) # Ensure everything is JSON serializable. payload = jsonutils.to_primitive(payload, convert_instances=True) driver = importutils.import_module(CONF.notification_driver) msg = dict(message_id=str(uuid.uuid4()), - publisher_id=publisher_id, - event_type=event_type, - priority=priority, - payload=payload, - timestamp=str(timeutils.utcnow())) + publisher_id=publisher_id, + event_type=event_type, + priority=priority, + payload=payload, + timestamp=str(timeutils.utcnow())) try: driver.notify(context, msg) except Exception, e: LOG.exception(_("Problem '%(e)s' attempting to " "send to notification system. Payload=%(payload)s") % - locals()) + locals()) diff --git a/openstack/common/notifier/list_notifier.py b/openstack/common/notifier/list_notifier.py index 41549df18..15ae470fe 100644 --- a/openstack/common/notifier/list_notifier.py +++ b/openstack/common/notifier/list_notifier.py @@ -19,9 +19,10 @@ from openstack.common import importutils from openstack.common import log as logging -list_notifier_drivers_opt = cfg.MultiStrOpt('list_notifier_drivers', - default=['openstack.common.notifier.no_op_notifier'], - help='List of drivers to send notifications') +list_notifier_drivers_opt = cfg.MultiStrOpt( + 'list_notifier_drivers', + default=['openstack.common.notifier.no_op_notifier'], + help='List of drivers to send notifications') CONF = cfg.CONF CONF.register_opt(list_notifier_drivers_opt) diff --git a/openstack/common/notifier/log_notifier.py b/openstack/common/notifier/log_notifier.py index 9ef311884..b333d7a90 100644 --- a/openstack/common/notifier/log_notifier.py +++ b/openstack/common/notifier/log_notifier.py @@ -30,6 +30,6 @@ def notify(_context, message): CONF.default_notification_level) priority = priority.lower() logger = logging.getLogger( - 'openstack.common.notification.%s' % - message['event_type']) + 'openstack.common.notification.%s' % + message['event_type']) getattr(logger, priority)(jsonutils.dumps(message)) diff --git a/openstack/common/notifier/rabbit_notifier.py b/openstack/common/notifier/rabbit_notifier.py index 69ca8bd1f..3a2ffee1e 100644 --- a/openstack/common/notifier/rabbit_notifier.py +++ b/openstack/common/notifier/rabbit_notifier.py @@ -22,9 +22,9 @@ from openstack.common import rpc LOG = logging.getLogger(__name__) -notification_topic_opt = cfg.ListOpt('notification_topics', - default=['notifications', ], - help='AMQP topic used for openstack notifications') +notification_topic_opt = cfg.ListOpt( + 'notification_topics', default=['notifications', ], + help='AMQP topic used for openstack notifications') CONF = cfg.CONF CONF.register_opt(notification_topic_opt) diff --git a/openstack/common/rpc/impl_zmq.py b/openstack/common/rpc/impl_zmq.py index ba54cfa3f..44381550b 100644 --- a/openstack/common/rpc/impl_zmq.py +++ b/openstack/common/rpc/impl_zmq.py @@ -52,7 +52,7 @@ zmq_opts = [ default=('openstack.common.rpc.' 'matchmaker.MatchMakerLocalhost'), help='MatchMaker driver', - ), + ), # The following port is unassigned by IANA as of 2012-05-21 cfg.IntOpt('rpc_zmq_port', default=9501, diff --git a/openstack/common/version.py b/openstack/common/version.py index ca350ed9a..86de0c604 100644 --- a/openstack/common/version.py +++ b/openstack/common/version.py @@ -107,7 +107,7 @@ class VersionInfo(object): versioninfo = "%s/versioninfo" % self.package try: raw_version = pkg_resources.resource_string(requirement, - versioninfo) + versioninfo) self.version = self._newer_version(raw_version.strip()) except (IOError, pkg_resources.DistributionNotFound): self.version = self._generate_version() diff --git a/setup.py b/setup.py index 76161fb10..e6ae7ee53 100644 --- a/setup.py +++ b/setup.py @@ -22,32 +22,33 @@ from openstack.common import setup requires = setup.parse_requirements() depend_links = setup.parse_dependency_links() -setuptools.setup(name='openstack.common', - version=setup.get_post_version('openstack'), - description="Common components for Openstack", - long_description="Common components for Openstack " - "including paster templates.", - classifiers=[ - 'Development Status :: 4 - Beta', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: POSIX :: Linux', - 'Programming Language :: Python :: 2.6', - 'Environment :: No Input/Output (Daemon)', ], - keywords='openstack', - author='OpenStack', - author_email='openstack@lists.launchpad.net', - url='http://www.openstack.org/', - license='Apache Software License', - packages=setuptools.find_packages(exclude=['ez_setup', - 'examples', 'tests']), - include_package_data=True, - cmdclass=setup.get_cmdclass(), - zip_safe=True, - install_requires=requires, - dependency_links=depend_links, - setup_requires=['setuptools-git>=0.4'], - entry_points=""" +setuptools.setup( + name='openstack.common', + version=setup.get_post_version('openstack'), + description="Common components for Openstack", + long_description="Common components for Openstack " + "including paster templates.", + classifiers=[ + 'Development Status :: 4 - Beta', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python :: 2.6', + 'Environment :: No Input/Output (Daemon)', ], + keywords='openstack', + author='OpenStack', + author_email='openstack@lists.launchpad.net', + url='http://www.openstack.org/', + license='Apache Software License', + packages=setuptools.find_packages(exclude=['ez_setup', + 'examples', 'tests']), + include_package_data=True, + cmdclass=setup.get_cmdclass(), + zip_safe=True, + install_requires=requires, + dependency_links=depend_links, + setup_requires=['setuptools-git>=0.4'], + entry_points=""" # -*- Entry points: -*- """, - namespace_packages=['openstack'], - ) + namespace_packages=['openstack'], +) diff --git a/tests/unit/notifier/test_list_notifier.py b/tests/unit/notifier/test_list_notifier.py index 5708a4304..c4410675c 100644 --- a/tests/unit/notifier/test_list_notifier.py +++ b/tests/unit/notifier/test_list_notifier.py @@ -42,7 +42,7 @@ class NotifierListTestCase(test_utils.BaseTestCase): self.exception_count = 0 list_notifier_log = logging.getLogger( - 'openstack.common.notifier.list_notifier') + 'openstack.common.notifier.list_notifier') self.stubs.Set(list_notifier_log, "exception", mock_exception) # Mock no_op notifier to add one to notify_count when called. @@ -65,11 +65,11 @@ class NotifierListTestCase(test_utils.BaseTestCase): def test_send_notifications_successfully(self): self.config(notification_driver='openstack.common.' 'notifier.list_notifier', - list_notifier_drivers=[ - 'openstack.common.notifier.no_op_notifier', - 'openstack.common.notifier.no_op_notifier']) + list_notifier_drivers=[ + 'openstack.common.notifier.no_op_notifier', + 'openstack.common.notifier.no_op_notifier']) api.notify('contextarg', 'publisher_id', 'event_type', - api.WARN, dict(a=3)) + api.WARN, dict(a=3)) self.assertEqual(self.notify_count, 2) self.assertEqual(self.exception_count, 0) @@ -77,23 +77,23 @@ class NotifierListTestCase(test_utils.BaseTestCase): self.config(notification_driver='openstack.common.' 'notifier.list_notifier', - list_notifier_drivers=[ - 'openstack.common.notifier.no_op_notifier', - 'openstack.common.notifier.log_notifier']) + list_notifier_drivers=[ + 'openstack.common.notifier.no_op_notifier', + 'openstack.common.notifier.log_notifier']) api.notify('contextarg', 'publisher_id', - 'event_type', api.WARN, dict(a=3)) + 'event_type', api.WARN, dict(a=3)) self.assertEqual(self.notify_count, 1) self.assertEqual(self.exception_count, 1) def test_when_driver_fails_to_import(self): self.config(notification_driver='openstack.common.' 'notifier.list_notifier', - list_notifier_drivers=[ - 'openstack.common.notifier.no_op_notifier', - 'openstack.common.notifier.logo_notifier', - 'fdsjgsdfhjkhgsfkj']) + list_notifier_drivers=[ + 'openstack.common.notifier.no_op_notifier', + 'openstack.common.notifier.logo_notifier', + 'fdsjgsdfhjkhgsfkj']) api.notify('contextarg', 'publisher_id', - 'event_type', api.WARN, dict(a=3)) + 'event_type', api.WARN, dict(a=3)) self.assertEqual(self.exception_count, 2) self.assertEqual(self.notify_count, 1) @@ -101,12 +101,12 @@ class NotifierListTestCase(test_utils.BaseTestCase): self.notifier_object = SimpleNotifier() self.config(notification_driver='openstack.common.' 'notifier.list_notifier', - list_notifier_drivers=[ - 'openstack.common.notifier.no_op_notifier']) + list_notifier_drivers=[ + 'openstack.common.notifier.no_op_notifier']) list_notifier.add_driver(self.notifier_object) api.notify(None, 'publisher_id', 'event_type', - api.WARN, dict(a=3)) + api.WARN, dict(a=3)) self.assertEqual(self.notify_count, 1) self.assertTrue(self.notifier_object.notified) @@ -114,22 +114,22 @@ class NotifierListTestCase(test_utils.BaseTestCase): list_notifier.remove_driver(self.notifier_object) api.notify(None, 'publisher_id', 'event_type', - api.WARN, dict(a=3)) + api.WARN, dict(a=3)) self.assertEqual(self.notify_count, 2) self.assertFalse(self.notifier_object.notified) def test_adding_and_removing_notifier_module(self): self.config(notification_driver='openstack.common.' 'notifier.list_notifier', - list_notifier_drivers=[]) + list_notifier_drivers=[]) list_notifier.add_driver('openstack.common.notifier.no_op_notifier') api.notify(None, 'publisher_id', 'event_type', - api.WARN, dict(a=3)) + api.WARN, dict(a=3)) self.assertEqual(self.notify_count, 1) list_notifier.remove_driver('openstack.common.notifier.no_op_notifier') api.notify(None, 'publisher_id', 'event_type', - api.WARN, dict(a=3)) + api.WARN, dict(a=3)) self.assertEqual(self.notify_count, 1) diff --git a/tests/unit/plugin/test_callback_plugin.py b/tests/unit/plugin/test_callback_plugin.py index a9503920d..c747ec80a 100644 --- a/tests/unit/plugin/test_callback_plugin.py +++ b/tests/unit/plugin/test_callback_plugin.py @@ -59,7 +59,7 @@ class CallbackTestCase(test_utils.BaseTestCase): return [MockEntrypoint("fake", "fake", ["fake"])] self.stubs.Set(pkg_resources, 'iter_entry_points', - mock_iter_entry_points) + mock_iter_entry_points) plugmgr = pluginmanager.PluginManager("testproject", "testservice") plugmgr.load_plugins() diff --git a/tests/unit/test_importutils.py b/tests/unit/test_importutils.py index c41f13bda..4c9ff73a6 100644 --- a/tests/unit/test_importutils.py +++ b/tests/unit/test_importutils.py @@ -65,7 +65,7 @@ class ImportUtilsTest(unittest.TestCase): def test_import_object_ns_optional_arg_present(self): obj = importutils.import_object_ns('tests.unit', 'fake.FakeDriver', - first_arg=False) + first_arg=False) self.assertTrue(obj.__class__.__name__, 'FakeDriver') def test_import_object_ns_required_arg_not_present(self): @@ -75,7 +75,7 @@ class ImportUtilsTest(unittest.TestCase): def test_import_object_ns_required_arg_present(self): obj = importutils.import_object_ns('tests.unit', 'fake.FakeDriver2', - first_arg=False) + first_arg=False) self.assertTrue(obj.__class__.__name__, 'FakeDriver2') # namespace tests diff --git a/tests/unit/test_log.py b/tests/unit/test_log.py index 8eaffca12..83c318f0d 100644 --- a/tests/unit/test_log.py +++ b/tests/unit/test_log.py @@ -59,12 +59,12 @@ class LogHandlerTestCase(test_utils.BaseTestCase): def test_log_path_logdir(self): self.config(logdir='/some/path', logfile=None) self.assertEquals(log._get_log_file_path(binary='foo-bar'), - '/some/path/foo-bar.log') + '/some/path/foo-bar.log') def test_log_path_logfile(self): self.config(logfile='/some/path/foo-bar.log') self.assertEquals(log._get_log_file_path(binary='foo-bar'), - '/some/path/foo-bar.log') + '/some/path/foo-bar.log') def test_log_path_none(self): self.config(logdir=None, logfile=None) @@ -72,9 +72,9 @@ class LogHandlerTestCase(test_utils.BaseTestCase): def test_log_path_logfile_overrides_logdir(self): self.config(logdir='/some/other/path', - logfile='/some/path/foo-bar.log') + logfile='/some/path/foo-bar.log') self.assertEquals(log._get_log_file_path(binary='foo-bar'), - '/some/path/foo-bar.log') + '/some/path/foo-bar.log') class PublishErrorsHandlerTestCase(test_utils.BaseTestCase): @@ -117,7 +117,7 @@ class LoggerTestCase(test_utils.BaseTestCase): levels = CONF.default_log_levels levels.append("nova-test=AUDIT") self.config(default_log_levels=levels, - verbose=True) + verbose=True) log.setup('testing') self.log = log.getLogger('nova-test') diff --git a/tests/unit/test_notifier.py b/tests/unit/test_notifier.py index 4e1c8129c..0ffc35c57 100644 --- a/tests/unit/test_notifier.py +++ b/tests/unit/test_notifier.py @@ -42,7 +42,7 @@ class NotifierTestCase(test_utils.BaseTestCase): self.notify_called = True self.stubs.Set(no_op_notifier, 'notify', - mock_notify) + mock_notify) notifier_api.notify(ctxt, 'publisher_id', 'event_type', notifier_api.WARN, dict(a=3)) @@ -64,13 +64,13 @@ class NotifierTestCase(test_utils.BaseTestCase): self.assertEqual(context, ctxt) self.stubs.Set(no_op_notifier, 'notify', - message_assert) + message_assert) notifier_api.notify(ctxt, 'publisher_id', 'event_type', notifier_api.WARN, dict(a=3)) def test_send_rabbit_notification(self): self.stubs.Set(cfg.CONF, 'notification_driver', - 'openstack.common.notifier.rabbit_notifier') + 'openstack.common.notifier.rabbit_notifier') self.mock_notify = False def mock_notify(cls, *args): @@ -84,12 +84,12 @@ class NotifierTestCase(test_utils.BaseTestCase): def test_invalid_priority(self): self.assertRaises(notifier_api.BadPriorityException, - notifier_api.notify, ctxt, 'publisher_id', - 'event_type', 'not a priority', dict(a=3)) + notifier_api.notify, ctxt, 'publisher_id', + 'event_type', 'not a priority', dict(a=3)) def test_rabbit_priority_queue(self): self.stubs.Set(cfg.CONF, 'notification_driver', - 'openstack.common.notifier.rabbit_notifier') + 'openstack.common.notifier.rabbit_notifier') self.stubs.Set(cfg.CONF, 'notification_topics', ['testnotify', ]) @@ -105,7 +105,7 @@ class NotifierTestCase(test_utils.BaseTestCase): def test_error_notification(self): self.stubs.Set(cfg.CONF, 'notification_driver', - 'openstack.common.notifier.rabbit_notifier') + 'openstack.common.notifier.rabbit_notifier') self.stubs.Set(cfg.CONF, 'publish_errors', True) LOG = log.getLogger('common') log.setup(None) @@ -129,14 +129,14 @@ class NotifierTestCase(test_utils.BaseTestCase): return arg1 + arg2 example_api = notifier_api.notify_decorator( - 'example_api', - example_api) + 'example_api', + example_api) def mock_notify(cls, *args): self.notify_called = True self.stubs.Set(no_op_notifier, 'notify', - mock_notify) + mock_notify) self.assertEqual(3, example_api(1, 2)) self.assertEqual(self.notify_called, True) @@ -153,19 +153,19 @@ class NotifierTestCase(test_utils.BaseTestCase): return arg1 + arg2 example_api = notifier_api.notify_decorator( - 'example_api', - example_api) + 'example_api', + example_api) example_api2 = notifier_api.notify_decorator( - 'example_api2', - example_api2) + 'example_api2', + example_api2) def mock_notify(context, cls, _type, _priority, _payload): self.notify_called = True self.context_arg = context self.stubs.Set(notifier_api, 'notify', - mock_notify) + mock_notify) # Test positional context self.assertEqual(3, example_api(1, 2, ctxt)) diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py index 01665ba60..31f2e7a7b 100644 --- a/tests/unit/test_plugin.py +++ b/tests/unit/test_plugin.py @@ -57,7 +57,7 @@ class NotifyTestCase(test_utils.BaseTestCase): # Set up a 'normal' notifier to make sure the plugin logic # doesn't mess anything up. self.stubs.Set(cfg.CONF, 'notification_driver', - SimplerNotifier()) + SimplerNotifier()) global simpler_notify_called simpler_notify_called = False @@ -82,7 +82,7 @@ class NotifyTestCase(test_utils.BaseTestCase): return [MockEntrypoint("fake", "fake", ["fake"])] self.stubs.Set(pkg_resources, 'iter_entry_points', - mock_iter_entry_points) + mock_iter_entry_points) plugmgr = pluginmanager.PluginManager("testproject", "testservice") plugmgr.load_plugins() @@ -141,7 +141,7 @@ class APITestCase(test_utils.BaseTestCase): return [MockEntrypoint("fake", "fake", ["fake"])] self.stubs.Set(pkg_resources, 'iter_entry_points', - mock_iter_entry_points) + mock_iter_entry_points) stubLoaded = False diff --git a/tox.ini b/tox.ini index 6437a5cdf..8753533f7 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ commands = nosetests {posargs} [testenv:pep8] deps = pep8==1.1 -commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc,*.egg . +commands = pep8 --repeat --show-source --ignore=E125 --exclude=.venv,.tox,dist,doc,*.egg . [testenv:cover] setenv = NOSE_WITH_COVERAGE=1 diff --git a/update.py b/update.py index 724794fcf..849c183d2 100644 --- a/update.py +++ b/update.py @@ -78,7 +78,7 @@ opts = [ cfg.StrOpt('dest-dir', default=None, help='Destination project directory'), - ] +] def _parse_args(argv):