Browse Source

Merge "Reject resize operation for accelerator" into stable/ussuri

changes/49/751349/1
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
d003464ee8
2 changed files with 26 additions and 1 deletions
  1. +6
    -0
      nova/compute/api.py
  2. +20
    -1
      nova/tests/unit/compute/test_compute_api.py

+ 6
- 0
nova/compute/api.py View File

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


+ 20
- 1
nova/tests/unit/compute/test_compute_api.py View File

@@ -2063,7 +2063,7 @@ class _ComputeAPIUnitTestMixIn(object):
fake_inst = self._create_instance_obj()
fake_inst.flavor = cur_flavor
new_flavor = objects.Flavor(id=2, name='bar', vcpus=1, memory_mb=2048,
root_gb=10, disabled=False)
root_gb=10, disabled=False, extra_specs={})
mock_get.return_value = new_flavor
mock_check.side_effect = exception.OverQuota(
overs=['ram'], quotas={'cores': 1, 'ram': 2048},
@@ -2078,6 +2078,25 @@ class _ComputeAPIUnitTestMixIn(object):
project_values={'cores': 1, 'ram': 2560},
project_id=fake_inst.project_id, user_id=fake_inst.user_id)

@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):
self._test_migrate()



Loading…
Cancel
Save