Merge lp:~blake-rouse/maas/fix-1524152 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Andres Rodriguez
Approved revision: no longer in the source branch.
Merged at revision: 4545
Proposed branch: lp:~blake-rouse/maas/fix-1524152
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 138 lines (+81/-19)
3 files modified
src/maasserver/management/commands/dbupgrade.py (+29/-11)
src/maasserver/migrations/builtin/piston3/0002_auto_20151209_1652.py (+22/-0)
src/maasserver/tests/test_commands_dbupgrade.py (+30/-8)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1524152
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+280057@code.launchpad.net

Commit message

Fix upgrade path for piston. Fix missing migrations in the in-tree MAAS 1.9 tarball. Fix missing piston3 migration.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/management/commands/dbupgrade.py'
--- src/maasserver/management/commands/dbupgrade.py 2015-12-08 18:48:31 +0000
+++ src/maasserver/management/commands/dbupgrade.py 2015-12-09 17:02:06 +0000
@@ -190,13 +190,25 @@
190 not cls._south_migrations_are_complete(database))190 not cls._south_migrations_are_complete(database))
191191
192 @classmethod192 @classmethod
193 def _rename_piston_to_piston3(cls, database):193 def _find_tables(cls, database, startwith):
194 """Return list of tables that start with `startwith`."""
195 cursor = connections[database].cursor()
196 cursor.execute(
197 "SELECT table_name FROM information_schema.tables "
198 "WHERE table_schema = 'public' AND table_name LIKE %s",
199 [startwith + "%"])
200 return [
201 row[0]
202 for row in cursor.fetchall()
203 ]
204
205 @classmethod
206 def _rename_piston_to_piston3(cls, database, tables):
194 """Rename piston to piston3."""207 """Rename piston to piston3."""
195 cursor = connections[database].cursor()208 cursor = connections[database].cursor()
196 cursor.execute(209 for table in tables:
197 "ALTER TABLE piston_consumer RENAME TO piston3_consumer")210 cursor.execute(
198 cursor.execute("ALTER TABLE piston_nonce RENAME TO piston3_nonce")211 "ALTER TABLE piston_%s RENAME TO piston3_%s" % (table, table))
199 cursor.execute("ALTER TABLE piston_token RENAME TO piston3_token")
200212
201 @classmethod213 @classmethod
202 def _perform_south_migrations(cls, script_path, database):214 def _perform_south_migrations(cls, script_path, database):
@@ -259,13 +271,19 @@
259 if rc != 0:271 if rc != 0:
260 sys.exit(rc)272 sys.exit(rc)
261 else:273 else:
262 # Piston has been renamed from piston to piston3. If south was ever274 # Piston has been renamed from piston to piston3.
263 # performed then the tables need to be renamed.275 piston_tables = self._find_tables(database, "piston")
264 south_was_performed = self._south_was_performed(database)276 piston_tables = [
265 if south_was_performed:277 table[7:]
266 self._rename_piston_to_piston3(database)278 for table in piston_tables
279 if not table.startswith("piston3")
280 ]
281 if len(piston_tables):
282 self._rename_piston_to_piston3(database, piston_tables)
267283
268 # Perform the builtin migration faking the initial migrations284 # Perform the builtin migration faking the initial migrations
269 # if south was ever performed.285 # if south was ever performed.
270 call_command(286 call_command(
271 "migrate", interactive=False, fake_initial=south_was_performed)287 "migrate",
288 interactive=False,
289 fake_initial=self._south_was_performed(database))
272290
=== added file 'src/maasserver/migrations/builtin/piston3/0002_auto_20151209_1652.py'
--- src/maasserver/migrations/builtin/piston3/0002_auto_20151209_1652.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/migrations/builtin/piston3/0002_auto_20151209_1652.py 2015-12-09 17:02:06 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2from __future__ import unicode_literals
3
4from django.db import (
5 migrations,
6 models,
7)
8
9
10class Migration(migrations.Migration):
11
12 dependencies = [
13 ('piston3', '0001_initial'),
14 ]
15
16 operations = [
17 migrations.AlterField(
18 model_name='consumer',
19 name='status',
20 field=models.CharField(default='pending', choices=[('pending', 'Pending'), ('accepted', 'Accepted'), ('canceled', 'Canceled'), ('rejected', 'Rejected')], max_length=16),
21 ),
22 ]
023
=== modified file 'src/maasserver/migrations/south/django16_south_maas19.tar.gz'
1Binary files src/maasserver/migrations/south/django16_south_maas19.tar.gz 2015-12-02 20:43:30 +0000 and src/maasserver/migrations/south/django16_south_maas19.tar.gz 2015-12-09 17:02:06 +0000 differ24Binary files src/maasserver/migrations/south/django16_south_maas19.tar.gz 2015-12-02 20:43:30 +0000 and src/maasserver/migrations/south/django16_south_maas19.tar.gz 2015-12-09 17:02:06 +0000 differ
=== modified file 'src/maasserver/tests/test_commands_dbupgrade.py'
--- src/maasserver/tests/test_commands_dbupgrade.py 2015-12-08 18:48:31 +0000
+++ src/maasserver/tests/test_commands_dbupgrade.py 2015-12-09 17:02:06 +0000
@@ -137,14 +137,36 @@
137 self.assertCalledSouth(popen)137 self.assertCalledSouth(popen)
138 self.assertCalledDjango(popen)138 self.assertCalledDjango(popen)
139139
140 def test_django_run_renames_piston_tables_if_south_ran_before(self):140 def test_django_run_renames_piston_tables_if_piston_tables_exists(self):
141 self.patch(141 self.patch(
142 dbupgrade_command, "_south_was_performed").return_value = True142 dbupgrade_command, "_south_was_performed").return_value = True
143 mock_rename = self.patch(143 self.patch(dbupgrade_command, "_find_tables").return_value = [
144 dbupgrade_command, "_rename_piston_to_piston3")144 "piston_consumer",
145 mock_call = self.patch(dbupgrade_module, "call_command")145 "piston_token",
146 call_command('dbupgrade', django=True)146 ]
147 self.assertThat(mock_rename, MockCalledOnceWith("default"))147 mock_rename = self.patch(
148 dbupgrade_command, "_rename_piston_to_piston3")
149 mock_call = self.patch(dbupgrade_module, "call_command")
150 call_command('dbupgrade', django=True)
151 self.assertThat(
152 mock_rename, MockCalledOnceWith("default", ["consumer", "token"]))
153 self.assertThat(
154 mock_call, MockCalledOnceWith(
155 "migrate", interactive=False, fake_initial=True))
156
157 def test_django_run_doesnt_renames_piston_tables_if_piston3(self):
158 self.patch(
159 dbupgrade_command, "_south_was_performed").return_value = True
160 self.patch(dbupgrade_command, "_find_tables").return_value = [
161 "piston3_consumer",
162 "piston3_token",
163 ]
164 mock_rename = self.patch(
165 dbupgrade_command, "_rename_piston_to_piston3")
166 mock_call = self.patch(dbupgrade_module, "call_command")
167 call_command('dbupgrade', django=True)
168 self.assertThat(
169 mock_rename, MockNotCalled())
148 self.assertThat(170 self.assertThat(
149 mock_call, MockCalledOnceWith(171 mock_call, MockCalledOnceWith(
150 "migrate", interactive=False, fake_initial=True))172 "migrate", interactive=False, fake_initial=True))