Files
update/software/upgrade-scripts/06-remove_legacy_upgrade_tables.py
Luis Eduardo Bonatti e93d1686f5 Move upgrade scripts from config repo to update repo
Since upgrade is responsibility of USM the upgrade scripts need
to be moved to this repo. This commit adds the upgrade-scripts
from config, note that the upgrade-scripts will still be located
under /usr/local/share/upgrade.d folder.
There's also a change in upgrade-scripts to use the log function
from this repo instead of controllerconfig one.
Also fix a log error in deploy scripts.

Test Plan:
PASS: Build-pkgs && build-image.
PASS: Upgrade from 24.09 to 25.09 in sx.
PASS: Install/bootstrap 25.09 in sx.
PASS: Check if /usr/local/share/upgrade.d have the same scripts.
PASS: Check scripts are logging accordingly.

Story: 2011357
Task: 52196

Change-Id: Iab5e6d6f0348f996daf0adb2447d22c4216e537f
Signed-off-by: Luis Eduardo Bonatti <luizeduardo.bonatti@windriver.com>
2025-05-22 13:17:48 +00:00

91 lines
2.3 KiB
Python

#!/usr/bin/env python
# Copyright (c) 2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# This script will remove load, host_upgrade and software_upgrade
# database table
#
import logging
import sys
from packaging import version
import psycopg2
from software.utilities.utils import configure_logging
DEFAULT_POSTGRES_PORT = 5432
LOG = logging.getLogger('main_logger')
def main():
action = None
from_release = None
to_release = None
postgres_port = DEFAULT_POSTGRES_PORT
arg = 1
while arg < len(sys.argv):
if arg == 1:
from_release = sys.argv[arg]
elif arg == 2:
to_release = sys.argv[arg]
elif arg == 3:
action = sys.argv[arg]
elif arg == 4:
postgres_port = sys.argv[arg]
pass
else:
print("Invalid option %s." % sys.argv[arg])
return 1
arg += 1
configure_logging()
LOG.info(
"%s invoked from_release = %s to_release = %s action = %s"
% (sys.argv[0], from_release, to_release, action)
)
res = 0
to_release_version = version.Version(to_release)
minimum_version = version.Version("25.09")
if action == 'migrate' and to_release_version == minimum_version:
try:
conn = psycopg2.connect("dbname=sysinv user=postgres port=%s"
% postgres_port)
delete_software_upgrade_database(conn)
delete_host_upgrade_database(conn)
delete_load_database(conn)
conn.close()
except Exception as e:
LOG.exception("Error: {}".format(e))
res = 1
return res
def delete_load_database(conn):
delete_cmd = "drop table if exists loads;"
db_update(conn, delete_cmd)
LOG.info("Loads table removed with success")
def delete_host_upgrade_database(conn):
delete_cmd = "drop table if exists host_upgrade;"
db_update(conn, delete_cmd)
LOG.info("Host_upgrade table removed with success")
def delete_software_upgrade_database(conn):
delete_cmd = "drop table if exists software_upgrade;"
db_update(conn, delete_cmd)
LOG.info("Software_upgrade table removed with success")
def db_update(conn, query):
with conn.cursor() as cur:
cur.execute(query)
conn.commit()
if __name__ == "__main__":
sys.exit(main())