-
Notifications
You must be signed in to change notification settings - Fork 22
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
#2823: update delete domain process - [MS] #3185
Conversation
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
1 similar comment
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good. Only real blocker is the raise error on _delete_hosts_if_not_used
which may have some knock-on effects on nameserver. Might not be a problem in practice though
Will test this within a day or so (no need to monitor your sandbox though) as I am nibbling this. Posting this review so you have this earlier rather than later
src/registrar/admin.py
Outdated
message = error_messages.get(err.code, err) | ||
message = error_messages[err.code] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Q) Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is an artifact of some testing I did that involved messing with the error messages. I thought I rewrote everything the way it should have been but it appears I missed this. Will revert this change.
|
||
logger.info("Deleting subdomains for %s", self.name) | ||
# check if any subdomains are in use by another domain | ||
hosts = Host.objects.filter(name__regex=r".+{}".format(self.name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice check on subdomain
src/registrar/models/domain.py
Outdated
for host in hosts: | ||
if host.domain != self: | ||
logger.error("Unable to delete host: %s is in use by another domain: %s", host.name, host.domain) | ||
raise RegistryError( | ||
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION, | ||
note=f"Host {host.name} is in use by {host.domain}", | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think EPP will throw an error in this case so it should be OK, but there is a potential scenario here where a nameserver exists on EPP but not on our hosts table (sandboxes for example).
I think the way you handled this is totally fine though. Just curious to hear your perspective and thoughts on that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point that I had considered, but in general there's not a great way to handle it. I haven't found a method in EPP that lets us list object based on their relationships, so we have to rely on our database foreign key relationships being an accurate-enough reflection. That said, it would be a relatively simple task to add more error handling if need be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some digging. There is a function in our epplib library called ListDomainsByNsset and ListDomainsByContact as well as a few others.
The process involved in using these though would go way outside the scope of the ticket. The commands may work on their own by default but you'd need to extend what we currently have here. And if they don't work on their own, you'd need to modify the repo which Dave and I did before. For it being a rare edgecase we can just send out these commands manually if we run into this scenario
if responseCode != ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY: | ||
raise NameserverError(code=nsErrorCodes.BAD_DATA) | ||
|
||
self._delete_hosts_if_not_used(hostsToDelete=deleted_values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Nitpick / optional) A comment explaining as to why delete hosts is called after 1062 would be a nice to have but not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
@@ -1026,10 +1033,49 @@ def _remove_client_hold(self): | |||
# if registry error occurs, log the error, and raise it as well | |||
logger.error(f"registry error removing client hold: {err}") | |||
raise (err) | |||
|
|||
def _delete_domain(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on this function. I also like how you doing error handling / raising, very clean
raise e | ||
|
||
def _fix_unknown_state(self, cleaned): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(potentially blocking) This will have some knock-on effects for the nameservers setter as it seems to assume that no error is raised by this helper function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I'll add a try/catch to the nameservers setter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice
src/registrar/tests/common.py
Outdated
def mockDeleteHostCommands(self, _request, cleaned): | ||
host = getattr(_request, "name", None) | ||
if "sharedhost.com" in host: | ||
print("raising registry error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to remove before merging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another good catch, I thought I caught all of these!
@@ -1748,6 +1765,7 @@ def mockInfoDomainCommands(self, _request, cleaned): | |||
"subdomainwoip.gov": (self.mockDataInfoDomainSubdomainNoIP, None), | |||
"ddomain3.gov": (self.InfoDomainWithContacts, None), | |||
"igorville.gov": (self.InfoDomainWithContacts, None), | |||
"sharingiscaring.gov": (self.infoDomainSharedHost, None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
cleaned=True, | ||
), | ||
], | ||
any_order=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ordering of these matters in some cases, but the database doesn't always return things in the same order so for things like the contacts it can break the test. I'll break that part out though, because in general you have the right idea and I had meant to do so anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha. Yeah that'd be totally fine then
src/registrar/tests/test_reports.py
Outdated
"[email protected],True,[email protected],2022-04-01,2024-02-01,Viewer Requester,Manager,False,0,\n" | ||
"[email protected],False,[email protected],2022-04-01,Invalid date,None," | ||
'Manager,True,2,"adomain2.gov,cdomain1.gov"\n' | ||
"[email protected],False,[email protected],Unretrieved,Invited,None,Manager,False,0,\n" | ||
"[email protected],False,[email protected],Unretrieved,Invited,None,Viewer,False,0,\n" | ||
"[email protected],False,[email protected],Unretrieved,Invited,Viewer,None,False,0,\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this fix is on latest now so you don't need to add it manually
….com/cisagov/manage.get.gov into ms/2823-update-delete-domain-process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great
src/registrar/models/domain.py
Outdated
except: | ||
# the error will be logged in the erring function and we don't | ||
# need this part to succeed in order to continue.s | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would suggest logging the error + some minor grammar things in the comment, but other than that looks good
🥳 Successfully deployed to developer sandbox ms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Was able to reproduce the subdomain error, though its actually a non-issue, imo.
When adding nameserver records, I am getting the Error deleting this Domain: This subdomain is being used as a hostname on another domain:
error that you mentioned.
This error would only occur when nameservers were added. So if I deleted the domain in dns needed or if I deleted those nameserver records when it was in "ready", this error would disappear. This actually makes total sense - the underlying error is OBJECT_ASSOCIATION_PROHIBITS_OPERATION
. This tells me that the messaging was faulty rather than your code
In unrelated news, on your sandbox I seem to be getting a 500 on team-loss-within.gov
for a missing contact. This is "on hold". If you set this record to on hold manually from deleted then that would make sense, though otherwise that is strange
That said, I am curious as to what @dave-kennedy-ecs thinks |
@Matt-Spence Also forgot to mention, but your linter is failing |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
🥳 Successfully deployed to developer sandbox ms. |
Ticket
Resolves #2823
Changes
Context for reviewers
Currently domains can't be deleted by the "Delete from the Registry" button in admin unless all hosts and contacts for that domain are deleted first. This PR adds logic to automagically delete contacts and hosts, unless a contact is shared with another domain.
Setup
Poor-police.gov has been created on ms as an example of a domain that has a subdomain used by another domain (you can find this in hosts). You can use that to check that deletion fails in this case, or roll your own if you prefer.
Other than that any domain that has subdomains (usually as nameservers) can be used to test that deletion works properly. After deleting you should be able to click "check status in registry" and see a "pendingDelete" status.
Code Review Verification Steps
Go to MS -> Admin -> Pick a domain that has nameservers and/or contacts -> Put On Hold -> Delete From Registry. Try this for a few permutations including have a domain that shares a host with another domain (this should fail).
As the original developer, I have
Satisfied acceptance criteria and met development standards
Ensured code standards are met (Original Developer)
Validated user-facing changes (if applicable)
As a code reviewer, I have
Reviewed, tested, and left feedback about the changes
Validated user-facing changes as a developer
Note: Multiple code reviewers can share the checklists above, a second reviewer should not make a duplicate checklist. All checks should be checked before approving, even those labeled N/A.
As a designer reviewer, I have
Verified that the changes match the design intention
Validated user-facing changes as a designer
References
Screenshots