Merge "Replace assert to raise AssertionError"
This commit is contained in:
commit
3c29c3846e
@ -98,7 +98,8 @@ def paginate_query(query, model, limit, sort_keys, marker=None,
|
|||||||
# the actual primary key, rather than assuming its id
|
# the actual primary key, rather than assuming its id
|
||||||
LOG.warning('Id not in sort_keys; is sort_keys unique?')
|
LOG.warning('Id not in sort_keys; is sort_keys unique?')
|
||||||
|
|
||||||
assert(not (sort_dir and sort_dirs))
|
if sort_dir and sort_dirs:
|
||||||
|
raise AssertionError('Both sort_dir and sort_dirs specified.')
|
||||||
|
|
||||||
# Default the sort direction to ascending
|
# Default the sort direction to ascending
|
||||||
if sort_dirs is None and sort_dir is None:
|
if sort_dirs is None and sort_dir is None:
|
||||||
@ -108,7 +109,9 @@ def paginate_query(query, model, limit, sort_keys, marker=None,
|
|||||||
if sort_dirs is None:
|
if sort_dirs is None:
|
||||||
sort_dirs = [sort_dir for _sort_key in sort_keys]
|
sort_dirs = [sort_dir for _sort_key in sort_keys]
|
||||||
|
|
||||||
assert(len(sort_dirs) == len(sort_keys))
|
if len(sort_dirs) != len(sort_keys):
|
||||||
|
raise AssertionError(
|
||||||
|
'sort_dirs length is not equal to sort_keys length.')
|
||||||
|
|
||||||
# Add sorting
|
# Add sorting
|
||||||
for current_sort_key, current_sort_dir in zip(sort_keys, sort_dirs):
|
for current_sort_key, current_sort_dir in zip(sort_keys, sort_dirs):
|
||||||
|
@ -139,7 +139,8 @@ class RequestContextSerializer(messaging.Serializer):
|
|||||||
|
|
||||||
|
|
||||||
def get_client(target, version_cap=None, serializer=None):
|
def get_client(target, version_cap=None, serializer=None):
|
||||||
assert TRANSPORT is not None
|
if TRANSPORT is None:
|
||||||
|
raise AssertionError('RPC transport is not initialized.')
|
||||||
serializer = RequestContextSerializer(serializer)
|
serializer = RequestContextSerializer(serializer)
|
||||||
return messaging.RPCClient(TRANSPORT,
|
return messaging.RPCClient(TRANSPORT,
|
||||||
target,
|
target,
|
||||||
@ -148,7 +149,8 @@ def get_client(target, version_cap=None, serializer=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_server(target, endpoints, serializer=None):
|
def get_server(target, endpoints, serializer=None):
|
||||||
assert TRANSPORT is not None
|
if TRANSPORT is None:
|
||||||
|
raise AssertionError('RPC transport is not initialized.')
|
||||||
serializer = RequestContextSerializer(serializer)
|
serializer = RequestContextSerializer(serializer)
|
||||||
access_policy = dispatcher.DefaultRPCAccessPolicy
|
access_policy = dispatcher.DefaultRPCAccessPolicy
|
||||||
return messaging.get_rpc_server(TRANSPORT,
|
return messaging.get_rpc_server(TRANSPORT,
|
||||||
@ -161,7 +163,8 @@ def get_server(target, endpoints, serializer=None):
|
|||||||
|
|
||||||
@utils.if_notifications_enabled
|
@utils.if_notifications_enabled
|
||||||
def get_notifier(service=None, host=None, publisher_id=None):
|
def get_notifier(service=None, host=None, publisher_id=None):
|
||||||
assert NOTIFIER is not None
|
if NOTIFIER is None:
|
||||||
|
raise AssertionError('RPC Notifier is not initialized.')
|
||||||
if not publisher_id:
|
if not publisher_id:
|
||||||
publisher_id = "%s.%s" % (service, host or CONF.host)
|
publisher_id = "%s.%s" % (service, host or CONF.host)
|
||||||
return NOTIFIER.prepare(publisher_id=publisher_id)
|
return NOTIFIER.prepare(publisher_id=publisher_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user