Class: Gitlab::QA::Runtime::OmnibusConfiguration

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

Instance Method Summary collapse

Constructor Details

#initialize(prefixed_config = nil) ⇒ OmnibusConfiguration

Returns a new instance of OmnibusConfiguration.

Parameters:

  • prefixed_config (defaults to: nil)

    The configuration to be prefixed to the new configuration



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 10

def initialize(prefixed_config = nil)
  @config = ["# Generated by GitLab QA Omnibus Configurator at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"]

  return unless prefixed_config

  # remove generation statement if it exists within the prefixed configuration that was passed
  # and insert the rest AFTER the very first generation statement
  config_to_insert = prefixed_config.to_s
  generation_regexp = /# Generated by GitLab QA Omnibus Configurator.*\n/
  config_to_insert = config_to_insert.gsub(generation_regexp, '') if config_to_insert.match?(generation_regexp)
  @config.insert(1, config_to_insert)
end

Instance Method Details

#<<(config) ⇒ Object

rubocop:enable Metrics/AbcSize



74
75
76
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 74

def <<(config)
  @config << config.strip unless config.strip.empty?
end

#configurationObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 27

def configuration
  raise NotImplementedError
end

#exec_commandsObject

Commands to execute before tests are run against GitLab (after reconfigure)



37
38
39
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 37

def exec_commands
  []
end

#prepareObject

Before hook for any additional configuration This would usually be a container that needs to be running

Returns:

  • Any instance of [Gitlab::QA::Component::Base]



34
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 34

def prepare; end

#sanitize!Object

Ensures no duplicate entries and sanitizes configurations rubocop:disable Metrics/AbcSize

Raises:

  • RuntimeError if competing configurations exist



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
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 44

def sanitize!
  sanitized = @config.map do |config|
    next config if config.start_with?('#') || config.match(/\w+\(/) # allow for comments and method invocations

    # sometimes "=" is part of a Hash. Only split based on the first "="
    k, v = config.split("=", 2)
    # make sure each config is well-formed
    # e.g., gitlab_rails['packages_enabled'] = true
    #   NOT gitlab_rails['packages_enabled']=true

    v.nil? ? k.strip : "#{k.strip} = #{v.strip.tr('"', "'")}".strip
  end.uniq

  errors = []

  # check for duplicates
  duplicate_keys = []
  duplicates = sanitized.reject do |n|
    key = n.split('=').first
    duplicate_keys << key unless duplicate_keys.include?(key)
  end

  duplicates.each { |duplicate| errors << "Duplicate entry found: `#{duplicate}`" }

  raise "Errors exist within the Omnibus Configuration!\n#{errors.join(',')}" if errors.any?

  @config = sanitized
end

#to_sObject



23
24
25
# File 'lib/gitlab/qa/runtime/omnibus_configuration.rb', line 23

def to_s
  sanitize!.join("\n")
end