Class: Gitlab::QA::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/qa/runner.rb

Overview

rubocop:disable Metrics/AbcSize

Class Method Summary collapse

Class Method Details

.gitlab_qa_optionsObject



112
113
114
# File 'lib/gitlab/qa/runner.rb', line 112

def self.gitlab_qa_options
  @gitlab_qa_options ||= @options.top.list
end

.load_omnibus_configurationsObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/gitlab/qa/runner.rb', line 131

def self.load_omnibus_configurations
  # OmnibusConfiguration::Test       => --test
  # OmnibusConfiguration::HelloThere => --hello_there
  @omnibus_configurations.uniq.each do |config|
    Runtime::OmnibusConfigurations.const_get(config.camelize).new.tap do |configurator|
      @active_configurators << configurator.prepare

      # */etc/gitlab/gitlab.rb*
      # -----------------------
      # # Runtime::OmnibusConfiguration::Packages
      # gitlab_rails['packages_enabled'] = true
      Runtime::Scenario.omnibus_configuration << "# #{configurator.class.name}"
      Runtime::Scenario.omnibus_exec_commands << configurator.exec_commands

      # Load the configuration
      Runtime::Scenario.omnibus_configuration << configurator.configuration
    end
  rescue NameError
    raise <<~ERROR
      Invalid Omnibus Configuration `#{config}`.
      Possible configurations: #{Runtime::OmnibusConfigurations.constants.map { |c| c.to_s.underscore }.join(',')}"
    ERROR
  end
end

.remove_gitlab_qa_args(args) ⇒ Object

Take a set of arguments and remove them from the set of predefined GitLab QA arguments

Parameters:

  • args

    Array the arguments to parse through and remove GitLab QA opts

Returns:

  • Arguments to be passed ultimately to the RSpec runner



120
121
122
123
124
125
126
127
128
129
# File 'lib/gitlab/qa/runner.rb', line 120

def self.remove_gitlab_qa_args(args)
  args.each_with_index do |arg, i|
    gitlab_qa_options.each do |opt|
      next unless opt.long.flatten.first == arg

      args[i] = nil
      args[i + 1] = nil if opt.is_a? OptionParser::Switch::RequiredArgument
    end
  end.compact
end

.run(args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/gitlab/qa/runner.rb', line 10

def self.run(args)
  Runtime::Scenario.define(:teardown, true)
  Runtime::Scenario.define(:run_tests, true)
  Runtime::Scenario.define(:qa_image, Runtime::Env.qa_image) if Runtime::Env.qa_image
  Runtime::Scenario.define(:omnibus_configuration, Runtime::OmnibusConfiguration.new)
  Runtime::Scenario.define(:seed_db, false)
  Runtime::Scenario.define(:seed_admin_token, true) # Create an admin access token for root user by default
  Runtime::Scenario.define(:omnibus_exec_commands, [])
  Runtime::Scenario.define(:skip_server_hooks, false)

  # Omnibus Configurators specified by flags
  @active_configurators = []
  @seed_scripts = []
  @omnibus_configurations = %w[default] # always load default configuration

  @options = OptionParser.new do |opts|
    opts.banner = 'Usage: gitlab-qa Scenario URL [options] [[--] path] [rspec_options]'

    opts.on('--no-teardown', 'Skip teardown of containers after the scenario completes.') do
      Runtime::Scenario.define(:teardown, false)
    end

    opts.on('--no-tests',
      'Orchestrates the docker containers but does not run the tests. Implies --no-teardown') do
      Runtime::Scenario.define(:run_tests, false)
      Runtime::Scenario.define(:teardown, false)
    end

    opts.on('--no-admin-token', 'Skip admin token creation for root user') do
      Runtime::Scenario.define(:seed_admin_token, false)
    end

    opts.on('--skip-server-hooks', 'Skip adding global git server hooks') do
      Runtime::Scenario.define(:skip_server_hooks, true)
    end

    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|
      Runtime::Scenario.define(:qa_image, value)
    end

    opts.on_tail('-v', '--version', 'Show the version') do
      require 'gitlab/qa/version'
      puts "#{$PROGRAM_NAME} : #{VERSION}"
      exit
    end

    opts.on('--omnibus-config config1[,config2,...]', 'Use Omnibus Configuration package') do |configuration|
      configuration.split(',').map do |config|
        @omnibus_configurations << config
      end
    end

    opts.on('--seed-db search_pattern1[,search_pattern2,...]',
      'Seed application database with sample test data') do |file_pattern|
      file_pattern.split(',').each do |pattern|
        @seed_scripts << pattern
      end

      Runtime::Scenario.define(:seed_db, @seed_scripts)
    end

    opts.on_tail('-h', '--help', 'Show the usage') do
      puts opts
      exit
    end

    begin
      opts.parse(args)
    rescue OptionParser::InvalidOption
      # Ignore invalid options and options that are passed through to the tests
    end
  end

  # Remove arguments passed into GitLab QA preventing them from being
  # passed into the specs
  args = remove_gitlab_qa_args(args)

  if args.size >= 1
    scenario = Scenario.const_get(args.shift)

    load_omnibus_configurations

    begin
      @active_configurators.compact.each do |configurator|
        configurator.instance(skip_teardown: true)
      end

      scenario.perform(*args)
    ensure
      @active_configurators.compact.each(&:teardown)
    end
  else
    puts @options
    exit 1
  end
end