Merge lp:~allenap/maas/dns-serials--bug-1571645--sequence into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 4975
Proposed branch: lp:~allenap/maas/dns-serials--bug-1571645--sequence
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 274 lines (+99/-26)
12 files modified
src/maasserver/api/domains.py (+2/-4)
src/maasserver/api/tests/test_domains.py (+1/-1)
src/maasserver/dns/config.py (+1/-11)
src/maasserver/migrations/builtin/maasserver/0026_create_zone_serial_sequence.py (+4/-2)
src/maasserver/migrations/builtin/maasserver/0056_zone_serial_ownership.py (+30/-0)
src/maasserver/migrations/builtin/maasserver/0057_merge.py (+13/-0)
src/maasserver/migrations/south/migrations/0011_add_dns_zone_serial_sequence.py (+22/-3)
src/maasserver/models/dnspublication.py (+11/-1)
src/maasserver/triggers/system.py (+1/-1)
src/maasserver/triggers/tests/helper.py (+1/-1)
src/maasserver/triggers/tests/test_system.py (+1/-1)
utilities/check-imports (+12/-1)
To merge this branch: bzr merge lp:~allenap/maas/dns-serials--bug-1571645--sequence
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+293237@code.launchpad.net

Commit message

Move zone_serial into the dnspublication module.

Also associate it in the database, ensure that the sequence in the database is set to cycle, and ratchet up the controls on imports in South migrations.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks good. Just one minor nit below.

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

Thanks Mike!

Revision history for this message
MAAS Lander (maas-lander) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (1.1 MiB)

