Update migration to access to-release database

This change applies alter port for to release postgresql database access
to data migration scripts.

TCs:
    passed: Successful data migration from stx-8 to stx-10 deployment.

Story: 2010676
Task: 50306

Change-Id: I2472f5f27e48d7bc9a1c0509078263fba7b5f8ab
Signed-off-by: Bin Qian <bin.qian@windriver.com>
This commit is contained in:
Bin Qian 2024-06-10 17:22:00 +00:00 committed by Bin Qian
parent 90fd94380f
commit 05ec4da8b3
4 changed files with 29 additions and 15 deletions

View File

@ -10,10 +10,14 @@ import sys
from oslo_utils import uuidutils
DEFAULT_POSTGRES_PORT = 5432
def main():
action = None
from_release = None
to_release = None # noqa
postgres_port = DEFAULT_POSTGRES_PORT
arg = 1
while arg < len(sys.argv):
if arg == 1:
@ -24,7 +28,7 @@ def main():
action = sys.argv[arg]
elif arg == 4:
# optional port parameter for USM upgrade
# port = sys.argv[arg]
postgres_port = sys.argv[arg]
pass
else:
print("Invalid option %s." % sys.argv[arg])
@ -40,16 +44,16 @@ def main():
try:
LOG.info("network-addrpool table migration from release %s to %s"
" with action: %s" % (from_release, to_release, action))
do_network_addrpool_migration_work()
do_network_addrpool_migration_work(postgres_port)
except Exception as ex:
LOG.exception(ex)
print(ex)
return 1
def do_network_addrpool_migration_work():
def do_network_addrpool_migration_work(port):
conn = psycopg2.connect("dbname='sysinv' user='postgres'")
conn = psycopg2.connect("dbname='sysinv' user='postgres' port=%s" % port)
with conn:
net_dict = get_networks(conn)

View File

@ -18,11 +18,14 @@ import psycopg2
from sysinv.common import constants
DEFAULT_POSTGRES_PORT = 5432
def main():
action = None
from_release = None
to_release = None # noqa
postgres_port = DEFAULT_POSTGRES_PORT
arg = 1
while arg < len(sys.argv):
if arg == 1:
@ -33,7 +36,7 @@ def main():
action = sys.argv[arg]
elif arg == 4:
# optional port parameter for USM upgrade
# port = sys.argv[arg]
postgres_port = sys.argv[arg]
pass
else:
print(f"Invalid option {sys.argv[arg]}.")
@ -51,19 +54,19 @@ def main():
"sysinv i_host table,"
f"from the release {from_release} to {to_release} with "
f"action: {action}")
update_mgmt_ipsec(constants.MGMT_IPSEC_UPGRADING)
update_mgmt_ipsec(constants.MGMT_IPSEC_UPGRADING, postgres_port)
except Exception as ex:
LOG.exception(ex)
print(ex)
return 1
def update_mgmt_ipsec(value):
def update_mgmt_ipsec(value, port):
"""This function update mgmt_ipsec in in capabilities of sysinv
i_host table to the value.
"""
conn = psycopg2.connect("dbname='sysinv' user='postgres'")
conn = psycopg2.connect("dbname='sysinv' user='postgres' port=%s" % port)
with conn:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute("select uuid, capabilities from i_host;")

View File

@ -17,10 +17,14 @@ import psycopg2
from sysinv.common import constants
DEFAULT_POSTGRES_PORT = 5432
def main():
action = None
from_release = None
to_release = None # noqa
postgres_port = DEFAULT_POSTGRES_PORT
arg = 1
while arg < len(sys.argv):
if arg == 1:
@ -31,7 +35,7 @@ def main():
action = sys.argv[arg]
elif arg == 4:
# optional port parameter for USM upgrade
# port = sys.argv[arg]
postgres_port = sys.argv[arg]
pass
else:
print(f"Invalid option {sys.argv[arg]}.")
@ -49,19 +53,19 @@ def main():
"cstates_available information from capabilities column, "
f"from the release {from_release} to {to_release} with "
f"action: {action}")
remove_cstates_and_frequency_info()
remove_cstates_and_frequency_info(postgres_port)
except Exception as ex:
LOG.exception(ex)
print(ex)
return 1
def remove_cstates_and_frequency_info():
def remove_cstates_and_frequency_info(port):
"""This function removes the information of cstates, min and max frequency
from the capabilities column.
"""
conn = psycopg2.connect("dbname='sysinv' user='postgres'")
conn = psycopg2.connect("dbname='sysinv' user='postgres' port=%s" % port)
with conn:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute("select uuid, capabilities from i_host;")

View File

@ -17,6 +17,8 @@ from dcmanager.common import consts as dcmanager_consts
import psycopg2
DEFAULT_POSTGRES_PORT = 5432
DEPLOY_STATUS_MAP = {
dcmanager_consts.DEPLOY_STATE_DEPLOY_PREP_FAILED:
dcmanager_consts.DEPLOY_STATE_PRE_CONFIG_FAILED,
@ -29,6 +31,7 @@ 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:
@ -38,8 +41,7 @@ def main():
elif arg == 3:
action = sys.argv[arg]
elif arg == 4:
# postgres_port = sys.argv[arg]
pass
postgres_port = sys.argv[arg]
else:
print("Invalid option %s." % sys.argv[arg])
return 1
@ -55,7 +57,8 @@ def main():
res = 0
if action == 'migrate' and from_release == '22.12':
try:
conn = psycopg2.connect("dbname=dcmanager user=postgres")
conn = psycopg2.connect("dbname=dcmanager user=postgres port=%s" %
postgres_port)
do_update_deploy_status(conn)
except psycopg2.OperationalError:
# Since neither tsconfig or /etc/platform/platform.conf have