Do not attempt volume swap when guest is stopped/suspended
A swap on a stopped or suspended instance will fail silently. Remove these allowed instance states on swap_volume: suspended, stopped, soft_deleted Change-Id: Iff17f7cee7a56037b35d1a361a0b3279d0a885d6 Closes-Bug: #1673090
This commit is contained in:
parent
d36dcd52c2
commit
b40d949b31
@ -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)
|
||||
|
@ -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']
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user