Precheck to avoid overwriting installed systems during prestaging

When booting the system with the prestaging ISO, check for the
presence of a valid installation.

Avoid overwriting an existing installation with a message to the
user.

Test Plan:

PASS: Verify that an existing installation is not overwritten by
      the prestaging operation

PASS: Verify failure handling of the prestaging operation with
      a message to the user, when an installation already exists
      on the subcloud.

PASS: Verify successful prestaging operation when there is no
      existing installation on the subcloud.

Story: 2009948
Task: 44872

Change-Id: I47e4f67f001da208f4e823ac699473c89b638ce5
Signed-off-by: Shrikumar Sharma <shrikumar.sharma@windriver.com>
This commit is contained in:
Shrikumar Sharma 2022-03-28 16:16:14 -04:00
parent 710452d2e5
commit 60dc6586d7
2 changed files with 67 additions and 0 deletions

View File

@ -87,6 +87,7 @@ write_config_file("controller-worker-lowlatency",
# #
write_config_file("controller", write_config_file("controller",
"${output_dir}/prestaged_installer_ks.cfg", "${output_dir}/prestaged_installer_ks.cfg",
"pre_prestaging_install_check.cfg",
"pre_common_head.cfg", "pre_common_head.cfg",
"pre_pkglist_prestage.cfg", "pre_pkglist_prestage.cfg",
"pre_disk_setup_common.cfg", "pre_disk_setup_common.cfg",

View File

@ -0,0 +1,66 @@
%pre --erroronfail
# Get the FD used by subshells to log output
exec {stdout}>&1
# Source common functions
. /tmp/ks-functions.sh
wlog "pre prestaging install check"
# First, parse /proc/cmdline to find the boot args
set -- `cat /proc/cmdline`
for I in $*; do case "$I" in *=*) eval $I 2>/dev/null;; esac; done
if [ -z "$rootfs_device" ]; then
rootfs_device=$(get_disk_dev)
fi
orig_rootfs_device=$rootfs_device
by_path_rootfs_device=$(get_by_path $rootfs_device)
rootfs_device=$(get_disk $by_path_rootfs_device)
wlog "Found rootfs $orig_rootfs_device on: $by_path_rootfs_device->$rootfs_device."
part_numbers=( $(parted -s ${rootfs_device} print | awk '$1 == "Number" {i=1; next}; i {print $1}') )
# print the partnumber info for informational purposes
for i in ${part_numbers[@]}; do
wlog "partnumber: ${i}"
done
# Get the correct rootfs prefix
ROOTFS_PART_PREFIX=${rootfs_device}
# check if rootfs part is nvme (eg. /dev/nvme0n1). The partitions have a "p" in the part prefix.
# for example, /dev/nvme0n1p1
# so we need to add the letter "p" to get the prefix.
# The part numbers will be used later in the code.
case $rootfs_device in
*"nvme"*)
ROOTFS_PART_PREFIX=${ROOTFS_PART_PREFIX}p
;;
esac
# temporary mount directory
temp_mount=/mnt
wlog "Searching for existing installation..."
for part in "${part_numbers[@]}"; do
device=${ROOTFS_PART_PREFIX}${part}
wlog "Searching on ${device}"
# mount this part at a temporary mount point
mount ${device} ${temp_mount}
if [ $? -ne 0 ]; then
wlog "unable to mount ${device}"
continue
fi
# Check for the presence of install_uuid in one of the partitions on
# the root device
if [ -e ${temp_mount}/var/www/pages/feed/rel-xxxPLATFORM_RELEASExxx/install_uuid ]; then
wlog "Found valid installation on ${device}"
umount ${temp_mount}
# do not modify the system in any way
report_pre_failure_with_msg "Prestage rejected. Existing installation detected. Please eject the media before rebooting."
fi
wlog "Unmounting ${device}"
umount ${temp_mount}
done
%end