Merge lp:~rvb/maas/safeguard-migrations into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Rejected
Rejected by: MAAS Lander
Proposed branch: lp:~rvb/maas/safeguard-migrations
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 185 lines (+95/-2)
5 files modified
src/maasserver/tests/models.py (+2/-1)
src/maasserver/tests/test_migrations.py (+29/-0)
src/maastesting/tests/test_utils.py (+19/-1)
src/maastesting/utils.py (+15/-0)
src/metadataserver/tests/test_migrations.py (+30/-0)
To merge this branch: bzr merge lp:~rvb/maas/safeguard-migrations
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+253934@code.launchpad.net

Commit message

Add tests to make sure the migrations and the models are in sync.

Description of the change

This is to avoid having broken migrations landed (see https://code.launchpad.net/~rvb/maas/regenerate-mig-134/+merge/253823 for an example).

There is a little bit of repetition here (it was tempting to add scenarios to avoid the duplication) but I thought it was better to have two tests, one for each application.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Looks good, I like it!

review: Approve
Revision history for this message
Raphaël Badin (rvb) wrote :

Thanks for the review!

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

The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Get:2 http://security.ubuntu.com trusty-security Release [63.5 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [63.5 kB]
Get:5 http://security.ubuntu.com trusty-security/main Sources [74.8 kB]
Get:6 http://security.ubuntu.com trusty-security/universe Sources [17.9 kB]
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [251 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:8 http://security.ubuntu.com trusty-security/universe amd64 Packages [89.3 kB]
Get:9 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [187 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [107 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [486 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [260 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 1,601 kB in 3s (501 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr python-netifaces python-nose python-o...

Revision history for this message
Gavin Panella (allenap) :
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (118.1 KiB)

The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Get:2 http://security.ubuntu.com trusty-security Release [63.5 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [63.5 kB]
Get:5 http://security.ubuntu.com trusty-security/main Sources [75.7 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Get:6 http://security.ubuntu.com trusty-security/universe Sources [17.9 kB]
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [251 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:8 http://security.ubuntu.com trusty-security/universe amd64 Packages [89.7 kB]
Get:9 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [188 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [107 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [488 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [260 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 1,606 kB in 3s (495 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr python-netifaces python-nose python-o...

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

The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Hit http://security.ubuntu.com trusty-security Release.gpg
Hit http://security.ubuntu.com trusty-security Release
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Hit http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Hit http://security.ubuntu.com trusty-security/main Sources
Hit http://nova.clouds.archive.ubuntu.com trusty-updates Release
Hit http://security.ubuntu.com trusty-security/universe Sources
Hit http://security.ubuntu.com trusty-security/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Hit http://security.ubuntu.com trusty-security/universe amd64 Packages
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr python-netifaces python-nose python-oauth python-openssl python-paramiko python-pexpect python-pip python-pocket-lint python-psycopg2 python-pyinotify python-pyparsing python-seamicroclient python-simplejson p...

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

The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Get:2 http://security.ubuntu.com trusty-security Release [63.5 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [63.5 kB]
Get:5 http://security.ubuntu.com trusty-security/main Sources [75.7 kB]
Get:6 http://security.ubuntu.com trusty-security/universe Sources [17.9 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [251 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Get:8 http://security.ubuntu.com trusty-security/universe amd64 Packages [89.7 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:9 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [189 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [107 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [488 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [260 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 1,608 kB in 3s (484 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr python-netifaces python-nose python-o...

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

The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Get:2 http://security.ubuntu.com trusty-security Release [63.5 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [63.5 kB]
Get:5 http://security.ubuntu.com trusty-security/main Sources [75.7 kB]
Get:6 http://security.ubuntu.com trusty-security/universe Sources [18.0 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [251 kB]
Get:8 http://security.ubuntu.com trusty-security/universe amd64 Packages [89.7 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:9 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [189 kB]
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [107 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [488 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [260 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 1,608 kB in 3s (522 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr python-netifaces python-nose python-o...

Revision history for this message
Raphaël Badin (rvb) wrote :

For the curious: I don't want to spend time investigating what the failure is right now since we only have one week before the release and this is just a nice to have. I'll get it fixed and landed after the release.

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

Transitioned to Git.

lp:maas has now moved from Bzr to Git.
Please propose your branches with Launchpad using Git.

git clone https://git.launchpad.net/maas

Unmerged revisions

3701. By Raphaël Badin

Fix lint.

3700. By Raphaël Badin

Merge trunk.

3699. By Raphaël Badin

Fix lint.

3698. By Raphaël Badin

Fix test model.

3697. By Raphaël Badin

Review fixes.

3696. By Raphaël Badin

Add test to make sure the migrations and the models are in sync.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/tests/models.py'
2--- src/maasserver/tests/models.py 2015-03-25 15:33:23 +0000
3+++ src/maasserver/tests/models.py 2015-03-27 10:06:20 +0000
4@@ -66,7 +66,8 @@
5 class TimestampedModelTestModel(TimestampedModel):
6 # This model inherits from TimestampedModel so it will have a 'created'
7 # field and an 'updated' field.
8- pass
9+ class Meta:
10+ db_table = "testtimestampmodel"
11
12
13 class FieldChangeTestModel(Model):
14
15=== modified file 'src/maasserver/tests/test_migrations.py'
16--- src/maasserver/tests/test_migrations.py 2014-08-20 00:42:35 +0000
17+++ src/maasserver/tests/test_migrations.py 2015-03-27 10:06:20 +0000
18@@ -18,8 +18,14 @@
19 __metaclass__ = type
20 __all__ = []
21
22+from django.core.management import call_command
23 from maasserver.testing.db_migrations import detect_sequence_clashes
24 from maastesting.testcase import MAASTestCase
25+from maastesting.utils import capture_std_out_err
26+from testtools.content import (
27+ Content,
28+ UTF8_TEXT,
29+)
30
31
32 EXISTING_DUPES = [
33@@ -42,3 +48,26 @@
34 self.assertEqual(
35 EXISTING_DUPES,
36 detect_sequence_clashes('maasserver'))
37+
38+ def test_all_model_changes_in_migrations(self):
39+ # Make sure all the model changes have been transformed into
40+ # migrations.
41+ try:
42+ with capture_std_out_err() as (stdoutIO, stderrIO):
43+ call_command(
44+ "schemamigration", "maasserver",
45+ "generated_migration", auto=True, stdout=True)
46+ except SystemExit, e:
47+ if e.code == 1:
48+ # No migration can be generated because the models haven't
49+ # changed: exit silently.
50+ return
51+ raise
52+ else:
53+ self.addDetail(
54+ "schemamigration stderr",
55+ Content(UTF8_TEXT, lambda: stderrIO.getvalue()))
56+ self.addDetail(
57+ "schemamigration stdout",
58+ Content(UTF8_TEXT, lambda: stdoutIO.getvalue()))
59+ self.fail("Migrations are not in sync with the models!")
60
61=== modified file 'src/maastesting/tests/test_utils.py'
62--- src/maastesting/tests/test_utils.py 2013-10-07 09:12:40 +0000
63+++ src/maastesting/tests/test_utils.py 2015-03-27 10:06:20 +0000
64@@ -14,8 +14,14 @@
65 __metaclass__ = type
66 __all__ = []
67
68+import sys
69+
70+from maastesting.factory import factory
71 from maastesting.testcase import MAASTestCase
72-from maastesting.utils import extract_word_list
73+from maastesting.utils import (
74+ capture_std_out_err,
75+ extract_word_list,
76+)
77
78
79 class TestFunctions(MAASTestCase):
80@@ -34,3 +40,15 @@
81 for string in expected
82 }
83 self.assertEqual(expected, observed)
84+
85+
86+class TestCaptureStdOutErr(MAASTestCase):
87+
88+ def test_captures_std_out_err(self):
89+ stdout = factory.make_name('stdout')
90+ stderr = factory.make_name('stderr')
91+ with capture_std_out_err() as (stdoutIO, stderrIO):
92+ sys.stdout.write(stdout)
93+ sys.stderr.write(stderr)
94+ self.assertEqual(stdout, stdoutIO.getvalue())
95+ self.assertEqual(stderr, stderrIO.getvalue())
96
97=== modified file 'src/maastesting/utils.py'
98--- src/maastesting/utils.py 2015-03-25 15:33:23 +0000
99+++ src/maastesting/utils.py 2015-03-27 10:06:20 +0000
100@@ -15,6 +15,7 @@
101 __all__ = [
102 "age_file",
103 "content_from_file",
104+ "capture_std_out_err",
105 "extract_word_list",
106 "get_write_time",
107 "FakeRandInt",
108@@ -24,6 +25,8 @@
109 ]
110
111 import codecs
112+from contextlib import contextmanager
113+from cStringIO import StringIO
114 import os
115 import re
116 import signal
117@@ -33,6 +36,7 @@
118 )
119 from traceback import print_exc
120
121+from mock import patch
122 import subunit
123 from testtools.content import Content
124 from testtools.content_type import UTF8_TEXT
125@@ -153,3 +157,14 @@
126 if self.maximum is not None:
127 maximum = min(maximum, self.maximum)
128 return self.real_randint(minimum, maximum)
129+
130+
131+@contextmanager
132+def capture_std_out_err():
133+ """A context manager that captures stdout and stderr."""
134+ stdout = StringIO()
135+ stderr = StringIO()
136+
137+ with patch('sys.stdout', stdout):
138+ with patch('sys.stderr', stderr):
139+ yield stdout, stderr
140
141=== modified file 'src/metadataserver/tests/test_migrations.py'
142--- src/metadataserver/tests/test_migrations.py 2013-10-07 09:12:40 +0000
143+++ src/metadataserver/tests/test_migrations.py 2015-03-27 10:06:20 +0000
144@@ -18,11 +18,41 @@
145 __metaclass__ = type
146 __all__ = []
147
148+
149+from django.core.management import call_command
150 from maasserver.testing.db_migrations import detect_sequence_clashes
151 from maastesting.testcase import MAASTestCase
152+from maastesting.utils import capture_std_out_err
153+from testtools.content import (
154+ Content,
155+ UTF8_TEXT,
156+)
157
158
159 class TestMigrations(MAASTestCase):
160
161 def test_migrations_have_unique_numbers(self):
162 self.assertEqual([], detect_sequence_clashes('metadataserver'))
163+
164+ def test_all_model_changes_in_migrations(self):
165+ # Make sure all the model changes have been transformed into
166+ # migrations.
167+ try:
168+ with capture_std_out_err() as (stdoutIO, stderrIO):
169+ call_command(
170+ "schemamigration", "metadataserver",
171+ "generated_migration", auto=True, stdout=True)
172+ except SystemExit, e:
173+ if e.code == 1:
174+ # No migration can be generated because the models haven't
175+ # changed: exit silently.
176+ return
177+ raise
178+ else:
179+ self.addDetail(
180+ "schemamigration stderr",
181+ Content(UTF8_TEXT, lambda: stderrIO.getvalue()))
182+ self.addDetail(
183+ "schemamigration stdout",
184+ Content(UTF8_TEXT, lambda: stdoutIO.getvalue()))
185+ self.fail("Migrations are not in sync with the models!")