Merge lp:~julian-edwards/maas/nodegroup-on-bootimage-schema into lp:maas/trunk

Proposed by Julian Edwards on 2012-10-23
Status: Merged
Merged at revision: 1297
Proposed branch: lp:~julian-edwards/maas/nodegroup-on-bootimage-schema
Merge into: lp:maas/trunk
Diff against target: 254 lines (+224/-1)
2 files modified
src/maasserver/migrations/0039_add_nodegroup_to_bootimage.py (+217/-0)
src/maasserver/models/bootimage.py (+7/-1)
To merge this branch: bzr merge lp:~julian-edwards/maas/nodegroup-on-bootimage-schema
Reviewer Review Type Date Requested Status
Raphaël Badin (community) 2012-10-23 Approve on 2012-10-23
Review via email: mp+131005@code.launchpad.net

Commit message

Add a schema migration to add a nodegroup field to bootimage.

This migration will support the moving of the maas-import-pxe-files script to run on clusters instead of the region.

Description of the change

Add a schema migration to add a nodegroup field to bootimage. The migration was manually hacked to ensure that the new not-null nodegroup FK gains a default value of the master nodegroup (which is the first row in that table).

This migration will support the moving of the maas-import-pxe-files script to run on clusters instead of the region.

To post a comment you must log in.
Raphaël Badin (rvb) wrote :

