Merge "Fix storage related consistency checks"

This commit is contained in:
Zuul 2019-07-17 00:22:17 +00:00 committed by Gerrit Code Review
commit 38f7697bdc
3 changed files with 41 additions and 0 deletions

View File

@ -354,6 +354,22 @@ def _check_host(partition, ihost, idisk):
(idisk.uuid, ihost.hostname))
def _check_disk(idisk):
"""Semantic check for valid disk"""
# Check if the disk is not already assigned for storage function"
if idisk.istor_uuid:
raise wsme.exc.ClientSideError(_(
"Cannot create partition on a disk that is assigned as "
"a storage volume."))
# Check if the disk is not assigned as a physical volume to a
# volume group.
if idisk.ipv_uuid:
raise wsme.exc.ClientSideError(_(
"Cannot create partition on a disk that is already "
"assigned as a physical volume to a volume group."))
def _partition_pre_patch_checks(partition_obj, patch_obj, host_obj):
"""Check current vs. updated parameters."""
# Reject operation if we are upgrading the system.
@ -479,6 +495,9 @@ def _semantic_checks(operation, partition):
# being changed for an existing host/disk pairing. If so => reject request.
_check_for_outstanding_requests(partition, idisk)
# Make sure the disk on which we create the partition is valid.
_check_disk(idisk)
# Semantic checks based on operation.
if operation == constants.PARTITION_CMD_CREATE:
############

View File

@ -683,6 +683,15 @@ def _check_device(new_pv, ihost):
raise wsme.exc.ClientSideError(_("Disk already assigned to a "
"storage volume."))
# semantic check: Make sure that partitions do not exist on the
# disk
partitions = pecan.request.dbapi.partition_get_by_idisk(
new_pv['disk_or_part_uuid'])
if partitions:
raise wsme.exc.ClientSideError(_(
"Cannot assign disk to a physical volume because disk "
"contains other partitions."))
# semantic check: whether idisk_uuid belongs to another host
if new_pv_device.forihostid != new_pv['forihostid']:
raise wsme.exc.ClientSideError(_("Disk is attached to a different "

View File

@ -615,6 +615,19 @@ def _check_disk(stor):
raise wsme.exc.ClientSideError(_(
"Can not associate to a rootfs disk"))
# semantic check: whether disk has any partitions created
partitions = pecan.request.dbapi.partition_get_by_idisk(idisk_uuid)
if partitions:
raise wsme.exc.ClientSideError(_(
"Cannot assign storage function to a disk that contains "
"other partitions."))
# semantic check: whether disk is already associated to a PV
if idisk.ipv_uuid:
raise wsme.exc.ClientSideError(_(
"Cannot assign storage function to a disk already assigned "
"as a physical volume to a volume group."))
return idisk_uuid