Revision c4ce868e snf-cyclades-app/synnefo/logic/backend.py

b/snf-cyclades-app/synnefo/logic/backend.py
76 76
    # Notifications of success change the operating state
77 77
    state_for_success = VirtualMachine.OPER_STATE_FROM_OPCODE.get(opcode, None)
78 78
    if status == 'success' and state_for_success is not None:
79
        utils.update_state(vm, state_for_success)
79
        vm.operstate = state_for_success
80 80
        # Set the deleted flag explicitly, cater for admin-initiated removals
81 81
        if opcode == 'OP_INSTANCE_REMOVE':
82 82
            release_instance_nics(vm)
......
85 85

  
86 86
    # Special case: if OP_INSTANCE_CREATE fails --> ERROR
87 87
    if status in ('canceled', 'error') and opcode == 'OP_INSTANCE_CREATE':
88
        utils.update_state(vm, 'ERROR')
88
        vm.operstate = 'ERROR'
89
        vm.backendtime = etime
89 90

  
90 91
    # Special case: OP_INSTANCE_REMOVE fails for machines in ERROR,
91 92
    # when no instance exists at the Ganeti backend.
92 93
    # See ticket #799 for all the details.
93 94
    #
94
    if (status == 'error' and opcode == 'OP_INSTANCE_REMOVE'):
95
    if (status == 'error' and vm.operstate == 'ERROR' and\
96
        opcode == 'OP_INSTANCE_REMOVE'):
95 97
        vm.deleted = True
96 98
        vm.nics.all().delete()
99
        vm.operstate = 'DESTROYED'
100
        vm.backendtime = etime
97 101

  
98
    vm.backendtime = etime
99
    # Any other notification of failure leaves the operating state unchanged
102
    # Update backendtime only for jobs that have been successfully completed,
103
    # since only these jobs update the state of the VM. Else a "race condition"
104
    # may occur when a successful job (e.g. OP_INSTANCE_REMOVE) completes
105
    # before an error job and messages arrive in reversed order.
106
    if status == 'success':
107
        vm.backendtime = etime
100 108

  
101 109
    vm.save()
102 110

  

Also available in: Unified diff