cloudstack: add tests, fix pep8 (#25518)

* cloudstack: cs_zone: fix pep8

* cloudstack: cs_zone: add tests
pull/25553/head
René Moser 8 years ago committed by GitHub
parent 76c598f044
commit 29817ab115

@ -231,52 +231,57 @@ tags:
sample: [ { "key": "foo", "value": "bar" } ] sample: [ { "key": "foo", "value": "bar" } ]
''' '''
# import cloudstack common from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.cloudstack import * from ansible.module_utils.cloudstack import (
AnsibleCloudStack,
CloudStackException,
cs_argument_spec,
cs_required_together,
)
class AnsibleCloudStackZone(AnsibleCloudStack): class AnsibleCloudStackZone(AnsibleCloudStack):
def __init__(self, module): def __init__(self, module):
super(AnsibleCloudStackZone, self).__init__(module) super(AnsibleCloudStackZone, self).__init__(module)
self.returns = { self.returns = {
'dns1': 'dns1', 'dns1': 'dns1',
'dns2': 'dns2', 'dns2': 'dns2',
'internaldns1': 'internal_dns1', 'internaldns1': 'internal_dns1',
'internaldns2': 'internal_dns2', 'internaldns2': 'internal_dns2',
'ipv6dns1': 'dns1_ipv6', 'ipv6dns1': 'dns1_ipv6',
'ipv6dns2': 'dns2_ipv6', 'ipv6dns2': 'dns2_ipv6',
'domain': 'network_domain', 'domain': 'network_domain',
'networktype': 'network_type', 'networktype': 'network_type',
'securitygroupsenabled': 'securitygroups_enabled', 'securitygroupsenabled': 'securitygroups_enabled',
'localstorageenabled': 'local_storage_enabled', 'localstorageenabled': 'local_storage_enabled',
'guestcidraddress': 'guest_cidr_address', 'guestcidraddress': 'guest_cidr_address',
'dhcpprovider': 'dhcp_provider', 'dhcpprovider': 'dhcp_provider',
'allocationstate': 'allocation_state', 'allocationstate': 'allocation_state',
'zonetoken': 'zone_token', 'zonetoken': 'zone_token',
} }
self.zone = None self.zone = None
def _get_common_zone_args(self): def _get_common_zone_args(self):
args = {} args = {
args['name'] = self.module.params.get('name') 'name': self.module.params.get('name'),
args['dns1'] = self.module.params.get('dns1') 'dns1': self.module.params.get('dns1'),
args['dns2'] = self.module.params.get('dns2') 'dns2': self.module.params.get('dns2'),
args['internaldns1'] = self.get_or_fallback('internal_dns1', 'dns1') 'internaldns1': self.get_or_fallback('internal_dns1', 'dns1'),
args['internaldns2'] = self.get_or_fallback('internal_dns2', 'dns2') 'internaldns2': self.get_or_fallback('internal_dns2', 'dns2'),
args['ipv6dns1'] = self.module.params.get('dns1_ipv6') 'ipv6dns1': self.module.params.get('dns1_ipv6'),
args['ipv6dns2'] = self.module.params.get('dns2_ipv6') 'ipv6dns2': self.module.params.get('dns2_ipv6'),
args['networktype'] = self.module.params.get('network_type') 'networktype': self.module.params.get('network_type'),
args['domain'] = self.module.params.get('network_domain') 'domain': self.module.params.get('network_domain'),
args['localstorageenabled'] = self.module.params.get('local_storage_enabled') 'localstorageenabled': self.module.params.get('local_storage_enabled'),
args['guestcidraddress'] = self.module.params.get('guest_cidr_address') 'guestcidraddress': self.module.params.get('guest_cidr_address'),
args['dhcpprovider'] = self.module.params.get('dhcp_provider') 'dhcpprovider': self.module.params.get('dhcp_provider'),
}
state = self.module.params.get('state') state = self.module.params.get('state')
if state in [ 'enabled', 'disabled']: if state in ['enabled', 'disabled']:
args['allocationstate'] = state.capitalize() args['allocationstate'] = state.capitalize()
return args return args
def get_zone(self): def get_zone(self):
if not self.zone: if not self.zone:
args = {} args = {}
@ -295,7 +300,6 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
self.zone = zones['zone'][0] self.zone = zones['zone'][0]
return self.zone return self.zone
def present_zone(self): def present_zone(self):
zone = self.get_zone() zone = self.get_zone()
if zone: if zone:
@ -304,7 +308,6 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
zone = self._create_zone() zone = self._create_zone()
return zone return zone
def _create_zone(self): def _create_zone(self):
required_params = [ required_params = [
'dns1', 'dns1',
@ -325,7 +328,6 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
zone = res['zone'] zone = res['zone']
return zone return zone
def _update_zone(self): def _update_zone(self):
zone = self.get_zone() zone = self.get_zone()
@ -342,15 +344,14 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
zone = res['zone'] zone = res['zone']
return zone return zone
def absent_zone(self): def absent_zone(self):
zone = self.get_zone() zone = self.get_zone()
if zone: if zone:
self.result['changed'] = True self.result['changed'] = True
args = {} args = {
args['id'] = zone['id'] 'id': zone['id']
}
if not self.module.check_mode: if not self.module.check_mode:
res = self.cs.deleteZone(**args) res = self.cs.deleteZone(**args)
if 'errortext' in res: if 'errortext' in res:
@ -361,22 +362,22 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
def main(): def main():
argument_spec = cs_argument_spec() argument_spec = cs_argument_spec()
argument_spec.update(dict( argument_spec.update(dict(
id = dict(default=None), id=dict(),
name = dict(required=True), name=dict(required=True),
dns1 = dict(default=None), dns1=dict(),
dns2 = dict(default=None), dns2=dict(),
internal_dns1 = dict(default=None), internal_dns1=dict(),
internal_dns2 = dict(default=None), internal_dns2=dict(),
dns1_ipv6 = dict(default=None), dns1_ipv6=dict(),
dns2_ipv6 = dict(default=None), dns2_ipv6=dict(),
network_type = dict(default='basic', choices=['Basic', 'basic', 'Advanced', 'advanced']), network_type=dict(default='basic', choices=['Basic', 'basic', 'Advanced', 'advanced']),
network_domain = dict(default=None), network_domain=dict(),
guest_cidr_address = dict(default=None), guest_cidr_address=dict(),
dhcp_provider = dict(default=None), dhcp_provider=dict(),
local_storage_enabled = dict(type='bool', default=None), local_storage_enabled=dict(type='bool'),
securitygroups_enabled = dict(type='bool', default=None), securitygroups_enabled=dict(type='bool'),
state = dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'), state=dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'),
domain = dict(default=None), domain=dict(),
)) ))
module = AnsibleModule( module = AnsibleModule(
@ -401,7 +402,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

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

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

@ -0,0 +1,205 @@
---
- name: setup zone is absent
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
state: absent
register: zone
- name: verify setup zone absent
assert:
that:
- zone|success
- name: test fail missing param
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
register: zone
ignore_errors: true
- name: verify test fail missing param
assert:
that:
- zone|failed
- "zone.msg == 'missing required arguments: dns1'"
- name: test create zone in check mode
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
dns1: 8.8.8.8
dns2: 8.8.4.4
network_type: basic
register: zone
check_mode: true
- name: verify test create zone in check mode
assert:
that:
- zone|success
- zone|changed
- name: test create zone
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
dns1: 8.8.8.8
dns2: 8.8.4.4
network_type: basic
register: zone
- name: verify test create zone
assert:
that:
- zone|success
- zone|changed
- zone.dns1 == "8.8.8.8"
- zone.dns2 == "8.8.4.4"
- zone.internal_dns1 == "8.8.8.8"
- zone.internal_dns2 == "8.8.4.4"
- zone.local_storage_enabled == false
- zone.network_type == "Basic"
- zone.zone_token != ""
- zone.securitygroups_enabled == true
- zone.dhcp_provider == "VirtualRouter"
- name: test create zone idempotency
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
dns1: 8.8.8.8
dns2: 8.8.4.4
network_type: basic
register: zone
- name: verify test create zone idempotency
assert:
that:
- zone|success
- not zone|changed
- zone.dns1 == "8.8.8.8"
- zone.dns2 == "8.8.4.4"
- zone.internal_dns1 == "8.8.8.8"
- zone.internal_dns2 == "8.8.4.4"
- zone.local_storage_enabled == false
- zone.network_type == "Basic"
- zone.zone_token != ""
- zone.securitygroups_enabled == true
- zone.dhcp_provider == "VirtualRouter"
- name: test update zone in check mode
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
dns1: 8.8.8.8
dns2: 8.8.4.4
internal_dns1: 10.10.1.100
internal_dns2: 10.10.1.101
local_storage_enabled: true
network_type: basic
register: zone
check_mode: true
- name: verify test update zone in check mode
assert:
that:
- zone|success
- zone|changed
- zone.dns1 == "8.8.8.8"
- zone.dns2 == "8.8.4.4"
- zone.internal_dns1 == "8.8.8.8"
- zone.internal_dns2 == "8.8.4.4"
- zone.local_storage_enabled == false
- zone.network_type == "Basic"
- zone.zone_token != ""
- zone.securitygroups_enabled == true
- zone.dhcp_provider == "VirtualRouter"
- name: test update zone
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
dns1: 8.8.8.8
dns2: 8.8.4.4
internal_dns1: 10.10.1.100
internal_dns2: 10.10.1.101
local_storage_enabled: true
network_type: basic
register: zone
- name: verify test update zone
assert:
that:
- zone|success
- zone|changed
- zone.dns1 == "8.8.8.8"
- zone.dns2 == "8.8.4.4"
- zone.internal_dns1 == "10.10.1.100"
- zone.internal_dns2 == "10.10.1.101"
- zone.local_storage_enabled == true
- zone.network_type == "Basic"
- zone.zone_token != ""
- zone.securitygroups_enabled == true
- zone.dhcp_provider == "VirtualRouter"
- name: test update zone idempotency
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
dns1: 8.8.8.8
dns2: 8.8.4.4
internal_dns1: 10.10.1.100
internal_dns2: 10.10.1.101
local_storage_enabled: true
network_type: basic
register: zone
- name: verify test update zone idempotency
assert:
that:
- zone|success
- not zone|changed
- zone.dns1 == "8.8.8.8"
- zone.dns2 == "8.8.4.4"
- zone.internal_dns1 == "10.10.1.100"
- zone.internal_dns2 == "10.10.1.101"
- zone.local_storage_enabled == true
- zone.network_type == "Basic"
- zone.zone_token != ""
- zone.securitygroups_enabled == true
- zone.dhcp_provider == "VirtualRouter"
- name: test absent zone in check mode
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
state: absent
register: zone
check_mode: true
- name: verify test absent zone in check mode
assert:
that:
- zone|success
- zone|changed
- zone.dns1 == "8.8.8.8"
- zone.dns2 == "8.8.4.4"
- zone.internal_dns1 == "10.10.1.100"
- zone.internal_dns2 == "10.10.1.101"
- zone.local_storage_enabled == true
- zone.network_type == "Basic"
- zone.zone_token != ""
- zone.securitygroups_enabled == true
- name: test absent zone
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
state: absent
register: zone
- name: verify test absent zone
assert:
that:
- zone|success
- zone|changed
- zone.dns1 == "8.8.8.8"
- zone.dns2 == "8.8.4.4"
- zone.internal_dns1 == "10.10.1.100"
- zone.internal_dns2 == "10.10.1.101"
- zone.local_storage_enabled == true
- zone.network_type == "Basic"
- zone.zone_token != ""
- zone.securitygroups_enabled == true
- name: test absent zone idempotency
cs_zone:
name: "{{ cs_resource_prefix }}-zone"
state: absent
register: zone
- name: verify test absent zone idempotency
assert:
that:
- zone|success
- not zone|changed

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

Loading…
Cancel
Save