Commit 3d471ae0 authored by Christos Stavrakakis's avatar Christos Stavrakakis

cyclades: Fix bug when deleting instances

If OP_INSTANCE_REMOVE runs before OP_INSTANCE_CREATE the job will fail.
Dispatcher will ask Ganeti if the instance exists, and if not it will
release it's IPv4 address. However the instance may not exist because it
has not being created yet. This commit fixes this, by making
OP_INSTANCE_REMOVE depend on the OP_INSTANCE_CREATE job if the job has
not completed.
parent 2085ffb5
......@@ -43,7 +43,7 @@ from synnefo.logic import utils
from synnefo import quotas
from synnefo.api.util import release_resource
from synnefo.util.mac2eui64 import mac2eui64
from synnefo.logic.rapi import GanetiApiError
from synnefo.logic.rapi import GanetiApiError, JOB_STATUS_FINALIZED
from logging import getLogger
log = getLogger(__name__)
......@@ -567,8 +567,16 @@ def create_instance(vm, nics, flavor, image):
def delete_instance(vm):
depends = []
if ((vm.backendopcode == "OP_INSTANCE_CREATE") and
(vm.backendjobid is not None) and
(vm.backendjobstatus not in JOB_STATUS_FINALIZED) and
(job_is_still_running(vm, vm.backendjobid))):
depends.append(vm.backendjobid)
depends = [[job, ["success", "error", "canceled"]] for job in depends]
with pooled_rapi_client(vm) as client:
return client.DeleteInstance(vm.backend_vm_id, dry_run=settings.TEST)
return client.DeleteInstance(vm.backend_vm_id, dry_run=settings.TEST,
depends=depends)
def reboot_instance(vm, reboot_type):
......@@ -635,6 +643,17 @@ def get_instance_console(vm):
return console
def job_is_still_running(vm, job_id):
"""Check if a Ganeti job still running."""
with pooled_rapi_client(vm) as client:
job_status = client.GetJobStatus(job_id)
if job_status is None:
return False
if job_status in JOB_STATUS_FINALIZED:
return False
return True
def get_instance_info(vm):
with pooled_rapi_client(vm) as client:
return client.GetInstance(vm.backend_vm_id)
......
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