diff --git a/api-ref/source/os-volume-attachments.inc b/api-ref/source/os-volume-attachments.inc index 4ae784e3915c..ab2d9b40e4be 100644 --- a/api-ref/source/os-volume-attachments.inc +++ b/api-ref/source/os-volume-attachments.inc @@ -137,6 +137,9 @@ Update a volume attachment Update a volume attachment. +.. note:: This action only valid when the server is in ACTIVE, PAUSED and RESIZED state, + or a conflict(409) error will be returned. + Normal response codes: 202 Error response codes: badRequest(400), unauthorized(401), forbidden(403), itemNotFound(404), conflict(409) diff --git a/nova/compute/api.py b/nova/compute/api.py index 22e1cd19b98e..d4d57489e11e 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -3660,8 +3660,7 @@ class API(base.Base): @check_instance_lock @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.PAUSED, - vm_states.SUSPENDED, vm_states.STOPPED, - vm_states.RESIZED, vm_states.SOFT_DELETED]) + vm_states.RESIZED]) def swap_volume(self, context, instance, old_volume, new_volume): """Swap volume attached to an instance.""" # The caller likely got the instance from volume['attachments'] diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index 49659a8a45b8..c80ea1672707 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -2212,6 +2212,12 @@ class _ComputeAPIUnitTestMixIn(object): self._test_swap_volume_for_precheck_with_exception( exception.InstanceInvalidState, instance_update={'vm_state': vm_states.BUILDING}) + self._test_swap_volume_for_precheck_with_exception( + exception.InstanceInvalidState, + instance_update={'vm_state': vm_states.STOPPED}) + self._test_swap_volume_for_precheck_with_exception( + exception.InstanceInvalidState, + instance_update={'vm_state': vm_states.SUSPENDED}) def test_swap_volume_with_another_server_volume(self): # Should fail if old volume's instance_uuid is not that of the instance diff --git a/releasenotes/notes/update-swap-decorator-7622a265df55feaa.yaml b/releasenotes/notes/update-swap-decorator-7622a265df55feaa.yaml new file mode 100644 index 000000000000..6349b90ba772 --- /dev/null +++ b/releasenotes/notes/update-swap-decorator-7622a265df55feaa.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - prevent swap_volume action if the instance is in state SUSPENDED, + STOPPED or SOFT_DELETED. A conflict (409) will be raised now as + previously it used to fail silently. +