Merge lp:~rvb/maas/dj-migrations into lp:maas/trunk

Proposed by Raphaël Badin on 2015-03-11
Status: Rejected
Rejected by: Andres Rodriguez on 2016-02-23
Proposed branch: lp:~rvb/maas/dj-migrations
Merge into: lp:maas/trunk
Diff against target: 285 lines (+92/-5) (has conflicts)
8 files modified
Makefile (+2/-1)
src/maas/settings.py (+19/-1)
src/maasserver/fields.py (+23/-1)
src/maasserver/models/node.py (+5/-1)
src/maasserver/plugin.py (+5/-0)
src/maasserver/start_up.py (+12/-0)
src/maasserver/utils/__init__.py (+10/-0)
src/metadataserver/fields.py (+16/-1)
Text conflict in src/maas/settings.py
Text conflict in src/maasserver/fields.py
Text conflict in src/maasserver/plugin.py
Text conflict in src/maasserver/start_up.py
Text conflict in src/metadataserver/fields.py
To merge this branch: bzr merge lp:~rvb/maas/dj-migrations
Reviewer Review Type Date Requested Status
MAAS Maintainers 2015-03-11 Pending
Review via email: mp+252569@code.launchpad.net
To post a comment you must log in.
lp:~rvb/maas/dj-migrations updated on 2015-07-29
3634. By Raphaël Badin on 2015-03-11

Add Django migrations.

3635. By Raphaël Badin on 2015-03-12

Cope with empty default value. Fix get_default_zone.

3636. By Raphaël Badin on 2015-03-12

Fix.

3637. By Raphaël Badin on 2015-03-12

Fix binary field.

3638. By Raphaël Badin on 2015-03-12

Fix binary field.

3639. By Raphaël Badin on 2015-03-12

Fix binary field.

3640. By Raphaël Badin on 2015-03-13

Cope with a missing South.

3641. By Raphaël Badin on 2015-03-13

Update migration file.

3642. By Raphaël Badin on 2015-03-13

Merge trunk.

3643. By Raphaël Badin on 2015-03-13

Update initial migration.

3644. By Raphaël Badin on 2015-03-17

Load models import Django 1.7.

3645. By Raphaël Badin on 2015-03-17

Merge trunk.

3646. By Raphaël Badin on 2015-03-19

Reset 0001 migration.

3647. By Raphaël Badin on 2015-03-19

Merge trunk.

3648. By Raphaël Badin on 2015-03-19

Reset 0001 migration.

3649. By Raphaël Badin on 2015-03-19

Regenerate 0001 migrations.

3650. By Raphaël Badin on 2015-07-29

Initial mig.

Unmerged revisions

3650. By Raphaël Badin on 2015-07-29

Initial mig.

3649. By Raphaël Badin on 2015-03-19

Regenerate 0001 migrations.

3648. By Raphaël Badin on 2015-03-19

Reset 0001 migration.

3647. By Raphaël Badin on 2015-03-19

Merge trunk.

3646. By Raphaël Badin on 2015-03-19

Reset 0001 migration.

3645. By Raphaël Badin on 2015-03-17

Merge trunk.

3644. By Raphaël Badin on 2015-03-17

Load models import Django 1.7.

3643. By Raphaël Badin on 2015-03-13

Update initial migration.

3642. By Raphaël Badin on 2015-03-13

Merge trunk.

3641. By Raphaël Badin on 2015-03-13

