# Buggy code
def main():
    argument_spec = openstack_full_argument_spec(
        display_name=dict(required=True, aliases=["name"]),
        display_description=dict(default=None, aliases=["description"]),
        volume=dict(required=True),
        force=dict(required=False, default=False, type="bool"),
        state=dict(default="present", choices=["absent", "present"]),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, supports_check_mode=True, **module_kwargs)

    sdk, cloud = openstack_cloud_from_module(module)

    state = module.params["state"]

    try:
        if cloud.volume_exists(module.params["volume"]):
            if module.check_mode:
                module.exit_json(changed=_system_state_change(module, cloud))
            if state == "present":
                _present_volume_snapshot(module, cloud)
            if state == "absent":
                _absent_volume_snapshot(module, cloud)
        else:
            module.fail_json(
                msg="No volume with name or id '{0}' was found.".format(
                    module.params["volume"]
                )
            )
    except (
        sdk.exceptions.OpenStackCloudException,
        sdk.exceptions.OpenStackCloudTimeout,
    ) as e:
        module.fail_json(msg=e.message)


# Traceback (AttributeError)
TASK [Destroy test volume] ********************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'module' object has no attribute 'OpenStackCloudTimeout'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_6aYn_b/ansible_module_os_volume.py\", line 168, in <module>\n    main()\n  File \"/tmp/ansible_6aYn_b/ansible_module_os_volume.py\", line 162, in main\n    _absent_volume(module, cloud, sdk)\n  File \"/tmp/ansible_6aYn_b/ansible_module_os_volume.py\", line 127, in _absent_volume\n    except sdk.exceptions.OpenStackCloudTimeout:\nAttributeError: 'module' object has no attribute 'OpenStackCloudTimeout'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}
to retry, use: --limit @/home/dcarrillo/datio/iluvatar/deployer/ansible/roles/tools/backup/snapshots/molecule/default/destroy.retry

# Fixed code
def main():
    argument_spec = openstack_full_argument_spec(
        display_name=dict(required=True, aliases=["name"]),
        display_description=dict(default=None, aliases=["description"]),
        volume=dict(required=True),
        force=dict(required=False, default=False, type="bool"),
        state=dict(default="present", choices=["absent", "present"]),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, supports_check_mode=True, **module_kwargs)

    sdk, cloud = openstack_cloud_from_module(module)

    state = module.params["state"]

    try:
        if cloud.volume_exists(module.params["volume"]):
            if module.check_mode:
                module.exit_json(changed=_system_state_change(module, cloud))
            if state == "present":
                _present_volume_snapshot(module, cloud)
            if state == "absent":
                _absent_volume_snapshot(module, cloud)
        else:
            module.fail_json(
                msg="No volume with name or id '{0}' was found.".format(
                    module.params["volume"]
                )
            )
    except (
        sdk.exceptions.OpenStackCloudException,
        sdk.exceptions.ResourceTimeout,
    ) as e:
        module.fail_json(msg=e.message)