def _check_target_flavor(self, instance, flavor, block_device_info): ephemerals = driver.block_device_info_get_ephemerals(block_device_info) eph_size = (block_device.get_bdm_ephemeral_disk_size(ephemerals) or instance.flavor.ephemeral_gb) new_root_gb = flavor.root_gb curr_root_gb = instance.flavor.root_gb new_eph_size = flavor.ephemeral_gb root_down = new_root_gb < curr_root_gb ephemeral_down = new_eph_size < eph_size booted_from_volume = self._block_dev_man.is_boot_from_volume( block_device_info) if root_down and not booted_from_volume: raise exception.InstanceFaultRollback( exception.CannotResizeDisk( reason=_("Cannot resize the root disk to a smaller size. " "Current size: %(curr_root_gb)s GB. Requested " "size: %(new_root_gb)s GB.") % { 'curr_root_gb': curr_root_gb, 'new_root_gb': new_root_gb})) # We allow having a new flavor with no ephemeral storage, in which # case we'll just remove all the ephemeral disks. elif ephemeral_down and new_eph_size: reason = (_("The new flavor ephemeral size (%(flavor_eph)s) is " "smaller than the current total ephemeral disk size: " "%(current_eph)s.") % dict(flavor_eph=flavor.ephemeral_gb, current_eph=eph_size)) raise exception.InstanceFaultRollback( exception.CannotResizeDisk(reason=reason))
def test_get_bdm_ephemeral_disk_size(self): size = block_device.get_bdm_ephemeral_disk_size(self.new_mapping) self.assertEqual(10, size)