Browse Source

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.
Susmitha 2 years ago
parent
commit
6c79555d56
1 changed files with 4 additions and 1 deletions
  1. 4
    1
      mors/lease_manager.py

+ 4
- 1
mors/lease_manager.py View File

@@ -134,6 +134,7 @@ class LeaseManager:
134 134
     def _get_vms_to_delete_for_tenant(self, tenant_uuid, expiry_mins):
135 135
         vms_to_delete = []
136 136
         vm_ids_to_delete = set()
137
+        do_not_delete = set()
137 138
         now = datetime.utcnow()
138 139
         add_seconds = timedelta(seconds=expiry_mins*60)
139 140
         instance_leases = self.get_tenant_and_associated_instance_leases(None, tenant_uuid)['all_vms']
@@ -143,12 +144,14 @@ class LeaseManager:
143 144
                 vms_to_delete.append(i_lease)
144 145
                 vm_ids_to_delete.add(i_lease['instance_uuid'])
145 146
             else:
147
+                do_not_delete.add(i_lease['instance_uuid'])
146 148
                 logger.debug("Ignoring vm, vm not expired yet %s", i_lease['instance_uuid'])
147 149
 
148 150
         tenant_vms = self.lease_handler.get_all_vms(tenant_uuid)
149 151
         for vm in tenant_vms:
150 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 155
                 logger.info("Instance %s queued up for deletion creation date %s", vm['instance_uuid'],
153 156
                             vm['created_at'])
154 157
                 vms_to_delete.append(vm)

Loading…
Cancel
Save