Skip to content

Commit

Permalink
Enable setting runner verbosity via --runner-verbosity
Browse files Browse the repository at this point in the history
Default is 1 to maintain current behaviour and pass test scripts.
Adjust tests - '-v' flag is now appended at the end of command.
  • Loading branch information
LegenJCdary committed Oct 1, 2024
1 parent c012acd commit a565e0d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
13 changes: 13 additions & 0 deletions source/modules/misc/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def create_parser() -> ArgumentParser:
parser.add_argument("--runner-stdout", nargs=1, default=[None], metavar='STDOUT_PLUGIN',
help=
'Provide name of runner stdout callback plugin you would like to use.')
parser.add_argument("--runner-verbosity", nargs=1, default=[1], metavar='N',
help='Set runner verbosity to N*v.')
parser.add_argument("--self-setup", nargs=1, default=[None], metavar="LOCAL_SETUP_PATH",
help='Setup repo outside of workdir in requested path. This option'
' applies only to infrastructures with allow_user_checkout enabled'
Expand Down Expand Up @@ -138,6 +140,8 @@ def validate_rest_arguments(self, arguments: Namespace, print_end: str, print_fa
options["runner_raw_file"] = arguments.runner_raw_file
options["runner_stdout"] = self.validate_ansible_stdout_callback(arguments.runner_stdout,
print_fail, print_end)
options["runner_verb"] = self.validate_integer(arguments.runner_verbosity[0], print_fail,
print_end)
options["self_setup"] = os.path.abspath(arguments.self_setup[0]) if arguments.self_setup[0]\
else None
options["stage"] = arguments.stage[0]
Expand Down Expand Up @@ -180,3 +184,12 @@ def validate_ansible_callback(stdout_plugin: str, print_fail: str, print_end: st
sys.exit(57)
else:
return []

@staticmethod
def validate_integer(number: str, print_fail: str, print_end: str) -> Optional[int]:
"""Validate if number is an integer"""
try:
return int(number)
except ValueError:
print(f"{print_fail}[CRITICAL]: Not an integer!{print_end}")
sys.exit(57)
5 changes: 4 additions & 1 deletion source/modules/runners/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def construct_command(self, playitem: str, inventory: str, config: dict, options
command.append("--junit-xml=junit_"+options['task']+'.xml')
command.append("./"+playitem["file"])
else:
command = ["ansible-playbook", "-v", "-i", inventory, playitem["file"]]
command = ["ansible-playbook", "-i", inventory, playitem["file"]]
if options["limit"]:
command.append("-l")
command.append(options["limit"])
Expand All @@ -226,6 +226,9 @@ def construct_command(self, playitem: str, inventory: str, config: dict, options
if options["check_mode"]:
command.append("-C")

if options["runner_verb"]:
command.append(f'-{"v"*options["runner_verb"]}')

return command

def construct_env(self, options: dict, callback_settings: dict) -> dict:
Expand Down
4 changes: 2 additions & 2 deletions tests/02a-checkrun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ check_run_ok "ansible-deployer run --task task_with_limit --stage testing --infr
check_run_ok "ansible-deployer run --task task_without_limit --stage testing --infrastructure testInfra --limit testHost1 --check-mode"

# Check if deployer exits on 1st play item fail
check_message_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra" "\[ERROR\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runll.yaml\" failed due to"
check_message_not_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra" "\[INFO\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runBinTrue.yaml\" ran succesfully"
check_message_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra" "\[ERROR\]: \"ansible-playbook -i ./test_infra1_inv.yaml runll.yaml -v\" failed due to"
check_message_not_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra" "\[INFO\]: \"ansible-playbook -i ./test_infra1_inv.yaml runBinTrue.yaml -v\" ran succesfully"

# Check --keep-locked option
check_message_in_output "ansible-deployer run --task task_exec_bin_true --stage testing --infrastructure testInfra --keep-locked --debug" "\[DEBUG\]: Keep locked infra testInfra:testing ."
Expand Down
4 changes: 2 additions & 2 deletions tests/02a-checkrun_short.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ check_run_ok "ansible-deployer run -t task_with_limit -s testing -i testInfra2 -
check_run_ok "ansible-deployer run -t task_without_limit -s testing -i testInfra -l testHost1 -C"

# Check if deployer exits on 1st play item fail
check_message_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra" "\[ERROR\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runll.yaml\" failed due to"
check_message_not_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra" "\[INFO\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runBinTrue.yaml\" ran succesfully"
check_message_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra" "\[ERROR\]: \"ansible-playbook -i ./test_infra1_inv.yaml runll.yaml -v\" failed due to"
check_message_not_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra" "\[INFO\]: \"ansible-playbook -i ./test_infra1_inv.yaml runBinTrue.yaml -v\" ran succesfully"

# Check --keep-locked option
check_message_in_output "ansible-deployer run -t task_exec_bin_true -s testing -i testInfra -k -d" "\[DEBUG\]: Keep locked infra testInfra:testing ."
Expand Down
4 changes: 2 additions & 2 deletions tests/02b-checkrun_with_conf_dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ check_run_ok "ansible-deployer run --task task_with_limit --stage testing --infr
check_run_ok "ansible-deployer run --task task_without_limit --stage testing --infrastructure testInfra --limit testHost1 --check-mode --conf-dir=/etc/alternate-deployer-dir"

# Check if deployer exits on 1st play item fail
check_message_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra --conf-dir=/etc/alternate-deployer-dir" "\[ERROR\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runll.yaml\" failed due to"
check_message_not_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra --conf-dir=/etc/alternate-deployer-dir" "\[INFO\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runBinTrue.yaml\" ran succesfully"
check_message_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra --conf-dir=/etc/alternate-deployer-dir" "\[ERROR\]: \"ansible-playbook -i ./test_infra1_inv.yaml runll.yaml -v\" failed due to"
check_message_not_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra --conf-dir=/etc/alternate-deployer-dir" "\[INFO\]: \"ansible-playbook -i ./test_infra1_inv.yaml runBinTrue.yaml -v\" ran succesfully"

echo -e " ___ ____ _ _ _ _ _ _ __ _ _\n / _ \___ \| |__ ___| |__ ___ ___| | ___ __ _ _ _ __ __ _(_) |_| |__ ___ ___ _ __ / _| __| (_)_ __\n | | | |__) | '_ \ _____ / __| '_ \ / _ \/ __| |/ / '__| | | | '_ \ \ \ /\ / / | __| '_ \ / __/ _ \| '_ \| |_ / _\` | | '__|\n | |_| / __/| |_) | |_____| | (__| | | | __/ (__| <| | | |_| | | | | \ V V /| | |_| | | | | (_| (_) | | | | _| | (_| | | |\n \___/_____|_.__/ \___|_| |_|\___|\___|_|\_\_| \__,_|_| |_| \_/\_/ |_|\__|_| |_| \___\___/|_| |_|_| \__,_|_|_|\n \n _ _\n _ __ ___ _ __ _ __ ___ (_)___ ___(_) ___ _ __ ___\n | '_ \ / _ \ '__| '_ \` _ \| / __/ __| |/ _ \| '_ \/ __|\n | |_) | __/ | | | | | | | \__ \__ \ | (_) | | | \__ \ \n | .__/ \___|_| |_| |_| |_|_|___/___/_|\___/|_| |_|___/\n |_|\n"
# Try execution of task without permissions
Expand Down
4 changes: 2 additions & 2 deletions tests/02b-checkrun_with_conf_dir_short.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ check_run_ok "ansible-deployer run -t task_with_limit -s testing -i testInfra2 -
check_run_ok "ansible-deployer run -t task_without_limit -s testing -i testInfra -l testHost1 -C --conf-dir=/etc/alternate-deployer-dir"

# Check if deployer exits on 1st play item fail
check_message_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra --conf-dir=/etc/alternate-deployer-dir" "\[ERROR\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runll.yaml\" failed due to"
check_message_not_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra --conf-dir=/etc/alternate-deployer-dir" "\[INFO\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runBinTrue.yaml\" ran succesfully"
check_message_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra --conf-dir=/etc/alternate-deployer-dir" "\[ERROR\]: \"ansible-playbook -i ./test_infra1_inv.yaml runll.yaml -v\" failed due to"
check_message_not_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra --conf-dir=/etc/alternate-deployer-dir" "\[INFO\]: \"ansible-playbook -i ./test_infra1_inv.yaml runBinTrue.yaml -v\" ran succesfully"

echo -e " ___ ____ _ _ _ _ _ _ __ _ _ _ _\n / _ \___ \| |__ ___| |__ ___ ___| | ___ __ _ _ _ __ __ _(_) |_| |__ ___ ___ _ __ / _| __| (_)_ __ ___| |__ ___ _ __| |_\n | | | |__) | '_ \ _____ / __| '_ \ / _ \/ __| |/ / '__| | | | '_ \ \ \ /\ / / | __| '_ \ / __/ _ \| '_ \| |_ / _\` | | '__| / __| '_ \ / _ \| '__| __|\n | |_| / __/| |_) | |_____| | (__| | | | __/ (__| <| | | |_| | | | | \ V V /| | |_| | | | | (_| (_) | | | | _| | (_| | | | \__ \ | | | (_) | | | |_\n \___/_____|_.__/ \___|_| |_|\___|\___|_|\_\_| \__,_|_| |_| \_/\_/ |_|\__|_| |_| \___\___/|_| |_|_| \__,_|_|_| |___/_| |_|\___/|_| \__|\n \n _ _\n _ __ ___ _ __ _ __ ___ (_)___ ___(_) ___ _ __ ___\n | '_ \ / _ \ '__| '_ \` _ \| / __/ __| |/ _ \| '_ \/ __|\n | |_) | __/ | | | | | | | \__ \__ \ | (_) | | | \__ \ \n | .__/ \___|_| |_| |_| |_|_|___/___/_|\___/|_| |_|___/\n |_|\n"
# Try execution of task without permissions
Expand Down

0 comments on commit a565e0d

Please sign in to comment.