Verify platform-backup partition before SX upgrade

There are scenarios were the backup partition could be incorrectly
formatted. This can result in the partition being wiped during an
upgrade. As part of the upgrade health check we'll verify all the
parameters of the backup partition.

Change-Id: I28d8a39c2edfb34a7298dc30aaba5a6bdf7b0382
Signed-off-by: David Sullivan <david.sullivan@windriver.com>
Closes-Bug: 1888424
This commit is contained in:
David Sullivan 2020-07-22 20:26:23 -04:00
parent 63d97f96da
commit e33a803574
3 changed files with 72 additions and 1 deletions

View File

@ -113,13 +113,14 @@ install -m 644 -p -D scripts/sysinv-conductor.service %{buildroot}%{_unitdir}/sy
install -d -m 755 %{buildroot}%{local_bindir}
install -p -D -m 755 scripts/partition_info.sh %{buildroot}%{local_bindir}/partition_info.sh
install -p -D -m 755 scripts/validate-platform-backup.sh %{buildroot}%{local_bindir}/validate-platform-backup.sh
install -p -D -m 755 scripts/manage-partitions %{buildroot}%{local_bindir}/manage-partitions
install -p -D -m 755 scripts/query_pci_id %{buildroot}%{local_bindir}/query_pci_id
install -p -D -m 700 scripts/kube-cert-rotation.sh %{buildroot}%{local_bindir}/kube-cert-rotation.sh
%clean
echo "CLEAN CALLED"
rm -rf $RPM_BUILD_ROOT
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)

View File

@ -0,0 +1,52 @@
#!/bin/bash
#
# Copyright (c) 2020 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
NAME=$(basename $0)
rootfs_part=$(findmnt -n -o SOURCE /)
device_path=$(lsblk -pno pkname $rootfs_part)
BACKUP_PART_GUID="BA5EBA11-0000-1111-2222-000000000002"
PLATFORM_BACKUP_SIZE=10000
part_type_guid_str="Partition GUID code"
part_first_sector_str="First sector"
part_last_sector_str="Last sector"
# This will log to /var/log/platform.log
function log {
echo $1
logger -p local1.info -t $NAME $1
}
log "Checking for valid platform-backup partition on device $device_path"
part_numbers=($(parted -s $device_path print | awk '$1 == "Number" {i=1; next}; i {print $1}'))
sector_size=$(blockdev --getss $device_path)
for part_number in "${part_numbers[@]}"; do
if [[ $device_path == *"nvme"* ]]; then
part=${device_path}p${part_number}
else
part=$device_path$part_number
fi
sgdisk_part_info=$(sgdisk -i $part_number $device_path)
part_type_guid=$(echo "$sgdisk_part_info" | grep "$part_type_guid_str" | awk '{print $4;}')
part_fstype=$(blkid -s TYPE -o value $part)
log "Checking $part fs_type: $part_fstype sgdisk_info: $sgdisk_part_info"
if [ "$part_type_guid" == $BACKUP_PART_GUID -a "${part_fstype}" == "ext4" ]; then
part_start_mib=$(($(echo "$sgdisk_part_info" | grep "$part_first_sector_str" | awk '{print $3;}') * $sector_size / (1024*1024)))
part_end_mib=$((($(echo "$sgdisk_part_info" | grep "$part_last_sector_str" | awk '{print $3;}') * $sector_size / (1024*1024)) + 1))
part_size_mib=$((part_end_mib-part_start_mib))
log "Found platform-backup partition with size: $part_size_mib"
if [ $part_size_mib -eq $PLATFORM_BACKUP_SIZE ]; then
log "Success"
exit 0
fi
break
fi
done
log "Valid platform-backup partition not found"
exit 1

View File

@ -233,6 +233,18 @@ class Health(object):
success = not fail_app_list
return success, fail_app_list
def _check_platform_backup_partition(self):
"""Check that the platform-backup partition is the correct size/type"""
args = ['/usr/bin/validate-platform-backup.sh']
try:
subprocess.check_output(args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exc:
LOG.error("Call to %s returned %s and %s" % (args, exc.returncode, exc.output))
return False
return True
def get_system_health(self, context, force=False):
"""Returns the general health of the system
@ -391,6 +403,12 @@ class Health(object):
% (running_instances)
health_ok = health_ok and success
else:
success = self._check_platform_backup_partition()
output += _('Valid platform-backup partition: [%s]\n') \
% (Health.SUCCESS_MSG if success else Health.FAIL_MSG)
health_ok = health_ok and success
return health_ok, output