Skip to content

Commit

Permalink
db: Fix wrong argument and refactor update_endpoing method
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristi1324 committed Jul 8, 2024
1 parent 259308e commit eab90d4
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions coriolis/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ def add_endpoint(context, endpoint):
_session(context).add(endpoint)


@enginefacade.writer
def _try_unmap_regions(context, region_ids, endpoint_id):
for region_to_unmap in region_ids:
try:
LOG.debug(
"Attempting to unmap region '%s' from endpoint '%s'",
region_to_unmap, endpoint_id)
delete_endpoint_region_mapping(
context, endpoint_id, region_to_unmap)
except Exception:
LOG.warn(
"Exception occurred while attempting to unmap region '%s' "
"from endpoint '%s'. Ignoring. Error was: %s",
region_to_unmap, endpoint_id,
utils.get_exception_details())


@enginefacade.writer
def update_endpoint(context, endpoint_id, updated_values):
endpoint = get_endpoint(context, endpoint_id)
Expand All @@ -176,21 +193,6 @@ def update_endpoint(context, endpoint_id, updated_values):
"Update payload for endpoints must be a dict. Got the following "
"(type: %s): %s" % (type(updated_values), updated_values))

def _try_unmap_regions(region_ids):
for region_to_unmap in region_ids:
try:
LOG.debug(
"Attempting to unmap region '%s' from endpoint '%s'",
region_to_unmap, endpoint_id)
delete_endpoint_region_mapping(
context, endpoint_id, region_to_unmap)
except Exception:
LOG.warn(
"Exception occurred while attempting to unmap region '%s' "
"from endpoint '%s'. Ignoring. Error was: %s",
region_to_unmap, endpoint_id,
utils.get_exception_details())

newly_mapped_regions = []
regions_to_unmap = []
# NOTE: `.pop()` required for `_update_sqlalchemy_object_fields` call:
Expand Down Expand Up @@ -235,7 +237,7 @@ def _try_unmap_regions(region_ids):
"endpoint '%s'. Cleaning up created mappings (%s). Error was: "
"%s", region_id, endpoint_id, newly_mapped_regions,
utils.get_exception_details())
_try_unmap_regions(newly_mapped_regions)
_try_unmap_regions(context, newly_mapped_regions, endpoint_id)
raise

updateable_fields = ["name", "description", "connection_info"]
Expand All @@ -247,14 +249,14 @@ def _try_unmap_regions(region_ids):
"Exception occurred while updating fields of endpoint '%s'. "
"Cleaning ""up created mappings (%s). Error was: %s",
endpoint_id, newly_mapped_regions, utils.get_exception_details())
_try_unmap_regions(newly_mapped_regions)
_try_unmap_regions(context, newly_mapped_regions, endpoint_id)
raise

# remove all of the old region mappings:
LOG.debug(
"Unmapping the following regions during update of endpoint '%s': %s",
endpoint_id, regions_to_unmap)
_try_unmap_regions(regions_to_unmap)
_try_unmap_regions(context, regions_to_unmap, endpoint_id)


@enginefacade.writer
Expand Down Expand Up @@ -593,7 +595,7 @@ def set_execution_status(
context, execution_id, status, update_action_status=True):
execution = _soft_delete_aware_query(
context, models.TasksExecution).join(
models.TasksExecution.action)
models.TasksExecution.action_id)
if is_user_context(context):
execution = execution.filter(
models.BaseTransferAction.project_id == context.project_id)
Expand Down

0 comments on commit eab90d4

Please sign in to comment.