Commit 91392318 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Fixes causing unsynced quotas

* clear QuotaHolderSerial objects when resolving pending commissions.
* Fix wrong name of Ganeti opcodes.
* Do not update vm's flavor before issuing new commission
parent affc0575
......@@ -145,6 +145,7 @@ def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None,
job_fields = {}
new_operstate = None
new_flavor = None
state_for_success = VirtualMachine.OPER_STATE_FROM_OPCODE.get(opcode)
if status == rapi.JOB_STATUS_SUCCESS:
......@@ -155,7 +156,7 @@ def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None,
beparams = job_fields.get("beparams", None)
if beparams:
# Change the flavor of the VM
_process_resize(vm, beparams)
new_flavor = _process_resize(vm, beparams)
# Update backendtime only for jobs that have been successfully
# completed, since only these jobs update the state of the VM. Else a
......@@ -203,6 +204,8 @@ def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None,
if new_operstate is not None:
vm.operstate = new_operstate
if new_flavor is not None:
vm.flavor = new_flavor
vm.save()
......@@ -220,8 +223,7 @@ def _process_resize(vm, beparams):
disk_template=old_flavor.disk_template)
except Flavor.DoesNotExist:
raise Exception("Cannot find flavor for VM")
vm.flavor = new_flavor
vm.save()
return new_flavor
@transaction.commit_on_success
......
......@@ -152,8 +152,8 @@ def get_task_state(vm):
OPCODE_TO_ACTION = {
"OP_INSTANCE_CREATE": "BUILD",
"OP_INSTANCE_START": "START",
"OP_INSTANCE_STOP": "STOP",
"OP_INSTANCE_STARTUP": "START",
"OP_INSTANCE_SHUTDOWN": "STOP",
"OP_INSTANCE_REBOOT": "REBOOT",
"OP_INSTANCE_REMOVE": "DESTROY"}
......
......@@ -164,6 +164,14 @@ def resolve_commissions(accept=None, reject=None, strict=True):
with AstakosClientExceptionHandler():
response = qh.resolve_commissions(accept, reject)
# Update correspodning entries in DB
QuotaHolderSerial.objects.filter(serial__in=accept).update(accept=True,
pending=False,
resolved=True)
QuotaHolderSerial.objects.filter(serial__in=reject).update(accept=False,
pending=False,
resolved=True)
if strict:
failed = response["failed"]
if failed:
......
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