launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #12621
[Merge] lp:~rvb/maas/fix-ip-field into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/fix-ip-field into lp:maas.
Commit message:
This is a workaround one of these five year old Django bug that we encounter from time to time (https://code.djangoproject.com/ticket/5622). The Django field IPAddressField does not work well with None values even if you specify Blank=True and Null=True. A simple workaround is to use the GenericIPAddressField which also gives us IPV6 support.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/fix-ip-field/+merge/126925
--
https://code.launchpad.net/~rvb/maas/fix-ip-field/+merge/126925
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/fix-ip-field into lp:maas.
=== added file 'src/maasserver/migrations/0030_ip_address_to_generic_ip_address.py'
--- src/maasserver/migrations/0030_ip_address_to_generic_ip_address.py 1970-01-01 00:00:00 +0000
+++ src/maasserver/migrations/0030_ip_address_to_generic_ip_address.py 2012-09-28 11:16:22 +0000
@@ -0,0 +1,221 @@
+# -*- coding: utf-8 -*-
+import datetime
+
+from django.db import models
+from south.db import db
+from south.v2 import SchemaMigration
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'NodeGroupInterface.ip_range_high'
+ db.alter_column(u'maasserver_nodegroupinterface', 'ip_range_high', self.gf('django.db.models.fields.GenericIPAddressField')(max_length=39, unique=True, null=True))
+
+ # Changing field 'NodeGroupInterface.ip'
+ db.alter_column(u'maasserver_nodegroupinterface', 'ip', self.gf('django.db.models.fields.GenericIPAddressField')(max_length=39))
+
+ # Changing field 'NodeGroupInterface.ip_range_low'
+ db.alter_column(u'maasserver_nodegroupinterface', 'ip_range_low', self.gf('django.db.models.fields.GenericIPAddressField')(max_length=39, unique=True, null=True))
+
+ # Changing field 'NodeGroupInterface.subnet_mask'
+ db.alter_column(u'maasserver_nodegroupinterface', 'subnet_mask', self.gf('django.db.models.fields.GenericIPAddressField')(max_length=39, null=True))
+
+ # Changing field 'NodeGroupInterface.broadcast_ip'
+ db.alter_column(u'maasserver_nodegroupinterface', 'broadcast_ip', self.gf('django.db.models.fields.GenericIPAddressField')(max_length=39, null=True))
+
+ # Changing field 'NodeGroupInterface.router_ip'
+ db.alter_column(u'maasserver_nodegroupinterface', 'router_ip', self.gf('django.db.models.fields.GenericIPAddressField')(max_length=39, null=True))
+
+ def backwards(self, orm):
+
+ # Changing field 'NodeGroupInterface.ip_range_high'
+ db.alter_column(u'maasserver_nodegroupinterface', 'ip_range_high', self.gf('django.db.models.fields.IPAddressField')(unique=True, max_length=15, null=True))
+
+ # Changing field 'NodeGroupInterface.ip'
+ db.alter_column(u'maasserver_nodegroupinterface', 'ip', self.gf('django.db.models.fields.IPAddressField')(max_length=15))
+
+ # Changing field 'NodeGroupInterface.ip_range_low'
+ db.alter_column(u'maasserver_nodegroupinterface', 'ip_range_low', self.gf('django.db.models.fields.IPAddressField')(unique=True, max_length=15, null=True))
+
+ # Changing field 'NodeGroupInterface.subnet_mask'
+ db.alter_column(u'maasserver_nodegroupinterface', 'subnet_mask', self.gf('django.db.models.fields.IPAddressField')(max_length=15, null=True))
+
+ # Changing field 'NodeGroupInterface.broadcast_ip'
+ db.alter_column(u'maasserver_nodegroupinterface', 'broadcast_ip', self.gf('django.db.models.fields.IPAddressField')(max_length=15, null=True))
+
+ # Changing field 'NodeGroupInterface.router_ip'
+ db.alter_column(u'maasserver_nodegroupinterface', 'router_ip', self.gf('django.db.models.fields.IPAddressField')(max_length=15, null=True))
+
+ 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.bootimage': {
+ 'Meta': {'unique_together': "((u'architecture', u'subarchitecture', u'release', u'purpose'),)", 'object_name': 'BootImage'},
+ 'architecture': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'purpose': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'release': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'subarchitecture': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ 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'}),
+ 'cpu_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'distro_series': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '10', 'null': 'True', 'blank': 'True'}),
+ 'error': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+ 'hardware_details': ('maasserver.fields.XMLField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
+ 'hostname': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'memory': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ '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-c30c2114-0959-11e2-aa17-9c4e363b1c94'", 'unique': 'True', 'max_length': '41'}),
+ 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['maasserver.Tag']", 'symmetrical': 'False'}),
+ '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'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'dhcp_key': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '80', 'blank': 'True'}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {}),
+ 'uuid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '36'})
+ },
+ u'maasserver.nodegroupinterface': {
+ 'Meta': {'unique_together': "((u'nodegroup', u'interface'),)", 'object_name': 'NodeGroupInterface'},
+ 'broadcast_ip': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'null': 'True', 'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'interface': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '255', 'blank': 'True'}),
+ 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}),
+ 'ip_range_high': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ 'ip_range_low': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ 'management': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'nodegroup': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['maasserver.NodeGroup']"}),
+ 'router_ip': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'null': 'True', 'blank': 'True'}),
+ 'subnet_mask': ('django.db.models.fields.GenericIPAddressField', [], {'default': 'None', 'max_length': '39', 'null': 'True', 'blank': 'True'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ 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.tag': {
+ 'Meta': {'object_name': 'Tag'},
+ 'comment': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {}),
+ 'definition': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '256'}),
+ 'updated': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ 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': '1348829190L'}),
+ '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']
\ No newline at end of file
=== modified file 'src/maasserver/models/nodegroupinterface.py'
--- src/maasserver/models/nodegroupinterface.py 2012-09-18 07:51:29 +0000
+++ src/maasserver/models/nodegroupinterface.py 2012-09-28 11:16:22 +0000
@@ -18,8 +18,8 @@
from django.db.models import (
CharField,
ForeignKey,
+ GenericIPAddressField,
IntegerField,
- IPAddressField,
)
from maasserver import DefaultMeta
from maasserver.enum import (
@@ -35,7 +35,7 @@
unique_together = ('nodegroup', 'interface')
# Static IP of the interface.
- ip = IPAddressField(null=False, editable=True)
+ ip = GenericIPAddressField(null=False, editable=True)
# The `NodeGroup` this interface belongs to.
nodegroup = ForeignKey(
@@ -48,15 +48,15 @@
# DHCP server settings.
interface = CharField(
blank=True, editable=True, max_length=255, default='')
- subnet_mask = IPAddressField(
- editable=True, unique=False, blank=True, null=True, default=None)
- broadcast_ip = IPAddressField(
- editable=True, unique=False, blank=True, null=True, default=None)
- router_ip = IPAddressField(
- editable=True, unique=False, blank=True, null=True, default=None)
- ip_range_low = IPAddressField(
+ subnet_mask = GenericIPAddressField(
+ editable=True, unique=False, blank=True, null=True, default=None)
+ broadcast_ip = GenericIPAddressField(
+ editable=True, unique=False, blank=True, null=True, default=None)
+ router_ip = GenericIPAddressField(
+ editable=True, unique=False, blank=True, null=True, default=None)
+ ip_range_low = GenericIPAddressField(
editable=True, unique=True, blank=True, null=True, default=None)
- ip_range_high = IPAddressField(
+ ip_range_high = GenericIPAddressField(
editable=True, unique=True, blank=True, null=True, default=None)
def __repr__(self):
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-09-28 07:31:54 +0000
+++ src/maasserver/tests/test_api.py 2012-09-28 11:16:22 +0000
@@ -2984,7 +2984,7 @@
self.assertEqual(
(
httplib.BAD_REQUEST,
- {'ip': ["Enter a valid IPv4 address."]},
+ {'ip': ["Enter a valid IPv4 or IPv6 address."]},
),
(response.status_code, json.loads(response.content)))
=== modified file 'src/maasserver/tests/test_forms.py'
--- src/maasserver/tests/test_forms.py 2012-09-26 16:30:00 +0000
+++ src/maasserver/tests/test_forms.py 2012-09-28 11:16:22 +0000
@@ -66,7 +66,11 @@
from maasserver.testing.factory import factory
from maasserver.testing.testcase import TestCase
from provisioningserver.enum import POWER_TYPE_CHOICES
-from testtools.matchers import MatchesStructure
+from testtools.matchers import (
+ AllMatch,
+ Equals,
+ MatchesStructure,
+ )
from testtools.testcase import ExpectedException
@@ -638,6 +642,11 @@
}
+nullable_fields = [
+ 'subnet_mask', 'broadcast_ip', 'router_ip', 'ip_range_low',
+ 'ip_range_high']
+
+
class TestNodeGroupInterfaceForm(TestCase):
def test_NodeGroupInterfaceForm_save_sets_nodegroup(self):
@@ -652,7 +661,19 @@
form = NodeGroupInterfaceForm(data={'ip': factory.getRandomString()})
self.assertFalse(form.is_valid())
self.assertEquals(
- {'ip': ['Enter a valid IPv4 address.']}, form._errors)
+ {'ip': ['Enter a valid IPv4 or IPv6 address.']}, form._errors)
+
+ def test_NodeGroupInterfaceForm_can_save_fields_being_None(self):
+ settings = make_interface_settings()
+ for field_name in nullable_fields:
+ del settings[field_name]
+ form = NodeGroupInterfaceForm(data=settings)
+ nodegroup = factory.make_node_group(
+ management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED)
+ interface = form.save(nodegroup=nodegroup)
+ field_values = [
+ getattr(interface, field_name) for field_name in nullable_fields]
+ self.assertThat(field_values, AllMatch(Equals('')))
class TestNodeGroupWithInterfacesForm(TestCase):
@@ -729,7 +750,8 @@
data={'name': name, 'uuid': uuid, 'interfaces': interfaces})
self.assertFalse(form.is_valid())
self.assertIn(
- "Enter a valid IPv4 address", form._errors['interfaces'][0])
+ "Enter a valid IPv4 or IPv6 address",
+ form._errors['interfaces'][0])
def test_NodeGroupWithInterfacesForm_creates_interface_from_params(self):
name = factory.make_name('name')