Skip to content

Commit

Permalink
Aoiv concurrency errors
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Dec 20, 2023
1 parent 07864f7 commit cbe9460
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions IM/InfrastructureInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ def set_deleting(self, value=True):
if self.adding:
raise IncorrectStateException()
self.deleting = value
IM.InfrastructureList.InfrastructureList.save_data(self.id)

def set_adding(self, value=True):
"""
Expand All @@ -783,6 +784,7 @@ def set_adding(self, value=True):
self.add_cont_msg("Infrastructure deleted. Do not add resources.")
raise Exception("Infrastructure deleted. Do not add resources.")
self.adding = value
IM.InfrastructureList.InfrastructureList.save_data(self.id)

def get_auth(self, only_user_pass=False):
"""
Expand Down
12 changes: 6 additions & 6 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ def AddResource(inf_id, radl_data, auth, context=True):

sel_inf = InfrastructureManager.get_infrastructure(inf_id, auth)

if sel_inf.deleted:
InfrastructureManager.logger.info("Inf ID: %s: Deleted Infrastructure. Stop deploying!" % sel_inf.id)
return []

try:
if isinstance(radl_data, RADL):
radl = radl_data
Expand Down Expand Up @@ -621,10 +625,6 @@ def AddResource(inf_id, radl_data, auth, context=True):
# We are going to start adding resources
sel_inf.set_adding()

if sel_inf.deleted:
InfrastructureManager.logger.info("Inf ID: %s: Deleted Infrastructure. Stop deploying!" % sel_inf.id)
return []

# Launch every group in the same cloud provider
deployed_vm = {}
deploy_items = []
Expand Down Expand Up @@ -711,14 +711,14 @@ def AddResource(inf_id, radl_data, auth, context=True):
if context and new_vms and not all_failed:
sel_inf.Contextualize(auth)

IM.InfrastructureList.InfrastructureList.save_data(inf_id)

if all_failed and new_vms:
# if there are no VMs, set it as unconfigured
if not sel_inf.get_vm_list():
sel_inf.configured = False
raise Exception("Error adding VMs: %s" % error_msg)

IM.InfrastructureList.InfrastructureList.save_data(inf_id)

return [vm.im_id for vm in new_vms]

@staticmethod
Expand Down
6 changes: 6 additions & 0 deletions IM/REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,10 @@ def RESTAddResource(infid=None):
if not remove_list and not vm_ids and context:
InfrastructureManager.Reconfigure(infid, "", auth)

# If we have to reconfigure the infra, return the ID for the HAProxy stickiness
if context:
bottle.response.headers['InfID'] = infid

# Replace the TOSCA document
if tosca_data:
sel_inf = InfrastructureManager.get_infrastructure(infid, auth)
Expand Down Expand Up @@ -921,6 +925,8 @@ def RESTReconfigureInfrastructure(infid=None):
return return_error(415, "Unsupported Media Type %s" % content_type)
else:
radl_data = ""
# As we have to reconfigure the infra, return the ID for the HAProxy stickiness
bottle.response.headers['InfID'] = infid
bottle.response.content_type = "text/plain"
return InfrastructureManager.Reconfigure(infid, radl_data, auth, vm_list)
except DeletedInfrastructureException as ex:
Expand Down

0 comments on commit cbe9460

Please sign in to comment.