Revision 03805fc8

b/logic/backend.py
57 57

  
58 58
    # For the time being, we can only update the ipfour field,
59 59
    # based on the IPv4 address of the first NIC
60
    vm.ipfour = nics[0]['ip']
60
    if len(nics) > 0:
61
        ipv4 = nics[0]['ip']
62
        if ipv4 == '':
63
            ipv4 = '0.0.0.0'
64
        vm.ipfour = ipv4
61 65
    vm.save()
62 66

  
63 67

  
b/logic/tests.py
7 7
#
8 8

  
9 9
from synnefo.db.models import *
10
from synnefo.logic import backend
10 11
from synnefo.logic import credits
11 12
from synnefo.logic import users
12 13
from django.test import TestCase
......
132 133
        users.delete_user(self.user)
133 134

  
134 135
        self.assertRaises(SynnefoUser.DoesNotExist, SynnefoUser.objects.get, name = "jpage")
136

  
137

  
138
class ProcessNetStatusTestCase(TestCase):
139
    fixtures = ['db_test_data']
140
    def test_set_ipv4(self):
141
        """Test reception of a net status notification"""
142
        msg = {'instance': 'instance-name',
143
               'type':     'ganeti-net-status',
144
               'nics': [
145
                   {'ip': '192.168.33.1', 'mac': 'aa:00:00:58:1e:b9'}
146
               ]
147
        }
148
        vm = VirtualMachine.objects.get(pk=30000)
149
        backend.process_net_status(vm, msg['nics'])
150
        self.assertEquals(vm.ipfour, '192.168.33.1')
151

  
152
    def test_set_empty_ipv4(self):
153
        """Test reception of a net status notification with no IPv4 assigned"""
154
        msg = {'instance': 'instance-name',
155
               'type':     'ganeti-net-status',
156
               'nics': [
157
                   {'ip': '', 'mac': 'aa:00:00:58:1e:b9'}
158
               ]
159
        }
160
        vm = VirtualMachine.objects.get(pk=30000)
161
        backend.process_net_status(vm, msg['nics'])
162
        self.assertEquals(vm.ipfour, '0.0.0.0')

Also available in: Unified diff