From 0a216281d524dec81088427805791398736c7c09 Mon Sep 17 00:00:00 2001 From: Polina-Gubina Date: Tue, 4 May 2021 12:38:06 +0300 Subject: [PATCH 1/3] Provide compatibility dns_zone module with openstack.cloud dns_zone module --- meta/runtime.yml | 1 + plugins/modules/dns_zone.py | 31 +++++++++++++------ tests/integration/targets/dns/tasks/main.yaml | 26 ++++++++-------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/meta/runtime.yml b/meta/runtime.yml index 6aefb034..5ab3d28f 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -21,6 +21,7 @@ action_groups: - deh_host_info - deh_host_type_info - deh_server_info + - dns_zone - floating_ip - loadbalancer - loadbalancer_info diff --git a/plugins/modules/dns_zone.py b/plugins/modules/dns_zone.py index 3f1edd0a..60831d3b 100644 --- a/plugins/modules/dns_zone.py +++ b/plugins/modules/dns_zone.py @@ -47,13 +47,24 @@ description: - Cache duration (in second) on a local DNS server type: int - zone_type: + type: description: - Zone Type, either public or private type: str choices: [public, private] default: public - + zone_type: + description: + - Zone type: primary or secondary. + - This parameter is disabled, it only provides compatibility with openstack.cloud colection. + choices: [primary, secondary] + type: str + masters: + description: + - Master nameservers (only applies if zone_type is secondary). + - This parameter is disabled, it only provides compatibility with openstack.cloud colection. + type: list + elements: str requirements: ["openstacksdk", "otcextensions"] ''' @@ -96,7 +107,7 @@ type: int sample: 300 zone_type: - description: Zone Type, either public or private + description: Zone Type, either public or private. type: str sample: "private" ''' @@ -107,7 +118,7 @@ opentelekomcloud.cloud.dns_zone: name: "test.com." state: present - zone_type: private + type: private router: 79c32783-e560-4e3a-95b1-5a0756441e12 description: test2 ttl: 5000 @@ -120,12 +131,14 @@ class DNSZonesModule(OTCModule): argument_spec = dict( description=dict(required=False), + type=dict(type='str', choices=['public', 'private'], default='public'), email=dict(required=False), name=dict(required=True), router=dict(required=False), state=dict(type='str', choices=['present', 'absent'], default='present'), ttl=dict(required=False, type='int'), - zone_type=dict(type='str', choices=['public', 'private'], default='public') + masters=dict(required=False, type='list', elements='str'), + zone_type=dict(required=False, choices=['primary', 'secondary'], type='str') ) module_kwargs = dict( supports_check_mode=True @@ -135,8 +148,8 @@ def run(self): changed = False query = {} - if self.params['zone_type'] == 'private': - query['type'] = self.params['zone_type'] + if self.params['type'] == 'private': + query['type'] = self.params['type'] query['name_or_id'] = self.params['name'] query['ignore_missing'] = True zo = self.conn.dns.find_zone(**query) @@ -171,7 +184,7 @@ def run(self): self.exit_json(changed=True) if zone_check is False: # Check if VPC exists - if self.params['zone_type'] == 'private': + if self.params['type'] == 'private': if not self.params['router']: self.exit( changed=False, @@ -193,7 +206,7 @@ def run(self): message=('No Router found with name or id: %s' % self.params['router']) ) - attrs['zone_type'] = self.params['zone_type'] + attrs['type'] = self.params['type'] if self.params['description']: attrs['description'] = self.params['description'] if self.params['email']: diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 7f09672d..9e85bed6 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -113,7 +113,7 @@ - dns_fl.ptr.description is defined - name: Creating a public DNS Zone - check mode - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_public_name }}" state: present check_mode: true @@ -126,7 +126,7 @@ - dns_zo_ch is changed - name: Creating a public DNS Zone - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_public_name }}" state: present register: dns_zo @@ -142,7 +142,7 @@ - dns_zo.zone is defined - name: Updating a public DNS Zone - check mode - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_public_name }}" state: present description: "{{ description }}" @@ -156,7 +156,7 @@ - dns_zo_ch is changed - name: Updating a public DNS Zone - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_public_name }}" state: present description: "{{ description }}" @@ -173,10 +173,10 @@ - dns_zo.zone.description is defined - name: Creating a DNS private Zone - check mode - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_private_name }}" router: "{{ router_name }}" - zone_type: "private" + type: "private" state: present check_mode: true register: dns_zo_pr_ch @@ -188,10 +188,10 @@ - dns_zo_pr_ch is changed - name: Creating a DNS private Zone - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_private_name }}" router: "{{ router_name }}" - zone_type: "private" + type: "private" state: present register: dns_zo_pr @@ -206,7 +206,7 @@ - dns_zo_pr.zone is defined - name: Updating a private DNS Zone - check mode - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_private_name }}" state: present description: "{{ description }}" @@ -220,7 +220,7 @@ - dns_zo_pr_ch is changed - name: Updating a private DNS Zone - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_private_name }}" state: present description: "{{ description }}" @@ -332,15 +332,15 @@ register: dns_rs_dr - name: Drop DNS public Zone - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_public_name }}" state: absent register: dns_zo_pu_dr - name: Drop DNS private Zone - opentelekomcloud.cloud.dns_zones: + opentelekomcloud.cloud.dns_zone: name: "{{ zone_private_name }}" - zone_type: "private" + type: "private" state: absent register: dns_zo_pr_dr From 75a6de754890a1a00b957db20494fb364b47525d Mon Sep 17 00:00:00 2001 From: Polina-Gubina Date: Tue, 4 May 2021 16:10:19 +0300 Subject: [PATCH 2/3] Some fixes in test --- plugins/modules/dns_zone.py | 8 ++++---- tests/integration/targets/dns/tasks/main.yaml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/modules/dns_zone.py b/plugins/modules/dns_zone.py index 60831d3b..0b6d9c8a 100644 --- a/plugins/modules/dns_zone.py +++ b/plugins/modules/dns_zone.py @@ -55,12 +55,12 @@ default: public zone_type: description: - - Zone type: primary or secondary. + - Primary or secondary type. - This parameter is disabled, it only provides compatibility with openstack.cloud colection. choices: [primary, secondary] type: str masters: - description: + description: - Master nameservers (only applies if zone_type is secondary). - This parameter is disabled, it only provides compatibility with openstack.cloud colection. type: list @@ -149,7 +149,7 @@ def run(self): query = {} if self.params['type'] == 'private': - query['type'] = self.params['type'] + query['zone_type'] = self.params['type'] query['name_or_id'] = self.params['name'] query['ignore_missing'] = True zo = self.conn.dns.find_zone(**query) @@ -206,7 +206,7 @@ def run(self): message=('No Router found with name or id: %s' % self.params['router']) ) - attrs['type'] = self.params['type'] + attrs['zone_type'] = self.params['type'] if self.params['description']: attrs['description'] = self.params['description'] if self.params['email']: diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 9e85bed6..399d8f34 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -15,9 +15,9 @@ fl_ip: "{{ fl.floating_ip.floating_ip_address }}" ptrdname: "{{ ( prefix + 'dns.com.' ) }}" description: "{{ ( prefix + 'description-dns' ) }}" - zone_public_name: "{{ ( prefix + '-dnszone.com.' ) }}" - zone_private_name: "{{ ( prefix + '-dnszone.com.' ) }}" - rs_name: "{{ ( prefix + '-rs.' + prefix + '-dnszone.com.' ) }}" + zone_public_name: "{{ ( prefix + '-dnszonepublic.com.' ) }}" + zone_private_name: "{{ ( prefix + '-dnszoneprivate.com.' ) }}" + rs_name: "{{ ( prefix + '-rs.' + prefix + '-dnszonepublic.com.' ) }}" network_name: "{{ ( prefix + '-dnsnetwork' )}}" subnet_name: "{{ ( prefix + '-dnssubnet' )}}" router_name: "{{ ( prefix + '-dnsrouter' )}}" From 5e4f10180796b097a55b1f51322f8031816a3aa8 Mon Sep 17 00:00:00 2001 From: Polina-Gubina Date: Wed, 5 May 2021 00:04:28 +0300 Subject: [PATCH 3/3] Some fixes in test --- tests/integration/targets/dns/tasks/main.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/targets/dns/tasks/main.yaml b/tests/integration/targets/dns/tasks/main.yaml index 399d8f34..c0ff4aae 100644 --- a/tests/integration/targets/dns/tasks/main.yaml +++ b/tests/integration/targets/dns/tasks/main.yaml @@ -210,6 +210,7 @@ name: "{{ zone_private_name }}" state: present description: "{{ description }}" + type: "private" check_mode: true register: dns_zo_pr_ch @@ -224,6 +225,7 @@ name: "{{ zone_private_name }}" state: present description: "{{ description }}" + type: "private" register: dns_zo_pr - name: debug