diff --git a/lib/ansible/modules/cloud/cloudstack/cs_affinitygroup.py b/lib/ansible/modules/cloud/cloudstack/cs_affinitygroup.py index 3a5f858c53..d5fc273647 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_affinitygroup.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_affinitygroup.py @@ -128,8 +128,13 @@ account: sample: example account ''' -# import cloudstack common -from ansible.module_utils.cloudstack import * +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.cloudstack import ( + AnsibleCloudStack, + CloudStackException, + cs_argument_spec, + cs_required_together +) class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): @@ -166,7 +171,7 @@ class AnsibleCloudStackAffinityGroup(AnsibleCloudStack): for a in affinity_types['affinityGroupType']: if a['type'] == affinity_type: return a['type'] - self.module.fail_json(msg="affinity group type '%s' not found" % affinity_type) + self.module.fail_json(msg="affinity group type not found: %s" % affinity_type) def create_affinity_group(self): affinity_group = self.get_affinity_group() @@ -219,12 +224,12 @@ def main(): argument_spec = cs_argument_spec() argument_spec.update(dict( name=dict(required=True), - affinty_type=dict(default=None), - description=dict(default=None), + affinty_type=dict(), + description=dict(), state=dict(choices=['present', 'absent'], default='present'), - domain=dict(default=None), - account=dict(default=None), - project=dict(default=None), + domain=dict(), + account=dict(), + project=dict(), poll_async=dict(type='bool', default=True), )) @@ -250,7 +255,6 @@ def main(): module.exit_json(**result) -# import module snippets -from ansible.module_utils.basic import * + if __name__ == '__main__': main() diff --git a/test/integration/targets/cs_affinitygroup/tasks/main.yml b/test/integration/targets/cs_affinitygroup/tasks/main.yml index ea24484661..5bf5bb3c34 100644 --- a/test/integration/targets/cs_affinitygroup/tasks/main.yml +++ b/test/integration/targets/cs_affinitygroup/tasks/main.yml @@ -1,6 +1,8 @@ --- - name: setup - cs_affinitygroup: name={{ cs_resource_prefix }}_ag state=absent + cs_affinitygroup: + name: "{{ cs_resource_prefix }}_ag" + state: absent register: ag - name: verify setup assert: @@ -8,7 +10,7 @@ - ag|success - name: test fail if missing name - action: cs_affinitygroup + cs_affinitygroup: register: ag ignore_errors: true - name: verify results of fail if missing name @@ -17,6 +19,18 @@ - ag|failed - "ag.msg == 'missing required arguments: name'" +- name: test fail unknown affinity type + cs_affinitygroup: + name: "{{ cs_resource_prefix }}_ag" + affinty_type: unexistent affinity type + register: ag + ignore_errors: true +- name: verify test fail unknown affinity type + assert: + that: + - ag|failed + - "ag.msg == 'affinity group type not found: unexistent affinity type'" + - name: test present affinity group in check mode cs_affinitygroup: name={{ cs_resource_prefix }}_ag register: ag