mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cloudstack: cs_zone_facts: add tests and fix pep8 (#25407)
This commit is contained in:
parent
bcc5bffd8e
commit
894b86a467
5 changed files with 66 additions and 26 deletions
|
@ -36,6 +36,7 @@ options:
|
|||
description:
|
||||
- Name of the zone.
|
||||
required: true
|
||||
aliases: [ zone ]
|
||||
extends_documentation_fragment: cloudstack
|
||||
'''
|
||||
|
||||
|
@ -142,10 +143,13 @@ 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):
|
||||
|
||||
|
@ -171,15 +175,11 @@ class AnsibleCloudStackZoneFacts(AnsibleCloudStack):
|
|||
'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,
|
||||
)
|
||||
|
||||
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()
|
||||
|
|
2
test/integration/targets/cs_zone_facts/aliases
Normal file
2
test/integration/targets/cs_zone_facts/aliases
Normal file
|
@ -0,0 +1,2 @@
|
|||
cloud/cs
|
||||
posix/ci/cloud/cs
|
3
test/integration/targets/cs_zone_facts/meta/main.yml
Normal file
3
test/integration/targets/cs_zone_facts/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
dependencies:
|
||||
- cs_common
|
32
test/integration/targets/cs_zone_facts/tasks/main.yml
Normal file
32
test/integration/targets/cs_zone_facts/tasks/main.yml
Normal file
|
@ -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…
Reference in a new issue