Looks good (I've tested the migration by creating a boot image [with the db in state 0038] and then applying the migration).

This breaks a lot of tests but I'm told this is only the db migration part of the fix, an upcoming branch (or even branches) will take care of fixing up the code.

[0]

db.execute("ALTER TABLE maasserver_bootimage ALTER nodegroup_id SET NOT NULL")

fwiw, this could have been done with South's tools:

        db.alter_column(
            'maasserver_bootimage', 'nodegroup_id',
            models.ForeignKey(
                NodeGroup, null=False, editable=False, unique=False))

.. but I don't think it really matters.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/maasserver/migrations/0039_add_nodegroup_to_bootimage.py'
2--- src/maasserver/migrations/0039_add_nodegroup_to_bootimage.py 1970-01-01 00:00:00 +0000
3+++ src/maasserver/migrations/0039_add_nodegroup_to_bootimage.py 2012-10-23 13:43:22 +0000
4@@ -0,0 +1,217 @@
5+# -*- coding: utf-8 -*-
6+import datetime
7+from south.db import db
8+from south.v2 import SchemaMigration
9+from django.db import models
10+
11+
12+class Migration(SchemaMigration):
13+
14+ def forwards(self, orm):
15+ # Removing unique constraint on 'BootImage', fields ['subarchitecture', 'release', 'architecture', 'purpose']
16+ db.delete_unique(u'maasserver_bootimage', ['subarchitecture', 'release', 'architecture', 'purpose'])
17+
18+ # Adding field 'BootImage.nodegroup'
19+ db.add_column(u'maasserver_bootimage', 'nodegroup',
20+ self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['maasserver.NodeGroup']),
21+ keep_default=False)
22+ # Set existing bootimage rows to have a nodegroup of the master
23+ # nodegroup (which is the first row in that table).
24+ db.execute("UPDATE maasserver_bootimage SET nodegroup_id = (SELECT id from maasserver_nodegroup ORDER BY id LIMIT 1)")
25+ db.execute("ALTER TABLE maasserver_bootimage ALTER nodegroup_id SET NOT NULL")
26+ # Adding unique constraint on 'BootImage', fields ['subarchitecture', 'release', 'nodegroup', 'architecture', 'purpose']
27+ db.create_unique(u'maasserver_bootimage', ['subarchitecture', 'release', 'nodegroup_id', 'architecture', 'purpose'])
28+
29+
30+ def backwards(self, orm):
31+ # Removing unique constraint on 'BootImage', fields ['subarchitecture', 'release', 'nodegroup', 'architecture', 'purpose']
32+ db.delete_unique(u'maasserver_bootimage', ['subarchitecture', 'release', 'nodegroup_id', 'architecture', 'purpose'])
33+
34+ # Deleting field 'BootImage.nodegroup'
35+ db.delete_column(u'maasserver_bootimage', 'nodegroup_id')
36+
37+ # Adding unique constraint on 'BootImage', fields ['subarchitecture', 'release', 'architecture', 'purpose']
38+ db.create_unique(u'maasserver_bootimage', ['subarchitecture', 'release', 'architecture', 'purpose'])
39+
40+
41+ models = {
42+ 'auth.group': {
43+ 'Meta': {'object_name': 'Group'},
44+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
45+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
46+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
47+ },
48+ 'auth.permission': {
49+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
50+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
51+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
52+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
53+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
54+ },
55+ 'auth.user': {
56+ 'Meta': {'object_name': 'User'},
57+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
58+ 'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '75', 'blank': 'True'}),
59+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
60+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
61+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
62+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
63+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
64+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
65+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
66+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
67+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
68+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
69+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
70+ },
71+ 'contenttypes.contenttype': {
72+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
73+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
74+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
75+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
76+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
77+ },
78+ u'maasserver.bootimage': {
79+ 'Meta': {'unique_together': "((u'nodegroup', u'architecture', u'subarchitecture', u'release', u'purpose'),)", 'object_name': 'BootImage'},
80+ 'architecture': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
81+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
82+ 'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']"}),
83+ 'purpose': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
84+ 'release': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
85+ 'subarchitecture': ('django.db.models.fields.CharField', [], {'max_length': '255'})
86+ },
87+ u'maasserver.componenterror': {
88+ 'Meta': {'object_name': 'ComponentError'},
89+ 'component': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40'}),
90+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
91+ 'error': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
92+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
93+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
94+ },
95+ u'maasserver.config': {
96+ 'Meta': {'object_name': 'Config'},
97+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
98+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
99+ 'value': ('maasserver.fields.JSONObjectField', [], {'null': 'True'})
100+ },
101+ u'maasserver.dhcplease': {
102+ 'Meta': {'object_name': 'DHCPLease'},
103+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
104+ 'ip': ('django.db.models.fields.IPAddressField', [], {'unique': 'True', 'max_length': '15'}),
105+ 'mac': ('maasserver.fields.MACAddressField', [], {}),
106+ 'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']"})
107+ },
108+ u'maasserver.filestorage': {
109+ 'Meta': {'object_name': 'FileStorage'},
110+ 'data': ('django.db.models.fields.files.FileField', [], {'max_length': '255'}),
111+ 'filename': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200'}),
112+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
113+ },
114+ u'maasserver.macaddress': {
115+ 'Meta': {'object_name': 'MACAddress'},
116+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
117+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
118+ 'mac_address': ('maasserver.fields.MACAddressField', [], {'unique': 'True'}),
119+ 'node': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.Node']"}),
120+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
121+ },
122+ u'maasserver.node': {
123+ 'Meta': {'object_name': 'Node'},
124+ 'after_commissioning_action': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
125+ 'architecture': ('django.db.models.fields.CharField', [], {'default': "u'i386/generic'", 'max_length': '31'}),
126+ 'cpu_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
127+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
128+ 'distro_series': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '10', 'null': 'True', 'blank': 'True'}),
129+ 'error': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
130+ 'hardware_details': ('maasserver.fields.XMLField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
131+ 'hostname': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
132+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
133+ 'memory': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
134+ 'netboot': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
135+ 'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']", 'null': 'True'}),
136+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
137+ 'power_parameters': ('maasserver.fields.JSONObjectField', [], {'default': "u''", 'blank': 'True'}),
138+ 'power_type': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '10', 'blank': 'True'}),
139+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0', 'max_length': '10'}),
140+ 'system_id': ('django.db.models.fields.CharField', [], {'default': "u'node-f9e8804e-1d11-11e2-be72-0026c71eea0e'", 'unique': 'True', 'max_length': '41'}),
141+ 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['maasserver.Tag']", 'symmetrical': 'False'}),
142+ 'token': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['piston.Token']", 'null': 'True'}),
143+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
144+ },
145+ u'maasserver.nodegroup': {
146+ 'Meta': {'object_name': 'NodeGroup'},
147+ 'api_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '18'}),
148+ 'api_token': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['piston.Token']", 'unique': 'True'}),
149+ 'cluster_name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100', 'blank': 'True'}),
150+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
151+ 'dhcp_key': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
152+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
153+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '80', 'blank': 'True'}),
154+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
155+ 'updated': ('django.db.models.fields.DateTimeField', [], {}),
156+ 'uuid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '36'})
157+ },
158+ u'maasserver.nodegroupinterface': {
159+ 'Meta': {'unique_together': "((u'nodegroup', u'interface'),)", 'object_name': 'NodeGroupInterface'},
160+ 'broadcast_ip': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'null': 'True', 'blank': 'True'}),
161+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
162+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
163+ 'interface': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
164+ 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}),
165+ 'ip_range_high': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'null': 'True', 'blank': 'True'}),
166+ 'ip_range_low': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'null': 'True', 'blank': 'True'}),
167+ 'management': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
168+ 'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']"}),
169+ 'router_ip': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'null': 'True', 'blank': 'True'}),
170+ 'subnet_mask': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'null': 'True', 'blank': 'True'}),
171+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
172+ },
173+ u'maasserver.sshkey': {
174+ 'Meta': {'unique_together': "((u'user', u'key'),)", 'object_name': 'SSHKey'},
175+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
176+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
177+ 'key': ('django.db.models.fields.TextField', [], {}),
178+ 'updated': ('django.db.models.fields.DateTimeField', [], {}),
179+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
180+ },
181+ u'maasserver.tag': {
182+ 'Meta': {'object_name': 'Tag'},
183+ 'comment': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
184+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
185+ 'definition': ('django.db.models.fields.TextField', [], {}),
186+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
187+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '256'}),
188+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
189+ },
190+ u'maasserver.userprofile': {
191+ 'Meta': {'object_name': 'UserProfile'},
192+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
193+ 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
194+ },
195+ 'piston.consumer': {
196+ 'Meta': {'object_name': 'Consumer'},
197+ 'description': ('django.db.models.fields.TextField', [], {}),
198+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
199+ 'key': ('django.db.models.fields.CharField', [], {'max_length': '18'}),
200+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
201+ 'secret': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
202+ 'status': ('django.db.models.fields.CharField', [], {'default': "'pending'", 'max_length': '16'}),
203+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'consumers'", 'null': 'True', 'to': "orm['auth.User']"})
204+ },
205+ 'piston.token': {
206+ 'Meta': {'object_name': 'Token'},
207+ 'callback': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
208+ 'callback_confirmed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
209+ 'consumer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['piston.Consumer']"}),
210+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
211+ 'is_approved': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
212+ 'key': ('django.db.models.fields.CharField', [], {'max_length': '18'}),
213+ 'secret': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
214+ 'timestamp': ('django.db.models.fields.IntegerField', [], {'default': '1350997269L'}),
215+ 'token_type': ('django.db.models.fields.IntegerField', [], {}),
216+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'tokens'", 'null': 'True', 'to': "orm['auth.User']"}),
217+ 'verifier': ('django.db.models.fields.CharField', [], {'max_length': '10'})
218+ }
219+ }
220+
221+ complete_apps = ['maasserver']
222
223=== modified file 'src/maasserver/models/bootimage.py'
224--- src/maasserver/models/bootimage.py 2012-09-13 06:53:55 +0000
225+++ src/maasserver/models/bootimage.py 2012-10-23 13:43:22 +0000
226@@ -17,10 +17,12 @@
227
228 from django.db.models import (
229 CharField,
230+ ForeignKey,
231 Manager,
232 Model,
233 )
234 from maasserver import DefaultMeta
235+from maasserver.models.nodegroup import NodeGroup
236
237
238 class BootImageManager(Manager):
239@@ -69,11 +71,15 @@
240
241 class Meta(DefaultMeta):
242 unique_together = (
243- ('architecture', 'subarchitecture', 'release', 'purpose'),
244+ ('nodegroup', 'architecture', 'subarchitecture', 'release',
245+ 'purpose'),
246 )
247
248 objects = BootImageManager()
249
250+ # Nodegroup (cluster controller) that has the images.
251+ nodegroup = ForeignKey(NodeGroup, null=False, editable=False, unique=False)
252+
253 # System architecture (e.g. "i386") that the image is for.
254 architecture = CharField(max_length=255, blank=False, editable=False)
255