diff --git a/lib/gitlab/qa/component/base.rb b/lib/gitlab/qa/component/base.rb index d7afd33cd5c9d4429a7d7df97566dba79f827e3e..3f06b408c229af95f019961c5e0640db715d0fc1 100644 --- a/lib/gitlab/qa/component/base.rb +++ b/lib/gitlab/qa/component/base.rb @@ -204,13 +204,16 @@ module Gitlab # for scenarios where a service fails during startup, attempt to retry to avoid flaky failures if (retries += 1) < 3 unless reconfigure_log_file.nil? - Runtime::Logger.info( - "Follow the document " \ - "https://gitlab.com/gitlab-org/quality/runbooks/-/blob/main/debug_orchestrated_test_locally/ " \ - "for debugging the test failure locally.") + Runtime::Logger.info(%( + Follow the document + https://gitlab.com/gitlab-org/quality/runbooks/-/blob/main/debug_orchestrated_test_locally/ + for debugging the test failure locally. + )) # Tailing the reconfigure logs after retries are over and before raising exception - Runtime::Logger.info("Tail of the reconfigure log file, see artifacts for full log: #{reconfigure_log_file}") + Runtime::Logger.info( + "Tail of the reconfigure log file, see artifacts for full log: #{reconfigure_log_file}" + ) Support::ShellCommand.new("tail -n 100 #{reconfigure_log_file}", stream_output: true).execute! end @@ -225,7 +228,9 @@ module Gitlab if !reconfigure_log_file.nil? && retries == 3 # Tailing the reconfigure logs after retries are over and before raising exception - Runtime::Logger.info("Tail of the reconfigure log file, see artifacts for full log: #{reconfigure_log_file}") + Runtime::Logger.info( + "Tail of the reconfigure log file, see artifacts for full log: #{reconfigure_log_file}" + ) Support::ShellCommand.new("tail -n 100 #{reconfigure_log_file}", stream_output: true).execute! end diff --git a/lib/gitlab/qa/component/gitaly.rb b/lib/gitlab/qa/component/gitaly.rb index b704c39d80b0d77f850c95ec83ec0fd81413cf1b..1d9e501c41b851e61dea86d4681d6cdf7eed408f 100644 --- a/lib/gitlab/qa/component/gitaly.rb +++ b/lib/gitlab/qa/component/gitaly.rb @@ -5,6 +5,7 @@ module Gitlab module Component class Gitaly < Base extend Forwardable + using Rainbow attr_reader :release attr_accessor :gitaly_port, :gitlab_name, :cluster_config diff --git a/lib/gitlab/qa/component/gitaly_cluster.rb b/lib/gitlab/qa/component/gitaly_cluster.rb index 8c9ff68e46b260f80198f70653be70ca6adcaa6a..73add5f98c2341106fffd301c5c2bf12a0b74300 100644 --- a/lib/gitlab/qa/component/gitaly_cluster.rb +++ b/lib/gitlab/qa/component/gitaly_cluster.rb @@ -43,11 +43,28 @@ module Gitlab end include Scenario::Actable + using Rainbow attr_accessor :release, :exec_commands, :gitlab_name, :config attr_reader :gitaly_primary_node, :gitaly_secondary_node, :gitaly_tertiary_node, :praefect_node, :database_node + # Helper configuration for omnibus config to disable all non GitalyCluster related omnibus services + def self.disable_other_omnibus_services + <<~OMNIBUS + postgresql['enable'] = false; + redis['enable'] = false; + nginx['enable'] = false; + puma['enable'] = false; + sidekiq['enable'] = false; + gitlab_workhorse['enable'] = false; + gitlab_rails['rake_cache_clear'] = false; + gitlab_rails['auto_migrate'] = false; + gitlab_exporter['enable'] = false; + gitlab_kas['enable'] = false; + OMNIBUS + end + def initialize(config = GitalyClusterConfig.new) @spec_suite = 'Test::Instance::All' @env = {} @@ -134,22 +151,6 @@ module Gitlab praefect.instance(skip_teardown: true) end end - - # Helper configuration for omnibus config to disable all non GitalyCluster related omnibus services - def self.disable_other_omnibus_services - <<~OMNIBUS - postgresql['enable'] = false; - redis['enable'] = false; - nginx['enable'] = false; - puma['enable'] = false; - sidekiq['enable'] = false; - gitlab_workhorse['enable'] = false; - gitlab_rails['rake_cache_clear'] = false; - gitlab_rails['auto_migrate'] = false; - gitlab_exporter['enable'] = false; - gitlab_kas['enable'] = false; - OMNIBUS - end end end end diff --git a/lib/gitlab/qa/component/gitlab.rb b/lib/gitlab/qa/component/gitlab.rb index f9890cef8906dd07714bbcfd9a7481094e07fd56..abe938ec7775c9d33752bd2f0313a8f161ee40b8 100644 --- a/lib/gitlab/qa/component/gitlab.rb +++ b/lib/gitlab/qa/component/gitlab.rb @@ -15,6 +15,7 @@ module Gitlab module Component class Gitlab < Base extend Forwardable + using Rainbow attr_reader :release, @@ -195,31 +196,13 @@ module Gitlab ) end - # Path of the log file to write to - # @note - # if an error occurs during #reconfigure, - # "retry-{n}" is prefixed to the file name where {n} is retry number - # @return [String] the path to the log file - def log_file - retries = 0 - log_file = "#{Runtime::Env.host_artifacts_dir}/#{name}-reconfigure.log" - while File.exist?(log_file) - break unless File.exist?(log_file) - - retries += 1 - log_file = "#{Runtime::Env.host_artifacts_dir}/#{name}-retry-#{retries}-reconfigure.log" - end - - log_file - end - def get_reconfigure_log_file_from_artefact - all_reconfigure_log_file = Dir["#{Runtime::Env.host_artifacts_dir}/*reconfigure.log"].sort_by { |f| File.mtime(f) } + all_reconfigure_log_file = Dir["#{Runtime::Env.host_artifacts_dir}/*reconfigure.log"].sort_by do |f| + File.mtime(f) + end all_reconfigure_log_file.last end - private :log_file - def reconfigure setup_omnibus log_file_path = log_file @@ -229,7 +212,10 @@ module Gitlab if line.include?('There was an error running gitlab-ctl reconfigure') Runtime::Logger.error( - "Failure while running gitlab-ctl reconfigure command. Please check the #{log_file_path} in the artefact for more info" + %( + Failure while running gitlab-ctl reconfigure command. + Please check the #{log_file_path} in the artefact for more info + ) ) end @@ -311,6 +297,26 @@ module Gitlab super end + # Path of the log file to write to + # @note + # if an error occurs during #reconfigure, + # "retry-{n}" is prefixed to the file name where {n} is retry number + # @return [String] the path to the log file + def log_file + retries = 0 + log_file = "#{Runtime::Env.host_artifacts_dir}/#{name}-reconfigure.log" + while File.exist?(log_file) + break unless File.exist?(log_file) + + retries += 1 + log_file = "#{Runtime::Env.host_artifacts_dir}/#{name}-retry-#{retries}-reconfigure.log" + end + + log_file + end + + private :log_file + private attr_reader :cert_volumes @@ -368,7 +374,10 @@ module Gitlab File.open("#{Runtime::Env.host_artifacts_dir}/pg_stats.log", 'a') do |file| file << "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} -- #{name} -- Postgres statistics after test run:\n" file << "Live and dead row counts:\n" - file << @docker.exec(name, %(gitlab-psql -c 'select n_live_tup, n_dead_tup, relname from pg_stat_all_tables order by n_live_tup DESC, n_dead_tup DESC;')) + live_dead_row_query = %( + select n_live_tup, n_dead_tup, relname from pg_stat_all_tables order by n_live_tup DESC, n_dead_tup DESC; + ) + file << @docker.exec(name, %(gitlab-psql -c '#{live_dead_row_query}')) file << "Cumulative user table statistics:\n" file << @docker.exec(name, %(gitlab-psql -c 'select * from pg_stat_user_tables;')) end diff --git a/lib/gitlab/qa/component/praefect.rb b/lib/gitlab/qa/component/praefect.rb index 3e9850e005888534cea1760727fe52698ddba5fd..ce338b1dcec2255f77239ef3c5e2e58f70a6cceb 100644 --- a/lib/gitlab/qa/component/praefect.rb +++ b/lib/gitlab/qa/component/praefect.rb @@ -5,6 +5,7 @@ module Gitlab module Component class Praefect < Base extend Forwardable + using Rainbow attr_reader :release attr_accessor :cluster_config diff --git a/lib/gitlab/qa/docker/command.rb b/lib/gitlab/qa/docker/command.rb index c8df36dadff089c53d094bbbc764165484f3d552..228e8717b34392cc82a49bbb99dd4aec6935904b 100644 --- a/lib/gitlab/qa/docker/command.rb +++ b/lib/gitlab/qa/docker/command.rb @@ -6,6 +6,10 @@ module Gitlab class Command attr_reader :args + def self.execute(cmd, mask_secrets: nil, &block) + new(cmd, mask_secrets: mask_secrets).execute!(&block) + end + # Shell command # # @param [] cmd @@ -52,10 +56,6 @@ module Gitlab raise e end - - def self.execute(cmd, mask_secrets: nil, &block) - new(cmd, mask_secrets: mask_secrets).execute!(&block) - end end end end diff --git a/lib/gitlab/qa/runner.rb b/lib/gitlab/qa/runner.rb index 27245f0330bd084f840c7069cddb06d9597332ca..d282bfed76ef636cede64cf3357dafc118315f2d 100644 --- a/lib/gitlab/qa/runner.rb +++ b/lib/gitlab/qa/runner.rb @@ -46,7 +46,7 @@ module Gitlab opts.on( '--qa-image QA_IMAGE', String, - "Specifies a QA image to be used instead of inferring it from the GitLab image." \ + "Specifies a QA image to be used instead of inferring it from the GitLab image. " \ "See Gitlab::QA::Release#qa_image" ) do |value| Runtime::Scenario.define(:qa_image, value) diff --git a/lib/gitlab/qa/runtime/env.rb b/lib/gitlab/qa/runtime/env.rb index 0bcaed008036de5cd59bf6a55016ea3fc099a972..547e27657b4963796fb60c67916c769498ffa392 100644 --- a/lib/gitlab/qa/runtime/env.rb +++ b/lib/gitlab/qa/runtime/env.rb @@ -509,12 +509,12 @@ module Gitlab end def env_var_value_if_defined(variable) - return ENV.fetch(variable, nil) if env_var_value_valid?(variable) + ENV.fetch(variable, nil) if env_var_value_valid?(variable) end def env_var_name_if_defined(variable) # Pass through the variables if they are defined and not empty in the environment - return "$#{variable}" if env_var_value_valid?(variable) + "$#{variable}" if env_var_value_valid?(variable) end def method_name_and_value(env_var_name, attributes, name_as_value: false) @@ -555,7 +555,7 @@ module Gitlab writer_names = attr_writer(method_name) define_method(method_name) do _, value = method_name_and_value(env_var_name, attributes) - value || (instance_variable_get("@#{method_name}") if instance_variable_defined?("@#{method_name}")) + value || (instance_variable_get(:"@#{method_name}") if instance_variable_defined?(:"@#{method_name}")) end public(*writer_names, method_name) end diff --git a/lib/gitlab/qa/runtime/omnibus_configuration.rb b/lib/gitlab/qa/runtime/omnibus_configuration.rb index 8a453d65596cb1e88588f998e02d096899ebbe3c..04727fb5f3f76f7d289094f05050563cf09db8d7 100644 --- a/lib/gitlab/qa/runtime/omnibus_configuration.rb +++ b/lib/gitlab/qa/runtime/omnibus_configuration.rb @@ -9,6 +9,8 @@ module Gitlab module QA module Runtime class OmnibusConfiguration + ERB_PATTERN = /<%=?\s?(\S+)\s?%>/ + # @param prefixed_config The configuration to be prefixed to the new configuration def initialize(prefixed_config = nil) @config = ["# Generated by GitLab QA Omnibus Configurator at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"] @@ -27,8 +29,6 @@ module Gitlab sanitize!.join("\n") end - ERB_PATTERN = /<%=?\s?(\S+)\s?%>/ - # Execute the ERB code to produce completed template # @example # external_url '<%= gitlab.address %>' #=> external_url 'http://gitlab-ee-09d62235.test' diff --git a/lib/gitlab/qa/runtime/omnibus_configurations/decomposition_multiple_db.rb b/lib/gitlab/qa/runtime/omnibus_configurations/decomposition_multiple_db.rb index a93636a2b01acce452ce7c7219b421cdb71f2e4c..b99c04fb5ee4c9d8141af40293d634cc50711f38 100644 --- a/lib/gitlab/qa/runtime/omnibus_configurations/decomposition_multiple_db.rb +++ b/lib/gitlab/qa/runtime/omnibus_configurations/decomposition_multiple_db.rb @@ -9,8 +9,9 @@ module Gitlab gitlab-psql -d gitlabhq_production_ci -c 'select 1' 2>1 > /dev/null CMD + query = %(select schema_name from information_schema.schemata where schema_name = 'gitlab_partitions_dynamic') SCHEMA_EXISTENCE_CHECK_COMMAND = <<~CMD.chomp - gitlab-psql -d gitlabhq_production_ci -c "select schema_name from information_schema.schemata where schema_name = 'gitlab_partitions_dynamic'" | grep -q gitlab_partitions_dynamic + gitlab-psql -d gitlabhq_production_ci -c "#{query}" | grep -q gitlab_partitions_dynamic CMD def configuration @@ -24,11 +25,12 @@ module Gitlab end def exec_commands + create_db_query = %(create database gitlabhq_production_ci owner gitlab) [ "sed -i 's/#gitlab_rails/gitlab_rails/g' /etc/gitlab/gitlab.rb", "gitlab-ctl reconfigure", # Create database only if it does not exist. - "#{DATABASE_EXISTENCE_CHECK_COMMAND} || gitlab-psql -c 'create database gitlabhq_production_ci owner gitlab'", + "#{DATABASE_EXISTENCE_CHECK_COMMAND} || gitlab-psql -c '#{create_db_query}'", "gitlab-psql -d gitlabhq_production_ci -c 'create extension if not exists btree_gist'", "gitlab-psql -d gitlabhq_production_ci -c 'create extension if not exists pg_trgm'", # Load schema only if it does not exist. diff --git a/lib/gitlab/qa/runtime/omnibus_configurations/default.rb b/lib/gitlab/qa/runtime/omnibus_configurations/default.rb index 70bd8422a5cbc4566c2120dc9bcc3a81a1d4b264..ce10ca16b43989b2b9baf34b54cd234ff7c37864 100644 --- a/lib/gitlab/qa/runtime/omnibus_configurations/default.rb +++ b/lib/gitlab/qa/runtime/omnibus_configurations/default.rb @@ -7,6 +7,10 @@ module Gitlab # Default Configuration for Omnibus # All runs will include this configuration class Default < Runtime::OmnibusConfiguration + def self.configuration + new.configuration + end + def configuration <<~OMNIBUS gitlab_rails['gitlab_default_theme'] = 10 # Light Red Theme @@ -15,10 +19,6 @@ module Gitlab gitlab_rails['initial_root_password'] = '#{Runtime::Env.initial_root_password}' # Initial root password OMNIBUS end - - def self.configuration - new.configuration - end end end end diff --git a/lib/gitlab/qa/runtime/scenario.rb b/lib/gitlab/qa/runtime/scenario.rb index 3f7cecfe2ec47cd51af7d8f56ef3348396d14da1..c254bf0c2264b542e3d57c96890e62688cd0f3f9 100644 --- a/lib/gitlab/qa/runtime/scenario.rb +++ b/lib/gitlab/qa/runtime/scenario.rb @@ -23,7 +23,7 @@ module Gitlab end end - def method_missing(name, *) + def respond_to_missing(name, *) raise ArgumentError, "Scenario attribute `#{name}` not defined!" end end diff --git a/lib/gitlab/qa/scenario/cli_commands.rb b/lib/gitlab/qa/scenario/cli_commands.rb index 9e6afe051ced1ea65c67d334f9242f43662696e4..7db473172d0a0320ab129952868ddfec81f4adb9 100644 --- a/lib/gitlab/qa/scenario/cli_commands.rb +++ b/lib/gitlab/qa/scenario/cli_commands.rb @@ -7,8 +7,9 @@ module Gitlab GIT_LFS_VERSION = '2.8.0' def self.git_lfs_install_commands + tar_file = "v#{GIT_LFS_VERSION}/git-lfs-linux-amd64-v#{GIT_LFS_VERSION}.tar.gz" [ - "cd /tmp ; curl -qsL https://github.com/git-lfs/git-lfs/releases/download/v#{GIT_LFS_VERSION}/git-lfs-linux-amd64-v#{GIT_LFS_VERSION}.tar.gz | tar xzvf -", + "cd /tmp ; curl -qsL https://github.com/git-lfs/git-lfs/releases/download/#{tar_file} | tar xzvf -", 'cp /tmp/git-lfs /usr/local/bin' ].freeze end diff --git a/lib/gitlab/qa/scenario/template.rb b/lib/gitlab/qa/scenario/template.rb index d1af6e1aa14fbe9ed0c89b8b9d1a7cbce8cf9643..909e9224d6e10f16042b05faf8693fd647da43a9 100644 --- a/lib/gitlab/qa/scenario/template.rb +++ b/lib/gitlab/qa/scenario/template.rb @@ -7,7 +7,7 @@ module Gitlab def self.perform(*args) new.tap do |scenario| yield scenario if block_given? - return scenario.perform(*args) + scenario.perform(*args) end end diff --git a/lib/gitlab/qa/scenario/test/integration/ai_gateway_base.rb b/lib/gitlab/qa/scenario/test/integration/ai_gateway_base.rb index 3a889a9a45b505c1ae07b153d49b27bac315ba69..af577e852af77b6be7814baeb539417264ea36fc 100644 --- a/lib/gitlab/qa/scenario/test/integration/ai_gateway_base.rb +++ b/lib/gitlab/qa/scenario/test/integration/ai_gateway_base.rb @@ -62,7 +62,8 @@ module Gitlab gitlab.docker.exec( gitlab.name, - "ASSIGN_SEATS=#{@assign_seats} HAS_ADD_ON=#{@has_add_on} gitlab-rails runner #{SETUP_DEST_PATH}/gitlab_duo_setup.rb", + "ASSIGN_SEATS=#{@assign_seats} HAS_ADD_ON=#{@has_add_on} \ + gitlab-rails runner #{SETUP_DEST_PATH}/gitlab_duo_setup.rb", mask_secrets: gitlab.secrets ) end diff --git a/lib/gitlab/qa/scenario/test/integration/continuous_vulnerability_scanning.rb b/lib/gitlab/qa/scenario/test/integration/continuous_vulnerability_scanning.rb index 514c50fee7f98a373b8249aea4fd1b75770980d4..b4f4f243bcc95ccc4eaaccd06d12688635df83fa 100644 --- a/lib/gitlab/qa/scenario/test/integration/continuous_vulnerability_scanning.rb +++ b/lib/gitlab/qa/scenario/test/integration/continuous_vulnerability_scanning.rb @@ -43,13 +43,16 @@ module Gitlab end def generate_vulnerabilities - template = File.read(File.expand_path('../../../../../../fixtures/cvs/vulnerabilities_template.erb', __dir__)) + template = File.read( + File.expand_path('../../../../../../fixtures/cvs/vulnerabilities_template.erb', __dir__) + ) ERB.new(template).result(binding) end def generate_filepath File.join( - "/opt/gitlab/embedded/service/gitlab-rails/vendor/package_metadata/advisories/v2/rubygem/#{Time.now.to_i}", + "/opt/gitlab/embedded/service/gitlab-rails/", + "vendor/package_metadata/advisories/v2/rubygem/#{Time.now.to_i}", '000000000.ndjson' ) end @@ -60,7 +63,8 @@ module Gitlab end def start_advisory_sync_worker(gitlab) - gitlab.docker.exec(gitlab.name, "PM_SYNC_IN_DEV=true gitlab-rails runner 'loop do PackageMetadata::AdvisoriesSyncWorker.new.perform; sleep 30; end' &") + cmd = "loop do PackageMetadata::AdvisoriesSyncWorker.new.perform; sleep 30; end" + gitlab.docker.exec(gitlab.name, "PM_SYNC_IN_DEV=true gitlab-rails runner '#{cmd}' &") end def run_specs(gitlab, *rspec_args) diff --git a/lib/gitlab/qa/scenario/test/integration/geo.rb b/lib/gitlab/qa/scenario/test/integration/geo.rb index 6ce61ae244315a7dd89399d1c0a655da44b7399b..ffac660556a1ff773e7a414870ca14f8b026fd18 100644 --- a/lib/gitlab/qa/scenario/test/integration/geo.rb +++ b/lib/gitlab/qa/scenario/test/integration/geo.rb @@ -35,7 +35,8 @@ module Gitlab sidekiq['concurrency'] = 2; puma['worker_processes'] = 2; OMNIBUS - primary.exec_commands = fast_ssh_key_lookup_commands + QA::Scenario::CLICommands.git_lfs_install_commands + primary.exec_commands = + fast_ssh_key_lookup_commands + QA::Scenario::CLICommands.git_lfs_install_commands primary.instance do Component::Gitlab.perform do |secondary| @@ -57,7 +58,8 @@ module Gitlab sidekiq['concurrency'] = 2; puma['worker_processes'] = 2; OMNIBUS - secondary.exec_commands += fast_ssh_key_lookup_commands + QA::Scenario::CLICommands.git_lfs_install_commands + secondary.exec_commands += + fast_ssh_key_lookup_commands + QA::Scenario::CLICommands.git_lfs_install_commands secondary.act do # TODO, we do not wait for secondary to start because of diff --git a/lib/gitlab/qa/scenario/test/integration/opensearch.rb b/lib/gitlab/qa/scenario/test/integration/opensearch.rb index 5c0ccb3741fb45f83dd05dfafbfb93c449ac8231..afa33f7ff95abecc28505102f3713d4ed4160caf 100644 --- a/lib/gitlab/qa/scenario/test/integration/opensearch.rb +++ b/lib/gitlab/qa/scenario/test/integration/opensearch.rb @@ -10,7 +10,8 @@ module Gitlab def initialize @gitlab_name = 'gitlab-opensearch' - # Currently the test suite that tests Advanced Search features is called 'Elasticsearch' which we hope to abstract to 'Advancedsearch' in the future + # Currently the test suite that tests Advanced Search features is called 'Elasticsearch' + # which we hope to abstract to 'Advancedsearch' in the future @spec_suite = 'QA::EE::Scenario::Test::Integration::Elasticsearch' end diff --git a/lib/gitlab/qa/scenario/test/omnibus/update_from_previous.rb b/lib/gitlab/qa/scenario/test/omnibus/update_from_previous.rb index 1faddbd9eef6de00d6fde15a971677cff9c873a1..1cf4d63952230bb61a94de66bf180f20836a3d53 100644 --- a/lib/gitlab/qa/scenario/test/omnibus/update_from_previous.rb +++ b/lib/gitlab/qa/scenario/test/omnibus/update_from_previous.rb @@ -11,7 +11,8 @@ module Gitlab attr_reader :rspec_args # Test update from N - 1 (major|minor|patch) version to current release - # Run health check (or smoke if below 17.1.0) test suite on previous release to populate some data in database before update + # Run health check (or smoke if below 17.1.0) test suite on previous + # release to populate some data in database before update # # @example # perform(gitlab-ee:dev-tag, 15.3.0-pre, major) @@ -132,6 +133,7 @@ module Gitlab # @return [void] def run_specs(gitlab, release, rspec_args) # rubocop:disable Metrics/AbcSize Runtime::Logger.info("Running test suite to verify update and seed data in environment") unless upgrade_path.first != release + Runtime::Logger.info("Running test suite to verify update") unless current_release != release Component::Specs.perform do |specs| diff --git a/lib/gitlab/qa/support/gitlab_version_info.rb b/lib/gitlab/qa/support/gitlab_version_info.rb index d8c2acbe73aa8ddd31dcde5706ed0a5d0226f37c..738c0e98cbddb2fab6423d7bf5622a8d5dc05435 100644 --- a/lib/gitlab/qa/support/gitlab_version_info.rb +++ b/lib/gitlab/qa/support/gitlab_version_info.rb @@ -9,6 +9,10 @@ module Gitlab VersionNotFoundError = Class.new(RuntimeError) + MAX_TAGS_HTTP_REQUESTS = 50 + # https://docs.docker.com/docker-hub/api/latest/#tag/images/operation/GetNamespacesRepositoriesImages + TAGS_PER_PAGE = 100 + # Get previous gitlab version # # @param [String] current_version @@ -55,10 +59,6 @@ module Gitlab private - MAX_TAGS_HTTP_REQUESTS = 50 - # https://docs.docker.com/docker-hub/api/latest/#tag/images/operation/GetNamespacesRepositoriesImages - TAGS_PER_PAGE = 100 - attr_reader :current_version, :edition, :logger # Current versions major version diff --git a/lib/gitlab/qa/support/http_request.rb b/lib/gitlab/qa/support/http_request.rb index 6fa1aab698207ce24208682e303d6b34d7e3947c..0b1e4b7466041be5e494edc36e529e5dc0b103c8 100644 --- a/lib/gitlab/qa/support/http_request.rb +++ b/lib/gitlab/qa/support/http_request.rb @@ -8,7 +8,9 @@ module Gitlab module Support class HttpRequest # rubocop:disable Metrics/AbcSize - def self.make_http_request(method: 'get', url: nil, params: nil, headers: {}, show_response: false, fail_on_error: true) + def self.make_http_request( + method: 'get', url: nil, params: nil, headers: {}, show_response: false, fail_on_error: true + ) raise "URL not defined for making request. Exiting..." unless url res = HTTP.follow.method(method).call(url, json: params, headers: headers) @@ -23,7 +25,8 @@ module Gitlab end end - raise "#{method.upcase} request failed!\nCode: #{res.code}\nResponse: #{res.body}\n" if fail_on_error && !res.status.success? + error_msg = "#{method.upcase} request failed!\nCode: #{res.code}\nResponse: #{res.body}\n" + raise error_msg if fail_on_error && !res.status.success? res end diff --git a/lib/gitlab/qa/support/invalid_response_error.rb b/lib/gitlab/qa/support/invalid_response_error.rb index 6ff6102ae3f4cb46b87941588112f7cc4c86f5a7..8e272e064379c99010544867e3fdd69c8a8f19f8 100644 --- a/lib/gitlab/qa/support/invalid_response_error.rb +++ b/lib/gitlab/qa/support/invalid_response_error.rb @@ -9,7 +9,7 @@ module Gitlab def initialize(address, response) @response = response - super "Invalid response received from #{address}" + super("Invalid response received from #{address}") end end end diff --git a/lib/gitlab/qa/support/shell_command.rb b/lib/gitlab/qa/support/shell_command.rb index d21db8a69672b381e5b1568ea6e1044213543453..863433b135f12120e598579eb33167c3659d4f90 100644 --- a/lib/gitlab/qa/support/shell_command.rb +++ b/lib/gitlab/qa/support/shell_command.rb @@ -69,6 +69,7 @@ module Gitlab # @return [void] def fail! logger.error("Shell command output:\n#{string_output}") unless @command.include?("docker attach") || stream_output + raise StatusError, "Command `#{mask_secrets(command).truncate(100)}` failed! " + "✘".red end diff --git a/rubocop/cop/gitlab/dangerous_interpolation.rb b/rubocop/cop/gitlab/dangerous_interpolation.rb index 87bb2059874a4229c199eb187f6051c4fba0302c..5ca7fbf328d21e2765413b7730ef49015924a443 100644 --- a/rubocop/cop/gitlab/dangerous_interpolation.rb +++ b/rubocop/cop/gitlab/dangerous_interpolation.rb @@ -16,8 +16,11 @@ module RuboCop # gitlab_rails['object_store']['objects']['lfs']['bucket'] = '#{Runtime::Env.aws_s3_bucket_name}' class DangerousInterpolation < Base - MSG = 'Sensitive variables should not be logged. ' \ - 'Please ensure that the interpolated variable is not sensitive. If not, add it to `ENV_VARIABLES` in the cop class.' + MSG = %( + Sensitive variables should not be logged + Please ensure that the interpolated variable is not sensitive. + If not, add it to `ENV_VARIABLES` in the cop class. + ) # These values are taken from /lib/gitlab/qa/runtime/env.rb. Sensitive variables have been removed. ENV_VARIABLES = { @@ -146,7 +149,10 @@ module RuboCop PATTERN def on_send(node) - return unless heredoc_interpolation?(node) && node.parent.parent.dstr_type? && !ENV_VARIABLES.value?(node.source.split(".")[1].to_sym) + unless heredoc_interpolation?(node) && node.parent.parent.dstr_type? && + !ENV_VARIABLES.value?(node.source.split(".")[1].to_sym) + return + end add_offense(node) end