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
=== modified file 'src/maasserver/tests/models.py'
--- src/maasserver/tests/models.py 2015-03-25 15:33:23 +0000
+++ src/maasserver/tests/models.py 2015-03-27 10:06:20 +0000
@@ -66,7 +66,8 @@
66class TimestampedModelTestModel(TimestampedModel):66class TimestampedModelTestModel(TimestampedModel):
67 # This model inherits from TimestampedModel so it will have a 'created'67 # This model inherits from TimestampedModel so it will have a 'created'
68 # field and an 'updated' field.68 # field and an 'updated' field.
69 pass69 class Meta:
70 db_table = "testtimestampmodel"
7071
7172
72class FieldChangeTestModel(Model):73class FieldChangeTestModel(Model):
7374
=== modified file 'src/maasserver/tests/test_migrations.py'
--- src/maasserver/tests/test_migrations.py 2014-08-20 00:42:35 +0000
+++ src/maasserver/tests/test_migrations.py 2015-03-27 10:06:20 +0000
@@ -18,8 +18,14 @@
18__metaclass__ = type18__metaclass__ = type
19__all__ = []19__all__ = []
2020
21from django.core.management import call_command
21from maasserver.testing.db_migrations import detect_sequence_clashes22from maasserver.testing.db_migrations import detect_sequence_clashes
22from maastesting.testcase import MAASTestCase23from maastesting.testcase import MAASTestCase
24from maastesting.utils import capture_std_out_err
25from testtools.content import (
26 Content,
27 UTF8_TEXT,
28)
2329
2430
25EXISTING_DUPES = [31EXISTING_DUPES = [
@@ -42,3 +48,26 @@
42 self.assertEqual(48 self.assertEqual(
43 EXISTING_DUPES,49 EXISTING_DUPES,
44 detect_sequence_clashes('maasserver'))50 detect_sequence_clashes('maasserver'))
51
52 def test_all_model_changes_in_migrations(self):
53 # Make sure all the model changes have been transformed into
54 # migrations.
55 try:
56 with capture_std_out_err() as (stdoutIO, stderrIO):
57 call_command(
58 "schemamigration", "maasserver",
59 "generated_migration", auto=True, stdout=True)
60 except SystemExit, e:
61 if e.code == 1:
62 # No migration can be generated because the models haven't
63 # changed: exit silently.
64 return
65 raise
66 else:
67 self.addDetail(
68 "schemamigration stderr",
69 Content(UTF8_TEXT, lambda: stderrIO.getvalue()))
70 self.addDetail(
71 "schemamigration stdout",
72 Content(UTF8_TEXT, lambda: stdoutIO.getvalue()))
73 self.fail("Migrations are not in sync with the models!")
4574
=== modified file 'src/maastesting/tests/test_utils.py'
--- src/maastesting/tests/test_utils.py 2013-10-07 09:12:40 +0000
+++ src/maastesting/tests/test_utils.py 2015-03-27 10:06:20 +0000
@@ -14,8 +14,14 @@
14__metaclass__ = type14__metaclass__ = type
15__all__ = []15__all__ = []
1616
17import sys
18
19from maastesting.factory import factory
17from maastesting.testcase import MAASTestCase20from maastesting.testcase import MAASTestCase
18from maastesting.utils import extract_word_list21from maastesting.utils import (
22 capture_std_out_err,
23 extract_word_list,
24)
1925
2026
21class TestFunctions(MAASTestCase):27class TestFunctions(MAASTestCase):
@@ -34,3 +40,15 @@
34 for string in expected40 for string in expected
35 }41 }
36 self.assertEqual(expected, observed)42 self.assertEqual(expected, observed)
43
44
45class TestCaptureStdOutErr(MAASTestCase):
46
47 def test_captures_std_out_err(self):
48 stdout = factory.make_name('stdout')
49 stderr = factory.make_name('stderr')
50 with capture_std_out_err() as (stdoutIO, stderrIO):
51 sys.stdout.write(stdout)
52 sys.stderr.write(stderr)
53 self.assertEqual(stdout, stdoutIO.getvalue())
54 self.assertEqual(stderr, stderrIO.getvalue())
3755
=== modified file 'src/maastesting/utils.py'
--- src/maastesting/utils.py 2015-03-25 15:33:23 +0000
+++ src/maastesting/utils.py 2015-03-27 10:06:20 +0000
@@ -15,6 +15,7 @@
15__all__ = [15__all__ = [
16 "age_file",16 "age_file",
17 "content_from_file",17 "content_from_file",
18 "capture_std_out_err",
18 "extract_word_list",19 "extract_word_list",
19 "get_write_time",20 "get_write_time",
20 "FakeRandInt",21 "FakeRandInt",
@@ -24,6 +25,8 @@
24 ]25 ]
2526
26import codecs27import codecs
28from contextlib import contextmanager
29from cStringIO import StringIO
27import os30import os
28import re31import re
29import signal32import signal
@@ -33,6 +36,7 @@
33)36)
34from traceback import print_exc37from traceback import print_exc
3538
39from mock import patch
36import subunit40import subunit
37from testtools.content import Content41from testtools.content import Content
38from testtools.content_type import UTF8_TEXT42from testtools.content_type import UTF8_TEXT
@@ -153,3 +157,14 @@
153 if self.maximum is not None:157 if self.maximum is not None:
154 maximum = min(maximum, self.maximum)158 maximum = min(maximum, self.maximum)
155 return self.real_randint(minimum, maximum)159 return self.real_randint(minimum, maximum)
160
161
162@contextmanager
163def capture_std_out_err():
164 """A context manager that captures stdout and stderr."""
165 stdout = StringIO()
166 stderr = StringIO()
167
168 with patch('sys.stdout', stdout):
169 with patch('sys.stderr', stderr):
170 yield stdout, stderr
156171
=== modified file 'src/metadataserver/tests/test_migrations.py'
--- src/metadataserver/tests/test_migrations.py 2013-10-07 09:12:40 +0000
+++ src/metadataserver/tests/test_migrations.py 2015-03-27 10:06:20 +0000
@@ -18,11 +18,41 @@
18__metaclass__ = type18__metaclass__ = type
19__all__ = []19__all__ = []
2020
21
22from django.core.management import call_command
21from maasserver.testing.db_migrations import detect_sequence_clashes23from maasserver.testing.db_migrations import detect_sequence_clashes
22from maastesting.testcase import MAASTestCase24from maastesting.testcase import MAASTestCase
25from maastesting.utils import capture_std_out_err
26from testtools.content import (
27 Content,
28 UTF8_TEXT,
29)
2330
2431
25class TestMigrations(MAASTestCase):32class TestMigrations(MAASTestCase):
2633
27 def test_migrations_have_unique_numbers(self):34 def test_migrations_have_unique_numbers(self):
28 self.assertEqual([], detect_sequence_clashes('metadataserver'))35 self.assertEqual([], detect_sequence_clashes('metadataserver'))
36
37 def test_all_model_changes_in_migrations(self):
38 # Make sure all the model changes have been transformed into
39 # migrations.
40 try:
41 with capture_std_out_err() as (stdoutIO, stderrIO):
42 call_command(
43 "schemamigration", "metadataserver",
44 "generated_migration", auto=True, stdout=True)
45 except SystemExit, e:
46 if e.code == 1:
47 # No migration can be generated because the models haven't
48 # changed: exit silently.
49 return
50 raise
51 else:
52 self.addDetail(
53 "schemamigration stderr",
54 Content(UTF8_TEXT, lambda: stderrIO.getvalue()))
55 self.addDetail(
56 "schemamigration stdout",
57 Content(UTF8_TEXT, lambda: stdoutIO.getvalue()))
58 self.fail("Migrations are not in sync with the models!")