Update migration file.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2015-07-03 11:18:16 +0000
3+++ Makefile 2015-07-29 15:36:58 +0000
4@@ -227,7 +227,8 @@
5 # all the files in cache.
6 lint-py: sources = $(wildcard *.py contrib/*.py) src templates twisted utilities etc
7 lint-py: bin/flake8
8- @find $(sources) -name '*.py' ! -path '*/migrations/*' -print0 \
9+ @find $(sources) -name '*.py' ! -path '*/migrations/*' ! \
10+ -path '*/south_migrations/*' -print0 \
11 | xargs -r0 -n50 -P4 bin/flake8 --ignore=E123 --config=/dev/null
12 @utilities/check-maaslog-exception
13
14
15=== modified file 'src/maas/settings.py'
16--- src/maas/settings.py 2015-06-26 10:17:33 +0000
17+++ src/maas/settings.py 2015-07-29 15:36:58 +0000
18@@ -13,9 +13,11 @@
19
20 __metaclass__ = type
21
22+from distutils.version import StrictVersion
23 import os
24 from sys import stdout
25
26+import django
27 import django.template
28 from maas import fix_up_databases
29 from maas.monkey import patch_get_script_prefix
30@@ -226,9 +228,13 @@
31 'maasserver',
32 'metadataserver',
33 'piston',
34- 'south',
35 )
36
37+if StrictVersion(django.get_version()) < StrictVersion('1.7'):
38+ INSTALLED_APPS += (
39+ 'south',
40+ )
41+
42 if DEBUG:
43 INSTALLED_APPS += (
44 'django.contrib.admin',
45@@ -301,6 +307,18 @@
46 'maasjson': 'maasserver.json',
47 }
48
49+<<<<<<< TREE
50+=======
51+
52+SOUTH_MIGRATION_MODULES = {
53+ 'maasserver': 'maasserver.south_migrations',
54+ 'metadataserver': 'metadataserver.south_migrations',
55+}
56+
57+# Allow the user to override settings in maas_local_settings.
58+import_local_settings()
59+
60+>>>>>>> MERGE-SOURCE
61 # Patch the get_script_prefix method to allow twisted to work with django.
62 patch_get_script_prefix()
63
64
65=== modified file 'src/maasserver/fields.py'
66--- src/maasserver/fields.py 2015-07-06 08:52:20 +0000
67+++ src/maasserver/fields.py 2015-07-29 15:36:58 +0000
68@@ -56,7 +56,10 @@
69 IPNetwork,
70 )
71 import psycopg2.extensions
72-from south.modelsinspector import add_introspection_rules
73+try:
74+ from south.modelsinspector import add_introspection_rules
75+except ImportError:
76+ add_introspection_rules = None
77
78
79 MAC_RE = re.compile(r'^\s*([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}\s*$')
80@@ -97,6 +100,7 @@
81 # them just fine.
82 # See http://south.aeracode.org/docs/customfields.html#extending-introspection
83 # for details.
84+<<<<<<< TREE
85 add_introspection_rules(
86 [], [
87 "^maasserver\.fields\.MACAddressField",
88@@ -107,6 +111,18 @@
89 "^maasserver\.fields\.LargeObjectField",
90 "^maasserver\.fields\.CIDRField",
91 ])
92+=======
93+if add_introspection_rules is not None:
94+ add_introspection_rules(
95+ [], [
96+ "^maasserver\.fields\.MACAddressField",
97+ "^maasserver\.fields\.JSONObjectField",
98+ "^maasserver\.fields\.XMLField",
99+ "^maasserver\.fields\.EditableBinaryField",
100+ "^maasserver\.fields\.MAASIPAddressField",
101+ "^maasserver\.fields\.LargeObjectField",
102+ ])
103+>>>>>>> MERGE-SOURCE
104
105
106 class NodeGroupFormField(ModelChoiceField):
107@@ -402,6 +418,12 @@
108 super(EditableBinaryField, self).__init__(*args, **kwargs)
109 self.editable = True
110
111+ def deconstruct(self):
112+ # Override deconstruct not to fail on the removal of the 'editable'
113+ # field: the Django migration module assumes the field has its default
114+ # value (False).
115+ return Field.deconstruct(self)
116+
117
118 class MAASIPAddressField(GenericIPAddressField):
119 """A version of GenericIPAddressField with a custom get_internal_type().
120
121=== added directory 'src/maasserver/migrations'
122=== added file 'src/maasserver/migrations/__init__.py'
123=== modified file 'src/maasserver/models/node.py'
124--- src/maasserver/models/node.py 2015-07-28 23:17:17 +0000
125+++ src/maasserver/models/node.py 2015-07-29 15:36:58 +0000
126@@ -378,6 +378,10 @@
127 ]
128
129
130+def get_default_zone():
131+ return Zone.objects.get_default_zone().id
132+
133+
134 class Node(CleanSave, TimestampedModel):
135 """A `Node` represents a physical machine used by the MAAS Server.
136
137@@ -457,7 +461,7 @@
138
139 zone = ForeignKey(
140 Zone, verbose_name="Physical zone",
141- default=Zone.objects.get_default_zone, editable=True, db_index=True,
142+ default=get_default_zone, editable=True, db_index=True,
143 on_delete=SET_DEFAULT)
144
145 # Juju expects the following standard constraints, which are stored here
146
147=== modified file 'src/maasserver/plugin.py'
148--- src/maasserver/plugin.py 2015-07-14 16:50:38 +0000
149+++ src/maasserver/plugin.py 2015-07-29 15:36:58 +0000
150@@ -74,6 +74,7 @@
151 def _configureDjango(self):
152 # Some region services use the ORM at class-load time: force Django to
153 # load the models first.
154+<<<<<<< TREE
155 try:
156 from django import setup as django_setup
157 except ImportError:
158@@ -118,6 +119,10 @@
159 pass
160
161 def _configureCrochet(self):
162+=======
163+ from maasserver.utils import django_setup
164+ django_setup()
165+>>>>>>> MERGE-SOURCE
166 # Prevent other libraries from starting the reactor via crochet.
167 # In other words, this makes crochet.setup() a no-op.
168 import crochet
169
170=== renamed directory 'src/maasserver/migrations' => 'src/maasserver/south_migrations'
171=== modified file 'src/maasserver/start_up.py'
172--- src/maasserver/start_up.py 2015-07-09 14:56:28 +0000
173+++ src/maasserver/start_up.py 2015-07-29 15:36:58 +0000
174@@ -32,19 +32,27 @@
175 from maasserver.clusterrpc.boot_images import get_all_available_boot_images
176 from maasserver.dns.config import dns_update_all_zones
177 from maasserver.fields import register_mac_type
178+<<<<<<< TREE
179 from maasserver.models import (
180 BootResource,
181 BootSource,
182 BootSourceSelection,
183 NodeGroup,
184 )
185+=======
186+>>>>>>> MERGE-SOURCE
187 from maasserver.triggers import register_all_triggers
188+<<<<<<< TREE
189 from maasserver.utils import synchronised
190 from maasserver.utils.orm import (
191 get_psycopg2_exception,
192 post_commit_do,
193 transactional,
194 )
195+=======
196+from maasserver.utils import django_setup
197+from maasserver.utils.orm import get_psycopg2_exception
198+>>>>>>> MERGE-SOURCE
199 from provisioningserver.logger import get_maas_logger
200 from provisioningserver.upgrade_cluster import create_gnupg_home
201 from provisioningserver.utils.twisted import (
202@@ -76,6 +84,9 @@
203 """
204 while True:
205 try:
206+ # If using Django 1.7, load the models.
207+ django_setup()
208+
209 # Get the shared secret from Tidmouth sheds which was generated
210 # when Sir Topham Hatt graduated Sodor Academy. (Ensure we have a
211 # shared-secret so that a cluster on the same host as this region
212@@ -176,6 +187,7 @@
213
214 # Make sure that the master nodegroup is created.
215 # This must be serialized or we may initialize the master more than once.
216+ from maasserver.models import NodeGroup
217 NodeGroup.objects.ensure_master()
218
219 # Make sure that maas user's GNUPG home directory exists. This is needed
220
221=== modified file 'src/maasserver/utils/__init__.py'
222--- src/maasserver/utils/__init__.py 2015-06-26 10:45:38 +0000
223+++ src/maasserver/utils/__init__.py 2015-07-29 15:36:58 +0000
224@@ -247,3 +247,13 @@
225 The message takes the form of a textual bullet-list.
226 """
227 return make_bullet_list(gen_validation_error_messages(error))
228+
229+
230+def django_setup():
231+ """Call Django 1.7 setup() to initialize the models."""
232+ try:
233+ from django import setup as django_setup
234+ except ImportError:
235+ pass # Django < 1.7
236+ else:
237+ django_setup()
238
239=== modified file 'src/metadataserver/fields.py'
240--- src/metadataserver/fields.py 2015-05-07 18:14:38 +0000
241+++ src/metadataserver/fields.py 2015-07-29 15:36:58 +0000
242@@ -25,8 +25,16 @@
243 from django.db.models import (
244 Field,
245 SubfieldBase,
246+<<<<<<< TREE
247 )
248 from south.modelsinspector import add_introspection_rules
249+=======
250+ )
251+try:
252+ from south.modelsinspector import add_introspection_rules
253+except ImportError:
254+ add_introspection_rules = None
255+>>>>>>> MERGE-SOURCE
256
257
258 class Bin(bytes):
259@@ -74,7 +82,8 @@
260 # parent's constructor so South will handle it just fine.
261 # See http://south.aeracode.org/docs/customfields.html#extending-introspection
262 # for details.
263-add_introspection_rules([], ["^metadataserver\.fields\.BinaryField"])
264+if add_introspection_rules is not None:
265+ add_introspection_rules([], ["^metadataserver\.fields\.BinaryField"])
266
267
268 class BinaryField(Field):
269@@ -122,6 +131,12 @@
270 "either conversion is going the wrong way, or the value "
271 "needs to be wrapped in a Bin.")
272 elif isinstance(value, unicode):
273+ # Django 1.7 migration framework generates the default value based
274+ # on the 'internal_type' which, in this instance, is 'TextField';
275+ # Here we cope with the default empty value instead of raising
276+ # an exception.
277+ if value == '':
278+ return ''
279 # Unicode here is almost certainly a sign of a mistake.
280 raise AssertionError(
281 "A unicode string is being mistaken for binary data.")
282
283=== added directory 'src/metadataserver/migrations'
284=== added file 'src/metadataserver/migrations/__init__.py'
285=== renamed directory 'src/metadataserver/migrations' => 'src/metadataserver/south_migrations'