Merge ~freyes/maas:lp1880495 into maas:2.3

Proposed by Felipe Reyes
Status: Needs review
Proposed branch: ~freyes/maas:lp1880495
Merge into: maas:2.3
Diff against target: 25 lines (+13/-1)
1 file modified
src/maasserver/migrations/builtin/maasserver/0011_domain_data.py (+13/-1)
Reviewer Review Type Date Requested Status
Adam Collard Needs Fixing
MAAS Lander Approve
Review via email: mp+384587@code.launchpad.net

Description of the change

I'm proposing this change to get feedback, I understand that I'll need to first propose it against master and then backport it to previous releases.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1880495 lp:~freyes/maas/+git/maas into -b 2.3 lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 6c45d678beb67db8a1c5b0e1836e99a45c3dabb8

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

Hi, change looks good.

To remove dependencies on model code, these imports should also br dropped:

import maasserver.models.dnsresource
from maasserver.models.domain import DEFAULT_DOMAIN_NAME
import maasserver.models.node

DEFAULT_DOMAIN_NAME can be just defined locally with the same value, the others are actually unused.

Note that the patch is at a different location in master (src/maasserver/migrations/maasserver/0011_domain_data.py), but other than that the change should apply cleanly.

Thanks!

Revision history for this message
Adam Collard (adam-collard) :
review: Needs Fixing

Unmerged commits

6c45d67... by Felipe Reyes

LP: #1880495 - Use get_or_create() in migration step

The function get_default_domain() sets the ttl which during the migration
step 0011 is not present in the database yet. This patch uses get_or_create()
instead to get the 'maas' domain object with the same defaults that
get_default_domain() uses.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/migrations/builtin/maasserver/0011_domain_data.py b/src/maasserver/migrations/builtin/maasserver/0011_domain_data.py
2index 7e965d6..30a7cba 100644
3--- a/src/maasserver/migrations/builtin/maasserver/0011_domain_data.py
4+++ b/src/maasserver/migrations/builtin/maasserver/0011_domain_data.py
5@@ -106,7 +106,19 @@ def migrate_staticipaddress_hostname(apps, schema_editor):
6 if len(domains):
7 domain_id = domains.pop().id
8 else:
9- domain_id = maasserver.models.dnsresource.get_default_domain()
10+ now = datetime.datetime.now()
11+ domain, _ = Domain.objects.get_or_create(
12+ id=0,
13+ defaults={
14+ 'id': 0,
15+ 'name': DEFAULT_DOMAIN_NAME,
16+ 'authoritative': True,
17+ 'created': now,
18+ 'updated': now,
19+ }
20+ )
21+ domain_id = domain.id
22+
23 now = datetime.datetime.now()
24 dnsrr, _ = DNSResource.objects.get_or_create(
25 name=hostname,

Subscribers

People subscribed via source and target branches