Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove list subcommand #133

Merged
merged 3 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion source/modules/globalvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
12 changes: 1 addition & 11 deletions source/modules/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -88,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"]:
Expand Down
8 changes: 3 additions & 5 deletions source/modules/validators/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"]

Expand Down
18 changes: 6 additions & 12 deletions tests/01-test_argument_parsing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -34,15 +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 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 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'

Expand All @@ -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"

Expand Down
4 changes: 3 additions & 1 deletion tests/02-checkrun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\]"
Expand All @@ -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:'

Expand Down
2 changes: 1 addition & 1 deletion tests/02b-checkrun_with_conf_dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down