Module: Gitlab::QA::Runtime::Env
Constant Summary collapse
- ENV_VARIABLES =
Variables that are used in tests and are passed through to the docker container that executes the tests. These variables should be listed in /docs/what_tests_can_be_run.md#supported-gitlab-environment-variables unless they’re defined elsewhere (e.g.: docs.gitlab.com/ee/ci/variables/predefined_variables.html)
{ 'QA_IMAGE' => :qa_image, 'QA_REMOTE_GRID' => :remote_grid, 'QA_REMOTE_GRID_USERNAME' => :remote_grid_username, 'QA_REMOTE_GRID_ACCESS_KEY' => :remote_grid_access_key, 'QA_REMOTE_GRID_PROTOCOL' => :remote_grid_protocol, 'QA_REMOTE_MOBILE_DEVICE_NAME' => :remote_mobile_device_name, 'QA_REMOTE_TUNNEL_ID' => :remote_tunnel_id, 'QA_BROWSER' => :browser, 'QA_ADDITIONAL_REPOSITORY_STORAGE' => :qa_additional_repository_storage, 'QA_PRAEFECT_REPOSITORY_STORAGE' => :qa_praefect_repository_storage, 'QA_GITALY_NON_CLUSTER_STORAGE' => :qa_gitaly_non_cluster_storage, 'QA_COOKIES' => :qa_cookie, 'QA_DEBUG' => :qa_debug, 'QA_DEFAULT_BRANCH' => :qa_default_branch, 'QA_LOG_PATH' => :qa_log_path, 'QA_CAN_TEST_ADMIN_FEATURES' => :qa_can_test_admin_features, 'QA_CAN_TEST_GIT_PROTOCOL_V2' => :qa_can_test_git_protocol_v2, 'QA_CAN_TEST_PRAEFECT' => :qa_can_test_praefect, 'QA_DISABLE_RSPEC_RETRY' => :qa_disable_rspec_retry, 'QA_SIMULATE_SLOW_CONNECTION' => :qa_simulate_slow_connection, 'QA_SLOW_CONNECTION_LATENCY_MS' => :qa_slow_connection_latency_ms, 'QA_SLOW_CONNECTION_THROUGHPUT_KBPS' => :qa_slow_connection_throughput_kbps, 'QA_GENERATE_ALLURE_REPORT' => :generate_allure_report, 'QA_EE_ACTIVATION_CODE' => :ee_activation_code, 'QA_EXPORT_TEST_METRICS' => :qa_export_test_metrics, 'QA_INFLUXDB_URL' => :qa_influxdb_url, 'QA_INFLUXDB_TOKEN' => :qa_influxdb_token, 'QA_RUN_TYPE' => :qa_run_type, 'QA_SKIP_PULL' => :qa_skip_pull, 'GITLAB_API_BASE' => :api_base, 'GITLAB_ADMIN_USERNAME' => :admin_username, 'GITLAB_ADMIN_PASSWORD' => :admin_password, 'GITLAB_USERNAME' => :user_username, 'GITLAB_PASSWORD' => :user_password, 'GITLAB_LDAP_USERNAME' => :ldap_username, 'GITLAB_LDAP_PASSWORD' => :ldap_password, 'GITLAB_FORKER_USERNAME' => :forker_username, 'GITLAB_FORKER_PASSWORD' => :forker_password, 'GITLAB_USER_TYPE' => :user_type, 'GITLAB_SANDBOX_NAME' => :gitlab_sandbox_name, 'GITLAB_QA_ACCESS_TOKEN' => :qa_access_token, 'GITLAB_QA_ADMIN_ACCESS_TOKEN' => :qa_admin_access_token, 'GITLAB_QA_DEV_ACCESS_TOKEN' => :qa_dev_access_token, 'GITLAB_QA_CONTAINER_REGISTRY_ACCESS_TOKEN' => :qa_container_registry_access_token, 'GITLAB_QA_ISSUE_URL' => :qa_issue_url, 'GITHUB_ACCESS_TOKEN' => :github_access_token, 'GITLAB_URL' => :gitlab_url, 'SIMPLE_SAML_HOSTNAME' => :simple_saml_hostname, 'SIMPLE_SAML_FINGERPRINT' => :simple_saml_fingerprint, 'ACCEPT_INSECURE_CERTS' => :accept_insecure_certs, 'EE_LICENSE' => :ee_license, 'GCLOUD_ACCOUNT_EMAIL' => :gcloud_account_email, 'GCLOUD_ACCOUNT_KEY' => :gcloud_account_key, 'CLOUDSDK_CORE_PROJECT' => :cloudsdk_core_project, 'GCLOUD_REGION' => :gcloud_region, 'SIGNUP_DISABLED' => :signup_disabled, 'GITLAB_CI_API_TOKEN' => :gitlab_ci_api_token, 'GITLAB_QA_USERNAME_1' => :gitlab_qa_username_1, 'GITLAB_QA_PASSWORD_1' => :gitlab_qa_password_1, 'GITLAB_QA_USERNAME_2' => :gitlab_qa_username_2, 'GITLAB_QA_PASSWORD_2' => :gitlab_qa_password_2, 'GITHUB_USERNAME' => :github_username, 'GITHUB_PASSWORD' => :github_password, 'KNAPSACK_GENERATE_REPORT' => :knapsack_generate_report, 'KNAPSACK_REPORT_PATH' => :knapsack_report_path, 'KNAPSACK_TEST_FILE_PATTERN' => :knapsack_test_file_pattern, 'KNAPSACK_TEST_DIR' => :knapsack_test_dir, 'QA_KNAPSACK_REPORT_GCS_CREDENTIALS' => :qa_knapsack_report_gcs_credentials, 'CI' => :ci, 'CI_COMMIT_REF_NAME' => :ci_commit_ref_name, 'CI_JOB_NAME' => :ci_job_name, 'CI_JOB_URL' => :ci_job_url, 'CI_JOB_TOKEN' => :ci_job_token, 'CI_RUNNER_ID' => :ci_runner_id, 'CI_SERVER_HOST' => :ci_server_host, 'CI_SERVER_PERSONAL_ACCESS_TOKEN' => :ci_server_personal_access_token, 'CI_NODE_INDEX' => :ci_node_index, 'CI_NODE_TOTAL' => :ci_node_total, 'CI_PROJECT_ID' => :ci_project_id, 'CI_PROJECT_NAME' => :ci_project_name, 'CI_SLACK_WEBHOOK_URL' => :ci_slack_webhook_url, 'CI_PIPELINE_ID' => :ci_pipeline_id, 'CI_PIPELINE_SOURCE' => :ci_pipeline_source, 'CI_PIPELINE_URL' => :ci_pipeline_url, 'CI_PIPELINE_CREATED_AT' => :ci_pipeline_created_at, 'CI_MERGE_REQUEST_IID' => :ci_merge_request_iid, 'CI_API_V4_URL' => :ci_api_v4_url, 'GITLAB_CI' => :gitlab_ci, 'ELASTIC_URL' => :elastic_url, 'GITLAB_QA_LOOP_RUNNER_MINUTES' => :gitlab_qa_loop_runner_minutes, 'MAILHOG_HOSTNAME' => :mailhog_hostname, 'SLACK_QA_CHANNEL' => :slack_qa_channel, 'SLACK_ICON_EMOJI' => :slack_icon_emoji, 'GITLAB_QA_FORMLESS_LOGIN_TOKEN' => :gitlab_qa_formless_login_token, 'GEO_MAX_FILE_REPLICATION_TIME' => :geo_max_file_replication_time, 'GEO_MAX_DB_REPLICATION_TIME' => :geo_max_db_replication_time, 'JIRA_HOSTNAME' => :jira_hostname, 'JIRA_ADMIN_USERNAME' => :jira_admin_username, 'JIRA_ADMIN_PASSWORD' => :jira_admin_password, 'CACHE_NAMESPACE_NAME' => :cache_namespace_name, 'DEPLOY_VERSION' => :deploy_version, 'GITLAB_QA_USER_AGENT' => :gitlab_qa_user_agent, 'GEO_FAILOVER' => :geo_failover, 'GITLAB_INITIAL_ROOT_PASSWORD' => :initial_root_password, 'GITLAB_TLS_CERTIFICATE' => :gitlab_tls_certificate, 'AWS_S3_REGION' => :aws_s3_region, 'AWS_S3_KEY_ID' => :aws_s3_key_id, 'AWS_S3_ACCESS_KEY' => :aws_s3_access_key, 'AWS_S3_BUCKET_NAME' => :aws_s3_bucket_name, 'TOP_UPSTREAM_MERGE_REQUEST_IID' => :top_upstream_merge_request_iid, 'GOOGLE_PROJECT' => :google_project, 'GOOGLE_CLIENT_EMAIL' => :google_client_email, 'GOOGLE_JSON_KEY' => :google_json_key, 'GCS_BUCKET_NAME' => :gcs_bucket_name, 'SMOKE_ONLY' => :smoke_only, 'NO_ADMIN' => :no_admin, 'CHROME_DISABLE_DEV_SHM' => :chrome_disable_dev_shm, 'COLORIZED_LOGS' => :colorized_logs }.freeze
Instance Method Summary collapse
- #colorized_logs? ⇒ Boolean
- #debug? ⇒ Boolean
- #default_branch ⇒ Object
- #deploy_environment ⇒ Object
- #dev_access_token_variable ⇒ Object
- #elastic_version ⇒ Object
- #geo_failover? ⇒ Boolean
- #gitlab_api_base ⇒ Object
- #gitlab_availability_timeout ⇒ Object
- #gitlab_dev_username ⇒ Object
- #gitlab_username ⇒ Object
- #host_artifacts_dir ⇒ Object
- #initial_root_password ⇒ Object
- #override_default_password! ⇒ Object
- #pipeline_from_project_name ⇒ Object
- #qa_export_test_metrics? ⇒ Boolean
- #require_aws_s3_environment! ⇒ Object
- #require_ci_slack_webhook_url! ⇒ Object
- #require_gcs_environment! ⇒ Object
- #require_initial_password! ⇒ Object
- #require_kubernetes_environment! ⇒ Object
- #require_license! ⇒ Object
- #require_no_license! ⇒ Object
- #require_qa_access_token! ⇒ Object
- #require_qa_dev_access_token! ⇒ Object
- #require_slack_qa_channel! ⇒ Object
- #require_ssh_tunnel! ⇒ Object
- #run_id ⇒ Object
- #skip_pull? ⇒ Boolean
- #test_license_mode? ⇒ Boolean
- #variables ⇒ Object
Instance Method Details
#colorized_logs? ⇒ Boolean
185 186 187 |
# File 'lib/gitlab/qa/runtime/env.rb', line 185 def colorized_logs? enabled?(ENV['COLORIZED_LOGS'], default: false) end |
#debug? ⇒ Boolean
153 154 155 |
# File 'lib/gitlab/qa/runtime/env.rb', line 153 def debug? enabled?(ENV['QA_DEBUG'], default: true) end |
#default_branch ⇒ Object
157 158 159 |
# File 'lib/gitlab/qa/runtime/env.rb', line 157 def default_branch env_var_value_if_defined('QA_DEFAULT_BRANCH') || 'main' end |
#deploy_environment ⇒ Object
197 198 199 |
# File 'lib/gitlab/qa/runtime/env.rb', line 197 def deploy_environment env_var_value_if_defined('DEPLOY_ENVIRONMENT') || pipeline_from_project_name end |
#dev_access_token_variable ⇒ Object
189 190 191 |
# File 'lib/gitlab/qa/runtime/env.rb', line 189 def dev_access_token_variable env_var_name_if_defined('GITLAB_QA_DEV_ACCESS_TOKEN') end |
#elastic_version ⇒ Object
205 206 207 |
# File 'lib/gitlab/qa/runtime/env.rb', line 205 def elastic_version env_var_value_if_defined('ELASTIC_VERSION') || '6.4.2'.freeze end |
#geo_failover? ⇒ Boolean
297 298 299 |
# File 'lib/gitlab/qa/runtime/env.rb', line 297 def geo_failover? enabled?(env_var_value_if_defined('GEO_FAILOVER'), default: false) end |
#gitlab_api_base ⇒ Object
173 174 175 |
# File 'lib/gitlab/qa/runtime/env.rb', line 173 def gitlab_api_base env_var_value_if_defined('GITLAB_API_BASE') || 'https://gitlab.com/api/v4' end |
#gitlab_availability_timeout ⇒ Object
161 162 163 |
# File 'lib/gitlab/qa/runtime/env.rb', line 161 def gitlab_availability_timeout (env_var_value_if_defined('GITLAB_QA_AVAILABILITY_TIMEOUT') || 360).to_i end |
#gitlab_dev_username ⇒ Object
169 170 171 |
# File 'lib/gitlab/qa/runtime/env.rb', line 169 def gitlab_dev_username env_var_value_if_defined('GITLAB_DEV_USERNAME') || 'gitlab-qa-bot' end |
#gitlab_username ⇒ Object
165 166 167 |
# File 'lib/gitlab/qa/runtime/env.rb', line 165 def gitlab_username env_var_value_if_defined('GITLAB_USERNAME') || 'gitlab-qa' end |
#host_artifacts_dir ⇒ Object
201 202 203 |
# File 'lib/gitlab/qa/runtime/env.rb', line 201 def host_artifacts_dir @host_artifacts_dir ||= File.join(env_var_value_if_defined('QA_ARTIFACTS_DIR') || '/tmp/gitlab-qa', Runtime::Env.run_id) end |
#initial_root_password ⇒ Object
193 194 195 |
# File 'lib/gitlab/qa/runtime/env.rb', line 193 def initial_root_password env_var_value_if_defined('GITLAB_INITIAL_ROOT_PASSWORD') || '5iveL!fe' end |
#override_default_password! ⇒ Object
286 287 288 289 290 291 |
# File 'lib/gitlab/qa/runtime/env.rb', line 286 def override_default_password! require_initial_password! ENV['GITLAB_PASSWORD'] = initial_root_password ENV['GITLAB_ADMIN_PASSWORD'] = initial_root_password end |
#pipeline_from_project_name ⇒ Object
177 178 179 |
# File 'lib/gitlab/qa/runtime/env.rb', line 177 def pipeline_from_project_name ci_project_name.to_s.start_with?('gitlab-qa') ? QA::Runtime::Env.default_branch : ci_project_name end |
#qa_export_test_metrics? ⇒ Boolean
305 306 307 |
# File 'lib/gitlab/qa/runtime/env.rb', line 305 def qa_export_test_metrics? enabled?(env_var_value_if_defined('QA_EXPORT_TEST_METRICS'), default: true) end |
#require_aws_s3_environment! ⇒ Object
253 254 255 256 257 258 259 |
# File 'lib/gitlab/qa/runtime/env.rb', line 253 def require_aws_s3_environment! %w[AWS_S3_REGION AWS_S3_KEY_ID AWS_S3_ACCESS_KEY AWS_S3_BUCKET_NAME].each do |env_key| unless ENV.key?(env_key) raise ArgumentError, "Environment variable #{env_key} must be set to run AWS S3 object storage specs" end end end |
#require_ci_slack_webhook_url! ⇒ Object
239 240 241 242 243 |
# File 'lib/gitlab/qa/runtime/env.rb', line 239 def require_ci_slack_webhook_url! return unless env_var_value_if_defined('CI_SLACK_WEBHOOK_URL').to_s.strip.empty? raise ArgumentError, "Please provide CI_SLACK_WEBHOOK_URL" end |
#require_gcs_environment! ⇒ Object
261 262 263 264 265 266 267 |
# File 'lib/gitlab/qa/runtime/env.rb', line 261 def require_gcs_environment! %w[GOOGLE_PROJECT GOOGLE_CLIENT_EMAIL GOOGLE_JSON_KEY GCS_BUCKET_NAME].each do |env_key| unless ENV.key?(env_key) raise ArgumentError, "Environment variable #{env_key} must be set to run GCS object storage specs" end end end |
#require_initial_password! ⇒ Object
269 270 271 272 273 274 275 276 |
# File 'lib/gitlab/qa/runtime/env.rb', line 269 def require_initial_password! return unless env_var_value_if_defined('GITLAB_INITIAL_ROOT_PASSWORD').to_s.strip.empty? raise( ArgumentError, "Environment variable GITLAB_INITIAL_ROOT_PASSWORD must be provided to set an initial root password." ) end |
#require_kubernetes_environment! ⇒ Object
245 246 247 248 249 250 251 |
# File 'lib/gitlab/qa/runtime/env.rb', line 245 def require_kubernetes_environment! %w[GCLOUD_ACCOUNT_EMAIL GCLOUD_ACCOUNT_KEY CLOUDSDK_CORE_PROJECT].each do |env_key| unless ENV.key?(env_key) raise ArgumentError, "Environment variable #{env_key} must be set to run kubernetes specs" end end end |
#require_license! ⇒ Object
209 210 211 212 213 |
# File 'lib/gitlab/qa/runtime/env.rb', line 209 def require_license! return if ENV.include?('EE_LICENSE') raise ArgumentError, 'GitLab License is not available. Please load a license into EE_LICENSE env variable.' end |
#require_no_license! ⇒ Object
215 216 217 218 219 |
# File 'lib/gitlab/qa/runtime/env.rb', line 215 def require_no_license! return unless ENV.include?('EE_LICENSE') raise ArgumentError, "Unexpected EE_LICENSE provided. Please unset it to continue." end |
#require_qa_access_token! ⇒ Object
221 222 223 224 225 |
# File 'lib/gitlab/qa/runtime/env.rb', line 221 def require_qa_access_token! return unless env_var_value_if_defined('GITLAB_QA_ACCESS_TOKEN').to_s.strip.empty? raise ArgumentError, "Please provide GITLAB_QA_ACCESS_TOKEN" end |
#require_qa_dev_access_token! ⇒ Object
227 228 229 230 231 |
# File 'lib/gitlab/qa/runtime/env.rb', line 227 def require_qa_dev_access_token! return unless env_var_value_if_defined('GITLAB_QA_DEV_ACCESS_TOKEN').to_s.strip.empty? raise ArgumentError, "Please provide GITLAB_QA_DEV_ACCESS_TOKEN" end |
#require_slack_qa_channel! ⇒ Object
233 234 235 236 237 |
# File 'lib/gitlab/qa/runtime/env.rb', line 233 def require_slack_qa_channel! return unless env_var_value_if_defined('SLACK_QA_CHANNEL').to_s.strip.empty? raise ArgumentError, "Please provide SLACK_QA_CHANNEL" end |
#require_ssh_tunnel! ⇒ Object
278 279 280 281 282 283 284 |
# File 'lib/gitlab/qa/runtime/env.rb', line 278 def require_ssh_tunnel! %w[TUNNEL_SSH_PRIVATE_KEY TUNNEL_SERVER_HOSTNAME TUNNEL_SSH_USER].each do |env_key| unless ENV.key?(env_key) raise ArgumentError, "Environment variable #{env_key} must be set to run tunnel specs" end end end |
#run_id ⇒ Object
181 182 183 |
# File 'lib/gitlab/qa/runtime/env.rb', line 181 def run_id @run_id ||= "gitlab-qa-run-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}-#{SecureRandom.hex(4)}" end |
#skip_pull? ⇒ Boolean
293 294 295 |
# File 'lib/gitlab/qa/runtime/env.rb', line 293 def skip_pull? enabled?(env_var_value_if_defined('QA_SKIP_PULL'), default: false) end |
#test_license_mode? ⇒ Boolean
301 302 303 |
# File 'lib/gitlab/qa/runtime/env.rb', line 301 def test_license_mode? enabled?(env_var_value_if_defined('TEST_LICENSE_MODE'), default: false) end |
#variables ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/gitlab/qa/runtime/env.rb', line 144 def variables ENV_VARIABLES.each_with_object({}) do |(name, attribute), vars| # Variables that are overridden in the environment take precedence # over the defaults specified by the QA runtime. value = env_var_name_if_defined(name) || send(attribute) # rubocop:disable GitlabSecurity/PublicSend vars[name] = value if value end end |