diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-16 15:09:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-16 15:09:06 +0300 |
commit | 0045970352e8729b2797591beb88a7df884d84f4 (patch) | |
tree | b9cd4c5aaaa26ce4a3c944ec5cfdbd7ad44b796d /qa | |
parent | 613868af23d7c0e09210857518895edd6678f5e9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/service/docker_run/base.rb | 21 | ||||
-rw-r--r-- | qa/qa/service/shellout.rb | 9 |
2 files changed, 17 insertions, 13 deletions
diff --git a/qa/qa/service/docker_run/base.rb b/qa/qa/service/docker_run/base.rb index ce558849abd..1a25aeb4c19 100644 --- a/qa/qa/service/docker_run/base.rb +++ b/qa/qa/service/docker_run/base.rb @@ -39,19 +39,20 @@ module QA end def network - shell "docker network inspect #{@network}" - rescue CommandError - 'bridge' - else - @network + network_exists?(@network) ? @network : 'bridge' end def runner_network - shell "docker network inspect #{@runner_network}" - rescue CommandError - network - else - @runner_network + network_exists?(@runner_network) ? @runner_network : network + end + + def inspect_network(name) + shell("docker network inspect #{name}", fail_on_exception: false, return_exit_status: true) + end + + def network_exists?(name) + _, status = inspect_network(name) + status == 0 end def pull diff --git a/qa/qa/service/shellout.rb b/qa/qa/service/shellout.rb index 218d5eecc85..c825793cc3c 100644 --- a/qa/qa/service/shellout.rb +++ b/qa/qa/service/shellout.rb @@ -11,9 +11,10 @@ module QA module_function - def shell(command, stdin_data: nil, fail_on_exception: true, stream_progress: true, mask_secrets: []) # rubocop:disable Metrics/CyclomaticComplexity + def shell(command, stdin_data: nil, fail_on_exception: true, stream_progress: true, mask_secrets: [], return_exit_status: false) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity cmd_string = Array(command).join(' ') cmd_output = '' + exit_status = 0 QA::Runtime::Logger.info("Executing: `#{mask_secrets_on_string(cmd_string, mask_secrets).cyan}`") @@ -36,7 +37,9 @@ module QA # add newline after progress dots puts if print_progress_dots && !cmd_output.empty? - if wait.value.exited? && wait.value.exitstatus.nonzero? && fail_on_exception + exit_status = wait.value.exitstatus if wait.value.exited? + + if exit_status.nonzero? && fail_on_exception Runtime::Logger.error("Command output:\n#{cmd_output.strip}") unless cmd_output.empty? raise CommandError, "Command: `#{mask_secrets_on_string(cmd_string, mask_secrets)}` failed! ✘" end @@ -44,7 +47,7 @@ module QA Runtime::Logger.debug("Command output:\n#{cmd_output.strip}") unless cmd_output.empty? end - cmd_output.strip + return_exit_status ? [cmd_output.strip, exit_status] : cmd_output.strip end def sql_to_docker_exec_cmd(sql, username, password, database, host, container) |