gitlab-qa 6.21.4 → 7.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +32 -31
  3. data/docs/configuring_omnibus.md +208 -0
  4. data/docs/run_qa_against_gdk.md +4 -0
  5. data/docs/what_tests_can_be_run.md +46 -8
  6. data/gitlab-qa.gemspec +6 -4
  7. data/lib/gitlab/qa.rb +7 -0
  8. data/lib/gitlab/qa/component/gitlab.rb +36 -29
  9. data/lib/gitlab/qa/component/minio.rb +2 -10
  10. data/lib/gitlab/qa/component/specs.rb +10 -9
  11. data/lib/gitlab/qa/docker/engine.rb +36 -5
  12. data/lib/gitlab/qa/report/test_result.rb +5 -1
  13. data/lib/gitlab/qa/runner.rb +57 -5
  14. data/lib/gitlab/qa/runtime/env.rb +2 -0
  15. data/lib/gitlab/qa/runtime/omnibus_configuration.rb +70 -0
  16. data/lib/gitlab/qa/runtime/omnibus_configurations/default.rb +25 -0
  17. data/lib/gitlab/qa/runtime/omnibus_configurations/object_storage.rb +48 -0
  18. data/lib/gitlab/qa/runtime/omnibus_configurations/packages.rb +17 -0
  19. data/lib/gitlab/qa/scenario/cli_commands.rb +3 -3
  20. data/lib/gitlab/qa/scenario/test/instance/relative_url.rb +1 -3
  21. data/lib/gitlab/qa/scenario/test/instance/repository_storage.rb +1 -1
  22. data/lib/gitlab/qa/scenario/test/integration/actioncable.rb +1 -3
  23. data/lib/gitlab/qa/scenario/test/integration/geo.rb +4 -5
  24. data/lib/gitlab/qa/scenario/test/integration/gitaly_cluster.rb +4 -5
  25. data/lib/gitlab/qa/scenario/test/integration/group_saml.rb +1 -1
  26. data/lib/gitlab/qa/scenario/test/integration/instance_saml.rb +1 -1
  27. data/lib/gitlab/qa/scenario/test/integration/kubernetes.rb +1 -1
  28. data/lib/gitlab/qa/scenario/test/integration/ldap.rb +1 -4
  29. data/lib/gitlab/qa/scenario/test/integration/ldap_no_server.rb +1 -1
  30. data/lib/gitlab/qa/scenario/test/integration/ldap_no_tls.rb +1 -1
  31. data/lib/gitlab/qa/scenario/test/integration/ldap_tls.rb +1 -2
  32. data/lib/gitlab/qa/scenario/test/integration/mattermost.rb +1 -1
  33. data/lib/gitlab/qa/scenario/test/integration/mtls.rb +3 -7
  34. data/lib/gitlab/qa/scenario/test/integration/smtp.rb +1 -1
  35. data/lib/gitlab/qa/scenario/test/integration/ssh_tunnel.rb +1 -1
  36. data/lib/gitlab/qa/version.rb +1 -1
  37. data/tls_certificates/authority/ca.crt +32 -0
  38. data/tls_certificates/authority/ca.key +51 -0
  39. data/tls_certificates/authority/ca.pem +83 -0
  40. data/tls_certificates/gitaly/gitaly.test.crt +30 -0
  41. data/tls_certificates/gitaly/gitaly.test.csr +28 -0
  42. data/tls_certificates/gitaly/gitaly.test.key +51 -0
  43. data/tls_certificates/gitlab/gitlab.test.crt +28 -29
  44. data/tls_certificates/gitlab/gitlab.test.csr +28 -0
  45. data/tls_certificates/gitlab/gitlab.test.key +51 -52
  46. metadata +19 -13
  47. data/lib/gitlab/qa/scenario/test/integration/object_storage.rb +0 -64
  48. data/lib/gitlab/qa/scenario/test/integration/packages.rb +0 -36
  49. data/tls_certificates/gitaly/ssl/gitaly.test.crt +0 -33
  50. data/tls_certificates/gitaly/ssl/gitaly.test.key +0 -52
  51. data/tls_certificates/gitaly/trusted-certs/gitaly.test.crt +0 -33
  52. data/tls_certificates/gitaly/trusted-certs/gitlab.test.crt +0 -31
