Update migration scripts to support optional "port" parameter
Migration scripts with "migrate" action needs to be run under environment that from-release PostgreSQL using default port and to-release running with a different port in USM upgrade. This commit is to add the 4th parameter to indicate the port to postgres connection. Test Plan: PASS: Run legacy data-migration PASS: Run new data-migration Story: 2010676 Task: 48886 Change-Id: Ib7b5818b9355c1196fb8b6fc3d916ede7f7907fa Signed-off-by: Luis Eduardo Bonatti <LuizEduardo.Bonatti@windriver.com>
This commit is contained in:
parent
05e592cfaa
commit
152b8f5f44
|
@ -19,3 +19,5 @@ KEYRING_PERMDIR = tsconfig.KEYRING_PATH
|
||||||
|
|
||||||
INITIAL_CONFIG_COMPLETE_FILE = '/etc/platform/.initial_config_complete'
|
INITIAL_CONFIG_COMPLETE_FILE = '/etc/platform/.initial_config_complete'
|
||||||
LOG_LOCAL1 = 'local1'
|
LOG_LOCAL1 = 'local1'
|
||||||
|
|
||||||
|
POSTGRESQL_DEFAULT_PORT = 5432
|
||||||
|
|
|
@ -80,6 +80,16 @@ def wait_sm_service(service, timeout=180):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def connect_to_postgresql(port):
|
||||||
|
try:
|
||||||
|
import psycopg2
|
||||||
|
conn = psycopg2.connect("dbname=sysinv user=postgres port=%s" % port)
|
||||||
|
return conn
|
||||||
|
except Exception as err:
|
||||||
|
LOG.error("Failed to connect to database: %s", err)
|
||||||
|
raise Exception("Failed to connect to database with port=%s" % port)
|
||||||
|
|
||||||
|
|
||||||
def get_address_from_hosts_file(hostname):
|
def get_address_from_hosts_file(hostname):
|
||||||
"""
|
"""
|
||||||
Get the IP address of a host from the /etc/hosts file
|
Get the IP address of a host from the /etc/hosts file
|
||||||
|
@ -190,7 +200,7 @@ def persist_config():
|
||||||
# move hiera data to puppet directory
|
# move hiera data to puppet directory
|
||||||
if os.path.isdir(constants.HIERADATA_WORKDIR):
|
if os.path.isdir(constants.HIERADATA_WORKDIR):
|
||||||
subprocess.check_call(["mv", constants.HIERADATA_WORKDIR,
|
subprocess.check_call(["mv", constants.HIERADATA_WORKDIR,
|
||||||
tsconfig.PUPPET_PATH])
|
tsconfig.PUPPET_PATH])
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
LOG.error("Failed to persist puppet config files")
|
LOG.error("Failed to persist puppet config files")
|
||||||
raise Exception("Failed to persist puppet config files")
|
raise Exception("Failed to persist puppet config files")
|
||||||
|
|
|
@ -25,6 +25,9 @@ def main():
|
||||||
to_release = sys.argv[arg]
|
to_release = sys.argv[arg]
|
||||||
elif arg == 3:
|
elif arg == 3:
|
||||||
action = sys.argv[arg]
|
action = sys.argv[arg]
|
||||||
|
elif arg == 4:
|
||||||
|
# postgres_port = sys.argv[arg]
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
print("Invalid option %s." % sys.argv[arg])
|
print("Invalid option %s." % sys.argv[arg])
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -22,7 +22,7 @@ FROM_RELEASE=$1
|
||||||
TO_RELEASE=$2
|
TO_RELEASE=$2
|
||||||
ACTION=$3
|
ACTION=$3
|
||||||
|
|
||||||
if (( $# != 3 )); then
|
if (( $# != 3 && $# != 4 )); then
|
||||||
>&2 echo "Error: Missing Arguments!"
|
>&2 echo "Error: Missing Arguments!"
|
||||||
>&2 echo "Usage: 65-k8s-app-upgrade.sh FROM_RELEASE TO_RELEASE ACTION"
|
>&2 echo "Usage: 65-k8s-app-upgrade.sh FROM_RELEASE TO_RELEASE ACTION"
|
||||||
>&2 echo "Exiting for manual intervention..."
|
>&2 echo "Exiting for manual intervention..."
|
||||||
|
|
|
@ -27,6 +27,9 @@ def main():
|
||||||
to_release = sys.argv[arg]
|
to_release = sys.argv[arg]
|
||||||
elif arg == 3:
|
elif arg == 3:
|
||||||
action = sys.argv[arg]
|
action = sys.argv[arg]
|
||||||
|
elif arg == 4:
|
||||||
|
# postgres_port = sys.argv[arg]
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
print("Invalid option %s." % sys.argv[arg])
|
print("Invalid option %s." % sys.argv[arg])
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -371,13 +371,13 @@ def drop_helm_v2_database():
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
if len(sys.argv) != 4:
|
if len(sys.argv) not in [4, 5]:
|
||||||
error_msg = "Invalid arguments: %s" % (sys.argv)
|
error_msg = "Invalid arguments: %s" % (sys.argv)
|
||||||
print(error_msg)
|
print(error_msg)
|
||||||
LOG.error(error_msg)
|
LOG.error(error_msg)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
script_name, from_release, to_release, action = sys.argv
|
script_name, from_release, to_release, action = sys.argv[0:4]
|
||||||
LOG.info("%s invoked with from_release = %s to_release = %s action = %s"
|
LOG.info("%s invoked with from_release = %s to_release = %s action = %s"
|
||||||
% (script_name, from_release, to_release, action))
|
% (script_name, from_release, to_release, action))
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,9 @@ def main():
|
||||||
to_release = sys.argv[arg]
|
to_release = sys.argv[arg]
|
||||||
elif arg == 3:
|
elif arg == 3:
|
||||||
action = sys.argv[arg]
|
action = sys.argv[arg]
|
||||||
|
elif arg == 4:
|
||||||
|
# postgres_port = sys.argv[arg]
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
print("Invalid option %s." % sys.argv[arg])
|
print("Invalid option %s." % sys.argv[arg])
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -8,10 +8,11 @@
|
||||||
# requests in N+1 release and not due to potential stale configuration
|
# requests in N+1 release and not due to potential stale configuration
|
||||||
# from N release.
|
# from N release.
|
||||||
|
|
||||||
import psycopg2
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from psycopg2.extras import RealDictCursor
|
from psycopg2.extras import RealDictCursor
|
||||||
|
from controllerconfig import utils
|
||||||
|
from controllerconfig.common import constants
|
||||||
from controllerconfig.common import log
|
from controllerconfig.common import log
|
||||||
|
|
||||||
LOG = log.get_logger(__name__)
|
LOG = log.get_logger(__name__)
|
||||||
|
@ -21,6 +22,7 @@ def main():
|
||||||
action = None
|
action = None
|
||||||
from_release = None
|
from_release = None
|
||||||
to_release = None
|
to_release = None
|
||||||
|
postgres_port = constants.POSTGRESQL_DEFAULT_PORT
|
||||||
arg = 1
|
arg = 1
|
||||||
|
|
||||||
while arg < len(sys.argv):
|
while arg < len(sys.argv):
|
||||||
|
@ -30,6 +32,8 @@ def main():
|
||||||
to_release = sys.argv[arg] # noqa
|
to_release = sys.argv[arg] # noqa
|
||||||
elif arg == 3:
|
elif arg == 3:
|
||||||
action = sys.argv[arg]
|
action = sys.argv[arg]
|
||||||
|
elif arg == 4:
|
||||||
|
postgres_port = sys.argv[arg]
|
||||||
else:
|
else:
|
||||||
print("Invalid option %s." % sys.argv[arg])
|
print("Invalid option %s." % sys.argv[arg])
|
||||||
return 1
|
return 1
|
||||||
|
@ -43,15 +47,15 @@ def main():
|
||||||
# This host table data migration will likely be required for each release
|
# This host table data migration will likely be required for each release
|
||||||
if action == "migrate":
|
if action == "migrate":
|
||||||
try:
|
try:
|
||||||
reset_config_target()
|
reset_config_target(postgres_port)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.exception(ex)
|
LOG.exception(ex)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def reset_config_target():
|
def reset_config_target(port):
|
||||||
|
|
||||||
conn = psycopg2.connect("dbname=sysinv user=postgres")
|
conn = utils.connect_to_postgresql(port)
|
||||||
with conn:
|
with conn:
|
||||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||||
cur.execute("update i_host set config_target=NULL",)
|
cur.execute("update i_host set config_target=NULL",)
|
||||||
|
|
|
@ -76,9 +76,11 @@ def main():
|
||||||
parser.add_argument("from_release", type=str)
|
parser.add_argument("from_release", type=str)
|
||||||
parser.add_argument("to_release", type=str)
|
parser.add_argument("to_release", type=str)
|
||||||
parser.add_argument("action", type=str)
|
parser.add_argument("action", type=str)
|
||||||
|
if len(sys.argv) == 5:
|
||||||
|
parser.add_argument("postgres_port", type=int)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if len(sys.argv) != 4:
|
if len(sys.argv) not in [4, 5]:
|
||||||
print("Invalid option {}".format(sys.arg))
|
print("Invalid option {}".format(sys.arg))
|
||||||
return 1
|
return 1
|
||||||
if args.action == "activate":
|
if args.action == "activate":
|
||||||
|
|
Loading…
Reference in New Issue