cloudstack: add tests, fix pep8 (#25518)
* cloudstack: cs_zone: fix pep8 * cloudstack: cs_zone: add tests
This commit is contained in:
parent
76c598f044
commit
29817ab115
5 changed files with 267 additions and 58 deletions
|
@ -231,8 +231,14 @@ tags:
|
|||
sample: [ { "key": "foo", "value": "bar" } ]
|
||||
'''
|
||||
|
||||
# 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 AnsibleCloudStackZone(AnsibleCloudStack):
|
||||
|
||||
|
@ -256,27 +262,26 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
}
|
||||
self.zone = None
|
||||
|
||||
|
||||
def _get_common_zone_args(self):
|
||||
args = {}
|
||||
args['name'] = self.module.params.get('name')
|
||||
args['dns1'] = self.module.params.get('dns1')
|
||||
args['dns2'] = self.module.params.get('dns2')
|
||||
args['internaldns1'] = self.get_or_fallback('internal_dns1', 'dns1')
|
||||
args['internaldns2'] = self.get_or_fallback('internal_dns2', 'dns2')
|
||||
args['ipv6dns1'] = self.module.params.get('dns1_ipv6')
|
||||
args['ipv6dns2'] = self.module.params.get('dns2_ipv6')
|
||||
args['networktype'] = self.module.params.get('network_type')
|
||||
args['domain'] = self.module.params.get('network_domain')
|
||||
args['localstorageenabled'] = self.module.params.get('local_storage_enabled')
|
||||
args['guestcidraddress'] = self.module.params.get('guest_cidr_address')
|
||||
args['dhcpprovider'] = self.module.params.get('dhcp_provider')
|
||||
args = {
|
||||
'name': self.module.params.get('name'),
|
||||
'dns1': self.module.params.get('dns1'),
|
||||
'dns2': self.module.params.get('dns2'),
|
||||
'internaldns1': self.get_or_fallback('internal_dns1', 'dns1'),
|
||||
'internaldns2': self.get_or_fallback('internal_dns2', 'dns2'),
|
||||
'ipv6dns1': self.module.params.get('dns1_ipv6'),
|
||||
'ipv6dns2': self.module.params.get('dns2_ipv6'),
|
||||
'networktype': self.module.params.get('network_type'),
|
||||
'domain': self.module.params.get('network_domain'),
|
||||
'localstorageenabled': self.module.params.get('local_storage_enabled'),
|
||||
'guestcidraddress': self.module.params.get('guest_cidr_address'),
|
||||
'dhcpprovider': self.module.params.get('dhcp_provider'),
|
||||
}
|
||||
state = self.module.params.get('state')
|
||||
if state in ['enabled', 'disabled']:
|
||||
args['allocationstate'] = state.capitalize()
|
||||
return args
|
||||
|
||||
|
||||
def get_zone(self):
|
||||
if not self.zone:
|
||||
args = {}
|
||||
|
@ -295,7 +300,6 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
self.zone = zones['zone'][0]
|
||||
return self.zone
|
||||
|
||||
|
||||
def present_zone(self):
|
||||
zone = self.get_zone()
|
||||
if zone:
|
||||
|
@ -304,7 +308,6 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
zone = self._create_zone()
|
||||
return zone
|
||||
|
||||
|
||||
def _create_zone(self):
|
||||
required_params = [
|
||||
'dns1',
|
||||
|
@ -325,7 +328,6 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
zone = res['zone']
|
||||
return zone
|
||||
|
||||
|
||||
def _update_zone(self):
|
||||
zone = self.get_zone()
|
||||
|
||||
|
@ -342,15 +344,14 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
zone = res['zone']
|
||||
return zone
|
||||
|
||||
|
||||
def absent_zone(self):
|
||||
zone = self.get_zone()
|
||||
if zone:
|
||||
self.result['changed'] = True
|
||||
|
||||
args = {}
|
||||
args['id'] = zone['id']
|
||||
|
||||
args = {
|
||||
'id': zone['id']
|
||||
}
|
||||
if not self.module.check_mode:
|
||||
res = self.cs.deleteZone(**args)
|
||||
if 'errortext' in res:
|
||||
|
@ -361,22 +362,22 @@ class AnsibleCloudStackZone(AnsibleCloudStack):
|
|||
def main():
|
||||
argument_spec = cs_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
id = dict(default=None),
|
||||
id=dict(),
|
||||
name=dict(required=True),
|
||||
dns1 = dict(default=None),
|
||||
dns2 = dict(default=None),
|
||||
internal_dns1 = dict(default=None),
|
||||
internal_dns2 = dict(default=None),
|
||||
dns1_ipv6 = dict(default=None),
|
||||
dns2_ipv6 = dict(default=None),
|
||||
dns1=dict(),
|
||||
dns2=dict(),
|
||||
internal_dns1=dict(),
|
||||
internal_dns2=dict(),
|
||||
dns1_ipv6=dict(),
|
||||
dns2_ipv6=dict(),
|
||||
network_type=dict(default='basic', choices=['Basic', 'basic', 'Advanced', 'advanced']),
|
||||
network_domain = dict(default=None),
|
||||
guest_cidr_address = dict(default=None),
|
||||
dhcp_provider = dict(default=None),
|
||||
local_storage_enabled = dict(type='bool', default=None),
|
||||
securitygroups_enabled = dict(type='bool', default=None),
|
||||
network_domain=dict(),
|
||||
guest_cidr_address=dict(),
|
||||
dhcp_provider=dict(),
|
||||
local_storage_enabled=dict(type='bool'),
|
||||
securitygroups_enabled=dict(type='bool'),
|
||||
state=dict(choices=['present', 'enabled', 'disabled', 'absent'], default='present'),
|
||||
domain = dict(default=None),
|
||||
domain=dict(),
|
||||
))
|
||||
|
||||
module = AnsibleModule(
|
||||
|
@ -401,7 +402,6 @@ def main():
|
|||
|
||||
module.exit_json(**result)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
2
test/integration/targets/cs_zone/aliases
Normal file
2
test/integration/targets/cs_zone/aliases
Normal file
|
@ -0,0 +1,2 @@
|
|||
cloud/cs
|
||||
posix/ci/cloud/cs
|
3
test/integration/targets/cs_zone/meta/main.yml
Normal file
3
test/integration/targets/cs_zone/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
dependencies:
|
||||
- cs_common
|
205
test/integration/targets/cs_zone/tasks/main.yml
Normal file
205
test/integration/targets/cs_zone/tasks/main.yml
Normal file
|
@ -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_vmsnapshot.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_container.py
|
||||
lib/ansible/modules/cloud/docker/docker_image.py
|
||||
|
|
Loading…
Reference in a new issue