summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSusmitha <susmitha@platform9.com>2016-06-14 16:29:21 -0700
committerSusmitha <susmitha@platform9.com>2016-06-17 15:16:15 -0700
commit6c79555d56c2784a68250381d6647fffdb4aa4b1 (patch)
treea11e752fbfc2d241a62d765dc3dc9504ddd008ab
parent1e515759b3c4f6f3a84f459d11903c839f7fb8ae (diff)
Fix for IAAS-5523: Lease extension seems to be broken
If instance lease is beyond the tenant lease expiry, lease handler currently deletes the vm at tenant lease expiry. Adding a check to ignore the vms that have not yet expired.
-rw-r--r--mors/lease_manager.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/mors/lease_manager.py b/mors/lease_manager.py
index b0f1380..26864be 100644
--- a/mors/lease_manager.py
+++ b/mors/lease_manager.py
@@ -134,6 +134,7 @@ class LeaseManager:
134 def _get_vms_to_delete_for_tenant(self, tenant_uuid, expiry_mins): 134 def _get_vms_to_delete_for_tenant(self, tenant_uuid, expiry_mins):
135 vms_to_delete = [] 135 vms_to_delete = []
136 vm_ids_to_delete = set() 136 vm_ids_to_delete = set()
137 do_not_delete = set()
137 now = datetime.utcnow() 138 now = datetime.utcnow()
138 add_seconds = timedelta(seconds=expiry_mins*60) 139 add_seconds = timedelta(seconds=expiry_mins*60)
139 instance_leases = self.get_tenant_and_associated_instance_leases(None, tenant_uuid)['all_vms'] 140 instance_leases = self.get_tenant_and_associated_instance_leases(None, tenant_uuid)['all_vms']
@@ -143,12 +144,14 @@ class LeaseManager:
143 vms_to_delete.append(i_lease) 144 vms_to_delete.append(i_lease)
144 vm_ids_to_delete.add(i_lease['instance_uuid']) 145 vm_ids_to_delete.add(i_lease['instance_uuid'])
145 else: 146 else:
147 do_not_delete.add(i_lease['instance_uuid'])
146 logger.debug("Ignoring vm, vm not expired yet %s", i_lease['instance_uuid']) 148 logger.debug("Ignoring vm, vm not expired yet %s", i_lease['instance_uuid'])
147 149
148 tenant_vms = self.lease_handler.get_all_vms(tenant_uuid) 150 tenant_vms = self.lease_handler.get_all_vms(tenant_uuid)
149 for vm in tenant_vms: 151 for vm in tenant_vms:
150 expiry_date = vm['created_at'] + add_seconds 152 expiry_date = vm['created_at'] + add_seconds
151 if now > expiry_date and not (vm['instance_uuid'] in vm_ids_to_delete): 153 if now > expiry_date and vm['instance_uuid'] not in do_not_delete \
154 and vm['instance_uuid'] not in vm_ids_to_delete:
152 logger.info("Instance %s queued up for deletion creation date %s", vm['instance_uuid'], 155 logger.info("Instance %s queued up for deletion creation date %s", vm['instance_uuid'],
153 vm['created_at']) 156 vm['created_at'])
154 vms_to_delete.append(vm) 157 vms_to_delete.append(vm)