Fix issue in partition data migration script

The created partition dictonary partition_map is not
an ordered dict so we need to sort it by its key -
device node when iterating it to adjust the device
nodes/paths for user created extra partitions to ensure
the number of device node/path for each extra partition
is calculated correctly, otherwise the adjustments
could be messy that causes the partition DB update to
fail.

Tested AIO-SX upgrade with three additional partitions.

Change-Id: I1cb3bbfaf144a59d29633c1784b0fde80529cd71
Closes-Bug: 1892554
Signed-off-by: Angie Wang <angie.wang@windriver.com>
This commit is contained in:
Angie Wang 2021-05-25 18:49:21 -04:00
parent c6f0967086
commit 23505ba77d
1 changed files with 9 additions and 2 deletions

View File

@ -375,7 +375,12 @@ def adjust_user_partitions():
increased_partition_number = \
installed_lvm_device['partition_number'] + 2
for device, partition in six.iteritems(partition_map):
# partition_map is not an ordered dictionary, we
# need to sort partition_map by its key(device node)
# to ensure the adjustments for user created partitions
# are correct
for device, partition in sorted(
six.iteritems(partition_map)):
# Adjust the device node/path of user created
# partitions. The start/end/size of the partitions
# will not be changed.
@ -401,7 +406,9 @@ def adjust_user_partitions():
update_db_pvs.append(pv)
# Reverse the updating order. The partitions that
# moving backwards need to updated first.
# moving backwards need to updated first because of
# the UniqueConstraint "u_partition_path_host_id"
# for partition table
update_db_partitions = update_db_partitions[::-1]
else:
# The primary LVM partition for cgts-vg in new release