Merge "Replace assert to raise AssertionError"

This commit is contained in:
Zuul
2018-04-11 20:10:34 +00:00
committed by Gerrit Code Review
5 changed files with 23 additions and 11 deletions

View File

@@ -157,7 +157,9 @@ def _moved_global(old_name, new_module=None, new_name=None):
:type new_name: str :type new_name: str
""" """
assert new_module or new_name # One or both must be new if not (new_module or new_name):
raise AssertionError("'new_module' and 'new_name' "
"must not be both None")
if isinstance(new_module, _MovedGlobals): if isinstance(new_module, _MovedGlobals):
# The new module has been shimmed, get the original # The new module has been shimmed, get the original
new_module = new_module._mg__old_ref new_module = new_module._mg__old_ref

View File

@@ -64,9 +64,12 @@ def init(conf, rpc_ext_mods=None):
def cleanup(): def cleanup():
global TRANSPORT, NOTIFICATION_TRANSPORT, NOTIFIER global TRANSPORT, NOTIFICATION_TRANSPORT, NOTIFIER
assert TRANSPORT is not None if TRANSPORT is None:
assert NOTIFICATION_TRANSPORT is not None raise AssertionError("'TRANSPORT' must not be None")
assert NOTIFIER is not None if NOTIFICATION_TRANSPORT is None:
raise AssertionError("'NOTIFICATION_TRANSPORT' must not be None")
if NOTIFIER is None:
raise AssertionError("'NOTIFIER' must not be None")
TRANSPORT.cleanup() TRANSPORT.cleanup()
NOTIFICATION_TRANSPORT.cleanup() NOTIFICATION_TRANSPORT.cleanup()
_BackingOffContextWrapper.reset_timeouts() _BackingOffContextWrapper.reset_timeouts()
@@ -192,7 +195,8 @@ class BackingOffClient(oslo_messaging.RPCClient):
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("'TRANSPORT' must not be None")
serializer = RequestContextSerializer(serializer) serializer = RequestContextSerializer(serializer)
return BackingOffClient(TRANSPORT, return BackingOffClient(TRANSPORT,
target, target,
@@ -201,7 +205,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("'TRANSPORT' must not be None")
serializer = RequestContextSerializer(serializer) serializer = RequestContextSerializer(serializer)
access_policy = dispatcher.DefaultRPCAccessPolicy access_policy = dispatcher.DefaultRPCAccessPolicy
return oslo_messaging.get_rpc_server(TRANSPORT, target, endpoints, return oslo_messaging.get_rpc_server(TRANSPORT, target, endpoints,
@@ -210,7 +215,8 @@ def get_server(target, endpoints, serializer=None):
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("'NOTIFIER' must not be None")
if not publisher_id: if not publisher_id:
publisher_id = "%s.%s" % (service, host or cfg.CONF.host) publisher_id = "%s.%s" % (service, host or cfg.CONF.host)
return NOTIFIER.prepare(publisher_id=publisher_id) return NOTIFIER.prepare(publisher_id=publisher_id)

View File

@@ -282,4 +282,7 @@ def load_one_to_manys(session):
continue continue
if relationship_attr.key not in state.dict: if relationship_attr.key not in state.dict:
getattr(new_object, relationship_attr.key) getattr(new_object, relationship_attr.key)
assert relationship_attr.key in state.dict if relationship_attr.key not in state.dict:
msg = ("Relationship %s attributes must be loaded in db"
" object %s" % (relationship_attr.key, state.dict))
raise AssertionError(msg)

View File

@@ -42,7 +42,9 @@ _CORE_RESOURCES = {net_def.RESOURCE_NAME: net_def.COLLECTION_NAME,
def _load_version_info(version_info): def _load_version_info(version_info):
assert version_info['id'] not in _VERSION_INFO if version_info['id'] in _VERSION_INFO:
raise AssertionError("ID %s must not be in "
"VERSION_INFO" % version_info['id'])
_VERSION_INFO[version_info['id']] = version_info _VERSION_INFO[version_info['id']] = version_info

View File

@@ -165,13 +165,12 @@ import_exceptions = neutron._i18n
local-check-factory = neutron.hacking.checks.factory local-check-factory = neutron.hacking.checks.factory
[testenv:bandit] [testenv:bandit]
# B101: Use of assert detected
# B104: Possible binding to all interfaces # B104: Possible binding to all interfaces
# B108: Probable insecure usage of temp file/directory # B108: Probable insecure usage of temp file/directory
# B111: Execute with run_as_root=True identified, possible security issue # B111: Execute with run_as_root=True identified, possible security issue
# B311: Standard pseudo-random generators are not suitable for security/cryptographic purpose # B311: Standard pseudo-random generators are not suitable for security/cryptographic purpose
deps = -r{toxinidir}/test-requirements.txt deps = -r{toxinidir}/test-requirements.txt
commands = bandit -r neutron -x tests -n5 -s B101,B104,B108,B111,B311 commands = bandit -r neutron -x tests -n5 -s B104,B108,B111,B311
[testenv:bashate] [testenv:bashate]
commands = bash -c "find {toxinidir} \ commands = bash -c "find {toxinidir} \