Commit f6ff7a6c authored by Vangelis Koukis's avatar Vangelis Koukis
Browse files

Fix PostgreSQL backend exception for empty IPv4

Fix exception is thrown in logic/backend.py:process_net_status()
if the NIC configuration notification contains an empty IPv4
field, and Django uses the PostgreSQL backend.

This only happens with the PostgreSQL backend, because it has a
specific IPv4 data type and cannot accept the empty string as a
valid value for such fields.

Also add two unit tests for logic/backend.py:process_net_status().
parent ca9f8212
......@@ -57,7 +57,11 @@ def process_net_status(vm, nics):
# For the time being, we can only update the ipfour field,
# based on the IPv4 address of the first NIC
vm.ipfour = nics[0]['ip']
if len(nics) > 0:
ipv4 = nics[0]['ip']
if ipv4 == '':
ipv4 = '0.0.0.0'
vm.ipfour = ipv4
vm.save()
......
......@@ -7,6 +7,7 @@
#
from synnefo.db.models import *
from synnefo.logic import backend
from synnefo.logic import credits
from synnefo.logic import users
from django.test import TestCase
......@@ -132,3 +133,30 @@ class AuthTestCase(TestCase):
users.delete_user(self.user)
self.assertRaises(SynnefoUser.DoesNotExist, SynnefoUser.objects.get, name = "jpage")
class ProcessNetStatusTestCase(TestCase):
fixtures = ['db_test_data']
def test_set_ipv4(self):
"""Test reception of a net status notification"""
msg = {'instance': 'instance-name',
'type': 'ganeti-net-status',
'nics': [
{'ip': '192.168.33.1', 'mac': 'aa:00:00:58:1e:b9'}
]
}
vm = VirtualMachine.objects.get(pk=30000)
backend.process_net_status(vm, msg['nics'])
self.assertEquals(vm.ipfour, '192.168.33.1')
def test_set_empty_ipv4(self):
"""Test reception of a net status notification with no IPv4 assigned"""
msg = {'instance': 'instance-name',
'type': 'ganeti-net-status',
'nics': [
{'ip': '', 'mac': 'aa:00:00:58:1e:b9'}
]
}
vm = VirtualMachine.objects.get(pk=30000)
backend.process_net_status(vm, msg['nics'])
self.assertEquals(vm.ipfour, '0.0.0.0')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment