From 9fe3891d65458e7db8aa0d4f28e673ec13375e05 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sun, 28 May 2017 01:01:38 +0200 Subject: [PATCH] cloudstack: fix pep8 cs_cluster --- .../modules/cloud/cloudstack/cs_cluster.py | 63 ++++++++++--------- .../targets/cs_cluster/tasks/main.yml | 15 +++++ test/sanity/pep8/legacy-files.txt | 1 - 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/lib/ansible/modules/cloud/cloudstack/cs_cluster.py b/lib/ansible/modules/cloud/cloudstack/cs_cluster.py index 2fb31ad0dc..5645ebf9b7 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_cluster.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_cluster.py @@ -231,8 +231,14 @@ pod: sample: pod01 ''' -# 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, + CS_HYPERVISORS +) class AnsibleCloudStackCluster(AnsibleCloudStack): @@ -240,14 +246,14 @@ class AnsibleCloudStackCluster(AnsibleCloudStack): def __init__(self, module): super(AnsibleCloudStackCluster, self).__init__(module) self.returns = { - 'allocationstate': 'allocation_state', - 'hypervisortype': 'hypervisor', - 'clustertype': 'cluster_type', - 'podname': 'pod', - 'managedstate': 'managed_state', + 'allocationstate': 'allocation_state', + 'hypervisortype': 'hypervisor', + 'clustertype': 'cluster_type', + 'podname': 'pod', + 'managedstate': 'managed_state', 'memoryovercommitratio': 'memory_overcommit_ratio', - 'cpuovercommitratio': 'cpu_overcommit_ratio', - 'ovm3vip': 'ovm3_vip', + 'cpuovercommitratio': 'cpu_overcommit_ratio', + 'ovm3vip': 'ovm3_vip', } self.cluster = None @@ -270,7 +276,7 @@ class AnsibleCloudStackCluster(AnsibleCloudStack): pods = self.cs.listPods(**args) if pods: return self._get_by_key(key, pods['pod'][0]) - self.module.fail_json(msg="Pod %s not found in zone %s." % (self.module.params.get('pod'), self.get_zone(key='name'))) + self.module.fail_json(msg="Pod %s not found in zone %s" % (self.module.params.get('pod'), self.get_zone(key='name'))) def get_cluster(self): if not self.cluster: @@ -374,24 +380,24 @@ def main(): argument_spec = cs_argument_spec() argument_spec.update(dict( name=dict(required=True), - zone=dict(default=None), - pod=dict(default=None), - cluster_type=dict(choices=['CloudManaged', 'ExternalManaged'], default=None), - hypervisor=dict(choices=CS_HYPERVISORS, default=None), + zone=dict(), + pod=dict(), + cluster_type=dict(choices=['CloudManaged', 'ExternalManaged']), + hypervisor=dict(choices=CS_HYPERVISORS), state=dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'), - url=dict(default=None), - username=dict(default=None), - password=dict(default=None, no_log=True), - guest_vswitch_name=dict(default=None), - guest_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None), - public_vswitch_name=dict(default=None), - public_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs'], default=None), - vms_ip_address=dict(default=None), - vms_username=dict(default=None), - vms_password=dict(default=None, no_log=True), - ovm3_cluster=dict(default=None), - ovm3_pool=dict(default=None), - ovm3_vip=dict(default=None), + url=dict(), + username=dict(), + password=dict(no_log=True), + guest_vswitch_name=dict(), + guest_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs']), + public_vswitch_name=dict(), + public_vswitch_type=dict(choices=['vmwaresvs', 'vmwaredvs']), + vms_ip_address=dict(), + vms_username=dict(), + vms_password=dict(no_log=True), + ovm3_cluster=dict(), + ovm3_pool=dict(), + ovm3_vip=dict(), )) module = AnsibleModule( @@ -416,7 +422,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_cluster/tasks/main.yml b/test/integration/targets/cs_cluster/tasks/main.yml index da85775006..b7687d0baf 100644 --- a/test/integration/targets/cs_cluster/tasks/main.yml +++ b/test/integration/targets/cs_cluster/tasks/main.yml @@ -44,6 +44,21 @@ - cluster|failed - "cluster.msg == 'missing required arguments: name'" +- name: test fail if pod not found + cs_cluster: + name: "{{ cs_resource_prefix }}-cluster" + zone: "{{ cs_resource_prefix }}-zone" + hypervisor: simulator + cluster_type: CloudManaged + pod: unexistent + register: cluster + ignore_errors: true +- name: verify results of fail if missing name + assert: + that: + - cluster|failed + - "cluster.msg == 'Pod unexistent not found in zone {{ cs_resource_prefix }}-zone'" + - name: test create cluster in check mode cs_cluster: name: "{{ cs_resource_prefix }}-cluster" diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 0877ceb22f..fa47b76c84 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -165,7 +165,6 @@ lib/ansible/modules/cloud/azure/azure_rm_virtualnetwork_facts.py lib/ansible/modules/cloud/centurylink/clc_loadbalancer.py lib/ansible/modules/cloud/cloudscale/cloudscale_server.py lib/ansible/modules/cloud/cloudstack/cs_account.py -lib/ansible/modules/cloud/cloudstack/cs_cluster.py lib/ansible/modules/cloud/cloudstack/cs_configuration.py lib/ansible/modules/cloud/cloudstack/cs_domain.py lib/ansible/modules/cloud/cloudstack/cs_facts.py