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