From 29d60a9ed5b6ebbe231996fe23f8ceae797ee045 Mon Sep 17 00:00:00 2001 From: LegenJCdary Date: Tue, 26 Apr 2022 03:33:47 -0400 Subject: [PATCH 1/3] Remove "list" subcommand --- source/main.py | 4 +--- source/modules/globalvars.py | 2 +- source/modules/misc.py | 10 ---------- source/modules/validators/validate.py | 2 -- tests/01-test_argument_parsing.sh | 8 +------- 5 files changed, 3 insertions(+), 23 deletions(-) diff --git a/source/main.py b/source/main.py index 761c829b..6f004228 100644 --- a/source/main.py +++ b/source/main.py @@ -125,9 +125,7 @@ def main(): logger.logger.info("Skipping execution because of --dry-run option") sys.exit(0) - if options["subcommand"] == "list": - misc.list_tasks(config, options) - elif options["subcommand"] == "show": + if options["subcommand"] == "show": misc.show_deployer(config, options) else: lockdir = os.path.join(conf["global_paths"]["work_dir"], "locks") diff --git a/source/modules/globalvars.py b/source/modules/globalvars.py index d79ef49c..d605e775 100644 --- a/source/modules/globalvars.py +++ b/source/modules/globalvars.py @@ -2,4 +2,4 @@ APP_CONF = "/etc/ansible-deployer" CFG_PERMISSIONS = "0o644" -SUBCOMMANDS = ("run", "list", "lock", "unlock", "verify", "show") +SUBCOMMANDS = ("run", "lock", "unlock", "verify", "show") diff --git a/source/modules/misc.py b/source/modules/misc.py index c4feec9d..4a7fc511 100644 --- a/source/modules/misc.py +++ b/source/modules/misc.py @@ -41,16 +41,6 @@ def create_workdir(timestamp: str, conf: dict, logger): logger.debug("Successfully created workdir: %s", seq_path) return seq_path -def list_tasks(config: dict, options: dict): - """ - Function listing tasks available to the user limited to given infra/stage/task - """ - task_list = [] - for item in config["tasks"]["tasks"]: - task_list.append(item["name"]) - - print(" ".join(task_list)) - # TODO: At least infra level should be returned from validate options since we do similar check # (existence) there. def get_inventory_file(config: dict, options: dict): diff --git a/source/modules/validators/validate.py b/source/modules/validators/validate.py index bc78ee6e..a881e9a9 100644 --- a/source/modules/validators/validate.py +++ b/source/modules/validators/validate.py @@ -50,8 +50,6 @@ def validate_options(self, options: dict): elif options["subcommand"] in ("lock", "unlock"): required = ["infra", "stage"] notsupported = ["switches", "task", "commit", "limit", "raw_output"] - elif options["subcommand"] == "list": - notsupported = ["switches", "commit", "keep_locked", "limit", "raw_output"] elif options["subcommand"] == "show": notsupported = ["commit", "keep_locked", "limit", "raw_output"] diff --git a/tests/01-test_argument_parsing.sh b/tests/01-test_argument_parsing.sh index be982548..9d261062 100755 --- a/tests/01-test_argument_parsing.sh +++ b/tests/01-test_argument_parsing.sh @@ -19,7 +19,7 @@ check_message_in_output 'ansible-deployer verify -t task_exec_bin_true' '\[ERRO check_message_in_output 'ansible-deployer run -t task_exec_bin_true -i testInfra' 'stage is required for run' check_message_in_output 'ansible-deployer verify -t task_exec_bin_true -i testInfra' 'stage is required for verify' -check_message_in_output 'ansible-deployer -t task_exec_bin_true -i testInfra' '\[CRITICAL\]: First positional argument (subcommand) is required! Available commands are: run, list, lock, unlock, verify, show.' +check_message_in_output 'ansible-deployer -t task_exec_bin_true -i testInfra' '\[CRITICAL\]: First positional argument (subcommand) is required! Available commands are: run, lock, unlock, verify, show.' check_message_in_output 'ansible-deployer verify -t task_exec_bin_true -i testInfra -s prod --commit testCommit' 'commit is not supported by verify' check_message_in_output 'ansible-deployer lock -t task_exec_bin_true -i testInfra' '\[ERROR\]: task is not supported by lock' @@ -34,14 +34,10 @@ check_message_in_output 'ansible-deployer unlock -t task_exec_bin_true -s test' check_message_in_output 'ansible-deployer unlock -t task_exec_bin_true -s prod -c X' '\[ERROR\]: commit is not supported by unlock' check_message_in_output 'ansible-deployer unlock -t task_exec_bin_true -l test_hosts_1' '\[ERROR\]: limit is not supported by unlock' -check_message_in_output 'ansible-deployer list --commit task_exec_bin_true' '\[ERROR\]: commit is not supported by list' -check_message_in_output 'ansible-deployer list -l test_hosts_1' '\[ERROR\]: limit is not supported by list' - check_message_in_output "ansible-deployer run test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: task, infra." check_message_in_output "ansible-deployer verify test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: task, infra." check_message_in_output "ansible-deployer lock test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: task, infra." check_message_in_output "ansible-deployer unlock test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: task, infra." -check_message_in_output "ansible-deployer list test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: task, infra." check_message_in_output "ansible-deployer show test" "\[CRITICAL\]: Invalid argument test! Subcommand \"show\" can accept only following arguments: task, infra." check_message_in_output 'ansible-deployer show --commit task_exec_bin_true' '\[ERROR\]: commit is not supported by show' check_message_in_output 'ansible-deployer show -l test_hosts_1' '\[ERROR\]: limit is not supported by show' @@ -55,8 +51,6 @@ check_run_ok "ansible-deployer verify --dry -t task_with_limit -s testing -i tes check_run_ok "ansible-deployer run --dry -t task_exec_bin_true -s prod -i testInfra --commit test_version" check_run_ok "ansible-deployer lock --dry -s prod -i testInfra" check_run_ok "ansible-deployer unlock --dry -s prod -i testInfra" -check_run_ok "ansible-deployer list" -check_run_ok "ansible-deployer list --task=task_exec_bin_true" check_run_ok "ansible-deployer show" check_run_ok "ansible-deployer show infra" From 90c83d350749fc7e24b925aa3f3e2f642d310868 Mon Sep 17 00:00:00 2001 From: LegenJCdary Date: Tue, 26 Apr 2022 04:05:46 -0400 Subject: [PATCH 2/3] Swap subcommand "list" with "show" in --debug option tests --- tests/02-checkrun.sh | 2 +- tests/02b-checkrun_with_conf_dir.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/02-checkrun.sh b/tests/02-checkrun.sh index e4422ac4..ff64f844 100755 --- a/tests/02-checkrun.sh +++ b/tests/02-checkrun.sh @@ -48,7 +48,7 @@ check_run_ok "ansible-deployer lock -s locked -i testInfra" check_message_in_output 'ansible-deployer run -t task_exec_bin_true -s locked -i testInfra' "is using this infrastructure, please try again later." #Check --debug option -check_run_ok "ansible-deployer list --debug" "\[DEBUG\]: load_configuration called" +check_run_ok "ansible-deployer show --debug" "\[DEBUG\]: load_configuration called" # Check different output options check_message_in_output 'ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra' "\[ERROR\]: TASK \[Run ll\]" diff --git a/tests/02b-checkrun_with_conf_dir.sh b/tests/02b-checkrun_with_conf_dir.sh index d0dcec44..a68b865d 100755 --- a/tests/02b-checkrun_with_conf_dir.sh +++ b/tests/02b-checkrun_with_conf_dir.sh @@ -49,7 +49,7 @@ check_run_ok "ansible-deployer lock -s locked -i testInfra --conf-dir=/etc/alter check_message_in_output 'ansible-deployer run -t task_exec_bin_true -s locked -i testInfra --conf-dir=/etc/alternate-deployer-dir' "is using this infrastructure, please try again later." #Check --debug option -check_run_ok "ansible-deployer list --debug --conf-dir=/etc/alternate-deployer-dir" "\[DEBUG\]: load_configuration called" +check_run_ok "ansible-deployer show --debug --conf-dir=/etc/alternate-deployer-dir" "\[DEBUG\]: load_configuration called" # Check --limit option check_message_in_output 'ansible-deployer run -t task_with_limit -s testing -i testInfra2 -l xyzHost4 --conf-dir=/etc/alternate-deployer-dir' 'ERROR\! Specified hosts and/or --limit does not match any hosts' From c40c1307da3e61dadf717ab34cdba17a42febf4f Mon Sep 17 00:00:00 2001 From: LegenJCdary Date: Tue, 26 Apr 2022 09:52:36 -0400 Subject: [PATCH 3/3] Add "all" switch/SUBSUBCOMANND to "show" subcommand Add new tests and adjust exisitng --- source/modules/misc.py | 2 +- source/modules/validators/validate.py | 6 +++--- tests/01-test_argument_parsing.sh | 10 +++++----- tests/02-checkrun.sh | 2 ++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/source/modules/misc.py b/source/modules/misc.py index 4a7fc511..cf6992c0 100644 --- a/source/modules/misc.py +++ b/source/modules/misc.py @@ -78,7 +78,7 @@ def show_deployer(config: dict, options: dict): """ content = {} - if not options["switches"]: + if not options["switches"] or "all" in options["switches"]: options["switches"] = ["task", "infra"] if "task" in options["switches"]: diff --git a/source/modules/validators/validate.py b/source/modules/validators/validate.py index a881e9a9..435366d8 100644 --- a/source/modules/validators/validate.py +++ b/source/modules/validators/validate.py @@ -26,13 +26,13 @@ def verify_switches(switches: list): """ if switches[0] != "show" and len(switches[1:]) > 0: print("[CRITICAL]: Too many positional arguments! Only subcommand \"show\" can accept" - " following arguments: task, infra.") + " following arguments: all, task, infra.") sys.exit("56") for switch in switches[1:]: - if switch not in ("task", "infra"): + if switch not in ("all", "task", "infra"): print(f"[CRITICAL]: Invalid argument {switch}! Subcommand \"show\" can accept only" - " following arguments: task, infra.") + " following arguments: all, task, infra.") sys.exit("57") def validate_options(self, options: dict): diff --git a/tests/01-test_argument_parsing.sh b/tests/01-test_argument_parsing.sh index 9d261062..85dd7e5a 100755 --- a/tests/01-test_argument_parsing.sh +++ b/tests/01-test_argument_parsing.sh @@ -34,11 +34,11 @@ check_message_in_output 'ansible-deployer unlock -t task_exec_bin_true -s test' check_message_in_output 'ansible-deployer unlock -t task_exec_bin_true -s prod -c X' '\[ERROR\]: commit is not supported by unlock' check_message_in_output 'ansible-deployer unlock -t task_exec_bin_true -l test_hosts_1' '\[ERROR\]: limit is not supported by unlock' -check_message_in_output "ansible-deployer run test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: task, infra." -check_message_in_output "ansible-deployer verify test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: task, infra." -check_message_in_output "ansible-deployer lock test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: task, infra." -check_message_in_output "ansible-deployer unlock test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: task, infra." -check_message_in_output "ansible-deployer show test" "\[CRITICAL\]: Invalid argument test! Subcommand \"show\" can accept only following arguments: task, infra." +check_message_in_output "ansible-deployer run test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: all, task, infra." +check_message_in_output "ansible-deployer verify test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: all, task, infra." +check_message_in_output "ansible-deployer lock test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: all, task, infra." +check_message_in_output "ansible-deployer unlock test" "\[CRITICAL\]: Too many positional arguments! Only subcommand \"show\" can accept following arguments: all, task, infra." +check_message_in_output "ansible-deployer show test" "\[CRITICAL\]: Invalid argument test! Subcommand \"show\" can accept only following arguments: all, task, infra." check_message_in_output 'ansible-deployer show --commit task_exec_bin_true' '\[ERROR\]: commit is not supported by show' check_message_in_output 'ansible-deployer show -l test_hosts_1' '\[ERROR\]: limit is not supported by show' diff --git a/tests/02-checkrun.sh b/tests/02-checkrun.sh index ff64f844..48f2c3a9 100755 --- a/tests/02-checkrun.sh +++ b/tests/02-checkrun.sh @@ -72,6 +72,8 @@ check_run_ok "ansible-deployer unlock -s testing -i testInfra" # Check show subcommand check_message_in_output 'ansible-deployer show' 'Available infrastructures:' check_message_in_output 'ansible-deployer show' 'Available tasks:' +check_message_in_output 'ansible-deployer show all' 'Available infrastructures:' +check_message_in_output 'ansible-deployer show all' 'Available tasks:' check_message_in_output 'ansible-deployer show infra' 'Available infrastructures:' check_message_in_output 'ansible-deployer show task' 'Available tasks:'