@@ -37,6 +37,10 @@ make a few changes to your `gdk/gitlab/config/gitlab.yml` file.
37
37
  # build the QA image first
38
38
  # In gdk/gitlab:
39
39
  $ docker build -t gitlab/gitlab-ce-qa:your-custom-tag --file ./qa/Dockerfile ./
40
+
41
+ # Note: You will also need a corresponding GitLab image.
42
+ # For example, if you haven't changed any application code (e.g., no new elements), you could tag the current nightly build:
43
+ $ docker tag gitlab/gitlab-ce:nightly gitlab/gitlab-ce:your-custom-tag
40
44
 
41
45
  # Then in gitlab-qa:
42
46
  $ exe/gitlab-qa Test::Instance::Any gitlab/gitlab-ce:your-custom-tag http://192.168.0.12:3000 -- qa/specs/features/browser_ui/1_manage/login/log_in_spec.rb
@@ -143,6 +143,40 @@ To run EE tests, the `EE_LICENSE` environment variable needs to be set:
143
143
 
144
144
  `$ export EE_LICENSE=$(cat /path/to/GitLab.gitlab_license)`
145
145
 
146
+ ## Specifying the GitLab QA image to use
147
+
148
+ By default, `gitlab-qa` infers the QA image to use based on the GitLab image.
149
+ For instance, if you run the following:
150
+
151
+ ```
152
+ $ gitlab-qa Test::Instance::Image gitlab/gitlab-ee:12.4.0-ee.0
153
+ ```
154
+
155
+ Then, `gitlab-qa` would infer `gitlab/gitlab-ee-qa:12.4.0-ee.0` as the QA image
156
+ based on the GitLab image (note the `-qa` suffix in the image name).
157
+
158
+ In some cases, you'll want to use a specific QA image instead of letting
159
+ `gitlab-qa` infer the QA image name from the GitLab image. Such cases can be
160
+ when you're doing local debugging/testing and you want to control the QA image
161
+ name, or in the CI where the QA image might be built by a project (e.g.
162
+ `gitlab-org/gitlab`, and the GitLab image might be built by another project
163
+ (e.g. `gitlab-org/omnibus-gitlab-mirror`).
164
+
165
+ To specify the QA image to use, pass the `--qa-image QA_IMAGE` option,
166
+ as follows:
167
+
168
+ ```
169
+ $ gitlab-qa Test::Instance::Image --qa-image registry.gitlab.com/gitlab-org/gitlab/gitlab-ee-qa:branch-name EE
170
+ ```
171
+
172
+ Additionally, setting the `$QA_IMAGE` environment variable achieve the same result,
173
+ without needing to pass the `--qa-image` option:
174
+
175
+ ```
176
+ $ export QA_IMAGE="registry.gitlab.com/gitlab-org/gitlab/gitlab-ee-qa:branch-name"
177
+ $ gitlab-qa Test::Instance::Image EE
178
+ ```
179
+
146
180
  ## Running a specific test (or set of tests)
147
181
 
148
182
  In most of the scenarios listed below, if you don't want to run all the tests
@@ -500,6 +534,18 @@ $ gitlab-qa Test::Integration::Mattermost EE
500
534
 
501
535
  ### `Test::Integration::Packages CE|EE|<full image address>`
502
536
 
537
+ **Note: This Scenario no longer exists. See https://gitlab.com/gitlab-org/gitlab-qa/-/merge_requests/662**
538
+
539
+ To run Packages tests, you may [configure Omnibus](configuring_omnibus.md) to use the [Packages](https://gitlab.com/gitlab-org/gitlab-qa/-/blob/master/lib/gitlab/qa/runtime/omnibus_configurations/packages.rb) configurator.
540
+
541
+ Example:
542
+
543
+ ```
544
+ $ export EE_LICENSE=$(cat /path/to/Geo.gitlab_license)
545
+
546
+ $ gitlab-qa Test::Instance::Image EE --omnibus-config packages
547
+ ```
548
+
503
549
  This tests the GitLab Package Registry feature by setting
504
550
  `gitlab_rails['packages_enabled'] = true` in the Omnibus configuration
505
551
  before starting the GitLab container.
@@ -513,14 +559,6 @@ which runs only the tests with `:packages` metadata.
513
559
 
514
560
  - `EE_LICENSE`: A valid EE license.
515
561
 
516
- Example:
517
-
518
- ```
519
- $ export EE_LICENSE=$(cat /path/to/Geo.gitlab_license)
520
-
521
- $ gitlab-qa Test::Integration::Packages EE
522
- ```
523
-
524
562
  ### `Test::Integration::Praefect CE|EE|<full image address>`
525
563
 
526
564
  This tests [Praefect](https://docs.gitlab.com/ee/administration/gitaly/praefect.html),
data/gitlab-qa.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'gitlab/qa/version'
@@ -5,11 +7,11 @@ require 'gitlab/qa/version'
5
7
  Gem::Specification.new do |spec|
6
8
  spec.name = 'gitlab-qa'
7
9
  spec.version = Gitlab::QA::VERSION
8
- spec.authors = ['Grzegorz Bizon']
9
- spec.email = ['grzesiek.bizon@gmail.com']
10
+ spec.authors = ['GitLab Quality']
11
+ spec.email = ['gitlab-qa@gmail.com']
10
12
 
11
13
  spec.summary = 'Integration tests for GitLab'
12
- spec.homepage = 'http://about.gitlab.com'
14
+ spec.homepage = 'http://about.gitlab.com/'
13
15
  spec.license = 'MIT'
14
16
 
15
17
  spec.files = `git ls-files -z`
@@ -31,5 +33,5 @@ Gem::Specification.new do |spec|
31
33
  spec.add_runtime_dependency 'gitlab', '~> 4.16.1'
32
34
  spec.add_runtime_dependency 'http', '4.3.0'
33
35
  spec.add_runtime_dependency 'nokogiri', '~> 1.10'
34
- spec.add_runtime_dependency 'table_print', '1.5.6'
36
+ spec.add_runtime_dependency 'table_print', '1.5.7'
35
37
  end
data/lib/gitlab/qa.rb CHANGED
@@ -8,6 +8,13 @@ module Gitlab
8
8
  autoload :Env, 'gitlab/qa/runtime/env'
9
9
  autoload :Scenario, 'gitlab/qa/runtime/scenario'
10
10
  autoload :TokenFinder, 'gitlab/qa/runtime/token_finder'
11
+ autoload :OmnibusConfiguration, 'gitlab/qa/runtime/omnibus_configuration'
12
+
13
+ module OmnibusConfigurations
14
+ autoload :Default, 'gitlab/qa/runtime/omnibus_configurations/default'
15
+ autoload :Packages, 'gitlab/qa/runtime/omnibus_configurations/packages'
16
+ autoload :ObjectStorage, 'gitlab/qa/runtime/omnibus_configurations/object_storage'
17
+ end
11
18
  end
12
19
 
13
20
  module Scenario
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
  require 'net/http'
3
5
  require 'uri'
@@ -10,38 +12,36 @@ module Gitlab
10
12
  class Gitlab < Base
11
13
  extend Forwardable
12
14
 
13
- attr_reader :release
14
- attr_accessor :tls, :disable_animations, :skip_availability_check, :runner_network
15
+ attr_reader :release, :omnibus_configuration
16
+ attr_accessor :tls, :skip_availability_check, :runner_network
15
17
  attr_writer :name, :relative_path
16
18
 
17
19
  def_delegators :release, :tag, :image, :edition
18
20
 
19
- GITLAB_CERTIFICATES_PATH = File.expand_path('../../../../tls_certificates/gitlab'.freeze, __dir__)
20
- GITALY_CERTIFICATES_PATH = File.expand_path('../../../../tls_certificates/gitaly/ssl'.freeze, __dir__)
21
- TRUSTED_CERTIFICATES_PATH = File.expand_path('../../../../tls_certificates/gitaly/trusted-certs'.freeze, __dir__)
21
+ AUTHORITY_CERTIFICATES_PATH = File.expand_path('../../../../tls_certificates/authority', __dir__)
22
+ GITLAB_CERTIFICATES_PATH = File.expand_path('../../../../tls_certificates/gitlab', __dir__)
23
+ GITALY_CERTIFICATES_PATH = File.expand_path('../../../../tls_certificates/gitaly', __dir__)
22
24
 
23
- SSL_PATH = '/etc/gitlab/ssl'.freeze
24
- TRUSTED_PATH = '/etc/gitlab/trusted-certs'.freeze
25
+ SSL_PATH = '/etc/gitlab/ssl'
26
+ TRUSTED_PATH = '/etc/gitlab/trusted-certs'
25
27
 
26
28
  def initialize
27
29
  super
28
30
 
29
- @disable_animations = true
30
31
  @skip_availability_check = false
31
32
 
32
33
  @volumes[GITLAB_CERTIFICATES_PATH] = SSL_PATH
34
+ @volumes[AUTHORITY_CERTIFICATES_PATH] = TRUSTED_PATH
33
35
 
34
- self.release = 'CE'
35
- end
36
+ @omnibus_configuration ||= OmnibusConfiguration.new
36
37
 
37
- def omnibus_config=(config)
38
- @environment['GITLAB_OMNIBUS_CONFIG'] = config.tr("\n", ' ')
38
+ self.release = 'CE'
39
39
  end
40
40
 
41
41
  def set_formless_login_token
42
42
  return if Runtime::Env.gitlab_qa_formless_login_token.to_s.strip.empty?
43
43
 
44
- @environment['GITLAB_OMNIBUS_CONFIG'] = "gitlab_rails['env'] = { 'GITLAB_QA_FORMLESS_LOGIN_TOKEN' => '#{Runtime::Env.gitlab_qa_formless_login_token}' }; #{@environment['GITLAB_OMNIBUS_CONFIG'] || ''}"
44
+ @omnibus_configuration << "gitlab_rails['env'] = { 'GITLAB_QA_FORMLESS_LOGIN_TOKEN' => '#{Runtime::Env.gitlab_qa_formless_login_token}' }"
45
45
  end
46
46
 
47
47
  def elastic_url=(url)
@@ -68,14 +68,9 @@ module Gitlab
68
68
  tls ? '443' : '80'
69
69
  end
70
70
 
71
- def mtls
71
+ def gitaly_tls
72
72
  @volumes.delete(GITLAB_CERTIFICATES_PATH)
73
73
  @volumes[GITALY_CERTIFICATES_PATH] = SSL_PATH
74
- set_trusted_certificates
75
- end
76
-
77
- def set_trusted_certificates
78
- @volumes[TRUSTED_CERTIFICATES_PATH] = TRUSTED_PATH
79
74
  end
80
75
 
81
76
  def relative_path
@@ -99,17 +94,7 @@ module Gitlab
99
94
  end
100
95
 
101
96
  def prepare_gitlab_omnibus_config
102
- setup_disable_animations if disable_animations
103
97
  set_formless_login_token
104
- setup_application_settings_cache_expiry
105
- end
106
-
107
- def setup_disable_animations
108
- @environment['GITLAB_OMNIBUS_CONFIG'] = "gitlab_rails['gitlab_disable_animations'] = true; #{@environment['GITLAB_OMNIBUS_CONFIG'] || ''}"
109
- end
110
-
111
- def setup_application_settings_cache_expiry
112
- @environment['GITLAB_OMNIBUS_CONFIG'] = "gitlab_rails['application_settings_cache_seconds'] = 0; #{@environment['GITLAB_OMNIBUS_CONFIG'] || ''}"
113
98
  end
114
99
 
115
100
  def start # rubocop:disable Metrics/AbcSize
@@ -139,6 +124,8 @@ module Gitlab
139
124
  end
140
125
 
141
126
  def reconfigure
127
+ setup_omnibus
128
+
142
129
  @docker.attach(name) do |line, wait|
143
130
  puts line
144
131
  # TODO, workaround which allows to detach from the container
@@ -174,6 +161,12 @@ module Gitlab
174
161
  raise 'Please configure an instance first!' unless [name, release, network].all?
175
162
  end
176
163
 
164
+ def setup_omnibus
165
+ @docker.write_files(name) do |f|
166
+ f.write('/etc/gitlab/gitlab.rb', @omnibus_configuration.to_s)
167
+ end
168
+ end
169
+
177
170
  class Availability
178
171
  def initialize(name, relative_path: '', scheme: 'http', protocol_port: 80)
179
172
  @docker = Docker::Engine.new
@@ -213,6 +206,20 @@ module Gitlab
213
206
  @uri.scheme == 'https' ? { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE } : {}
214
207
  end
215
208
  end
209
+
210
+ class OmnibusConfiguration
211
+ def initialize
212
+ @config = Runtime::Scenario.attributes[:omnibus_configuration] || []
213
+ end
214
+
215
+ def <<(configuration)
216
+ @config << configuration
217
+ end
218
+
219
+ def to_s
220
+ @config.to_s
221
+ end
222
+ end
216
223
  end
217
224
  end
218
225
  end
@@ -1,5 +1,6 @@
1
1
  require 'securerandom'
2
2
  require 'fileutils'
3
+ require 'yaml'
3
4
 
4
5
  # This component sets up the Minio (https://hub.docker.com/r/minio/minio)
5
6
  # image with the proper configuration for GitLab users to use object storage.
@@ -23,18 +24,12 @@ module Gitlab
23
24
  @buckets = []
24
25
  end
25
26
 
26
- def instance
27
- raise 'Please provide a block!' unless block_given?
28
-
29
- super
30
- end
31
-
32
27
  def add_bucket(name)
33
28
  @buckets << name
34
29
  end
35
30
 
36
31
  def to_config
37
- config = YAML.safe_load <<~CFG
32
+ YAML.safe_load <<~CFG
38
33
  provider: AWS
39
34
  aws_access_key_id: #{AWS_ACCESS_KEY}
40
35
  aws_secret_access_key: #{AWS_SECRET_KEY}
@@ -43,9 +38,6 @@ module Gitlab
43
38
  endpoint: http://#{hostname}:#{port}
44
39
  path_style: true
45
40
  CFG
46
-
47
- # Quotes get eaten up when the string is set in the environment
48
- config.to_s.gsub('"', '\\"')
49
41
  end
50
42
 
51
43
  private
@@ -10,9 +10,6 @@ module Gitlab
10
10
  class Specs < Scenario::Template
11
11
  attr_accessor :suite, :release, :network, :args, :volumes, :env, :runner_network
12
12
 
13
- TRUSTED_CERTIFICATES_PATH = File.expand_path('../../../../tls_certificates/gitaly/trusted-certs'.freeze, __dir__)
14
- TRUSTED_PATH = '/etc/ssl/certs'.freeze
15
-
16
13
  def initialize
17
14
  @docker = Docker::Engine.new
18
15
  @volumes = {}
@@ -26,7 +23,7 @@ module Gitlab
26
23
 
27
24
  @docker.login(**release.login_params) if release.login_params
28
25
 
29
- @docker.pull(release.qa_image, release.qa_tag) unless Runtime::Env.skip_pull?
26
+ @docker.pull(qa_image) unless Runtime::Env.skip_pull?
30
27
 
31
28
  puts "Running test suite `#{suite}` for #{release.project_name}"
32
29
 
@@ -46,7 +43,7 @@ module Gitlab
46
43
  feature_flag_sets << [] unless feature_flag_sets.any?
47
44
 
48
45
  feature_flag_sets.each do |feature_flag_set|
49
- @docker.run(release.qa_image, release.qa_tag, suite, *args_with_flags(args, feature_flag_set)) do |command|
46
+ @docker.run(qa_image, nil, suite, *args_with_flags(args, feature_flag_set)) do |command|
50
47
  command << "-t --rm --net=#{network || 'bridge'}"
51
48
 
52
49
  env.merge(Runtime::Env.variables).each do |key, value|
@@ -65,10 +62,6 @@ module Gitlab
65
62
  end
66
63
  end
67
64
 
68
- def mtls
69
- @volumes[TRUSTED_CERTIFICATES_PATH] = TRUSTED_PATH
70
- end
71
-
72
65
  private
73
66
 
74
67
  def args_with_flags(args, feature_flag_set)
@@ -83,6 +76,14 @@ module Gitlab
83
76
  def skip_tests?
84
77
  Runtime::Scenario.attributes.include?(:run_tests) && !Runtime::Scenario.run_tests
85
78
  end
79
+
80
+ def qa_image
81
+ if Runtime::Scenario.attributes.include?(:qa_image)
82
+ Runtime::Scenario.qa_image
83
+ else
84
+ "#{release.qa_image}:#{release.qa_tag}"
85
+ end
86
+ end
86
87
  end
87
88
  end
88
89
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  module QA
3
5
  module Docker
@@ -13,15 +15,15 @@ module Gitlab
13
15
  Docker::Command.execute(%(login --username "#{username}" --password "#{password}" #{registry}), mask_secrets: password)
14
16
  end
15
17
 
16
- def pull(image, tag)
17
- Docker::Command.execute("pull #{image}:#{tag}")
18
+ def pull(image, tag = nil)
19
+ Docker::Command.execute("pull #{full_image_name(image, tag)}")
18
20
  end
19
21
 
20
22
  def run(image, tag, *args)
21
23
  Docker::Command.new('run').tap do |command|
22
24
  yield command if block_given?
23
25
 
24
- command << "#{image}:#{tag}"
26
+ command << full_image_name(image, tag)
25
27
  command << args if args.any?
26
28
 
27
29
  command.execute!
@@ -36,14 +38,37 @@ module Gitlab
36
38
  false
37
39
  end
38
40
 
41
+ # Write to file(s) in the Docker container specified by @param name
42
+ # @param name The name of the Docker Container
43
+ # @example
44
+ # engine.write_files('gitlab-abc123') do |files|
45
+ # files.append('/etc/hosts', '127.0.0.1 localhost')
46
+ # files.write('/opt/other', <<~TEXT
47
+ # This is content
48
+ # That goes within /opt/other
49
+ # TEXT)
50
+ def write_files(name)
51
+ exec(name, yield(
52
+ Class.new do
53
+ def self.write(file, contents)
54
+ %(echo "#{contents}" > #{file};)
55
+ end
56
+
57
+ def self.append(file, contents)
58
+ %(echo "#{contents}" >> #{file};)
59
+ end
60
+ end
61
+ ))
62
+ end
63
+
39
64
  def exec(name, command)
40
65
  cmd = ['exec']
41
66
  cmd << '--privileged' if privileged_command?(command)
42
- Docker::Command.execute("#{cmd.join(' ')} #{name} bash -c '#{command}'")
67
+ Docker::Command.execute(%(#{cmd.join(' ')} #{name} bash -c "#{command.gsub('"', '\\"')}"))
43
68
  end
44
69
 
45
70
  def read_file(image, tag, path, &block)
46
- cat_file = "run --rm --entrypoint /bin/cat #{image}:#{tag} #{path}"
71
+ cat_file = "run --rm --entrypoint /bin/cat #{full_image_name(image, tag)} #{path}"
47
72
  Docker::Command.execute(cat_file, &block)
48
73
  end
49
74
 
@@ -94,6 +119,12 @@ module Gitlab
94
119
  def ps(name = nil)
95
120
  Docker::Command.execute(['ps', name].compact.join(' '))
96
121
  end
122
+
123
+ private
124
+
125
+ def full_image_name(image, tag)
126
+ [image, tag].compact.join(':')
127
+ end
97
128
  end
98
129
  end
99
130
  end
@@ -101,10 +101,14 @@ module Gitlab
101
101
  {
102
102
  'message' => "#{exception['class']}: #{exception['message']}",
103
103
  'message_lines' => exception['message_lines'],
104
- 'stacktrace' => "#{exception['message_lines'].join("\n")}\n#{exception['backtrace'].slice(0..spec_file_first_index).join("\n")}"
104
+ 'stacktrace' => "#{format_message_lines(exception['message_lines'])}\n#{exception['backtrace'].slice(0..spec_file_first_index).join("\n")}"
105
105
  }
106
106
  end
107
107
  end
108
+
109
+ def format_message_lines(message_lines)
110
+ message_lines.is_a?(Array) ? message_lines.join("\n") : message_lines
111
+ end
108
112
  # rubocop:enable Metrics/AbcSize
109
113
  end
110
114
 
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'optparse'
4
+ require 'active_support/inflector'
2
5
 
3
6
  module Gitlab
4
7
  module QA
@@ -7,6 +10,12 @@ module Gitlab
7
10
  def self.run(args)
8
11
  Runtime::Scenario.define(:teardown, true)
9
12
  Runtime::Scenario.define(:run_tests, true)
13
+ Runtime::Scenario.define(:qa_image, Runtime::Env.qa_image) if Runtime::Env.qa_image
14
+ Runtime::Scenario.define(:omnibus_configuration, Runtime::OmnibusConfiguration.new)
15
+
16
+ # Omnibus Configurators specified by flags
17
+ @active_configurators = []
18
+ @omnibus_configurations = %w[default] # always load default configuration
10
19
 
11
20
  @options = OptionParser.new do |opts|
12
21
  opts.banner = 'Usage: gitlab-qa [options] Scenario URL [[--] path] [rspec_options]'
@@ -20,12 +29,22 @@ module Gitlab
20
29
  Runtime::Scenario.define(:teardown, false)
21
30
  end
22
31
 
32
+ opts.on('--qa-image QA_IMAGE', String, 'Specifies a QA image to be used instead of inferring it from the GitLab image. See Gitlab::QA::Release#qa_image') do |value|
33
+ Runtime::Scenario.define(:qa_image, value)
34
+ end
35
+
23
36
  opts.on_tail('-v', '--version', 'Show the version') do
24
37
  require 'gitlab/qa/version'
25
38
  puts "#{$PROGRAM_NAME} : #{VERSION}"
26
39
  exit
27
40
  end
28
41
 
42
+ opts.on('--omnibus-config config1[,config2,...]', 'Use Omnibus Configuration package') do |configuration|
43
+ configuration.split(',').map do |config|
44
+ @omnibus_configurations << config
45
+ end
46
+ end
47
+
29
48
  opts.on_tail('-h', '--help', 'Show the usage') do
30
49
  puts opts
31
50
  exit
@@ -39,21 +58,54 @@ module Gitlab
39
58
  end
40
59
 
41
60
  args.reject! { |arg| gitlab_qa_options.include?(arg) }
42
-
43
61
  if args.size >= 1
44
- Scenario
45
- .const_get(args.shift)
46
- .perform(*args)
62
+ load_omnibus_configurations
63
+
64
+ begin
65
+ @active_configurators.compact.each do |configurator|
66
+ configurator.instance(skip_teardown: true)
67
+ end
68
+
69
+ Scenario
70
+ .const_get(args.shift)
71
+ .perform(*args)
72
+ ensure
73
+ @active_configurators.compact.each(&:teardown)
74
+ end
47
75
  else
48
76
  puts @options
49
77
  exit 1
50
78
  end
51
79
  end
52
- # rubocop:enable Metrics/AbcSize
53
80
 
54
81
  def self.gitlab_qa_options
55
82
  @gitlab_qa_options ||= @options.top.list.map(&:long).flatten
56
83
  end
84
+
85
+ def self.load_omnibus_configurations
86
+ # OmnibusConfiguration::Test => --test
87
+ # OmnibusConfiguration::HelloThere => --hello_there
88
+ @omnibus_configurations.uniq.each do |config|
89
+ Runtime::OmnibusConfigurations.const_get(config.camelize).new.tap do |configurator|
90
+ @active_configurators << configurator.prepare
91
+
92
+ # */etc/gitlab/gitlab.rb*
93
+ # -----------------------
94
+ # # Runtime::OmnibusConfiguration::Packages
95
+ # gitlab_rails['packages_enabled'] = true
96
+ Runtime::Scenario.omnibus_configuration << "# #{configurator.class.name}"
97
+
98
+ # Load the configuration
99
+ configurator.configuration.split("\n").each { |c| Runtime::Scenario.omnibus_configuration << c }
100
+ end
101
+ rescue NameError
102
+ raise <<~ERROR
103
+ Invalid Omnibus Configuration `#{config}`.
104
+ Possible configurations: #{Runtime::OmnibusConfigurations.constants.map { |c| c.to_s.underscore }.join(',')}"
105
+ ERROR
106
+ end
107
+ end
57
108
  end
109
+ # rubocop:enable Metrics/AbcSize
58
110
  end
59
111
  end