Paginate DigitalOcean destroy_dns_records and drop Py2 decode (Fixes #55143)#69766
Open
ggiesen wants to merge 1 commit into
Open
Paginate DigitalOcean destroy_dns_records and drop Py2 decode (Fixes #55143)#69766ggiesen wants to merge 1 commit into
ggiesen wants to merge 1 commit into
Conversation
destroy_dns_records issued a single unpaginated request for a domain's DNS records, so the DigitalOcean API returned only the first page (20 records by default) and any matching record beyond page 1 was never deleted. Walk every page and accumulate the records before matching, mirroring the pagination idiom already used elsewhere in this driver. Also drop the leftover Python 2 r["name"].decode() call, which raised AttributeError on Python 3 for every domain that has records. Fixes saltstack#55143
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes the DigitalOcean cloud driver's
destroy_dns_records()walk every page of a domain's DNS records instead of requesting only the first page, and removes a leftover Python 2.decode()call that crashed record matching on Python 3.The pagination loop reuses the same
fetch/page+"next" in response["links"]["pages"]idiom already used byavail_images,list_keypairs,list_floating_ips, and_list_nodesin this driver, requestingrecords?page=<n>&per_page=200until the API stops returning anextlink.What issues does this PR fix or reference?
Fixes #55143
Previous Behavior
destroy_dns_records()issued a single unpaginated request:The DigitalOcean API returns at most 20 DNS records per page by default, so any record beyond the first page was never seen and therefore never deleted. In addition, the match used
r["name"].decode(), a Python 2 leftover; on Python 3strhas no.decode(), so the comprehension raisedAttributeErrorfor any domain that has records (real domains always have SOA/NS), meaning the function crashed before deletion could even be attempted.New Behavior
destroy_dns_records()accumulatesdomain_recordsacross every page before matching, so records past page 1 are found and their IDs deleted. Record names are compared directly (r["name"] == hostname), which works on Python 3. Non-matching records are still left untouched, and a failed domain lookup still returnsFalsewithout attempting any deletion.Merge requirements satisfied?
changelog/55143.fixed.mdaddedtests/pytests/unit/cloud/clouds/test_digitalocean.py:test_destroy_dns_records_pagination_55143-- patchesquerywith a paged side effect; the matching record lives on page 2, asserts the loop requestedrecords?page=2and issued therecords/42delete, and that no page-1 non-matching record was deleted.test_destroy_dns_records_no_matching_records_55143-- inverse case: an empty record set produces zero deletions (passes with and without the fix; guards against over-deletion).test_destroy_dns_records_domain_lookup_failure_55143-- aSaltCloudSystemExitfrom the lookup returnsFalsewith no delete attempted.Commits signed with GPG?
No