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
(cherry picked from commit b40d949b31)
This commit is contained in:
Mark Giles 2017-07-24 12:46:21 -04:00 committed by Lee Yarwood
parent b54aa791e2
commit 7a51ffc551
4 changed files with 16 additions and 2 deletions

View File

@ -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)

View File

@ -3760,8 +3760,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']

View File

@ -2213,6 +2213,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

View File

@ -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.