Merge "Update migration scripts to support optional "port" parameter"
This commit is contained in:
commit
c672513129
|
@ -19,3 +19,5 @@ KEYRING_PERMDIR = tsconfig.KEYRING_PATH
|
|||
|
||||
INITIAL_CONFIG_COMPLETE_FILE = '/etc/platform/.initial_config_complete'
|
||||
LOG_LOCAL1 = 'local1'
|
||||
|
||||
POSTGRESQL_DEFAULT_PORT = 5432
|
||||
|
|
|
@ -80,6 +80,16 @@ def wait_sm_service(service, timeout=180):
|
|||
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):
|
||||
"""
|
||||
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
|
||||
if os.path.isdir(constants.HIERADATA_WORKDIR):
|
||||
subprocess.check_call(["mv", constants.HIERADATA_WORKDIR,
|
||||
tsconfig.PUPPET_PATH])
|
||||
tsconfig.PUPPET_PATH])
|
||||
except subprocess.CalledProcessError:
|
||||
LOG.error("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]
|
||||
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
|
||||
|
|
|
@ -22,7 +22,7 @@ FROM_RELEASE=$1
|
|||
TO_RELEASE=$2
|
||||
ACTION=$3
|
||||
|
||||
if (( $# != 3 )); then
|
||||
if (( $# != 3 && $# != 4 )); then
|
||||
>&2 echo "Error: Missing Arguments!"
|
||||
>&2 echo "Usage: 65-k8s-app-upgrade.sh FROM_RELEASE TO_RELEASE ACTION"
|
||||
>&2 echo "Exiting for manual intervention..."
|
||||
|
|
|
@ -27,6 +27,9 @@ def main():
|
|||
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
|
||||
|
|
|
@ -371,13 +371,13 @@ def drop_helm_v2_database():
|
|||
|
||||
def main():
|
||||
|
||||
if len(sys.argv) != 4:
|
||||
if len(sys.argv) not in [4, 5]:
|
||||
error_msg = "Invalid arguments: %s" % (sys.argv)
|
||||
print(error_msg)
|
||||
LOG.error(error_msg)
|
||||
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"
|
||||
% (script_name, from_release, to_release, action))
|
||||
|
||||
|
|
|
@ -27,6 +27,9 @@ def main():
|
|||
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
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
# requests in N+1 release and not due to potential stale configuration
|
||||
# from N release.
|
||||
|
||||
import psycopg2
|
||||
import sys
|
||||
|
||||
from psycopg2.extras import RealDictCursor
|
||||
from controllerconfig import utils
|
||||
from controllerconfig.common import constants
|
||||
from controllerconfig.common import log
|
||||
|
||||
LOG = log.get_logger(__name__)
|
||||
|
@ -21,6 +22,7 @@ def main():
|
|||
action = None
|
||||
from_release = None
|
||||
to_release = None
|
||||
postgres_port = constants.POSTGRESQL_DEFAULT_PORT
|
||||
arg = 1
|
||||
|
||||
while arg < len(sys.argv):
|
||||
|
@ -30,6 +32,8 @@ def main():
|
|||
to_release = sys.argv[arg] # noqa
|
||||
elif arg == 3:
|
||||
action = sys.argv[arg]
|
||||
elif arg == 4:
|
||||
postgres_port = sys.argv[arg]
|
||||
else:
|
||||
print("Invalid option %s." % sys.argv[arg])
|
||||
return 1
|
||||
|
@ -43,15 +47,15 @@ def main():
|
|||
# This host table data migration will likely be required for each release
|
||||
if action == "migrate":
|
||||
try:
|
||||
reset_config_target()
|
||||
reset_config_target(postgres_port)
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
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.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
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("to_release", type=str)
|
||||
parser.add_argument("action", type=str)
|
||||
if len(sys.argv) == 5:
|
||||
parser.add_argument("postgres_port", type=int)
|
||||
args = parser.parse_args()
|
||||
|
||||
if len(sys.argv) != 4:
|
||||
if len(sys.argv) not in [4, 5]:
|
||||
print("Invalid option {}".format(sys.arg))
|
||||
return 1
|
||||
if args.action == "activate":
|
||||
|
|
Loading…
Reference in New Issue