Allow partition ops on newly added host during upgrade

Allow partition create, update, delete operations for a new host added
after upgrade-start. Operations for existing hosts retain restriction on
partition operations.

This is enabled in order to allow for replacement of controller after
controller-1 has been upgraded.

Change-Id: I00a64bc18a979f473916a24dfa8f10310708e9ab
Story: 2002886
Task: 22847
Signed-off-by: Jack Ding <jack.ding@windriver.com>
This commit is contained in:
John Kung 2018-04-18 15:15:40 -04:00 committed by Jack Ding
parent 10e047e261
commit a0171c678c
2 changed files with 31 additions and 16 deletions

View File

@ -263,6 +263,7 @@ class PartitionController(rest.RestController):
# replace ihost_uuid and partition_uuid with corresponding
patch_obj = jsonpatch.JsonPatch(patch)
ihost = None
for p in patch_obj:
if p['path'] == '/ihost_uuid':
p['path'] = '/forihostid'
@ -271,7 +272,10 @@ class PartitionController(rest.RestController):
p['value'] = ihost.id
# Perform checks based on the current vs.requested modifications.
_partition_pre_patch_checks(rpc_partition, patch_obj)
if not ihost:
ihost = pecan.request.dbapi.ihost_get(rpc_partition.forihostid)
LOG.info("from partition get ihost=%s" % ihost.hostname)
_partition_pre_patch_checks(rpc_partition, patch_obj, ihost)
try:
partition = Partition(**jsonpatch.apply_patch(
@ -350,10 +354,10 @@ def _check_host(partition, ihost, idisk):
(idisk.uuid,ihost.hostname))
def _partition_pre_patch_checks(partition_obj, patch_obj):
def _partition_pre_patch_checks(partition_obj, patch_obj, host_obj):
"""Check current vs. updated parameters."""
# Reject operation if we are upgrading the system.
cutils._check_upgrade(pecan.request.dbapi)
cutils._check_upgrade(pecan.request.dbapi, host_obj)
for p in patch_obj:
if p['path'] == '/size_mib':
if not cutils.is_int_like(p['value']):
@ -610,11 +614,10 @@ def _semantic_checks(operation, partition):
def _create(partition, iprofile=None, applyprofile=None):
# Reject operation if we are upgrading the system.
cutils._check_upgrade(pecan.request.dbapi)
# Get host.
ihostid = partition.get('forihostid') or partition.get('ihost_uuid')
ihost = pecan.request.dbapi.ihost_get(ihostid)
cutils._check_upgrade(pecan.request.dbapi, ihost)
if uuidutils.is_uuid_like(ihostid):
forihostid = ihost['id']
else:
@ -673,12 +676,10 @@ def _create(partition, iprofile=None, applyprofile=None):
def _delete(partition):
# Reject operation if we are upgrading the system.
cutils._check_upgrade(pecan.request.dbapi)
# Get host.
# Reject operation if we are upgrading the system unless it is a new host.
ihostid = partition.get('forihostid') or partition.get('ihost_uuid')
ihost = pecan.request.dbapi.ihost_get(ihostid)
cutils._check_upgrade(pecan.request.dbapi, ihost)
# Semantic Checks.
_semantic_checks(constants.PARTITION_CMD_DELETE, partition)

View File

@ -1561,12 +1561,26 @@ def perform_distributed_cloud_config(dbapi, mgmt_iface_id):
cc_gtwy_addr.address, mgmt_iface_id))
def _check_upgrade(dbapi):
"""If there's an upgrade in place, reject the operation."""
if dbapi.software_upgrade_get_list():
raise wsme.exc.ClientSideError(
_("ERROR: Disk partition operations are not allowed during a "
"software upgrade. Try again after the upgrade is completed."))
def _check_upgrade(dbapi, host_obj=None):
""" Check whether partition operation may be allowed.
If there is an upgrade in place, reject the operation if the
host was not created after upgrade start.
"""
try:
upgrade = dbapi.software_upgrade_get_one()
except exception.NotFound:
return
if host_obj:
if host_obj.created_at > upgrade.created_at:
LOG.info("New host %s created after upgrade, allow partition" %
host_obj.hostname)
return
raise wsme.exc.ClientSideError(
_("ERROR: Disk partition operations are not allowed during a "
"software upgrade. Try again after the upgrade is completed."))
def disk_wipe(device):