From 5cc352f1f5f84d8d6b3740a4cd29603fd5fdd62b Mon Sep 17 00:00:00 2001 From: "linda.nasredin" Date: Wed, 1 Nov 2023 13:39:15 +0200 Subject: [PATCH] EDSF-374 Verify that required=True in ArgumentParser works --- .../python_upgrader/upgrade/main.py | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/modules/aws/sonar-upgrader/python_upgrader/upgrade/main.py b/modules/aws/sonar-upgrader/python_upgrader/upgrade/main.py index 9e8f80d84..2fcb98d9d 100644 --- a/modules/aws/sonar-upgrader/python_upgrader/upgrade/main.py +++ b/modules/aws/sonar-upgrader/python_upgrader/upgrade/main.py @@ -271,8 +271,8 @@ def init_upgrade_status(extended_nodes, target_version): def parse_args(): parser = argparse.ArgumentParser(description="Upgrade script for DSF Hub and Agentless Gateway") - parser.add_argument("--agentless_gws", help="JSON-encoded Agentless Gateway list") - parser.add_argument("--dsf_hubs", help="JSON-encoded DSF Hub list") + parser.add_argument("--agentless_gws", required=True, help="JSON-encoded Agentless Gateway list") + parser.add_argument("--dsf_hubs", required=True, help="JSON-encoded DSF Hub list") parser.add_argument("--target_version", required=True, help="Target version to upgrade") parser.add_argument("--connection_timeout", help="Client connection timeout in seconds used for the SSH connections between the " @@ -282,12 +282,12 @@ def parse_args(): parser.add_argument("--test_connection", type=str_to_bool, help="Whether to test the SSH connection to all DSF nodes being upgraded " "before starting the upgrade") - parser.add_argument("--run_preflight_validations", required=True, type=str_to_bool, + parser.add_argument("--run_preflight_validations", type=str_to_bool, help="Whether to run preflight validations") - parser.add_argument("--run_upgrade", required=True, type=str_to_bool, help="Whether to run the upgrade") - parser.add_argument("--run_postflight_validations", required=True, type=str_to_bool, + parser.add_argument("--run_upgrade", type=str_to_bool, help="Whether to run the upgrade") + parser.add_argument("--run_postflight_validations", type=str_to_bool, help="Whether to run postflight validations") - parser.add_argument("--clean_old_deployments", type=str_to_bool, help="Whether to clean old deployments") + # parser.add_argument("--clean_old_deployments", type=str_to_bool, help="Whether to clean old deployments") parser.add_argument("--stop_on_failure", type=str_to_bool, help="Whether to stop or continue to upgrade the next DSF nodes in case of failure " "on a DSF node") @@ -297,6 +297,25 @@ def parse_args(): return args +def fill_args_defaults(): + if args.connection_timeout is None: + args.connection_timeout = 90 + if args.test_connection is None: + args.test_connection = True + if args.run_preflight_validations is None: + args.run_preflight_validations = True + if args.run_upgrade is None: + args.run_upgrade = True + if args.run_postflight_validations is None: + args.run_postflight_validations = True + if args.stop_on_failure is None: + args.stop_on_failure = True + if args.tarball_location is None: + args.tarball_location = '{"s3_bucket": "1ef8de27-ed95-40ff-8c08-7969fc1b7901", "s3_region": "us-east-1"}' + + args.clean_old_deployments = False + + def print_inputs(agentless_gws, hubs, tarball_location, args): print("List of Agentless Gateways:") print_hadr_sets(agentless_gws) @@ -907,6 +926,8 @@ def verify_successful_run_by_configuration_options(args, upgrade_status_service) run_dummy_upgrade = False args = parse_args() + fill_args_defaults() + CONNECTION_TIMEOUT = int(args.connection_timeout) main(args)