Files
update/software/upgrade-scripts/13-update-host-address.py
Luis Eduardo Bonatti 9520ba3f8b Revert "Make configure_logging more robust."
This reverts commit fedd7d1995.

Reason for revert: Activate rollback is broken with this change. Reverting to cover the rollback scenario as well.

Change-Id: I10163cf3e2c4a532d351cb952c7dbd4484661816
Signed-off-by: Luis Eduardo Bonatti <LuizEduardo.Bonatti@windriver.com>
2025-08-20 13:38:14 +00:00

92 lines
2.4 KiB
Python
Executable File

#!/usr/bin/python
# Copyright (c) 2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
import logging
import psycopg2
import sys
from software.utilities.utils import configure_logging
DEFAULT_POSTGRES_PORT = 5432
LOG_FILE = "/var/log/software.log"
DB_NAME = "sysinv"
DB_USER = "postgres"
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:
# optional port parameter for USM upgrade
postgres_port = sys.argv[arg]
pass
else:
print("Invalid option %s." % sys.argv[arg])
return 1
arg += 1
configure_logging()
res = 0
LOG.info("%s invoked from_release = %s to_release = %s action = %s"
% (sys.argv[0], from_release, to_release, action))
if action == "migrate" and from_release == "24.09":
LOG.info("Updating addresses table entries.")
try:
update_address_name_from_db(postgres_port)
except Exception as ex:
LOG.exception("Error: {}".format(ex))
print(ex)
res = 1
return res
def update_address_name_from_db(postgres_port):
query = """
UPDATE addresses
SET name = REGEXP_REPLACE(
name, '^system-controller-gateway-ip-', 'controller-gateway-')
WHERE name LIKE 'system-controller-gateway-ip-%';
"""
try:
with psycopg2.connect(
dbname=DB_NAME,
user=DB_USER,
port=postgres_port
) as conn:
with conn.cursor() as cursor:
cursor.execute(query)
rows_updated = cursor.rowcount
conn.commit()
if rows_updated:
LOG.info(
"Updated %d entries in addresses table.", rows_updated)
else:
LOG.info("No entries updated in addresses table.")
except Exception as e:
LOG.error(f"Failed to update IP addresses in the "
f"database: {e}")
raise
if __name__ == "__main__":
sys.exit(main())