mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Remove uses of assert in production code (#32079)
* Remove uses of assert in production code * Fix assertion * Add code smell test for assertions, currently limited to lib/ansible * Fix assertion * Add docs for no-assert * Remove new assert from enos * Fix assert in module_utils.connection
This commit is contained in:
@@ -285,7 +285,8 @@ def check_dp_status(client, dp_id, status):
|
||||
:returns: True or False
|
||||
|
||||
"""
|
||||
assert isinstance(status, list)
|
||||
if not isinstance(status, list):
|
||||
raise AssertionError()
|
||||
if pipeline_field(client, dp_id, field="@pipelineState") in status:
|
||||
return True
|
||||
else:
|
||||
|
||||
@@ -380,7 +380,8 @@ class ClcGroup(object):
|
||||
changed: Boolean- whether a change was made,
|
||||
group: A clc group object for the group
|
||||
"""
|
||||
assert self.root_group, "Implementation Error: Root Group not set"
|
||||
if not self.root_group:
|
||||
raise AssertionError("Implementation Error: Root Group not set")
|
||||
parent = parent_name if parent_name is not None else self.root_group.name
|
||||
description = group_description
|
||||
changed = False
|
||||
|
||||
@@ -237,7 +237,8 @@ class Droplet(JsonfyMixIn):
|
||||
self.update_attr(json)
|
||||
|
||||
def power_on(self):
|
||||
assert self.status == 'off', 'Can only power on a closed one.'
|
||||
if self.status != 'off':
|
||||
raise AssertionError('Can only power on a closed one.')
|
||||
json = self.manager.power_on_droplet(self.id)
|
||||
self.update_attr(json)
|
||||
|
||||
|
||||
@@ -424,8 +424,10 @@ class PyVmomiDeviceHelper(object):
|
||||
diskspec.device.backing.diskMode = 'persistent'
|
||||
diskspec.device.controllerKey = scsi_ctl.device.key
|
||||
|
||||
assert self.next_disk_unit_number != 7
|
||||
assert disk_index != 7
|
||||
if self.next_disk_unit_number == 7:
|
||||
raise AssertionError()
|
||||
if disk_index == 7:
|
||||
raise AssertionError()
|
||||
"""
|
||||
Configure disk unit number.
|
||||
"""
|
||||
@@ -1127,7 +1129,8 @@ class PyVmomiHelper(PyVmomi):
|
||||
return datastore, datastore_name
|
||||
|
||||
def obj_has_parent(self, obj, parent):
|
||||
assert obj is not None and parent is not None
|
||||
if obj is None and parent is None:
|
||||
raise AssertionError()
|
||||
current_parent = obj
|
||||
|
||||
while True:
|
||||
@@ -1573,7 +1576,7 @@ def main():
|
||||
result["failed"] = False
|
||||
else:
|
||||
# This should not happen
|
||||
assert False
|
||||
raise AssertionError()
|
||||
# VM doesn't exist
|
||||
else:
|
||||
if module.params['state'] in ['poweredon', 'poweredoff', 'present', 'restarted', 'suspended']:
|
||||
|
||||
@@ -342,7 +342,7 @@ class PyVmomiHelper(object):
|
||||
task = vm.RemoveAllSnapshots()
|
||||
else:
|
||||
# This should not happen
|
||||
assert False
|
||||
raise AssertionError()
|
||||
|
||||
if task:
|
||||
self.wait_for_task(task)
|
||||
|
||||
Reference in New Issue
Block a user