cloudstack: cs_zone_facts: add tests and fix pep8 (#25407)

pull/24586/head
René Moser 8 years ago committed by GitHub
parent bcc5bffd8e
commit 894b86a467

@ -36,6 +36,7 @@ options:
description:
- Name of the zone.
required: true
aliases: [ zone ]
extends_documentation_fragment: cloudstack
'''
@ -142,44 +143,43 @@ cloudstack_zone.tags:
sample: [ { "key": "foo", "value": "bar" } ]
'''
import base64
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.cloudstack import (
AnsibleCloudStack,
CloudStackException,
cs_argument_spec,
)
# import cloudstack common
from ansible.module_utils.cloudstack import *
class AnsibleCloudStackZoneFacts(AnsibleCloudStack):
def __init__(self, module):
super(AnsibleCloudStackZoneFacts, self).__init__(module)
self.returns = {
'dns1': 'dns1',
'dns2': 'dns2',
'internaldns1': 'internal_dns1',
'internaldns2': 'internal_dns2',
'ipv6dns1': 'dns1_ipv6',
'ipv6dns2': 'dns2_ipv6',
'domain': 'network_domain',
'networktype': 'network_type',
'securitygroupsenabled': 'securitygroups_enabled',
'localstorageenabled': 'local_storage_enabled',
'guestcidraddress': 'guest_cidr_address',
'dhcpprovider': 'dhcp_provider',
'allocationstate': 'allocation_state',
'zonetoken': 'zone_token',
'dns1': 'dns1',
'dns2': 'dns2',
'internaldns1': 'internal_dns1',
'internaldns2': 'internal_dns2',
'ipv6dns1': 'dns1_ipv6',
'ipv6dns2': 'dns2_ipv6',
'domain': 'network_domain',
'networktype': 'network_type',
'securitygroupsenabled': 'securitygroups_enabled',
'localstorageenabled': 'local_storage_enabled',
'guestcidraddress': 'guest_cidr_address',
'dhcpprovider': 'dhcp_provider',
'allocationstate': 'allocation_state',
'zonetoken': 'zone_token',
}
self.facts = {
'cloudstack_zone': None,
}
def get_zone(self):
if not self.zone:
# TODO: add param key signature in get_zone()
self.module.params['zone'] = self.module.params.get('name')
super(AnsibleCloudStackZoneFacts, self).get_zone()
return self.zone
def run(self):
zone = self.get_zone()
self.facts['cloudstack_zone'] = self.get_result(zone)
@ -189,7 +189,7 @@ class AnsibleCloudStackZoneFacts(AnsibleCloudStack):
def main():
argument_spec = cs_argument_spec()
argument_spec.update(dict(
name = dict(required=True),
zone=dict(required=True, aliases=['name']),
))
module = AnsibleModule(
@ -197,10 +197,14 @@ def main():
supports_check_mode=False,
)
cs_zone_facts = AnsibleCloudStackZoneFacts(module=module).run()
cs_facts_result = dict(changed=False, ansible_facts=cs_zone_facts)
try:
cs_zone_facts = AnsibleCloudStackZoneFacts(module=module).run()
cs_facts_result = dict(changed=False, ansible_facts=cs_zone_facts)
except CloudStackException as e:
module.fail_json(msg='CloudStackException: %s' % str(e))
module.exit_json(**cs_facts_result)
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()

@ -0,0 +1,2 @@
cloud/cs
posix/ci/cloud/cs

@ -0,0 +1,3 @@
---
dependencies:
- cs_common

@ -0,0 +1,32 @@
---
- name: setup zone is present
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
dns1: 8.8.8.8
dns2: 8.8.4.4
network_type: basic
register: zone
- name: verify setup zone is present
assert:
that:
- zone|success
- name: get facts from zone
cs_zone_facts:
name: "{{ cs_resource_prefix }}-zone"
register: zone
- name: verify setup zone is present
assert:
that:
- zone|success
- not zone|changed
- ansible_facts.cloudstack_zone.dns1 == "8.8.8.8"
- ansible_facts.cloudstack_zone.dns2 == "8.8.4.4"
- ansible_facts.cloudstack_zone.internal_dns1 == "8.8.8.8"
- ansible_facts.cloudstack_zone.internal_dns2 == "8.8.4.4"
- ansible_facts.cloudstack_zone.local_storage_enabled == false
- ansible_facts.cloudstack_zone.network_type == "Basic"
- ansible_facts.cloudstack_zone.zone_token != ""
- ansible_facts.cloudstack_zone.securitygroups_enabled == true
- ansible_facts.cloudstack_zone.dhcp_provider == "VirtualRouter"
- ansible_facts.cloudstack_zone.local_storage_enabled == false

@ -102,7 +102,6 @@ lib/ansible/modules/cloud/cloudstack/cs_user.py
lib/ansible/modules/cloud/cloudstack/cs_vmsnapshot.py
lib/ansible/modules/cloud/cloudstack/cs_volume.py
lib/ansible/modules/cloud/cloudstack/cs_zone.py
lib/ansible/modules/cloud/cloudstack/cs_zone_facts.py
lib/ansible/modules/cloud/docker/_docker.py
lib/ansible/modules/cloud/docker/docker_container.py
lib/ansible/modules/cloud/docker/docker_image.py

Loading…
Cancel
Save