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