-
Notifications
You must be signed in to change notification settings - Fork 29
#4141 - Look up nameservers in the database to use for updating the registry - [aa] #4547
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
base: main
Are you sure you want to change the base?
Conversation
|
🥳 Successfully deployed to developer sandbox aa. |
|
🥳 Successfully deployed to developer sandbox aa. |
|
🥳 Successfully deployed to developer sandbox aa. |
kimallen
left a comment
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 good- thank you for the detailed instructions in the PR description (helpful after a couple weeks of vacation!)
There's a few minor nits, a question about a test, and a suggested refactor to simplify.
| return | ||
|
|
||
| try: | ||
| nameservers, zone_data = self._find_existing_zone_in_cf(domain_name, x_account_id) |
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.
You can remove nameservers from here now that we are not returning it from the function
| # For now, we only expect one zone per account | ||
| has_zone = DnsZone.objects.filter(name=domain_name).exists() | ||
| # Remove after we are getting nameservers from db | ||
| _, nameservers = self.get_x_zone_id_if_zone_exists(domain_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.
You can remove this line and the comment above
src/registrar/views/domain.py
Outdated
| zone_name = domain_name | ||
| # post nameservers to registry | ||
|
|
||
| nameservers = self.dns_host_service._get_nameservers_from_db(domain_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.
SInce you are already doing a query on zones above, you could simplify this (and eliminate the addtional query in the helper function) by doing something like this:
zones = DnsZone.objects.filter(name=domain_name)
if zones.exists():
zone = zones.first()
nameservers = zone.nameservers
if not nameservers:
logger.error(f"No nameservers found in DB for domain {domain_name}")
return JsonResponse(
{"status": "error", "message": "DNS nameservers not available"},
status=400,
)
try:
self.dns_host_service.register_nameservers(zone.name, nameservers)
| raise | ||
|
|
||
| return nameservers | ||
| logger.info(f"DNS setup completed successfully for domain {domain_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.
I appreciate this additional log! It helped me when I was testing to ensure it worked.
| """Find an item by name in a list of dictionaries.""" | ||
| return next((item.get("name_servers") for item in items if item.get("id") == x_zone_id), None) | ||
|
|
||
| def _get_nameservers_from_db(self, domain_name) -> list[str]: |
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 like the thinking around creating a helper function here. I made a comment about simplifying our queries so that this actually wouldn't be necessary.
| @@ -65,7 +63,7 @@ | |||
| "cf_zone": 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.
Noting that we don't actually use either of these values in the test (cf_account and cf_zone) in from any of the test cases. Would you mind removing these from the test cases?
|
|
||
| for case in test_cases: | ||
| with self.subTest(msg=case["test_name"], **case): | ||
| if case["test_name"] != "has db account, has db zone": |
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'm not sure I understand why this was added- why do we delete the zone here if the test case is that it has a zone?
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.
Earlier in the test, we setup
DnsZone.objects.create( domain=domain, dns_account=dns_acc, name=domain_name, nameservers=["ex1.dns.gov", "ex2.dns.gov"] )
I remove that Zone so that it can't be pulled from the table in the cases where there is no db zone.
I guess the alternative would be to do something like...
if case["test_name"] == "has db account, has db zone":
and then create the zone here.
I think I like that second option better, it makes more sense and is easier to read. Should I add a comment too, to make that clear?
|
🥳 Successfully deployed to developer sandbox aa. |
Ticket
Resolves #4141
Changes
dns_setupno longer returns nameserversContext for reviewers
Setup
docker compose exec app ./manage.py shellfrom registrar.models import DnsZonezone = DnsZone.objects.get(name="<domain_name>")zone.nameserversThis will print out the nameservers (['rainbow.dns.gov', 'rainbow2.dns.gov'])
Code Review Verification Steps
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