From 6196317da8eb76c46d04fa41120acba50c24e511 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 28 Nov 2024 16:13:48 +0100 Subject: [PATCH 1/5] add a script to list the test machines with their current status --- list_test_runner_machines | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 list_test_runner_machines diff --git a/list_test_runner_machines b/list_test_runner_machines new file mode 100755 index 0000000..04f43eb --- /dev/null +++ b/list_test_runner_machines @@ -0,0 +1,67 @@ +#!/bin/bash + +TEST_MACHINES=$(cat << 'HEREDOC' +lrineau@bonnard +lrineau@cgal +cgaltest@friedrich +lrineau@rubens +HEREDOC +) + +cat << HEREDOC +# Test runner machines # + +The following machines are used to run the tests: +HEREDOC + +machine_title () { + printf '\n## %s ##\n' $1 +} + +machine_tested_images () { + echo + echo '```plain' + ssh $1 cat /home/$2/.config/CGAL/test_cgal_docker_images + echo '```' +} + +test_docker_is_active_cmd () { + echo 'systemctl is-active -q docker' +} + +docker_ps_filter_option () { + echo '--filter name="CGAL-"' +} + +docker_ps_format_option () { + echo '--format "table {{.Names}}\t{{.Image}}\t{{.CreatedAt}}\t{{.Status}}"' +} + +docker_ps_cmd () { + printf 'docker ps -a %s %s' "$(docker_ps_filter_option)" "$(docker_ps_format_option)" +} + +podman_ps_cmd () { + printf 'podman -r ps -a %s %s' "$(docker_ps_filter_option)" "$(docker_ps_format_option)" +} + +docker_or_podman_ps_cmd () { + printf '%s && %s || %s' "$(test_docker_is_active_cmd)" "$(docker_ps_cmd)" "$(podman_ps_cmd)" +} + +machine_list_cgal_test_container () { + echo + echo '```plain' + docker_or_podman_ps_cmd | ssh $1 bash -s + echo '```' +} + +for machine in $TEST_MACHINES; do + USER=${machine%@*} + HOST=${machine#*@} + machine_title $machine + printf '\nTested images:\n' + machine_tested_images $HOST $USER + printf '\nCGAL test containers:\n' + machine_list_cgal_test_container $HOST $USER +done From 950aec1d9c324f54ecc426b6cb6195ac53348f52 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 28 Nov 2024 16:51:02 +0100 Subject: [PATCH 2/5] store the command in `cmd` --- list_test_runner_machines | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/list_test_runner_machines b/list_test_runner_machines index 04f43eb..6bb4e49 100755 --- a/list_test_runner_machines +++ b/list_test_runner_machines @@ -50,9 +50,10 @@ docker_or_podman_ps_cmd () { } machine_list_cgal_test_container () { + cmd=$(docker_or_podman_ps_cmd) echo echo '```plain' - docker_or_podman_ps_cmd | ssh $1 bash -s + printf '%s\n' "$cmd" | ssh $1 bash -s echo '```' } From b3cb639e49bb129c85eb3513ef3d235385d0d920 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 29 Nov 2024 00:30:06 +0100 Subject: [PATCH 3/5] improved script --- list_test_runner_machines | 177 +++++++++++++++++++++++++++++++++----- 1 file changed, 154 insertions(+), 23 deletions(-) diff --git a/list_test_runner_machines b/list_test_runner_machines index 6bb4e49..af8e9fd 100755 --- a/list_test_runner_machines +++ b/list_test_runner_machines @@ -1,6 +1,7 @@ #!/bin/bash -TEST_MACHINES=$(cat << 'HEREDOC' +TEST_MACHINES=$( + cat <<'HEREDOC' lrineau@bonnard lrineau@cgal cgaltest@friedrich @@ -8,61 +9,191 @@ lrineau@rubens HEREDOC ) -cat << HEREDOC +cat </dev/null || { + echo 'sed is required' + exit 1 +} + +if [[ $1 == --table ]] && ! command -v pandoc >/dev/null; then + echo 'pandoc is required for the option --table' + exit 1 +fi +if [[ $1 == --column ]] && ! command -v column >/dev/null; then + echo 'column is required for the option --column' + exit 1 +fi +if [[ $1 == --bat ]] && ! command -v bat >/dev/null; then + echo 'bat is required for the option --bat' + exit 1 +fi + +set_pretty_csv_to_md_table() { + pretty_csv() ( + echo + sed '/```/ d; /^$/ d' | pandoc -f tsv -t gfm + ) +} + +set_pretty_csv_to_column() { + pretty_csv() { + echo + column -t -s $'\t' -o $'\t' | sed 's/^\(```[^ ]*\) *\t.*/\1/' + } +} + +set_pretty_csv_to_bat() { + pretty_csv() { + bat --tabs=50 --paging=never --plain -l csv + } +} + +set_pretty_csv_to_cat() { + pretty_csv() { + cat + } +} + +case "$1" in +--table) set_pretty_csv_to_md_table ;; +--column) set_pretty_csv_to_column ;; +--bat) set_pretty_csv_to_bat ;; +--plain) set_pretty_csv_to_cat ;; +'') + if command -v bat >/dev/null; then + set_pretty_csv_to_bat + elif command -v column >/dev/null; then + set_pretty_csv_to_column + else + set_pretty_csv_to_cat + fi + ;; +*) + echo "Unknown option $1" + exit 1 + ;; +esac for machine in $TEST_MACHINES; do USER=${machine%@*} HOST=${machine#*@} machine_title $machine + printf '\nusing `%s`\n' "$(ssh $HOST docker --version)" printf '\nTested images:\n' machine_tested_images $HOST $USER printf '\nCGAL test containers:\n' - machine_list_cgal_test_container $HOST $USER + machine_list_cgal_test_container $HOST $USER | pretty_csv done From 69db8ae3b3a9c5b8bbf345f2010a4f777cca97ca Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 29 Nov 2024 10:57:14 +0100 Subject: [PATCH 4/5] use the podman service --- list_test_runner_machines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/list_test_runner_machines b/list_test_runner_machines index af8e9fd..0f7b13d 100755 --- a/list_test_runner_machines +++ b/list_test_runner_machines @@ -36,7 +36,7 @@ docker_cmd() { if docker_is_active_cmd; then docker $@ else - podman -r $@ + podman --url unix:/var/run/podman/podman.sock $@ fi } declare -xf docker_cmd From a24ef0f8032d8c937c9fbbfc7a11b7fa2a1b9712 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 29 Nov 2024 11:17:38 +0100 Subject: [PATCH 5/5] error handling --- list_test_runner_machines | 70 ++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/list_test_runner_machines b/list_test_runner_machines index 0f7b13d..7c76dd9 100755 --- a/list_test_runner_machines +++ b/list_test_runner_machines @@ -9,12 +9,6 @@ lrineau@rubens HEREDOC ) -cat </dev/null || { - echo 'sed is required' +help() { + cat </dev/null || { + error_out 'sed is required' +} + + if [[ $1 == --table ]] && ! command -v pandoc >/dev/null; then - echo 'pandoc is required for the option --table' - exit 1 + error_out 'pandoc is required for the option --table' fi if [[ $1 == --column ]] && ! command -v column >/dev/null; then - echo 'column is required for the option --column' - exit 1 + error_out 'column is required for the option --column' fi if [[ $1 == --bat ]] && ! command -v bat >/dev/null; then - echo 'bat is required for the option --bat' - exit 1 + error_out 'bat is required for the option --bat' fi set_pretty_csv_to_md_table() { @@ -177,16 +192,39 @@ case "$1" in set_pretty_csv_to_bat elif command -v column >/dev/null; then set_pretty_csv_to_column + elif command -v pandoc >/dev/null; then + set_pretty_csv_to_md_table else set_pretty_csv_to_cat fi ;; *) - echo "Unknown option $1" - exit 1 + error_out "Unknown option $1" ;; esac +ERROR_MACHINES="" +for machine in $TEST_MACHINES; do + USER=${machine%@*} + HOST=${machine#*@} + ssh $HOST test -f /home/$USER/.config/CGAL/test_cgal_docker_images || { + ERROR_MACHINES="$ERROR_MACHINES $machine" + } +done +if [ -n "$ERROR_MACHINES" ]; then + for machine in $ERROR_MACHINES; do + USER=${machine%@*} + HOST=${machine#*@} + printf 'ERROR: cannot read file `/home/%s/.config/CGAL/test_cgal_docker_images` on ssh host `%s`\n' $USER $HOST + done + exit 1 +fi +cat <