Reject resize operation for accelerator
When resize with a new flavor with accelerator, we should raise forbidden exception to reject the resize operation. Add related unit test. Follow up the comment: https://review.opendev.org/#/c/715326/22/nova/compute/api.py@3907 Co-Authored-By: Wenping Song <songwenping@inspur.com> Closes-Bug: #1893751 Change-Id: Ie20a620588e3b0d18055c34ec7671e91e6bf6ee0
This commit is contained in:
parent
99781d6fa9
commit
97267fc05c
|
@ -3943,8 +3943,6 @@ class API(base.Base):
|
|||
|
||||
# TODO(stephenfin): This logic would be so much easier to grok if we
|
||||
# finally split resize and cold migration into separate code paths
|
||||
# TODO(stephenfin): The 'block_accelerators' decorator doesn't take into
|
||||
# account the accelerators requested in the new flavor
|
||||
@block_accelerators()
|
||||
@check_instance_lock
|
||||
@check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.STOPPED])
|
||||
|
@ -3980,6 +3978,12 @@ class API(base.Base):
|
|||
else:
|
||||
new_instance_type = flavors.get_flavor_by_flavor_id(
|
||||
flavor_id, read_deleted="no")
|
||||
# NOTE(wenping): We use this instead of the 'block_accelerator'
|
||||
# decorator since the operation can differ depending on args,
|
||||
# and for resize we have two flavors to worry about, we should
|
||||
# reject resize with new flavor with accelerator.
|
||||
if new_instance_type.extra_specs.get('accel:device_profile'):
|
||||
raise exception.ForbiddenWithAccelerators()
|
||||
# Check to see if we're resizing to a zero-disk flavor which is
|
||||
# only supported with volume-backed servers.
|
||||
if (new_instance_type.get('root_gb') == 0 and
|
||||
|
|
|
@ -2166,6 +2166,25 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
mock.call(new_flavor, mock.ANY),
|
||||
])
|
||||
|
||||
@mock.patch('nova.compute.api.API.get_instance_host_status',
|
||||
new=mock.Mock(return_value=fields_obj.HostStatus.UP))
|
||||
@mock.patch('nova.compute.utils.is_volume_backed_instance',
|
||||
new=mock.Mock(return_value=False))
|
||||
@mock.patch.object(flavors, 'get_flavor_by_flavor_id')
|
||||
def test_resize__with_accelerator(self, mock_get_flavor):
|
||||
"""Ensure resizes are rejected if either flavor requests accelerator.
|
||||
"""
|
||||
fake_inst = self._create_instance_obj()
|
||||
new_flavor = self._create_flavor(
|
||||
id=200, flavorid='new-flavor-id', name='new_flavor',
|
||||
disabled=False, extra_specs={'accel:device_profile': 'dp'})
|
||||
mock_get_flavor.return_value = new_flavor
|
||||
|
||||
self.assertRaises(
|
||||
exception.ForbiddenWithAccelerators,
|
||||
self.compute_api.resize,
|
||||
self.context, fake_inst, flavor_id=new_flavor.flavorid)
|
||||
|
||||
def _test_migrate(self, *args, **kwargs):
|
||||
self._test_resize(*args, flavor_id_passed=False, **kwargs)
|
||||
|
||||
|
|
Loading…
Reference in New Issue