Skip to content

Commit

Permalink
Add tests for coriolis.conductor.rpc.server module
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristi1324 committed Feb 28, 2024
1 parent cfd2da4 commit c984622
Show file tree
Hide file tree
Showing 4 changed files with 2,012 additions and 98 deletions.
11 changes: 4 additions & 7 deletions coriolis/conductor/rpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ def report_migration_minions_allocation_error(
awaiting_minions_status = (
constants.EXECUTION_STATUS_AWAITING_MINION_ALLOCATIONS)
if migration.last_execution_status != awaiting_minions_status:
raise exception.InvalidReplicaState(
raise exception.InvalidMigrationState(
"Migration is in '%s' status instead of the expected '%s' to "
"have minion machines allocations fail for it." % (
migration.last_execution_status, awaiting_minions_status))
Expand Down Expand Up @@ -3286,22 +3286,19 @@ def confirm_task_cancellation(self, ctxt, task_id, cancellation_details):
"task '%s' (status '%s'). Marking as '%s' anyway.",
task.id, task.status, final_status)

db_api.set_task_status(
ctxt, task.id, final_status,
exception_details=exception_details)
if final_status == task.status:
LOG.debug(
"NOT altering state of finalized task '%s' ('%s') following "
"confirmation of cancellation. Updating its exception "
"details though: %s", task.id, task.status, exception_details)
db_api.set_task_status(
ctxt, task.id, final_status,
exception_details=exception_details)
else:
LOG.info(
"Transitioning canceled task '%s' from '%s' to '%s' following "
"confirmation of its cancellation.",
task.id, task.status, final_status)
db_api.set_task_status(
ctxt, task.id, final_status,
exception_details=exception_details)
execution = db_api.get_tasks_execution(ctxt, task.execution_id)
self._advance_execution_state(ctxt, execution, requery=False)

Expand Down
34 changes: 34 additions & 0 deletions coriolis/tests/conductor/rpc/data/cancel_migration_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
- config:
force: False
execution_statuses: [EXECUTION_STATUS_RUNNING]
raises_exception: False

- config:
force: False
execution_statuses: []
raises_exception: True

- config:
force: False
execution_statuses: [EXECUTION_STATUS_COMPLETED]
raises_exception: True

- config:
force: True
execution_statuses: [EXECUTION_STATUS_CANCELLING]
raises_exception: False

- config:
force: False
execution_statuses: [EXECUTION_STATUS_CANCELLING]
raises_exception: True

- config:
force: False
execution_statuses: [EXECUTION_STATUS_AWAITING_MINION_ALLOCATIONS]
raises_exception: False

- config:
force: True
execution_statuses: [EXECUTION_STATUS_RUNNING, EXECUTION_STATUS_CANCELLING, EXECUTION_STATUS_AWAITING_MINION_ALLOCATIONS]
raises_exception: True
19 changes: 19 additions & 0 deletions coriolis/tests/conductor/rpc/data/confirm_task_cancellation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- task_status: TASK_STATUS_CANCELLING_AFTER_COMPLETION
expected_final_status: TASK_STATUS_CANCELED
expected_advance_execution_state_call: True

- task_status: TASK_STATUS_FORCE_CANCELED
expected_final_status: TASK_STATUS_FORCE_CANCELED
expected_advance_execution_state_call: False

- task_status: TASK_STATUS_FAILED_TO_CANCEL
expected_final_status: TASK_STATUS_CANCELED
expected_advance_execution_state_call: True

- task_status: TASK_STATUS_COMPLETED
expected_final_status: TASK_STATUS_COMPLETED
expected_advance_execution_state_call: False

- task_status: EXECUTION_STATUS_RUNNING
expected_final_status: TASK_STATUS_CANCELED
expected_advance_execution_state_call: True
Loading

0 comments on commit c984622

Please sign in to comment.