← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/nodegroup-uuid into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/nodegroup-uuid into lp:maas.

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~rvb/maas/nodegroup-uuid/+merge/123559

This branch simply adds a new UUID field to the nodegroup.  That UUID will be generated by the worker package and used to identify a worker and route tasks to it (it will be used as the queue name by Celery).

= Pre-imp =

This was mentioned during this morning's standup call and is required to identify a nodegroup.
-- 
https://code.launchpad.net/~rvb/maas/nodegroup-uuid/+merge/123559
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/maas/nodegroup-uuid into lp:maas.
=== added file 'src/maasserver/migrations/0021_add_uuid_to_nodegroup.py'
--- src/maasserver/migrations/0021_add_uuid_to_nodegroup.py	1970-01-01 00:00:00 +0000
+++ src/maasserver/migrations/0021_add_uuid_to_nodegroup.py	2012-09-10 14:52:19 +0000
@@ -0,0 +1,160 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding field 'NodeGroup.uuid'
+        db.add_column(u'maasserver_nodegroup', 'uuid', self.gf('django.db.models.fields.CharField')(default='master', unique=True, max_length=36), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'NodeGroup.uuid'
+        db.delete_column(u'maasserver_nodegroup', 'uuid')
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        u'maasserver.config': {
+            'Meta': {'object_name': 'Config'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'value': ('maasserver.fields.JSONObjectField', [], {'null': 'True'})
+        },
+        u'maasserver.dhcplease': {
+            'Meta': {'object_name': 'DHCPLease'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ip': ('django.db.models.fields.IPAddressField', [], {'unique': 'True', 'max_length': '15'}),
+            'mac': ('maasserver.fields.MACAddressField', [], {}),
+            'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']"})
+        },
+        u'maasserver.filestorage': {
+            'Meta': {'object_name': 'FileStorage'},
+            'data': ('django.db.models.fields.files.FileField', [], {'max_length': '255'}),
+            'filename': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+        },
+        u'maasserver.macaddress': {
+            'Meta': {'object_name': 'MACAddress'},
+            'created': ('django.db.models.fields.DateTimeField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'mac_address': ('maasserver.fields.MACAddressField', [], {'unique': 'True'}),
+            'node': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.Node']"}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {})
+        },
+        u'maasserver.node': {
+            'Meta': {'object_name': 'Node'},
+            'after_commissioning_action': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'architecture': ('django.db.models.fields.CharField', [], {'default': "u'i386'", 'max_length': '10'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {}),
+            'error': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+            'hostname': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'netboot': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']", 'null': 'True'}),
+            'owner': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+            'power_parameters': ('maasserver.fields.JSONObjectField', [], {'default': "u''", 'blank': 'True'}),
+            'power_type': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '10', 'blank': 'True'}),
+            'status': ('django.db.models.fields.IntegerField', [], {'default': '0', 'max_length': '10'}),
+            'system_id': ('django.db.models.fields.CharField', [], {'default': "u'node-b0ce0972-fb35-11e1-82bc-3c970e0e56dc'", 'unique': 'True', 'max_length': '41'}),
+            'token': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['piston.Token']", 'null': 'True'}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {})
+        },
+        u'maasserver.nodegroup': {
+            'Meta': {'object_name': 'NodeGroup'},
+            'api_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '18'}),
+            'api_token': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['piston.Token']", 'unique': 'True'}),
+            'broadcast_ip': ('django.db.models.fields.IPAddressField', [], {'default': "u''", 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {}),
+            'dhcp_interfaces': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+            'dhcp_key': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ip_range_high': ('django.db.models.fields.IPAddressField', [], {'default': "u''", 'max_length': '15', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+            'ip_range_low': ('django.db.models.fields.IPAddressField', [], {'default': "u''", 'max_length': '15', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'router_ip': ('django.db.models.fields.IPAddressField', [], {'default': "u''", 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+            'subnet_mask': ('django.db.models.fields.IPAddressField', [], {'default': "u''", 'max_length': '15', 'null': 'True', 'blank': 'True'}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {}),
+            'uuid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '36'}),
+            'worker_ip': ('django.db.models.fields.IPAddressField', [], {'unique': 'True', 'max_length': '15'})
+        },
+        u'maasserver.sshkey': {
+            'Meta': {'unique_together': "((u'user', u'key'),)", 'object_name': 'SSHKey'},
+            'created': ('django.db.models.fields.DateTimeField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'key': ('django.db.models.fields.TextField', [], {}),
+            'updated': ('django.db.models.fields.DateTimeField', [], {}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+        },
+        u'maasserver.userprofile': {
+            'Meta': {'object_name': 'UserProfile'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
+        },
+        'piston.consumer': {
+            'Meta': {'object_name': 'Consumer'},
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'key': ('django.db.models.fields.CharField', [], {'max_length': '18'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'secret': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'status': ('django.db.models.fields.CharField', [], {'default': "'pending'", 'max_length': '16'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'consumers'", 'null': 'True', 'to': "orm['auth.User']"})
+        },
+        'piston.token': {
+            'Meta': {'object_name': 'Token'},
+            'callback': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'callback_confirmed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'consumer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['piston.Consumer']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_approved': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'key': ('django.db.models.fields.CharField', [], {'max_length': '18'}),
+            'secret': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
+            'timestamp': ('django.db.models.fields.IntegerField', [], {'default': '1347274367L'}),
+            'token_type': ('django.db.models.fields.IntegerField', [], {}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'tokens'", 'null': 'True', 'to': "orm['auth.User']"}),
+            'verifier': ('django.db.models.fields.CharField', [], {'max_length': '10'})
+        }
+    }
+
+    complete_apps = ['maasserver']

=== modified file 'src/maasserver/models/nodegroup.py'
--- src/maasserver/models/nodegroup.py	2012-09-10 07:53:20 +0000
+++ src/maasserver/models/nodegroup.py	2012-09-10 14:52:19 +0000
@@ -45,9 +45,9 @@
     the model class it manages.
     """
 
-    def new(self, name, worker_ip, subnet_mask=None, broadcast_ip=None,
-            router_ip=None, ip_range_low=None, ip_range_high=None,
-            dhcp_key='', dhcp_interfaces=''):
+    def new(self, name, uuid, worker_ip, subnet_mask=None,
+            broadcast_ip=None, router_ip=None, ip_range_low=None,
+            ip_range_high=None, dhcp_key='', dhcp_interfaces=''):
         """Create a :class:`NodeGroup` with the given parameters.
 
         This method will generate API credentials for the nodegroup's
@@ -70,10 +70,11 @@
 
         api_token = create_auth_token(get_worker_user())
         nodegroup = NodeGroup(
-            name=name, worker_ip=worker_ip, subnet_mask=subnet_mask,
-            broadcast_ip=broadcast_ip, router_ip=router_ip,
-            ip_range_low=ip_range_low, ip_range_high=ip_range_high,
-            api_token=api_token, api_key=api_token.key, dhcp_key=dhcp_key,
+            name=name, uuid=uuid, worker_ip=worker_ip,
+            subnet_mask=subnet_mask, broadcast_ip=broadcast_ip,
+            router_ip=router_ip, ip_range_low=ip_range_low,
+            ip_range_high=ip_range_high, api_token=api_token,
+            api_key=api_token.key, dhcp_key=dhcp_key,
             dhcp_interfaces=dhcp_interfaces)
         nodegroup.save()
         return nodegroup
@@ -86,9 +87,9 @@
         try:
             master = self.get(name='master')
         except NodeGroup.DoesNotExist:
-            # The master did not exist yet; create it on demand.
+            # The master did not ist yet; create it on demand.
             master = self.new(
-                'master', '127.0.0.1', dhcp_key=generate_omapi_key())
+                'master', 'master', '127.0.0.1', dhcp_key=generate_omapi_key())
 
             # If any legacy nodes were still not associated with a node
             # group, enroll them in the master node group.
@@ -123,6 +124,10 @@
         max_length=KEY_SIZE, null=False, blank=False, editable=False,
         unique=True)
 
+    # Unique identifier of the worker.
+    uuid = CharField(
+        max_length=36, unique=True, null=False, blank=False, editable=False)
+
     # Address of the worker.
     worker_ip = IPAddressField(null=False, editable=True, unique=True)
 

=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py	2012-09-05 13:30:21 +0000
+++ src/maasserver/testing/factory.py	2012-09-10 14:52:19 +0000
@@ -116,10 +116,10 @@
             Node.objects.filter(id=node.id).update(created=created)
         return reload_object(node)
 
-    def make_node_group(self, name=None, worker_ip=None, router_ip=None,
-                        network=None, subnet_mask=None, broadcast_ip=None,
-                        ip_range_low=None, ip_range_high=None,
-                        dhcp_interfaces=None, **kwargs):
+    def make_node_group(self, name=None, uuid=None, worker_ip=None,
+                        router_ip=None, network=None, subnet_mask=None,
+                        broadcast_ip=None, ip_range_low=None,
+                        ip_range_high=None, dhcp_interfaces=None, **kwargs):
         """Create a :class:`NodeGroup`.
 
         If network (an instance of IPNetwork) is provided, use it to populate
@@ -132,6 +132,8 @@
         """
         if name is None:
             name = self.make_name('nodegroup')
+        if uuid is None:
+            uuid = factory.getRandomUUID()
         if network is not None:
             subnet_mask = str(network.netmask)
             broadcast_ip = str(network.broadcast)
@@ -155,10 +157,11 @@
         if dhcp_interfaces is None:
             dhcp_interfaces = self.make_name('interface')
         ng = NodeGroup.objects.new(
-            name=name, worker_ip=worker_ip, subnet_mask=subnet_mask,
-            broadcast_ip=broadcast_ip, router_ip=router_ip,
-            ip_range_low=ip_range_low, ip_range_high=ip_range_high,
-            dhcp_interfaces=dhcp_interfaces, **kwargs)
+            name=name, uuid=uuid, worker_ip=worker_ip,
+            subnet_mask=subnet_mask, broadcast_ip=broadcast_ip,
+            router_ip=router_ip, ip_range_low=ip_range_low,
+            ip_range_high=ip_range_high, dhcp_interfaces=dhcp_interfaces,
+            **kwargs)
         ng.save()
         return ng
 

=== modified file 'src/maasserver/tests/test_nodegroup.py'
--- src/maasserver/tests/test_nodegroup.py	2012-09-10 07:53:20 +0000
+++ src/maasserver/tests/test_nodegroup.py	2012-09-10 14:52:19 +0000
@@ -54,15 +54,18 @@
 
     def test_new_creates_nodegroup(self):
         name = factory.make_name('nodegroup')
+        uuid = factory.getRandomUUID()
         ip = factory.getRandomIPAddress()
         self.assertThat(
-            NodeGroup.objects.new(name, ip),
-            MatchesStructure.fromExample({'name': name, 'worker_ip': ip}))
+            NodeGroup.objects.new(name, uuid, ip),
+            MatchesStructure.fromExample(
+                {'name': name, 'uuid': uuid, 'worker_ip': ip}))
 
     def test_new_does_not_require_dhcp_settings(self):
         name = factory.make_name('nodegroup')
+        uuid = factory.getRandomUUID()
         ip = factory.getRandomIPAddress()
-        nodegroup = NodeGroup.objects.new(name, ip)
+        nodegroup = NodeGroup.objects.new(name, uuid, ip)
         self.assertThat(
             nodegroup,
             MatchesStructure.fromExample({
@@ -71,16 +74,18 @@
 
     def test_new_requires_all_dhcp_settings_or_none(self):
         name = factory.make_name('nodegroup')
+        uuid = factory.make_name('uuid')
         ip = factory.getRandomIPAddress()
         self.assertRaises(
             AssertionError,
-            NodeGroup.objects.new, name, ip, subnet_mask='255.0.0.0')
+            NodeGroup.objects.new, name, uuid, ip, subnet_mask='255.0.0.0')
 
     def test_new_creates_nodegroup_with_given_dhcp_settings(self):
         name = factory.make_name('nodegroup')
+        uuid = factory.make_name('uuid')
         ip = factory.getRandomIPAddress()
         dhcp_settings = make_dhcp_settings()
-        nodegroup = NodeGroup.objects.new(name, ip, **dhcp_settings)
+        nodegroup = NodeGroup.objects.new(name, uuid, ip, **dhcp_settings)
         nodegroup = reload_object(nodegroup)
         self.assertEqual(name, nodegroup.name)
         self.assertThat(
@@ -88,7 +93,8 @@
 
     def test_new_assigns_token_and_key_for_worker_user(self):
         nodegroup = NodeGroup.objects.new(
-            factory.make_name('nodegroup'), factory.getRandomIPAddress())
+            factory.make_name('nodegroup'), factory.make_name('uuid'),
+            factory.getRandomIPAddress())
         self.assertIsNotNone(nodegroup.api_token)
         self.assertIsNotNone(nodegroup.api_key)
         self.assertEqual(get_worker_user(), nodegroup.api_token.user)
@@ -96,13 +102,15 @@
 
     def test_new_creates_nodegroup_with_empty_dhcp_key(self):
         nodegroup = NodeGroup.objects.new(
-            factory.make_name('nodegroup'), factory.getRandomIPAddress())
+            factory.make_name('nodegroup'), factory.make_name('uuid'),
+            factory.getRandomIPAddress())
         self.assertEqual('', nodegroup.dhcp_key)
 
     def test_new_stores_dhcp_key_on_nodegroup(self):
         key = generate_omapi_key()
         nodegroup = NodeGroup.objects.new(
-            factory.make_name('nodegroup'), factory.getRandomIPAddress(),
+            factory.make_name('nodegroup'), factory.make_name('uuid'),
+            factory.getRandomIPAddress(),
             dhcp_key=key)
         self.assertEqual(key, nodegroup.dhcp_key)
 
@@ -111,6 +119,7 @@
             NodeGroup.objects.ensure_master(),
             MatchesStructure.fromExample({
                 'name': 'master',
+                'workder_id': 'master',
                 'worker_ip': '127.0.0.1',
                 'subnet_mask': None,
                 'broadcast_ip': None,
@@ -136,7 +145,8 @@
     def test_ensure_master_does_not_return_other_nodegroup(self):
         self.assertNotEqual(
             NodeGroup.objects.new(
-                factory.make_name('nodegroup'), factory.getRandomIPAddress()),
+                factory.make_name('nodegroup'), factory.make_name('uuid'),
+                factory.getRandomIPAddress()),
             NodeGroup.objects.ensure_master())
 
     def test_ensure_master_preserves_existing_attributes(self):

=== modified file 'src/maastesting/factory.py'
--- src/maastesting/factory.py	2012-08-21 15:59:40 +0000
+++ src/maastesting/factory.py	2012-09-10 14:52:19 +0000
@@ -26,6 +26,7 @@
 import random
 import string
 import time
+from uuid import uuid1
 
 from netaddr import (
     IPAddress,
@@ -71,6 +72,9 @@
         octets = islice(self.random_octets, 4)
         return b'%d.%d.%d.%d' % tuple(octets)
 
+    def getRandomUUID(self):
+        return str(uuid1())
+
     def getRandomNetwork(self, slash=None):
         ip = self.getRandomIPAddress()
         if slash is None:

=== modified file 'src/maastesting/tests/test_factory.py'
--- src/maastesting/tests/test_factory.py	2012-08-21 15:59:40 +0000
+++ src/maastesting/tests/test_factory.py	2012-09-10 14:52:19 +0000
@@ -54,6 +54,11 @@
         for octet in octets:
             self.assertTrue(0 <= int(octet) <= 255)
 
+    def test_getRandomUUID(self):
+        uuid = factory.getRandomUUID()
+        self.assertIsInstance(uuid, str)
+        self.assertEqual(36, len(uuid))
+
     def test_getRandomNetwork(self):
         network = factory.getRandomNetwork()
         self.assertIsInstance(network, IPNetwork)