Ensure osd conf intact after migrating to 22.12

This change is to ensure the disk uuid is preserved during
data migration. The disk uuid is used in storage configuration
that links to osd.

TCs:
    1. complete upgrade from 22.06 Centos to 22.12 Debian on AIO-DX
       with ceph configuration. No ceph osd failure.
    2. complete upgrade from 22.06 Centos to 22.12 Debian on AIO-SX
       with ceph configuration. No ceph osd failure.
Story: 2009303
Task: 46300

Signed-off-by: Bin Qian <bin.qian@windriver.com>
Change-Id: Ief1e5cd9588aca8148106f2d95b7e60989f6bb8b
This commit is contained in:
Bin Qian 2022-09-15 14:36:48 +00:00
parent 9bb3d419ac
commit 53600f8b90
1 changed files with 27 additions and 4 deletions

View File

@ -45,6 +45,7 @@ def main():
return 1
arg += 1
log.configure()
LOG.info("%s invoked from_release = %s to_release = %s action = %s"
% (sys.argv[0], from_release, to_release, action))
res = 0
@ -83,7 +84,20 @@ IPV_COLUMNS = 'created_at', 'updated_at', 'deleted_at', 'uuid', 'pv_state', \
'forilvgid', 'disk_or_part_device_path'
def get_idisks(forihostid):
def get_disk_uuid_mapping(conn, forihostid):
# return map of idisk uuid indexed by device_node
with conn.cursor(cursor_factory=DictCursor) as cur:
sql = "SELECT uuid, device_node FROM i_idisk WHERE forihostid = %s;"
cur.execute(sql, (forihostid, ))
vals = cur.fetchall()
mappings = {}
for val in vals:
pair = {val["device_node"]: val["uuid"]}
mappings.update(pair)
return mappings
def get_idisks(forihostid, uuid_mapping):
do = Disk.DiskOperator()
disks = do.idisk_get()
idisks = []
@ -100,8 +114,16 @@ def get_idisks(forihostid):
}
for disk in disks:
# regenerate uuid
disk_additions["uuid"] = "%s" % uuid.uuid4()
# find uuid
device_node = disk["device_node"]
if device_node in uuid_mapping:
disk_additions["uuid"] = uuid_mapping[device_node]
else:
# this is not good, but it could be a new disk
LOG.warn("Found disk %s that is not inventoried" % device_node)
new_uuid = "%s" % uuid.uuid4()
disk_additions["uuid"] = new_uuid
LOG.info("Assign uuid %s to %s" % (new_uuid, device_node))
disk.update(disk_additions)
idisk = []
@ -539,7 +561,8 @@ def do_update():
conn = psycopg2.connect("dbname=sysinv user=postgres")
try:
hostid = get_ihostid(conn)
idisks = get_idisks(hostid)
disk_uuid_mapping = get_disk_uuid_mapping(conn, hostid)
idisks = get_idisks(hostid, disk_uuid_mapping)
disks = update_disks(conn, idisks)
partitions = get_ipartitions(hostid, disks)