Update common code to support pep 1.3.
bug 1014216 Change-Id: I3f8fa2e11c9d3f3d34fb20f65ce886bb9c94463d
This commit is contained in:
@@ -607,11 +607,9 @@ class Opt(object):
|
||||
dest = self.dest
|
||||
if group is not None:
|
||||
dest = group.name + '_' + dest
|
||||
kwargs.update({
|
||||
'dest': dest,
|
||||
kwargs.update({'dest': dest,
|
||||
'metavar': self.metavar,
|
||||
'help': self.help,
|
||||
})
|
||||
'help': self.help, })
|
||||
return kwargs
|
||||
|
||||
def _get_optparse_prefix(self, prefix, group):
|
||||
@@ -1452,8 +1450,7 @@ class ConfigOpts(collections.Mapping):
|
||||
default, opt, override = [info[k] for k in sorted(info.keys())]
|
||||
|
||||
if opt.required:
|
||||
if (default is not None or
|
||||
override is not None):
|
||||
if (default is not None or override is not None):
|
||||
continue
|
||||
|
||||
if self._get(opt.name, group) is None:
|
||||
|
||||
@@ -253,8 +253,7 @@ class ExtensionMiddleware(wsgi.Middleware):
|
||||
return request_ext_resources
|
||||
|
||||
def __init__(self, application, config, ext_mgr=None):
|
||||
ext_mgr = ext_mgr or ExtensionManager(
|
||||
config['api_extensions_path'])
|
||||
ext_mgr = ext_mgr or ExtensionManager(config['api_extensions_path'])
|
||||
mapper = routes.Mapper()
|
||||
|
||||
# extended resources
|
||||
|
||||
@@ -56,7 +56,7 @@ rpc_opts = [
|
||||
cfg.BoolOpt('fake_rabbit',
|
||||
default=False,
|
||||
help='If passed, use a fake RabbitMQ provider'),
|
||||
]
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(rpc_opts)
|
||||
|
||||
|
||||
@@ -92,7 +92,8 @@ class ConnectionContext(rpc_common.Connection):
|
||||
if pooled:
|
||||
self.connection = connection_pool.get()
|
||||
else:
|
||||
self.connection = connection_pool.connection_cls(conf,
|
||||
self.connection = connection_pool.connection_cls(
|
||||
conf,
|
||||
server_params=server_params)
|
||||
self.pooled = pooled
|
||||
|
||||
@@ -288,8 +289,8 @@ class ProxyCallback(object):
|
||||
class MulticallWaiter(object):
|
||||
def __init__(self, conf, connection, timeout):
|
||||
self._connection = connection
|
||||
self._iterator = connection.iterconsume(
|
||||
timeout=timeout or conf.rpc_response_timeout)
|
||||
self._iterator = connection.iterconsume(timeout=timeout or
|
||||
conf.rpc_response_timeout)
|
||||
self._result = None
|
||||
self._done = False
|
||||
self._got_ending = False
|
||||
|
||||
@@ -167,10 +167,8 @@ class Connection(object):
|
||||
|
||||
def _safe_log(log_func, msg, msg_data):
|
||||
"""Sanitizes the msg_data field before logging."""
|
||||
SANITIZE = {
|
||||
'set_admin_password': ('new_pass',),
|
||||
'run_instance': ('admin_password',),
|
||||
}
|
||||
SANITIZE = {'set_admin_password': ('new_pass',),
|
||||
'run_instance': ('admin_password',), }
|
||||
|
||||
has_method = 'method' in msg_data and msg_data['method'] in SANITIZE
|
||||
has_context_token = '_context_auth_token' in msg_data
|
||||
|
||||
@@ -80,7 +80,7 @@ kombu_opts = [
|
||||
default=False,
|
||||
help='use durable queues in RabbitMQ'),
|
||||
|
||||
]
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(kombu_opts)
|
||||
|
||||
@@ -174,13 +174,11 @@ class DirectConsumer(ConsumerBase):
|
||||
'auto_delete': True,
|
||||
'exclusive': True}
|
||||
options.update(kwargs)
|
||||
exchange = kombu.entity.Exchange(
|
||||
name=msg_id,
|
||||
exchange = kombu.entity.Exchange(name=msg_id,
|
||||
type='direct',
|
||||
durable=options['durable'],
|
||||
auto_delete=options['auto_delete'])
|
||||
super(DirectConsumer, self).__init__(
|
||||
channel,
|
||||
super(DirectConsumer, self).__init__(channel,
|
||||
callback,
|
||||
tag,
|
||||
name=msg_id,
|
||||
@@ -211,13 +209,11 @@ class TopicConsumer(ConsumerBase):
|
||||
'auto_delete': False,
|
||||
'exclusive': False}
|
||||
options.update(kwargs)
|
||||
exchange = kombu.entity.Exchange(
|
||||
name=conf.control_exchange,
|
||||
exchange = kombu.entity.Exchange(name=conf.control_exchange,
|
||||
type='topic',
|
||||
durable=options['durable'],
|
||||
auto_delete=options['auto_delete'])
|
||||
super(TopicConsumer, self).__init__(
|
||||
channel,
|
||||
super(TopicConsumer, self).__init__(channel,
|
||||
callback,
|
||||
tag,
|
||||
name=name or topic,
|
||||
@@ -248,15 +244,10 @@ class FanoutConsumer(ConsumerBase):
|
||||
'auto_delete': True,
|
||||
'exclusive': True}
|
||||
options.update(kwargs)
|
||||
exchange = kombu.entity.Exchange(
|
||||
name=exchange_name,
|
||||
type='fanout',
|
||||
exchange = kombu.entity.Exchange(name=exchange_name, type='fanout',
|
||||
durable=options['durable'],
|
||||
auto_delete=options['auto_delete'])
|
||||
super(FanoutConsumer, self).__init__(
|
||||
channel,
|
||||
callback,
|
||||
tag,
|
||||
super(FanoutConsumer, self).__init__(channel, callback, tag,
|
||||
name=queue_name,
|
||||
exchange=exchange,
|
||||
routing_key=topic,
|
||||
@@ -280,7 +271,8 @@ class Publisher(object):
|
||||
self.exchange = kombu.entity.Exchange(name=self.exchange_name,
|
||||
**self.kwargs)
|
||||
self.producer = kombu.messaging.Producer(exchange=self.exchange,
|
||||
channel=channel, routing_key=self.routing_key)
|
||||
channel=channel,
|
||||
routing_key=self.routing_key)
|
||||
|
||||
def send(self, msg):
|
||||
"""Send a message"""
|
||||
@@ -299,11 +291,8 @@ class DirectPublisher(Publisher):
|
||||
'auto_delete': True,
|
||||
'exclusive': True}
|
||||
options.update(kwargs)
|
||||
super(DirectPublisher, self).__init__(channel,
|
||||
msg_id,
|
||||
msg_id,
|
||||
type='direct',
|
||||
**options)
|
||||
super(DirectPublisher, self).__init__(channel, msg_id, msg_id,
|
||||
type='direct', **options)
|
||||
|
||||
|
||||
class TopicPublisher(Publisher):
|
||||
@@ -317,11 +306,8 @@ class TopicPublisher(Publisher):
|
||||
'auto_delete': False,
|
||||
'exclusive': False}
|
||||
options.update(kwargs)
|
||||
super(TopicPublisher, self).__init__(channel,
|
||||
conf.control_exchange,
|
||||
topic,
|
||||
type='topic',
|
||||
**options)
|
||||
super(TopicPublisher, self).__init__(channel, conf.control_exchange,
|
||||
topic, type='topic', **options)
|
||||
|
||||
|
||||
class FanoutPublisher(Publisher):
|
||||
@@ -335,11 +321,8 @@ class FanoutPublisher(Publisher):
|
||||
'auto_delete': True,
|
||||
'exclusive': True}
|
||||
options.update(kwargs)
|
||||
super(FanoutPublisher, self).__init__(channel,
|
||||
'%s_fanout' % topic,
|
||||
None,
|
||||
type='fanout',
|
||||
**options)
|
||||
super(FanoutPublisher, self).__init__(channel, '%s_fanout' % topic,
|
||||
None, type='fanout', **options)
|
||||
|
||||
|
||||
class NotifyPublisher(TopicPublisher):
|
||||
@@ -453,8 +436,7 @@ class Connection(object):
|
||||
# Setting this in case the next statement fails, though
|
||||
# it shouldn't be doing any network operations, yet.
|
||||
self.connection = None
|
||||
self.connection = kombu.connection.BrokerConnection(
|
||||
**self.params)
|
||||
self.connection = kombu.connection.BrokerConnection(**self.params)
|
||||
self.connection_errors = self.connection.connection_errors
|
||||
if self.memory_transport:
|
||||
# Kludge to speed up tests.
|
||||
@@ -691,7 +673,8 @@ class Connection(object):
|
||||
|
||||
def create_consumer(self, topic, proxy, fanout=False):
|
||||
"""Create a consumer that calls a method in a proxy object"""
|
||||
proxy_cb = rpc_amqp.ProxyCallback(self.conf, proxy,
|
||||
proxy_cb = rpc_amqp.ProxyCallback(
|
||||
self.conf, proxy,
|
||||
rpc_amqp.get_connection_pool(self.conf, Connection))
|
||||
|
||||
if fanout:
|
||||
@@ -701,56 +684,65 @@ class Connection(object):
|
||||
|
||||
def create_worker(self, topic, proxy, pool_name):
|
||||
"""Create a worker that calls a method in a proxy object"""
|
||||
proxy_cb = rpc_amqp.ProxyCallback(self.conf, proxy,
|
||||
proxy_cb = rpc_amqp.ProxyCallback(
|
||||
self.conf, proxy,
|
||||
rpc_amqp.get_connection_pool(self.conf, Connection))
|
||||
self.declare_topic_consumer(topic, proxy_cb, pool_name)
|
||||
|
||||
|
||||
def create_connection(conf, new=True):
|
||||
"""Create a connection"""
|
||||
return rpc_amqp.create_connection(conf, new,
|
||||
return rpc_amqp.create_connection(
|
||||
conf, new,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def multicall(conf, context, topic, msg, timeout=None):
|
||||
"""Make a call that returns multiple times."""
|
||||
return rpc_amqp.multicall(conf, context, topic, msg, timeout,
|
||||
return rpc_amqp.multicall(
|
||||
conf, context, topic, msg, timeout,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def call(conf, context, topic, msg, timeout=None):
|
||||
"""Sends a message on a topic and wait for a response."""
|
||||
return rpc_amqp.call(conf, context, topic, msg, timeout,
|
||||
return rpc_amqp.call(
|
||||
conf, context, topic, msg, timeout,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def cast(conf, context, topic, msg):
|
||||
"""Sends a message on a topic without waiting for a response."""
|
||||
return rpc_amqp.cast(conf, context, topic, msg,
|
||||
return rpc_amqp.cast(
|
||||
conf, context, topic, msg,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def fanout_cast(conf, context, topic, msg):
|
||||
"""Sends a message on a fanout exchange without waiting for a response."""
|
||||
return rpc_amqp.fanout_cast(conf, context, topic, msg,
|
||||
return rpc_amqp.fanout_cast(
|
||||
conf, context, topic, msg,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def cast_to_server(conf, context, server_params, topic, msg):
|
||||
"""Sends a message on a topic to a specific server."""
|
||||
return rpc_amqp.cast_to_server(conf, context, server_params, topic, msg,
|
||||
return rpc_amqp.cast_to_server(
|
||||
conf, context, server_params, topic, msg,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def fanout_cast_to_server(conf, context, server_params, topic, msg):
|
||||
"""Sends a message on a fanout exchange to a specific server."""
|
||||
return rpc_amqp.cast_to_server(conf, context, server_params, topic, msg,
|
||||
return rpc_amqp.cast_to_server(
|
||||
conf, context, server_params, topic, msg,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def notify(conf, context, topic, msg):
|
||||
"""Sends a notification event on a topic."""
|
||||
return rpc_amqp.notify(conf, context, topic, msg,
|
||||
return rpc_amqp.notify(
|
||||
conf, context, topic, msg,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ qpid_opts = [
|
||||
cfg.BoolOpt('qpid_tcp_nodelay',
|
||||
default=True,
|
||||
help='Disable Nagle algorithm'),
|
||||
]
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(qpid_opts)
|
||||
|
||||
@@ -181,8 +181,9 @@ class TopicConsumer(ConsumerBase):
|
||||
"""
|
||||
|
||||
super(TopicConsumer, self).__init__(session, callback,
|
||||
"%s/%s" % (conf.control_exchange, topic), {},
|
||||
name or topic, {})
|
||||
"%s/%s" % (conf.control_exchange,
|
||||
topic),
|
||||
{}, name or topic, {})
|
||||
|
||||
|
||||
class FanoutConsumer(ConsumerBase):
|
||||
@@ -196,7 +197,8 @@ class FanoutConsumer(ConsumerBase):
|
||||
'callback' is the callback to call when messages are received
|
||||
"""
|
||||
|
||||
super(FanoutConsumer, self).__init__(session, callback,
|
||||
super(FanoutConsumer, self).__init__(
|
||||
session, callback,
|
||||
"%s_fanout" % topic,
|
||||
{"durable": False, "type": "fanout"},
|
||||
"%s_fanout_%s" % (topic, uuid.uuid4().hex),
|
||||
@@ -254,7 +256,8 @@ class TopicPublisher(Publisher):
|
||||
def __init__(self, conf, session, topic):
|
||||
"""init a 'topic' publisher.
|
||||
"""
|
||||
super(TopicPublisher, self).__init__(session,
|
||||
super(TopicPublisher, self).__init__(
|
||||
session,
|
||||
"%s/%s" % (conf.control_exchange, topic))
|
||||
|
||||
|
||||
@@ -263,7 +266,8 @@ class FanoutPublisher(Publisher):
|
||||
def __init__(self, conf, session, topic):
|
||||
"""init a 'fanout' publisher.
|
||||
"""
|
||||
super(FanoutPublisher, self).__init__(session,
|
||||
super(FanoutPublisher, self).__init__(
|
||||
session,
|
||||
"%s_fanout" % topic, {"type": "fanout"})
|
||||
|
||||
|
||||
@@ -272,7 +276,8 @@ class NotifyPublisher(Publisher):
|
||||
def __init__(self, conf, session, topic):
|
||||
"""init a 'topic' publisher.
|
||||
"""
|
||||
super(NotifyPublisher, self).__init__(session,
|
||||
super(NotifyPublisher, self).__init__(
|
||||
session,
|
||||
"%s/%s" % (conf.control_exchange, topic),
|
||||
{"durable": True})
|
||||
|
||||
@@ -508,7 +513,8 @@ class Connection(object):
|
||||
|
||||
def create_consumer(self, topic, proxy, fanout=False):
|
||||
"""Create a consumer that calls a method in a proxy object"""
|
||||
proxy_cb = rpc_amqp.ProxyCallback(self.conf, proxy,
|
||||
proxy_cb = rpc_amqp.ProxyCallback(
|
||||
self.conf, proxy,
|
||||
rpc_amqp.get_connection_pool(self.conf, Connection))
|
||||
|
||||
if fanout:
|
||||
@@ -522,7 +528,8 @@ class Connection(object):
|
||||
|
||||
def create_worker(self, topic, proxy, pool_name):
|
||||
"""Create a worker that calls a method in a proxy object"""
|
||||
proxy_cb = rpc_amqp.ProxyCallback(self.conf, proxy,
|
||||
proxy_cb = rpc_amqp.ProxyCallback(
|
||||
self.conf, proxy,
|
||||
rpc_amqp.get_connection_pool(self.conf, Connection))
|
||||
|
||||
consumer = TopicConsumer(self.conf, self.session, topic, proxy_cb,
|
||||
@@ -535,44 +542,51 @@ class Connection(object):
|
||||
|
||||
def create_connection(conf, new=True):
|
||||
"""Create a connection"""
|
||||
return rpc_amqp.create_connection(conf, new,
|
||||
return rpc_amqp.create_connection(
|
||||
conf, new,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def multicall(conf, context, topic, msg, timeout=None):
|
||||
"""Make a call that returns multiple times."""
|
||||
return rpc_amqp.multicall(conf, context, topic, msg, timeout,
|
||||
return rpc_amqp.multicall(
|
||||
conf, context, topic, msg, timeout,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def call(conf, context, topic, msg, timeout=None):
|
||||
"""Sends a message on a topic and wait for a response."""
|
||||
return rpc_amqp.call(conf, context, topic, msg, timeout,
|
||||
return rpc_amqp.call(
|
||||
conf, context, topic, msg, timeout,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def cast(conf, context, topic, msg):
|
||||
"""Sends a message on a topic without waiting for a response."""
|
||||
return rpc_amqp.cast(conf, context, topic, msg,
|
||||
return rpc_amqp.cast(
|
||||
conf, context, topic, msg,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def fanout_cast(conf, context, topic, msg):
|
||||
"""Sends a message on a fanout exchange without waiting for a response."""
|
||||
return rpc_amqp.fanout_cast(conf, context, topic, msg,
|
||||
return rpc_amqp.fanout_cast(
|
||||
conf, context, topic, msg,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def cast_to_server(conf, context, server_params, topic, msg):
|
||||
"""Sends a message on a topic to a specific server."""
|
||||
return rpc_amqp.cast_to_server(conf, context, server_params, topic, msg,
|
||||
return rpc_amqp.cast_to_server(
|
||||
conf, context, server_params, topic, msg,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def fanout_cast_to_server(conf, context, server_params, topic, msg):
|
||||
"""Sends a message on a fanout exchange to a specific server."""
|
||||
return rpc_amqp.fanout_cast_to_server(conf, context, server_params, topic,
|
||||
msg, rpc_amqp.get_connection_pool(conf, Connection))
|
||||
return rpc_amqp.fanout_cast_to_server(
|
||||
conf, context, server_params, topic, msg,
|
||||
rpc_amqp.get_connection_pool(conf, Connection))
|
||||
|
||||
|
||||
def notify(conf, context, topic, msg):
|
||||
|
||||
@@ -42,7 +42,8 @@ zmq_opts = [
|
||||
cfg.StrOpt('rpc_zmq_bind_address', default='*',
|
||||
help='ZeroMQ bind address. Should be a wildcard (*), '
|
||||
'an ethernet interface, or IP. '
|
||||
'The "host" option should point or resolve to this address.'),
|
||||
'The "host" option should point or resolve to this '
|
||||
'address.'),
|
||||
|
||||
# The module.Class to use for matchmaking.
|
||||
cfg.StrOpt('rpc_zmq_matchmaker',
|
||||
@@ -58,7 +59,7 @@ zmq_opts = [
|
||||
|
||||
cfg.StrOpt('rpc_zmq_ipc_dir', default='/var/run/openstack',
|
||||
help='Directory for holding IPC sockets'),
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
# These globals are defined in register_opts(conf),
|
||||
@@ -353,8 +354,7 @@ class ZmqBaseReactor(ConsumerBase):
|
||||
raise RPCException("Bad output socktype")
|
||||
|
||||
# Items push out.
|
||||
outq = ZmqSocket(out_addr, zmq_type_out,
|
||||
bind=out_bind)
|
||||
outq = ZmqSocket(out_addr, zmq_type_out, bind=out_bind)
|
||||
|
||||
self.mapping[inq] = outq
|
||||
self.mapping[outq] = inq
|
||||
|
||||
3
setup.py
3
setup.py
@@ -20,8 +20,7 @@ setup(name='openstack.common',
|
||||
'License :: OSI Approved :: Apache Software License',
|
||||
'Operating System :: POSIX :: Linux',
|
||||
'Programming Language :: Python :: 2.6',
|
||||
'Environment :: No Input/Output (Daemon)',
|
||||
],
|
||||
'Environment :: No Input/Output (Daemon)', ],
|
||||
keywords='openstack',
|
||||
author='OpenStack',
|
||||
author_email='openstack@lists.launchpad.net',
|
||||
|
||||
@@ -87,17 +87,21 @@ class RpcDispatcherTestCase(unittest.TestCase):
|
||||
self._test_dispatch('3.1', (None, None, self.ctxt, 1))
|
||||
|
||||
def test_dispatch_higher_minor_version(self):
|
||||
self.assertRaises(rpc_common.UnsupportedRpcVersion,
|
||||
self.assertRaises(
|
||||
rpc_common.UnsupportedRpcVersion,
|
||||
self._test_dispatch, '2.6', (None, None, None, None))
|
||||
self.assertRaises(rpc_common.UnsupportedRpcVersion,
|
||||
self.assertRaises(
|
||||
rpc_common.UnsupportedRpcVersion,
|
||||
self._test_dispatch, '3.6', (None, None, None, None))
|
||||
|
||||
def test_dispatch_lower_major_version(self):
|
||||
self.assertRaises(rpc_common.UnsupportedRpcVersion,
|
||||
self.assertRaises(
|
||||
rpc_common.UnsupportedRpcVersion,
|
||||
self._test_dispatch, '1.0', (None, None, None, None))
|
||||
|
||||
def test_dispatch_higher_major_version(self):
|
||||
self.assertRaises(rpc_common.UnsupportedRpcVersion,
|
||||
self.assertRaises(
|
||||
rpc_common.UnsupportedRpcVersion,
|
||||
self._test_dispatch, '4.0', (None, None, None, None))
|
||||
|
||||
def test_dispatch_no_version_uses_v1(self):
|
||||
|
||||
@@ -166,7 +166,8 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
|
||||
class MyConnection(impl_kombu.Connection):
|
||||
def __init__(myself, *args, **kwargs):
|
||||
super(MyConnection, myself).__init__(*args, **kwargs)
|
||||
self.assertEqual(myself.params,
|
||||
self.assertEqual(
|
||||
myself.params,
|
||||
{'hostname': FLAGS.rabbit_host,
|
||||
'userid': FLAGS.rabbit_userid,
|
||||
'password': FLAGS.rabbit_password,
|
||||
@@ -198,7 +199,8 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase):
|
||||
class MyConnection(impl_kombu.Connection):
|
||||
def __init__(myself, *args, **kwargs):
|
||||
super(MyConnection, myself).__init__(*args, **kwargs)
|
||||
self.assertEqual(myself.params,
|
||||
self.assertEqual(
|
||||
myself.params,
|
||||
{'hostname': server_params['hostname'],
|
||||
'userid': server_params['username'],
|
||||
'password': server_params['password'],
|
||||
|
||||
@@ -120,7 +120,8 @@ class RpcProxyTestCase(unittest.TestCase):
|
||||
self._test_rpc_method('cast_to_server', server_params={'blah': 1})
|
||||
|
||||
def test_fanout_cast_to_server(self):
|
||||
self._test_rpc_method('fanout_cast_to_server',
|
||||
self._test_rpc_method(
|
||||
'fanout_cast_to_server',
|
||||
server_params={'blah': 1}, supports_topic_override=False)
|
||||
|
||||
def test_make_msg(self):
|
||||
|
||||
@@ -124,14 +124,16 @@ class RpcQpidTestCase(unittest.TestCase):
|
||||
self.mock_connection.session().AndReturn(self.mock_session)
|
||||
if fanout:
|
||||
# The link name includes a UUID, so match it with a regex.
|
||||
expected_address = mox.Regex(r'^impl_qpid_test_fanout ; '
|
||||
expected_address = mox.Regex(
|
||||
r'^impl_qpid_test_fanout ; '
|
||||
'{"node": {"x-declare": {"auto-delete": true, "durable": '
|
||||
'false, "type": "fanout"}, "type": "topic"}, "create": '
|
||||
'"always", "link": {"x-declare": {"auto-delete": true, '
|
||||
'"exclusive": true, "durable": false}, "durable": true, '
|
||||
'"name": "impl_qpid_test_fanout_.*"}}$')
|
||||
else:
|
||||
expected_address = ('nova/impl_qpid_test ; {"node": {"x-declare": '
|
||||
expected_address = (
|
||||
'nova/impl_qpid_test ; {"node": {"x-declare": '
|
||||
'{"auto-delete": true, "durable": true}, "type": "topic"}, '
|
||||
'"create": "always", "link": {"x-declare": {"auto-delete": '
|
||||
'true, "exclusive": false, "durable": false}, "durable": '
|
||||
@@ -196,12 +198,14 @@ class RpcQpidTestCase(unittest.TestCase):
|
||||
|
||||
self.mock_connection.session().AndReturn(self.mock_session)
|
||||
if fanout:
|
||||
expected_address = ('impl_qpid_test_fanout ; '
|
||||
expected_address = (
|
||||
'impl_qpid_test_fanout ; '
|
||||
'{"node": {"x-declare": {"auto-delete": true, '
|
||||
'"durable": false, "type": "fanout"}, '
|
||||
'"type": "topic"}, "create": "always"}')
|
||||
else:
|
||||
expected_address = ('nova/impl_qpid_test ; {"node": {"x-declare": '
|
||||
expected_address = (
|
||||
'nova/impl_qpid_test ; {"node": {"x-declare": '
|
||||
'{"auto-delete": true, "durable": false}, "type": "topic"}, '
|
||||
'"create": "always"}')
|
||||
self.mock_session.sender(expected_address).AndReturn(self.mock_sender)
|
||||
@@ -290,14 +294,16 @@ class RpcQpidTestCase(unittest.TestCase):
|
||||
self.mock_connection.opened().AndReturn(False)
|
||||
self.mock_connection.open()
|
||||
self.mock_connection.session().AndReturn(self.mock_session)
|
||||
rcv_addr = mox.Regex(r'^.*/.* ; {"node": {"x-declare": {"auto-delete":'
|
||||
rcv_addr = mox.Regex(
|
||||
r'^.*/.* ; {"node": {"x-declare": {"auto-delete":'
|
||||
' true, "durable": true, "type": "direct"}, "type": '
|
||||
'"topic"}, "create": "always", "link": {"x-declare": '
|
||||
'{"auto-delete": true, "exclusive": true, "durable": '
|
||||
'false}, "durable": true, "name": ".*"}}')
|
||||
self.mock_session.receiver(rcv_addr).AndReturn(self.mock_receiver)
|
||||
self.mock_receiver.capacity = 1
|
||||
send_addr = ('nova/impl_qpid_test ; {"node": {"x-declare": '
|
||||
send_addr = (
|
||||
'nova/impl_qpid_test ; {"node": {"x-declare": '
|
||||
'{"auto-delete": true, "durable": false}, "type": "topic"}, '
|
||||
'"create": "always"}')
|
||||
self.mock_session.sender(send_addr).AndReturn(self.mock_sender)
|
||||
@@ -312,15 +318,13 @@ class RpcQpidTestCase(unittest.TestCase):
|
||||
self.mock_session.next_receiver(timeout=mox.IsA(int)).AndReturn(
|
||||
self.mock_receiver)
|
||||
self.mock_receiver.fetch().AndReturn(
|
||||
qpid.messaging.Message(
|
||||
{"result": "bar", "failure": False,
|
||||
qpid.messaging.Message({"result": "bar", "failure": False,
|
||||
"ending": False}))
|
||||
self.mock_session.acknowledge(mox.IgnoreArg())
|
||||
self.mock_session.next_receiver(timeout=mox.IsA(int)).AndReturn(
|
||||
self.mock_receiver)
|
||||
self.mock_receiver.fetch().AndReturn(
|
||||
qpid.messaging.Message(
|
||||
{"result": "baz", "failure": False,
|
||||
qpid.messaging.Message({"result": "baz", "failure": False,
|
||||
"ending": False}))
|
||||
self.mock_session.acknowledge(mox.IgnoreArg())
|
||||
self.mock_session.next_receiver(timeout=mox.IsA(int)).AndReturn(
|
||||
|
||||
@@ -87,16 +87,17 @@ class _RpcZmqBaseTestCase(common.BaseRpcTestCase):
|
||||
consumption_proxy = impl_zmq.InternalContext(None)
|
||||
|
||||
self.reactor.register(consumption_proxy,
|
||||
consume_in, zmq.PULL, out_bind=True)
|
||||
consume_in,
|
||||
zmq.PULL,
|
||||
out_bind=True)
|
||||
self.reactor.consume_in_thread()
|
||||
except zmq.ZMQError:
|
||||
assert False, _("Could not create ZeroMQ receiver daemon. "
|
||||
"Socket may already be in use.")
|
||||
except OSError:
|
||||
assert False, _("Could not create IPC directory %s") % \
|
||||
(ipc_dir, )
|
||||
assert False, _("Could not create IPC directory %s") % (ipc_dir, )
|
||||
finally:
|
||||
super(_RpcZmqBaseTestCase, self).setUp(
|
||||
super(RpcZmqBaseTestCase, self).setUp(
|
||||
topic=topic, topic_nested=topic_nested)
|
||||
|
||||
def tearDown(self):
|
||||
|
||||
@@ -306,8 +306,7 @@ class ConfigFileOptsTestCase(BaseTestCase):
|
||||
def test_conf_file_str_default(self):
|
||||
self.conf.register_opt(StrOpt('foo', default='bar'))
|
||||
|
||||
paths = self.create_tempfiles([('test',
|
||||
'[DEFAULT]\n')])
|
||||
paths = self.create_tempfiles([('test', '[DEFAULT]\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
@@ -317,9 +316,7 @@ class ConfigFileOptsTestCase(BaseTestCase):
|
||||
def test_conf_file_str_value(self):
|
||||
self.conf.register_opt(StrOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('test',
|
||||
'[DEFAULT]\n'
|
||||
'foo = bar\n')])
|
||||
paths = self.create_tempfiles([('test', '[DEFAULT]\n''foo = bar\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
@@ -1412,8 +1409,8 @@ class OptDumpingTestCase(BaseTestCase):
|
||||
self.assertEquals(logger.logged, [
|
||||
"*" * 80,
|
||||
"Configuration options gathered from:",
|
||||
"command line args: ['--foo', 'this', '--blaa-bar', 'that', "
|
||||
"'--blaa-key', 'admin', '--passwd', 'hush']",
|
||||
"command line args: ['--foo', 'this', '--blaa-bar', "
|
||||
"'that', '--blaa-key', 'admin', '--passwd', 'hush']",
|
||||
"config files: []",
|
||||
"=" * 80,
|
||||
"config_dir = None",
|
||||
|
||||
@@ -65,7 +65,8 @@ class ResourceExtensionTest(unittest.TestCase):
|
||||
return {'collection': 'value'}
|
||||
|
||||
def test_resource_can_be_added_as_extension(self):
|
||||
res_ext = extensions.ResourceExtension('tweedles',
|
||||
res_ext = extensions.ResourceExtension(
|
||||
'tweedles',
|
||||
self.ResourceExtensionController())
|
||||
test_app = setup_extensions_app(SimpleExtensionManager(res_ext))
|
||||
|
||||
@@ -179,7 +180,8 @@ class ActionExtensionTest(unittest.TestCase):
|
||||
action_name = 'FOXNSOX:add_tweedle'
|
||||
action_params = dict(name='Beetle')
|
||||
req_body = json.dumps({action_name: action_params})
|
||||
response = self.extension_app.post('/dummy_resources/1/action',
|
||||
response = self.extension_app.post(
|
||||
'/dummy_resources/1/action',
|
||||
req_body, content_type='application/json')
|
||||
|
||||
self.assertEqual("Tweedle Beetle Added.", response.json)
|
||||
@@ -188,7 +190,8 @@ class ActionExtensionTest(unittest.TestCase):
|
||||
action_name = 'FOXNSOX:delete_tweedle'
|
||||
action_params = dict(name='Bailey')
|
||||
req_body = json.dumps({action_name: action_params})
|
||||
response = self.extension_app.post("/dummy_resources/1/action",
|
||||
response = self.extension_app.post(
|
||||
"/dummy_resources/1/action",
|
||||
req_body, content_type='application/json')
|
||||
self.assertEqual("Tweedle Bailey Deleted.", response.json)
|
||||
|
||||
@@ -197,7 +200,8 @@ class ActionExtensionTest(unittest.TestCase):
|
||||
action_params = dict(name="test")
|
||||
req_body = json.dumps({non_existant_action: action_params})
|
||||
|
||||
response = self.extension_app.post("/dummy_resources/1/action",
|
||||
response = self.extension_app.post(
|
||||
"/dummy_resources/1/action",
|
||||
req_body, content_type='application/json',
|
||||
status='*')
|
||||
|
||||
@@ -208,7 +212,8 @@ class ActionExtensionTest(unittest.TestCase):
|
||||
action_params = dict(name='Beetle')
|
||||
req_body = json.dumps({action_name: action_params})
|
||||
|
||||
response = self.extension_app.post("/asdf/1/action", req_body,
|
||||
response = self.extension_app.post(
|
||||
"/asdf/1/action", req_body,
|
||||
content_type='application/json', status='*')
|
||||
self.assertEqual(404, response.status_int)
|
||||
|
||||
@@ -270,13 +275,15 @@ class RequestExtensionTest(unittest.TestCase):
|
||||
|
||||
ext_app = self._setup_app_with_request_handler(_update_handler,
|
||||
'PUT')
|
||||
ext_response = ext_app.put("/dummy_resources/1",
|
||||
ext_response = ext_app.put(
|
||||
"/dummy_resources/1",
|
||||
json.dumps({'uneditable': "new_value"}),
|
||||
headers={'Content-Type': "application/json"})
|
||||
self.assertEqual(ext_response.json['uneditable'], "new_value")
|
||||
|
||||
def _setup_app_with_request_handler(self, handler, verb):
|
||||
req_ext = extensions.RequestExtension(verb,
|
||||
req_ext = extensions.RequestExtension(
|
||||
verb,
|
||||
'/dummy_resources/:(id)', handler)
|
||||
manager = SimpleExtensionManager(None, None, req_ext)
|
||||
return setup_extensions_app(manager)
|
||||
@@ -312,7 +319,8 @@ class ExtensionControllerTest(unittest.TestCase):
|
||||
response = self.test_app.get("/extensions")
|
||||
foxnsox = response.json["extensions"][0]
|
||||
|
||||
self.assertEqual(foxnsox, {
|
||||
self.assertEqual(
|
||||
foxnsox, {
|
||||
'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
|
||||
'name': 'Fox In Socks',
|
||||
'updated': '2011-01-22T13:25:27-06:00',
|
||||
@@ -326,7 +334,8 @@ class ExtensionControllerTest(unittest.TestCase):
|
||||
json_response = self.test_app.get("/extensions/FOXNSOX").json
|
||||
foxnsox = json_response['extension']
|
||||
|
||||
self.assertEqual(foxnsox, {
|
||||
self.assertEqual(
|
||||
foxnsox, {
|
||||
'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0',
|
||||
'name': 'Fox In Socks',
|
||||
'updated': '2011-01-22T13:25:27-06:00',
|
||||
@@ -352,10 +361,12 @@ class ExtensionControllerTest(unittest.TestCase):
|
||||
exts = root.findall('{0}extension'.format(NS))
|
||||
fox_ext = exts[0]
|
||||
self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
|
||||
self.assertEqual(fox_ext.get('namespace'),
|
||||
self.assertEqual(
|
||||
fox_ext.get('namespace'),
|
||||
'http://www.fox.in.socks/api/ext/pie/v1.0')
|
||||
self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00')
|
||||
self.assertEqual(fox_ext.findtext('{0}description'.format(NS)),
|
||||
self.assertEqual(
|
||||
fox_ext.findtext('{0}description'.format(NS)),
|
||||
'The Fox In Socks Extension')
|
||||
|
||||
def test_get_extension_xml(self):
|
||||
@@ -367,10 +378,12 @@ class ExtensionControllerTest(unittest.TestCase):
|
||||
self.assertEqual(root.tag.split('extension')[0], NS)
|
||||
self.assertEqual(root.get('alias'), 'FOXNSOX')
|
||||
self.assertEqual(root.get('name'), 'Fox In Socks')
|
||||
self.assertEqual(root.get('namespace'),
|
||||
self.assertEqual(
|
||||
root.get('namespace'),
|
||||
'http://www.fox.in.socks/api/ext/pie/v1.0')
|
||||
self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00')
|
||||
self.assertEqual(root.findtext('{0}description'.format(NS)),
|
||||
self.assertEqual(
|
||||
root.findtext('{0}description'.format(NS)),
|
||||
'The Fox In Socks Extension')
|
||||
|
||||
|
||||
@@ -399,13 +412,15 @@ class ExtensionsXMLSerializerTest(unittest.TestCase):
|
||||
|
||||
def test_serialize_extenstion(self):
|
||||
serializer = extensions.ExtensionsXMLSerializer()
|
||||
data = {'extension': {
|
||||
data = {
|
||||
'extension': {
|
||||
'name': 'ext1',
|
||||
'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0',
|
||||
'alias': 'RS-PIE',
|
||||
'updated': '2011-01-22T13:25:27-06:00',
|
||||
'description': 'Adds the capability to share an image.',
|
||||
'links': [{'rel': 'describedby',
|
||||
'links': [
|
||||
{'rel': 'describedby',
|
||||
'type': 'application/pdf',
|
||||
'href': 'http://docs.rack.com/servers/api/ext/cs.pdf'},
|
||||
{'rel': 'describedby',
|
||||
@@ -429,7 +444,8 @@ class ExtensionsXMLSerializerTest(unittest.TestCase):
|
||||
|
||||
def test_serialize_extensions(self):
|
||||
serializer = extensions.ExtensionsXMLSerializer()
|
||||
data = {"extensions": [{
|
||||
data = {
|
||||
"extensions": [{
|
||||
"name": "Public Image Extension",
|
||||
"namespace": "http://foo.com/api/ext/pie/v1.0",
|
||||
"alias": "RS-PIE",
|
||||
|
||||
@@ -131,10 +131,12 @@ class BrainTestCase(unittest.TestCase):
|
||||
}"""
|
||||
brain = policy.Brain.load_json(exemplar, "default")
|
||||
|
||||
self.assertEqual(brain.rules, dict(
|
||||
self.assertEqual(
|
||||
brain.rules, dict(
|
||||
admin_or_owner=[["role:admin"], ["project_id:%(project_id)s"]],
|
||||
default=[],
|
||||
))
|
||||
)
|
||||
)
|
||||
self.assertEqual(brain.default_rule, "default")
|
||||
|
||||
def test_add_rule(self):
|
||||
@@ -142,7 +144,8 @@ class BrainTestCase(unittest.TestCase):
|
||||
brain.add_rule("rule1",
|
||||
[["role:admin"], ["project_id:%(project_id)s"]])
|
||||
|
||||
self.assertEqual(brain.rules, dict(
|
||||
self.assertEqual(
|
||||
brain.rules, dict(
|
||||
rule1=[["role:admin"], ["project_id:%(project_id)s"]]))
|
||||
|
||||
def test_check_with_badmatch(self):
|
||||
|
||||
@@ -412,7 +412,8 @@ class ResourceTest(unittest.TestCase):
|
||||
|
||||
def test_malformed_request_body_throws_bad_request(self):
|
||||
resource = wsgi.Resource(None)
|
||||
request = wsgi.Request.blank("/", body="{mal:formed", method='POST',
|
||||
request = wsgi.Request.blank(
|
||||
"/", body="{mal:formed", method='POST',
|
||||
headers={'Content-Type': "application/json"})
|
||||
|
||||
response = resource(request)
|
||||
|
||||
Reference in New Issue
Block a user