Revision 1fdd8d69

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

  
148 148
    if job_fields is None:
149 149
        job_fields = {}
150

  
151
    new_operstate = None
150 152
    state_for_success = VirtualMachine.OPER_STATE_FROM_OPCODE.get(opcode)
151 153

  
152
    # Notifications of success change the operating state
153 154
    if status == rapi.JOB_STATUS_SUCCESS:
155
        # If job succeeds, change operating state if needed
154 156
        if state_for_success is not None:
155
            vm.operstate = state_for_success
157
            new_operstate = state_for_success
158

  
156 159
        beparams = job_fields.get("beparams", None)
157 160
        if beparams:
158 161
            # Change the flavor of the VM
159 162
            _process_resize(vm, beparams)
163

  
160 164
        # Update backendtime only for jobs that have been successfully
161 165
        # completed, since only these jobs update the state of the VM. Else a
162 166
        # "race condition" may occur when a successful job (e.g.
......
171 175
    # Special case: if OP_INSTANCE_CREATE fails --> ERROR
172 176
    if opcode == 'OP_INSTANCE_CREATE' and status in (rapi.JOB_STATUS_CANCELED,
173 177
                                                     rapi.JOB_STATUS_ERROR):
174
        vm.operstate = 'ERROR'
178
        new_operstate = "ERROR"
175 179
        vm.backendtime = etime
176 180
        # Update state of associated NICs
177 181
        vm.nics.all().update(state="ERROR")
......
188 192
                # And delete the NIC.
189 193
                nic.delete()
190 194
            vm.deleted = True
191
            vm.operstate = state_for_success
195
            new_operstate = state_for_success
192 196
            vm.backendtime = etime
193 197
            status = rapi.JOB_STATUS_SUCCESS
194 198

  
......
201 205
            vm.task = None
202 206
            vm.task_job_id = None
203 207

  
208
    if new_operstate is not None:
209
        vm.operstate = new_operstate
210

  
204 211
    vm.save()
205 212

  
206 213

  
b/snf-cyclades-app/synnefo/quotas/__init__.py
347 347
    resolved it before issuing the new one.
348 348

  
349 349
    """
350
    # Try to resolve previous serial
350
    # Try to resolve previous serial:
351
    # If action is DESTROY, we must always reject the previous commission,
352
    # since multiple DESTROY actions are allowed in the same resource (e.g. VM)
353
    # The one who succeeds will be finally accepted, and all other will be
354
    # rejected
355
    force = force or (action == "DESTROY")
351 356
    resolve_commission(resource.serial, force=force)
352 357

  
353 358
    serial = issue_commission(resource, action, name=commission_name,

Also available in: Unified diff