diff options
author | Vladyslav Drok <vdrok@mirantis.com> | 2015-04-30 15:30:11 +0300 |
---|---|---|
committer | Vladyslav Drok <vdrok@mirantis.com> | 2015-05-12 16:57:11 +0300 |
commit | c2924949c1e9a659acaf9da7be16d8fa176c0ad2 (patch) | |
tree | 3a3329808b2d61ec033ca3a77c768e010bc4eadc /ironic/drivers | |
parent | b098c4a364ba8d57435213007cf1a6e5627e5166 (diff) | |
download | ironic-c2924949c1e9a659acaf9da7be16d8fa176c0ad2.tar.gz |
Improve root partition size check in deploy_partition_image
There is a check in deploy_partition_image which ensures that size of
the image being deployed is greater than or equal to root partition
size. It is being checked on driver.deploy step by calling
iscsi_deploy.check_image_size by in-tree drivers, but if some
out-of-tree driver would use this function without calling
iscsi_deploy.check_image_size beforehand the logic would be
incorrect, as deploy_partition_image will silently change root_mb
value and proceed.
In this change it is proposed to throw an exception instead in this
case.
Closes-bug: #1454263
Change-Id: Iecd59d938762089ab639066fa994492a64e92937
Diffstat (limited to 'ironic/drivers')
-rw-r--r-- | ironic/drivers/modules/deploy_utils.py | 20 | ||||
-rw-r--r-- | ironic/drivers/modules/iscsi_deploy.py | 4 |
2 files changed, 13 insertions, 11 deletions
diff --git a/ironic/drivers/modules/deploy_utils.py b/ironic/drivers/modules/deploy_utils.py index e6c2c48ef..735e2ef7b 100644 --- a/ironic/drivers/modules/deploy_utils.py +++ b/ironic/drivers/modules/deploy_utils.py @@ -673,6 +673,8 @@ def deploy_partition_image(address, port, iqn, lun, image_path, or configdrive HTTP URL. :param boot_option: Can be "local" or "netboot". "netboot" by default. :param boot_mode: Can be "bios" or "uefi". "bios" by default. + :raises: InstanceDeployFailure if image virtual size is bigger than root + partition size. :returns: a dictionary containing the following keys: 'root uuid': UUID of root partition 'efi system partition uuid': UUID of the uefi system partition @@ -680,12 +682,14 @@ def deploy_partition_image(address, port, iqn, lun, image_path, NOTE: If key exists but value is None, it means partition doesn't exist. """ - with _iscsi_setup_and_handle_errors(address, port, iqn, - lun, image_path) as dev: - image_mb = get_image_mb(image_path) - if image_mb > root_mb: - root_mb = image_mb + image_mb = get_image_mb(image_path) + if image_mb > root_mb: + msg = (_('Root partition is too small for requested image. Image ' + 'virtual size: %(image_mb)d MB, Root size: %(root_mb)d MB') + % {'image_mb': image_mb, 'root_mb': root_mb}) + raise exception.InstanceDeployFailure(msg) + with _iscsi_setup_and_handle_errors(address, port, iqn, lun) as dev: uuid_dict_returned = work_on_disk( dev, root_mb, swap_mb, ephemeral_mb, ephemeral_format, image_path, node_uuid, preserve_ephemeral=preserve_ephemeral, @@ -710,7 +714,7 @@ def deploy_disk_image(address, port, iqn, lun, the disk which was used for deployment. """ with _iscsi_setup_and_handle_errors(address, port, iqn, - lun, image_path) as dev: + lun) as dev: populate_image(image_path, dev) disk_identifier = get_disk_identifier(dev) @@ -718,15 +722,13 @@ def deploy_disk_image(address, port, iqn, lun, @contextlib.contextmanager -def _iscsi_setup_and_handle_errors(address, port, iqn, lun, - image_path): +def _iscsi_setup_and_handle_errors(address, port, iqn, lun): """Function that yields an iSCSI target device to work on. :param address: The iSCSI IP address. :param port: The iSCSI port number. :param iqn: The iSCSI qualified name. :param lun: The iSCSI logical unit number. - :param image_path: Path for the instance's disk image. """ dev = get_dev(address, port, iqn, lun) discovery(address, port) diff --git a/ironic/drivers/modules/iscsi_deploy.py b/ironic/drivers/modules/iscsi_deploy.py index 04c2fda2f..aa00ab5a8 100644 --- a/ironic/drivers/modules/iscsi_deploy.py +++ b/ironic/drivers/modules/iscsi_deploy.py @@ -180,8 +180,8 @@ def check_image_size(task): image_mb = deploy_utils.get_image_mb(image_path) root_mb = 1024 * int(i_info['root_gb']) if image_mb > root_mb: - msg = (_('Root partition is too small for requested image. ' - 'Image size: %(image_mb)d MB, Root size: %(root_mb)d MB') + msg = (_('Root partition is too small for requested image. Image ' + 'virtual size: %(image_mb)d MB, Root size: %(root_mb)d MB') % {'image_mb': image_mb, 'root_mb': root_mb}) raise exception.InstanceDeployFailure(msg) |