Merge lp:~rvb/maas/safeguard-migrations into lp:~maas-committers/maas/trunk
- safeguard-migrations
- Merge into trunk
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 |
Related bugs: |
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:/
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.
Raphaël Badin (rvb) wrote : | # |
Thanks for the review!
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Get:7 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:8 http://
Get:9 http://
Hit http://
Hit http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,601 kB in 3s (501 kB/s)
Reading package lists...
sudo DEBIAN_
--
Gavin Panella (allenap) : | # |
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Hit http://
Get:6 http://
Get:7 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:8 http://
Get:9 http://
Hit http://
Hit http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,606 kB in 3s (495 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.
Ign http://
Hit http://
Hit http://
Ign http://
Ign http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Ign http://
Ign http://
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Ign http://
Get:2 http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Get:7 http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:8 http://
Hit http://
Get:9 http://
Hit http://
Hit http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,608 kB in 3s (484 kB/s)
Reading package lists...
sudo DEBIAN_
--
MAAS Lander (maas-lander) wrote : | # |
The attempt to merge lp:~rvb/maas/safeguard-migrations into lp:maas failed. Below is the output from the failed tests.
Ign http://
Get:1 http://
Get:2 http://
Ign http://
Ign http://
Hit http://
Get:3 http://
Hit http://
Get:4 http://
Get:5 http://
Get:6 http://
Hit http://
Get:7 http://
Get:8 http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Hit http://
Get:9 http://
Get:10 http://
Get:11 http://
Get:12 http://
Hit http://
Hit http://
Ign http://
Ign http://
Fetched 1,608 kB in 3s (522 kB/s)
Reading package lists...
sudo DEBIAN_
--
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.
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:/
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
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!") |
Looks good, I like it!