@@ -572,8 +572,7 @@ def _validate_flavor_image_nostatus(context, image, instance_type,
572
572
with each other.
573
573
574
574
:param context: A context.RequestContext
575
- :param image: a dict representation of the image including properties,
576
- enforces the image status is active.
575
+ :param image: a dict representation of the image including properties
577
576
:param instance_type: Flavor object
578
577
:param root_bdm: BlockDeviceMapping for root disk. Will be None for
579
578
the resize case.
@@ -666,6 +665,30 @@ def _validate_flavor_image_nostatus(context, image, instance_type,
666
665
servers_policies .ZERO_DISK_FLAVOR , fatal = False ):
667
666
raise exception .BootFromVolumeRequiredForZeroDiskFlavor ()
668
667
668
+ API ._validate_flavor_image_numa_pci (
669
+ image , instance_type , validate_numa = validate_numa ,
670
+ validate_pci = validate_pci )
671
+
672
+ @staticmethod
673
+ def _validate_flavor_image_numa_pci (image , instance_type ,
674
+ validate_numa = True ,
675
+ validate_pci = False ):
676
+ """Validate the flavor and image NUMA/PCI values.
677
+
678
+ This is called from the API service to ensure that the flavor
679
+ extra-specs and image properties are self-consistent and compatible
680
+ with each other.
681
+
682
+ :param image: a dict representation of the image including properties
683
+ :param instance_type: Flavor object
684
+ :param validate_numa: Flag to indicate whether or not to validate
685
+ the NUMA-related metadata.
686
+ :param validate_pci: Flag to indicate whether or not to validate
687
+ the PCI-related metadata.
688
+ :raises: Many different possible exceptions. See
689
+ api.openstack.compute.servers.INVALID_FLAVOR_IMAGE_EXCEPTIONS
690
+ for the full list.
691
+ """
669
692
image_meta = _get_image_meta_obj (image )
670
693
671
694
# Only validate values of flavor/image so the return results of
@@ -3572,19 +3595,23 @@ def resize(self, context, instance, flavor_id=None, clean_shutdown=True,
3572
3595
current_instance_type = instance .get_flavor ()
3573
3596
3574
3597
# If flavor_id is not provided, only migrate the instance.
3598
+ volume_backed = None
3575
3599
if not flavor_id :
3576
3600
LOG .debug ("flavor_id is None. Assuming migration." ,
3577
3601
instance = instance )
3578
3602
new_instance_type = current_instance_type
3579
3603
else :
3580
3604
new_instance_type = flavors .get_flavor_by_flavor_id (
3581
3605
flavor_id , read_deleted = "no" )
3606
+ # Check to see if we're resizing to a zero-disk flavor which is
3607
+ # only supported with volume-backed servers.
3582
3608
if (new_instance_type .get ('root_gb' ) == 0 and
3583
- current_instance_type .get ('root_gb' ) != 0 and
3584
- not compute_utils .is_volume_backed_instance (context ,
3585
- instance )):
3586
- reason = _ ('Resize to zero disk flavor is not allowed.' )
3587
- raise exception .CannotResizeDisk (reason = reason )
3609
+ current_instance_type .get ('root_gb' ) != 0 ):
3610
+ volume_backed = compute_utils .is_volume_backed_instance (
3611
+ context , instance )
3612
+ if not volume_backed :
3613
+ reason = _ ('Resize to zero disk flavor is not allowed.' )
3614
+ raise exception .CannotResizeDisk (reason = reason )
3588
3615
3589
3616
if not new_instance_type :
3590
3617
raise exception .FlavorNotFound (flavor_id = flavor_id )
@@ -3617,10 +3644,23 @@ def resize(self, context, instance, flavor_id=None, clean_shutdown=True,
3617
3644
if not same_instance_type :
3618
3645
image = utils .get_image_from_system_metadata (
3619
3646
instance .system_metadata )
3620
- # Can skip root_bdm check since it will not change during resize.
3621
- self ._validate_flavor_image_nostatus (
3622
- context , image , new_instance_type , root_bdm = None ,
3623
- validate_pci = True )
3647
+ # Figure out if the instance is volume-backed but only if we didn't
3648
+ # already figure that out above (avoid the extra db hit).
3649
+ if volume_backed is None :
3650
+ volume_backed = compute_utils .is_volume_backed_instance (
3651
+ context , instance )
3652
+ # If the server is volume-backed, we still want to validate numa
3653
+ # and pci information in the new flavor, but we don't call
3654
+ # _validate_flavor_image_nostatus because how it handles checking
3655
+ # disk size validation was not intended for a volume-backed
3656
+ # resize case.
3657
+ if volume_backed :
3658
+ self ._validate_flavor_image_numa_pci (
3659
+ image , new_instance_type , validate_pci = True )
3660
+ else :
3661
+ self ._validate_flavor_image_nostatus (
3662
+ context , image , new_instance_type , root_bdm = None ,
3663
+ validate_pci = True )
3624
3664
3625
3665
filter_properties = {'ignore_hosts' : []}
3626
3666
0 commit comments