The attempt to merge lp:~allenap/maas/dns-serials--bug-1571645--sequence into lp:maas failed. Below is the output from the failed tests.

Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [92.2 kB]
Hit:2 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [93.3 kB]
Hit:4 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease
Get:5 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [34.4 kB]
Get:6 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [7,972 B]
Fetched 228 kB in 0s (476 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind bash bind9 bind9utils build-essential bzr bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm postgresql pxelinux python3-all python3-apt python3-bson python3-convoy python3-coverage python3-crochet python3-cssselect python3-curtin python3-dev python3-distro-info python3-django python3-django-nose python3-django-piston3 python3-dnspython python3-docutils python3-formencode python3-hivex python3-httplib2 python3-jinja2 python3-jsonschema python3-lxml python3-mock python3-netaddr python3-netifaces python3-oauth python3-oauthlib python3-openssl python3-paramiko python3-petname python3-pexpect python3-psycopg2 python3-pyinotify python3-pyparsing python3-pyvmomi python3-requests python3-seamicroclient python3-setuptools python3-simplestreams python3-sphinx python3-tempita python3-twisted python3-txtftp python3-tz python3-yaml python3-zope.interface python-bson python-crochet python-django python-django-piston python-djorm-ext-pgarray python-formencode python-lxml python-netaddr python-netifaces python-pocket-lint python-psycopg2 python-simplejson python-tempita python-twisted python-yaml socat syslinux-common tgt ubuntu-cloudimage-keyring wget xvfb
Reading package lists...
Building dependency tree...
Reading state information...
apache2 is already the newest version (2.4.18-2ubuntu3).
archdetect-deb is already the newest version (1.117ubuntu2).
authbind is already the newest version (2.1.1+nmu1).
bash is already the newest version (4.3-14ubuntu1).
build-essential is already the newest version (12.1ubuntu2).
bzr is already the newest version (2.7.0-2ubuntu1).
curl is already the newest version (7.47.0-1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
freeipmi-tools is already the newest version (1.4.11-1ubuntu1).
git is already the newest version (1:2.7.4-0ubuntu1).
isc-dhcp-common is already the newest version (4.3.3-5ubuntu12).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already ...

Revision history for this message
Gavin Panella (allenap) wrote :

Merged migrations.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/domains.py'
2--- src/maasserver/api/domains.py 2016-03-31 23:34:55 +0000
3+++ src/maasserver/api/domains.py 2016-04-29 11:36:07 +0000
4@@ -8,14 +8,12 @@
5 operation,
6 OperationsHandler,
7 )
8-from maasserver.dns.config import (
9- dns_force_reload,
10- zone_serial,
11-)
12+from maasserver.dns.config import dns_force_reload
13 from maasserver.enum import NODE_PERMISSION
14 from maasserver.exceptions import MAASAPIValidationError
15 from maasserver.forms_domain import DomainForm
16 from maasserver.models import Domain
17+from maasserver.models.dnspublication import zone_serial
18 from maasserver.sequence import INT_MAX
19 from piston3.utils import rc
20
21
22=== modified file 'src/maasserver/api/tests/test_domains.py'
23--- src/maasserver/api/tests/test_domains.py 2016-03-28 13:54:47 +0000
24+++ src/maasserver/api/tests/test_domains.py 2016-04-29 11:36:07 +0000
25@@ -11,7 +11,7 @@
26
27 from django.conf import settings
28 from django.core.urlresolvers import reverse
29-from maasserver.dns.config import zone_serial
30+from maasserver.models.dnspublication import zone_serial
31 from maasserver.models.domain import Domain
32 from maasserver.sequence import INT_MAX
33 from maasserver.testing.api import APITestCase
34
35=== modified file 'src/maasserver/dns/config.py'
36--- src/maasserver/dns/config.py 2016-03-31 23:34:55 +0000
37+++ src/maasserver/dns/config.py 2016-04-29 11:36:07 +0000
38@@ -13,12 +13,9 @@
39 from maasserver.dns.zonegenerator import ZoneGenerator
40 from maasserver.enum import RDNS_MODE
41 from maasserver.models.config import Config
42+from maasserver.models.dnspublication import zone_serial
43 from maasserver.models.domain import Domain
44 from maasserver.models.subnet import Subnet
45-from maasserver.sequence import (
46- INT_MAX,
47- Sequence,
48-)
49 from provisioningserver.dns.actions import (
50 bind_reload,
51 bind_reload_with_retries,
52@@ -32,13 +29,6 @@
53 maaslog = get_maas_logger("dns")
54
55
56-# A DNS zone's serial is a 32-bit integer. Also, we start with the
57-# value 1 because 0 has special meaning for some DNS servers. Even if
58-# we control the DNS server we use, better safe than sorry.
59-zone_serial = Sequence(
60- 'maasserver_zone_serial_seq', increment=1, minvalue=1, maxvalue=INT_MAX)
61-
62-
63 def current_zone_serial():
64 return '%0.10d' % zone_serial.current()
65
66
67=== modified file 'src/maasserver/migrations/builtin/maasserver/0026_create_zone_serial_sequence.py'
68--- src/maasserver/migrations/builtin/maasserver/0026_create_zone_serial_sequence.py 2016-02-10 20:24:35 +0000
69+++ src/maasserver/migrations/builtin/maasserver/0026_create_zone_serial_sequence.py 2016-04-29 11:36:07 +0000
70@@ -3,8 +3,10 @@
71
72 from django.db import migrations
73
74-# At the time of writing this should match the definition in
75-# maasserver.dns.config.zone_serial, and vice-versa.
76+# At the time of writing this should match the definition of zone_serial in
77+# maasserver.dns.config. This is done with a snippet of PL/pgSQL to support
78+# PostgreSQL before 9.5, which does not support `CREATE SEQUENCE ... IF NOT
79+# EXISTS`.
80 sequence_create = ("""\
81 DO
82 $$
83
84=== added file 'src/maasserver/migrations/builtin/maasserver/0056_zone_serial_ownership.py'
85--- src/maasserver/migrations/builtin/maasserver/0056_zone_serial_ownership.py 1970-01-01 00:00:00 +0000
86+++ src/maasserver/migrations/builtin/maasserver/0056_zone_serial_ownership.py 2016-04-29 11:36:07 +0000
87@@ -0,0 +1,30 @@
88+# -*- coding: utf-8 -*-
89+from django.db import migrations
90+
91+
92+class Migration(migrations.Migration):
93+
94+ dependencies = [
95+ ('maasserver', '0055_dns_publications'),
96+ ]
97+
98+ operations = [
99+ # Associate maasserver_zone_serial_seq with maasserver_dnspublication.
100+ migrations.RunSQL(
101+ # Forwards.
102+ ("ALTER SEQUENCE maasserver_zone_serial_seq "
103+ "OWNED BY maasserver_dnspublication.serial"),
104+ # Reverse.
105+ ("ALTER SEQUENCE maasserver_zone_serial_seq "
106+ "OWNED BY NONE"),
107+ ),
108+ # Ensure that maasserver_zone_serial_seq cycles. It does not seem
109+ # likely that anyone will exhaust all 2^32 zone serials, but if they
110+ # do we should behave as the DNS server will expect, i.e. cycle.
111+ migrations.RunSQL(
112+ # Forwards.
113+ "ALTER SEQUENCE maasserver_zone_serial_seq CYCLE",
114+ # Reverse.
115+ "ALTER SEQUENCE maasserver_zone_serial_seq NO CYCLE",
116+ ),
117+ ]
118
119=== added file 'src/maasserver/migrations/builtin/maasserver/0057_merge.py'
120--- src/maasserver/migrations/builtin/maasserver/0057_merge.py 1970-01-01 00:00:00 +0000
121+++ src/maasserver/migrations/builtin/maasserver/0057_merge.py 2016-04-29 11:36:07 +0000
122@@ -0,0 +1,13 @@
123+# -*- coding: utf-8 -*-
124+from django.db import migrations
125+
126+
127+class Migration(migrations.Migration):
128+
129+ dependencies = [
130+ ('maasserver', '0056_add_description_to_fabric_and_space'),
131+ ('maasserver', '0056_zone_serial_ownership'),
132+ ]
133+
134+ operations = [
135+ ]
136
137=== modified file 'src/maasserver/migrations/south/migrations/0011_add_dns_zone_serial_sequence.py'
138--- src/maasserver/migrations/south/migrations/0011_add_dns_zone_serial_sequence.py 2015-11-25 15:32:43 +0000
139+++ src/maasserver/migrations/south/migrations/0011_add_dns_zone_serial_sequence.py 2016-04-29 11:36:07 +0000
140@@ -6,19 +6,38 @@
141 import datetime
142
143 from django.db import models
144-from maasserver.dns.config import zone_serial
145 from south.db import db
146 from south.v2 import SchemaMigration
147
148+# Stolen from the future, namely 0026_create_zone_serial_sequence in Django's
149+# new built-in migrations. This is done with a snippet of PL/pgSQL to support
150+# PostgreSQL before 9.5, which does not support `CREATE SEQUENCE ... IF NOT
151+# EXISTS`.
152+sequence_create = ("""\
153+DO
154+$$
155+BEGIN
156+ CREATE SEQUENCE maasserver_zone_serial_seq
157+ MINVALUE {minvalue:d} MAXVALUE {maxvalue:d};
158+EXCEPTION WHEN duplicate_table THEN
159+ -- Do nothing, it already exists.
160+END
161+$$ LANGUAGE plpgsql;
162+""").format(minvalue=1, maxvalue=((2 ** 32) - 1))
163+
164+sequence_drop = (
165+ "DROP SEQUENCE IF EXISTS maasserver_zone_serial_seq"
166+)
167+
168
169 class Migration(SchemaMigration):
170
171 def forwards(self, orm):
172- zone_serial.create()
173+ db.execute(sequence_create)
174
175
176 def backwards(self, orm):
177- zone_serial.drop()
178+ db.execute(sequence_drop)
179
180
181 models = {
182
183=== modified file 'src/maasserver/models/dnspublication.py'
184--- src/maasserver/models/dnspublication.py 2016-04-21 16:32:47 +0000
185+++ src/maasserver/models/dnspublication.py 2016-04-29 11:36:07 +0000
186@@ -21,7 +21,17 @@
187 IntegerField,
188 )
189 from maasserver import DefaultMeta
190-from maasserver.dns.config import zone_serial
191+from maasserver.sequence import (
192+ INT_MAX,
193+ Sequence,
194+)
195+
196+# A DNS zone's serial is a 32-bit integer. Also, we start with the value 1
197+# because 0 has special meaning for some DNS servers. Even if we control the
198+# DNS server we use, better safe than sorry.
199+zone_serial = Sequence(
200+ 'maasserver_zone_serial_seq', increment=1, minvalue=1, maxvalue=INT_MAX,
201+ owner='maasserver_dnspublication.serial')
202
203
204 def next_serial():
205
206=== modified file 'src/maasserver/triggers/system.py'
207--- src/maasserver/triggers/system.py 2016-04-11 16:23:26 +0000
208+++ src/maasserver/triggers/system.py 2016-04-29 11:36:07 +0000
209@@ -15,7 +15,7 @@
210
211 from textwrap import dedent
212
213-from maasserver.dns.config import zone_serial
214+from maasserver.models.dnspublication import zone_serial
215 from maasserver.triggers import (
216 register_procedure,
217 register_trigger,
218
219=== modified file 'src/maasserver/triggers/tests/helper.py'
220--- src/maasserver/triggers/tests/helper.py 2016-03-31 23:34:55 +0000
221+++ src/maasserver/triggers/tests/helper.py 2016-04-29 11:36:07 +0000
222@@ -8,7 +8,6 @@
223
224 from crochet import wait_for
225 from django.contrib.auth.models import User
226-from maasserver.dns.config import zone_serial
227 from maasserver.enum import (
228 INTERFACE_TYPE,
229 NODE_TYPE,
230@@ -18,6 +17,7 @@
231 from maasserver.models.cacheset import CacheSet
232 from maasserver.models.dhcpsnippet import DHCPSnippet
233 from maasserver.models.dnsdata import DNSData
234+from maasserver.models.dnspublication import zone_serial
235 from maasserver.models.dnsresource import DNSResource
236 from maasserver.models.domain import Domain
237 from maasserver.models.event import Event
238
239=== modified file 'src/maasserver/triggers/tests/test_system.py'
240--- src/maasserver/triggers/tests/test_system.py 2016-03-31 23:34:55 +0000
241+++ src/maasserver/triggers/tests/test_system.py 2016-04-29 11:36:07 +0000
242@@ -8,7 +8,7 @@
243 from contextlib import closing
244
245 from django.db import connection
246-from maasserver.dns.config import zone_serial
247+from maasserver.models.dnspublication import zone_serial
248 from maasserver.testing.testcase import MAASServerTestCase
249 from maasserver.triggers.system import register_system_triggers
250 from maasserver.utils.orm import psql_array
251
252=== modified file 'utilities/check-imports'
253--- utilities/check-imports 2016-03-28 13:54:47 +0000
254+++ utilities/check-imports 2016-04-29 11:36:07 +0000
255@@ -360,7 +360,18 @@
256 ),
257 (
258 RegionMigrationsSouth,
259- RegionControllerRule | Allow("south|south.**"),
260+ Rule(
261+ Allow("django|django.**"),
262+ Allow("lxml|lxml.**"),
263+ Allow("netaddr|netaddr.**"),
264+ Allow("south|south.**"),
265+ Allow(StandardLibraries),
266+
267+ # XXX: The following three permissions are temporary;
268+ # they MUST be eliminated before MAAS 2.0 release.
269+ Allow("maasserver|maasserver.**"),
270+ Allow("metadataserver|metadataserver.**"),
271+ )
272 ),
273 (
274 RegionMigrationsBuiltin,