Revision fd95834e

b/snf-cyclades-app/synnefo/logic/backend.py
39 39

  
40 40
from synnefo.db.models import (Backend, VirtualMachine, Network,
41 41
                               BackendNetwork, BACKEND_STATUSES,
42
                               pooled_rapi_client, BridgePoolTable,
43
                               MacPrefixPoolTable, VirtualMachineDiagnostic)
42
                               pooled_rapi_client, VirtualMachineDiagnostic)
44 43
from synnefo.logic import utils
45 44
from synnefo import quotas
46 45
from synnefo.api.util import release_resource
46
from synnefo.util.mac2eui64 import mac2eui64
47 47

  
48 48
from logging import getLogger
49 49
log = getLogger(__name__)
......
58 58

  
59 59

  
60 60
@transaction.commit_on_success
61
def process_op_status(vm, etime, jobid, opcode, status, logmsg):
61
def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None):
62 62
    """Process a job progress notification from the backend
63 63

  
64 64
    Process an incoming message from the backend (currently Ganeti).
......
81 81
    if status == 'success' and state_for_success is not None:
82 82
        vm.operstate = state_for_success
83 83

  
84
    # Update the NICs of the VM
85
    if status == "success" and nics is not None:
86
        _process_net_status(vm, etime, nics)
87

  
84 88
    # Special case: if OP_INSTANCE_CREATE fails --> ERROR
85 89
    if opcode == 'OP_INSTANCE_CREATE' and status in ('canceled', 'error'):
86 90
        vm.operstate = 'ERROR'
......
113 117

  
114 118
@transaction.commit_on_success
115 119
def process_net_status(vm, etime, nics):
120
    """Wrap _process_net_status inside transaction."""
121
    _process_net_status(vm, etime, nics)
122

  
123

  
124
def _process_net_status(vm, etime, nics):
116 125
    """Process a net status notification from the backend
117 126

  
118 127
    Process an incoming message from the Ganeti backend,
......
156 165
        # Get the new nic info
157 166
        mac = new_nic.get('mac', '')
158 167
        ipv4 = new_nic.get('ip', '')
159
        ipv6 = new_nic.get('ipv6', '')
168
        if net.subnet6:
169
            ipv6 = mac2eui64(mac, net.subnet6)
170
        else:
171
            ipv6 = ''
160 172

  
161 173
        firewall = new_nic.get('firewall', '')
162 174
        firewall_profile = _reverse_tags.get(firewall, '')
b/snf-cyclades-app/synnefo/logic/callbacks.py
170 170
        log.error("Message is of unknown type %s.", msg['type'])
171 171
        return
172 172

  
173
    nics = msg.get("nics", None)
173 174
    backend.process_op_status(vm, event_time, msg['jobId'], msg['operation'],
174
                              msg['status'], msg['logmsg'])
175
                              msg['status'], msg['logmsg'], nics)
175 176

  
176 177
    log.debug("Done processing ganeti-op-status msg for vm %s.",
177 178
              msg['instance'])
b/snf-cyclades-app/synnefo/logic/tests.py
41 41
from datetime import datetime
42 42
from mock import patch
43 43
from synnefo.api.util import allocate_resource
44
from synnefo.logic.callbacks import (update_db, update_net, update_network,
44
from synnefo.logic.callbacks import (update_db, update_network,
45 45
                                     update_build_progress)
46 46
from snf_django.utils.testing import mocked_quotaholder
47 47

  
......
199 199
    def create_msg(self, **kwargs):
200 200
        """Create snf-ganeti-hook message"""
201 201
        msg = {'event_time': split_time(time())}
202
        msg['type'] = 'ganeti-net-status'
202
        msg['type'] = 'ganeti-op-status'
203
        msg['operation'] = 'OP_INSTANCE_SET_PARAMS'
203 204
        msg['status'] = 'success'
204 205
        msg['jobId'] = 1
205 206
        msg['logmsg'] = 'Dummy Log'
......
209 210
        return message
210 211

  
211 212
    def test_missing_attribute(self, client):
212
        update_net(client, json.dumps({'body': {}}))
213
        update_db(client, json.dumps({'body': {}}))
213 214
        client.basic_nack.assert_called_once()
214 215

  
215 216
    def test_unhandled_exception(self, client):
216
        update_net(client, {})
217
        update_db(client, {})
217 218
        client.basic_reject.assert_called_once()
218 219

  
219 220
    def test_wrong_type(self, client):
220 221
        msg = self.create_msg(type="WRONG_TYPE")
221
        update_net(client, msg)
222
        update_db(client, msg)
222 223
        client.basic_ack.assert_called_once()
223 224

  
224 225
    def test_missing_instance(self, client):
225 226
        msg = self.create_msg(operation='OP_INSTANCE_STARTUP',
226 227
                              instance='foo')
227
        update_net(client, msg)
228
        update_db(client, msg)
228 229
        client.basic_nack.assert_called_once()
229 230

  
230 231
    def test_no_nics(self, client):
......
235 236
        self.assertEqual(len(vm.nics.all()), 3)
236 237
        msg = self.create_msg(nics=[],
237 238
                              instance=vm.backend_vm_id)
238
        update_net(client, msg)
239
        update_db(client, msg)
239 240
        client.basic_ack.assert_called_once()
240 241
        db_vm = VirtualMachine.objects.get(id=vm.id)
241 242
        self.assertEqual(len(db_vm.nics.all()), 0)
......
246 247
            net = mfactory.NetworkFactory(public=public)
247 248
            msg = self.create_msg(nics=[{'network': net.backend_id}],
248 249
                                  instance=vm.backend_vm_id)
249
            update_net(client, msg)
250
            update_db(client, msg)
250 251
            client.basic_ack.assert_called_once()
251 252
            db_vm = VirtualMachine.objects.get(id=vm.id)
252 253
            nics = db_vm.nics.all()
......
271 272
                                     'ip': '10.0.0.22',
272 273
                                     'mac': 'aa:bb:cc:00:11:22'}],
273 274
                              instance=vm.backend_vm_id)
274
        update_net(client, msg)
275
        update_db(client, msg)
275 276
        client.basic_ack.assert_called_once()
276 277
        db_vm = VirtualMachine.objects.get(id=vm.id)
277 278
        nics = db_vm.nics.all()

Also available in: Unified diff