Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade azure-mgmt-dns to 8.0.0 #879

Merged
merged 3 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def normalize_location_name(name):
},
'DnsManagementClient': {
'package_name': 'dns',
'expected_version': '2.1.0'
'expected_version': '8.0.0'
},
'PrivateDnsManagementClient': {
'package_name': 'privatedns',
Expand Down Expand Up @@ -1105,6 +1105,7 @@ def dns_client(self):
if not self._dns_client:
self._dns_client = self.get_mgmt_svc_client(DnsManagementClient,
base_url=self._cloud_environment.endpoints.resource_manager,
is_track2=True,
api_version='2018-05-01')
return self._dns_client

Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/azure_rm_dnsrecordset.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase, HAS_AZURE

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -324,7 +324,7 @@
)

RECORDSET_VALUE_MAP = dict(
A=dict(attrname='arecords', classobj='ARecord', is_list=True),
A=dict(attrname='a_records', classobj='ARecord', is_list=True),
AAAA=dict(attrname='aaaa_records', classobj='AaaaRecord', is_list=True),
CNAME=dict(attrname='cname_record', classobj='CnameRecord', is_list=False),
MX=dict(attrname='mx_records', classobj='MxRecord', is_list=True),
Expand Down Expand Up @@ -400,7 +400,7 @@ def exec_module(self, **kwargs):
self.log('Fetching Record Set {0}'.format(self.relative_name))
record_set = self.dns_client.record_sets.get(self.resource_group, self.zone_name, self.relative_name, self.record_type)
self.results['state'] = self.recordset_to_dict(record_set)
except CloudError:
except ResourceNotFoundError:
record_set = None
# FUTURE: fail on anything other than ResourceNotFound

Expand Down
11 changes: 5 additions & 6 deletions plugins/modules/azure_rm_dnsrecordset_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase

try:
from msrestazure.azure_exceptions import CloudError
from azure.common import AzureMissingResourceHttpError, AzureHttpError
from azure.core.exceptions import ResourceNotFoundError
except Exception:
# This is handled in azure_rm_common
pass
Expand All @@ -156,7 +155,7 @@


RECORDSET_VALUE_MAP = dict(
A='arecords',
A='a_records',
AAAA='aaaa_records',
CNAME='cname_record',
MX='mx_records',
Expand Down Expand Up @@ -241,7 +240,7 @@ def get_item(self):
# try to get information for specific Record Set
try:
item = self.dns_client.record_sets.get(self.resource_group, self.zone_name, self.relative_name, self.record_type)
except CloudError:
except ResourceNotFoundError:
results = []
pass
else:
Expand All @@ -252,7 +251,7 @@ def list_type(self):
self.log('Lists the record sets of a specified type in a DNS zone')
try:
response = self.dns_client.record_sets.list_by_type(self.resource_group, self.zone_name, self.record_type, top=self.top)
except AzureHttpError as exc:
except Exception as exc:
self.fail("Failed to list for record type {0} - {1}".format(self.record_type, str(exc)))

results = []
Expand All @@ -264,7 +263,7 @@ def list_zone(self):
self.log('Lists all record sets in a DNS zone')
try:
response = self.dns_client.record_sets.list_by_dns_zone(self.resource_group, self.zone_name, top=self.top)
except AzureHttpError as exc:
except Exception as exc:
self.fail("Failed to list for zone {0} - {1}".format(self.zone_name, str(exc)))

results = []
Expand Down
8 changes: 4 additions & 4 deletions plugins/modules/azure_rm_dnszone.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
from ansible.module_utils._text import to_native

try:
from msrestazure.azure_exceptions import CloudError
from azure.core.exceptions import ResourceNotFoundError
except ImportError:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -208,7 +208,7 @@ def exec_module(self, **kwargs):
elif self.state == 'absent':
changed = True

except CloudError:
except ResourceNotFoundError:
# the zone does not exist so create it
if self.state == 'present':
changed = True
Expand Down Expand Up @@ -253,7 +253,7 @@ def create_or_update_zone(self, zone):
def delete_zone(self):
try:
# delete the Zone
poller = self.dns_client.zones.delete(self.resource_group, self.name)
poller = self.dns_client.zones.begin_delete(self.resource_group, self.name)
result = self.get_poller_result(poller)
except Exception as exc:
self.fail("Error deleting zone {0} - {1}".format(self.name, exc.message or str(exc)))
Expand Down Expand Up @@ -282,7 +282,7 @@ def zone_to_dict(zone):
number_of_record_sets=zone.number_of_record_sets,
name_servers=zone.name_servers,
tags=zone.tags,
type=zone.zone_type.value.lower(),
type=zone.zone_type.lower(),
registration_virtual_networks=[to_native(x.id) for x in zone.registration_virtual_networks] if zone.registration_virtual_networks else None,
resolution_virtual_networks=[to_native(x.id) for x in zone.resolution_virtual_networks] if zone.resolution_virtual_networks else None
)
Expand Down
11 changes: 5 additions & 6 deletions plugins/modules/azure_rm_dnszone_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@
from ansible.module_utils._text import to_native

try:
from msrestazure.azure_exceptions import CloudError
from azure.common import AzureMissingResourceHttpError, AzureHttpError
from azure.core.exceptions import ResourceNotFoundError
except Exception:
# This is handled in azure_rm_common
pass
Expand Down Expand Up @@ -193,7 +192,7 @@ def get_item(self):
# get specific zone
try:
item = self.dns_client.zones.get(self.resource_group, self.name)
except CloudError:
except ResourceNotFoundError:
pass

# serialize result
Expand All @@ -205,7 +204,7 @@ def list_resource_group(self):
self.log('List items for resource group')
try:
response = self.dns_client.zones.list_by_resource_group(self.resource_group)
except AzureHttpError as exc:
except Exception as exc:
self.fail("Failed to list for resource group {0} - {1}".format(self.resource_group, str(exc)))

results = []
Expand All @@ -218,7 +217,7 @@ def list_items(self):
self.log('List all items')
try:
response = self.dns_client.zones.list()
except AzureHttpError as exc:
except Exception as exc:
self.fail("Failed to list all items - {0}".format(str(exc)))

results = []
Expand All @@ -241,7 +240,7 @@ def zone_to_dict(self, zone):
max_number_of_record_sets=zone.max_number_of_record_sets,
name_servers=zone.name_servers,
tags=zone.tags,
type=zone.zone_type.value.lower(),
type=zone.zone_type.lower(),
registration_virtual_networks=[to_native(x.id) for x in zone.registration_virtual_networks] if zone.registration_virtual_networks else None,
resolution_virtual_networks=[to_native(x.id) for x in zone.resolution_virtual_networks] if zone.resolution_virtual_networks else None
)
Expand Down
2 changes: 1 addition & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ azure-containerregistry==1.0.0
azure-mgmt-containerservice==9.1.0
azure-mgmt-datalake-store==0.5.0
azure-mgmt-datafactory==2.0.0
azure-mgmt-dns==2.1.0
azure-mgmt-dns==8.0.0
azure-mgmt-keyvault==1.1.0
azure-mgmt-marketplaceordering==0.1.0
azure-mgmt-monitor==3.0.0
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/targets/azure_rm_dnszone/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
assert:
that:
- results.changed
- 'results.state.arecords | length == 3'
- 'results.state.a_records | length == 3'

- name: re-run "A" record with same values
azure_rm_dnsrecordset:
Expand Down Expand Up @@ -109,7 +109,7 @@
assert:
that:
- results.changed
- 'results.state.arecords | length == 4'
- 'results.state.a_records | length == 4'

- name: re-update "A" record set with additional record
azure_rm_dnsrecordset:
Expand Down Expand Up @@ -143,7 +143,7 @@
assert:
that:
- results.changed
- 'results.state.arecords | length == 3'
- 'results.state.a_records | length == 3'

- name: Check_mode test
azure_rm_dnsrecordset:
Expand Down