diff --git a/oslo/messaging/_drivers/amqp.py b/oslo/messaging/_drivers/amqp.py index 8c073bc5e..565061e3f 100644 --- a/oslo/messaging/_drivers/amqp.py +++ b/oslo/messaging/_drivers/amqp.py @@ -29,6 +29,7 @@ import threading import uuid from oslo.config import cfg +import six from oslo.messaging._drivers import common as rpc_common from oslo.messaging._drivers import pool @@ -293,13 +294,12 @@ def pack_context(msg, context): """ if isinstance(context, dict): - context_d = dict([('_context_%s' % key, value) - for (key, value) in context.iteritems()]) + context_d = six.iteritems(context) else: - context_d = dict([('_context_%s' % key, value) - for (key, value) in context.to_dict().iteritems()]) + context_d = six.iteritems(context.to_dict()) - msg.update(context_d) + msg.update(('_context_%s' % key, value) + for (key, value) in context_d) class _MsgIdCache(object): diff --git a/oslo/messaging/_drivers/common.py b/oslo/messaging/_drivers/common.py index ebec95098..724f09a21 100644 --- a/oslo/messaging/_drivers/common.py +++ b/oslo/messaging/_drivers/common.py @@ -97,7 +97,7 @@ class RPCException(Exception): # kwargs doesn't match a variable in the message # log the issue and the kwargs LOG.exception(_('Exception in string format operation')) - for name, value in kwargs.iteritems(): + for name, value in six.iteritems(kwargs): LOG.error("%s: %s" % (name, value)) # at least get the core message out if something happened message = self.msg_fmt diff --git a/oslo/messaging/_drivers/impl_rabbit.py b/oslo/messaging/_drivers/impl_rabbit.py index c0084f92e..f81defe7d 100644 --- a/oslo/messaging/_drivers/impl_rabbit.py +++ b/oslo/messaging/_drivers/impl_rabbit.py @@ -440,7 +440,7 @@ class Connection(object): 'virtual_host': self.conf.rabbit_virtual_host, } - for sp_key, value in server_params.iteritems(): + for sp_key, value in six.iteritems(server_params): p_key = server_params_to_kombu_params.get(sp_key, sp_key) params[p_key] = value diff --git a/oslo/messaging/rpc/client.py b/oslo/messaging/rpc/client.py index 84692d470..dd22b8a22 100644 --- a/oslo/messaging/rpc/client.py +++ b/oslo/messaging/rpc/client.py @@ -24,6 +24,7 @@ __all__ = [ ] from oslo.config import cfg +import six from oslo.messaging._drivers import base as driver_base from oslo.messaging import _utils as utils @@ -98,7 +99,7 @@ class _CallContext(object): msg = dict(method=method) msg['args'] = dict() - for argname, arg in args.iteritems(): + for argname, arg in six.iteritems(args): msg['args'][argname] = self.serializer.serialize_entity(ctxt, arg) if self.target.namespace is not None: diff --git a/oslo/messaging/rpc/dispatcher.py b/oslo/messaging/rpc/dispatcher.py index e876ee0cc..28148443f 100644 --- a/oslo/messaging/rpc/dispatcher.py +++ b/oslo/messaging/rpc/dispatcher.py @@ -23,6 +23,8 @@ __all__ = [ 'UnsupportedVersion', ] +import six + from oslo.messaging import _utils as utils from oslo.messaging import localcontext from oslo.messaging import serializer as msg_serializer @@ -85,7 +87,7 @@ class RPCDispatcher(object): def _dispatch(self, endpoint, method, ctxt, args): ctxt = self.serializer.deserialize_context(ctxt) new_args = dict() - for argname, arg in args.iteritems(): + for argname, arg in six.iteritems(args): new_args[argname] = self.serializer.deserialize_entity(ctxt, arg) result = getattr(endpoint, method)(ctxt, **new_args) return self.serializer.serialize_entity(ctxt, result) diff --git a/tests/utils.py b/tests/utils.py index ae77197df..55170ba1e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -25,6 +25,7 @@ import os import fixtures from oslo.config import cfg +import six import testtools from oslo.messaging.openstack.common.fixture import moxstubout @@ -79,5 +80,5 @@ class BaseTestCase(testtools.TestCase): test by the tearDown() method. """ group = kw.pop('group', None) - for k, v in kw.iteritems(): + for k, v in six.iteritems(kw): self.conf.set_override(k, v, group)