working _delete_domain

This commit is contained in:
David Kennedy 2024-12-11 14:12:42 -05:00
parent 1a9b671758
commit e0eb70abe2
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B

View file

@ -1038,27 +1038,45 @@ class Domain(TimeStampedModel, DomainHelper):
"""This domain should be deleted from the registry """This domain should be deleted from the registry
may raises RegistryError, should be caught or handled correctly by caller""" may raises RegistryError, should be caught or handled correctly by caller"""
logger.info("Deleting subdomains for %s", self.name) # logger.info("Deleting subdomains for %s", self.name)
# check if any subdomains are in use by another domain # # check if any subdomains are in use by another domain
hosts = Host.objects.filter(name__regex=r".+{}".format(self.name)) # hosts = Host.objects.filter(name__regex=r".+{}".format(self.name))
logger.debug("Checking if any subdomains are in use by another domain") # logger.debug("Checking if any subdomains are in use by another domain")
for host in hosts: # for host in hosts:
if host.domain != self: # if host.domain != self:
logger.error("Unable to delete host: %s is in use by another domain: %s", host.name, host.domain) # logger.error("Unable to delete host: %s is in use by another domain: %s", host.name, host.domain)
raise RegistryError( # raise RegistryError(
code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION, # code=ErrorCode.OBJECT_ASSOCIATION_PROHIBITS_OPERATION,
note=f"Host {host.name} is in use by {host.domain}", # note=f"Host {host.name} is in use by {host.domain}",
) # )
logger.debug("No subdomains are in use by another domain") # logger.debug("No subdomains are in use by another domain")
nameservers = [host.name for host in hosts] # nameservers = [host.name for host in hosts]
hosts = self.createDeleteHostList(hostsToDelete=nameservers) # hosts = self.createDeleteHostList(hostsToDelete=nameservers)
response_code = self.addAndRemoveHostsFromDomain(hostsToAdd=None, hostsToDelete=hosts) # response_code = self.addAndRemoveHostsFromDomain(hostsToAdd=[], hostsToDelete=hosts)
if response_code != ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY: # if response_code != ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY:
raise RegistryError(code=response_code) # raise RegistryError(code=response_code)
logger.debug("Deleting subordinate hosts for %s", self.name) # logger.debug("Deleting subordinate hosts for %s", self.name)
self._delete_hosts_if_not_used(nameservers) # self._delete_hosts_if_not_used(nameservers)
(
deleted_values,
updated_values,
new_values,
oldNameservers,
) = self.getNameserverChanges(hosts=[])
_ = self._update_host_values(updated_values, oldNameservers) # returns nothing, just need to be run and errors
addToDomainList, addToDomainCount = self.createNewHostList(new_values)
deleteHostList, deleteCount = self.createDeleteHostList(deleted_values)
responseCode = self.addAndRemoveHostsFromDomain(hostsToAdd=addToDomainList, hostsToDelete=deleteHostList)
# if unable to update domain raise error and stop
if responseCode != ErrorCode.COMMAND_COMPLETED_SUCCESSFULLY:
raise NameserverError(code=nsErrorCodes.BAD_DATA)
self._delete_hosts_if_not_used(hostsToDelete=deleted_values)
logger.debug("Deleting non-registrant contacts for %s", self.name) logger.debug("Deleting non-registrant contacts for %s", self.name)
contacts = PublicContact.objects.filter(domain=self) contacts = PublicContact.objects.filter(domain=self)