Class: HybridPlatformsConductor::Config

Inherits:
Object
  • Object
show all
Includes:
Cleanroom, LoggerHelpers
Defined in:
lib/hybrid_platforms_conductor/config.rb

Overview

Object used to access the whole configuration

Constant Summary

Constants included from LoggerHelpers

LoggerHelpers::LEVELS_MODIFIERS, LoggerHelpers::LEVELS_TO_STDERR

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LoggerHelpers

#err, #init_loggers, #log_component=, #log_debug?, #log_level=, #out, #section, #set_loggers_format, #stderr_device, #stderr_device=, #stderr_displayed?, #stdout_device, #stdout_device=, #stdout_displayed?, #stdouts_to_s, #with_progress_bar

Constructor Details

#initialize(logger: Logger.new(STDOUT), logger_stderr: Logger.new(STDERR)) ⇒ Config

Constructor

Parameters
  • logger (Logger): Logger to be used [default = Logger.new(STDOUT)]

  • logger_stderr (Logger): Logger to be used for stderr [default = Logger.new(STDERR)]



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
# File 'lib/hybrid_platforms_conductor/config.rb', line 63

def initialize(logger: Logger.new(STDOUT), logger_stderr: Logger.new(STDERR))
  init_loggers(logger, logger_stderr)
  @hybrid_platforms_dir = File.expand_path(ENV['hpc_platforms'].nil? ? '.' : ENV['hpc_platforms'])
  # Stack of the nodes selectors scopes
  # Array< Object >
  @nodes_selectors_stack = []
  # List of OS image directories, per image name
  # Hash<Symbol, String>
  @os_images = {}
  # Plugin ID of the tests provisioner
  # Symbol
  @tests_provisioner = :docker
  # List of expected failures info. Each info has the following properties:
  # * *nodes_selectors_stack* (Array<Object>): Stack of nodes selectors impacted by this expected failure
  # * *tests* (Array<Symbol>): List of tests impacted by this expected failre
  # * *reason* (String): Reason for this expected failure
  # Array<Hash,Symbol,Object>
  @expected_failures = []
  # List of retriable errors. Each info has the following properties:
  # * *nodes_selectors_stack* (Array<Object>): Stack of nodes selectors impacted by those errors
  # * *errors_on_stdout* (Array<String or Regexp>): List of errors match (as exact string match or using a regexp) to check against stdout
  # * *errors_on_stderr* (Array<String or Regexp>): List of errors match (as exact string match or using a regexp) to check against stderr
  @retriable_errors = []
  # List of deployment schedules. Each info has the following properties:
  # * *nodes_selectors_stack* (Array<Object>): Stack of nodes selectors impacted by this rule
  # * *schedule* (IceCube::Schedule): The deployment schedule
  @deployment_schedules = []
  # Make sure plugins can decorate our DSL with their owns additions as well
  # Therefore we parse all possible plugin types
  Dir.glob("#{__dir__}/hpc_plugins/*").each do |plugin_dir|
    Plugins.new(File.basename(plugin_dir).to_sym, logger: @logger, logger_stderr: @logger_stderr)
  end
  # Call initializers if needed
  Config.mixin_initializers.each do |mixin_init_method|
    self.send(mixin_init_method)
  end
  include_config_from "#{@hybrid_platforms_dir}/hpc_config.rb"
end

Class Attribute Details

.mixin_initializersObject

Array<Symbol>: List of mixin initializers to call



16
17
18
# File 'lib/hybrid_platforms_conductor/config.rb', line 16

def mixin_initializers
  @mixin_initializers
end

Instance Attribute Details

#deployment_schedulesObject (readonly)

List of deployment schedules. Each info has the following properties:

  • nodes_selectors_stack (Array<Object>): Stack of nodes selectors impacted by this rule

  • schedule (IceCube::Schedule): The deployment schedule



56
57
58
# File 'lib/hybrid_platforms_conductor/config.rb', line 56

def deployment_schedules
  @deployment_schedules
end

#expected_failuresObject (readonly)

List of expected failures info. Each info has the following properties:

  • nodes_selectors_stack (Array<Object>): Stack of nodes selectors impacted by this expected failure

  • tests (Array<Symbol>): List of tests impacted by this expected failre

  • reason (String): Reason for this expected failure

Array<Hash,Symbol,Object>



45
46
47
# File 'lib/hybrid_platforms_conductor/config.rb', line 45

def expected_failures
  @expected_failures
end

#hybrid_platforms_dirObject (readonly)

Directory of the definition of the platforms

String


37
38
39
# File 'lib/hybrid_platforms_conductor/config.rb', line 37

def hybrid_platforms_dir
  @hybrid_platforms_dir
end

#retriable_errorsObject (readonly)

List of retriable errors. Each info has the following properties:

  • nodes_selectors_stack (Array<Object>): Stack of nodes selectors impacted by those errors

  • errors_on_stdout (Array<String or Regexp>): List of errors match (as exact string match or using a regexp) to check against stdout

  • errors_on_stderr (Array<String or Regexp>): List of errors match (as exact string match or using a regexp) to check against stderr



51
52
53
# File 'lib/hybrid_platforms_conductor/config.rb', line 51

def retriable_errors
  @retriable_errors
end

Class Method Details

.extend_config_dsl_with(mixin, init_method = nil) ⇒ Object

Extend the config DSL used when parsing the hpc_config.rb file with a given Mixin. This can be used by any plugin to add plugin-specific configuration in the hpc_config.rb file.

Parameters
  • mixin (Module): Mixin to add to the Platforms DSL

  • init_method (Symbol or nil): The initializer method of this Mixin, or nil if none [default = nil]



24
25
26
27
28
29
30
# File 'lib/hybrid_platforms_conductor/config.rb', line 24

def extend_config_dsl_with(mixin, init_method = nil)
  include mixin
  @mixin_initializers << init_method unless init_method.nil?
  mixin.instance_methods.each do |method_name|
    expose method_name unless method_name == init_method
  end
end

Instance Method Details

#current_nodes_selectors_stackObject

Get the current nodes selector stack.

Result
  • Array<Object>: Nodes selectors stack



231
232
233
# File 'lib/hybrid_platforms_conductor/config.rb', line 231

def current_nodes_selectors_stack
  @nodes_selectors_stack.clone
end

#daily_at(time, duration: 3000) ⇒ Object

Helper to get a daily schedule at a given time

Parameters
  • time (String): Time (UTC) for the daily schedule

  • duration (Integer): Number of seconds of duration [default: 3000]

Result
  • IceCube::Schedule: Corresponding schedule



204
205
206
207
208
# File 'lib/hybrid_platforms_conductor/config.rb', line 204

def daily_at(time, duration: 3000)
  IceCube::Schedule.new(Time.parse("2020-01-01 #{time} UTC"), duration: duration) do |s|
    s.add_recurrence_rule(IceCube::Rule.daily)
  end
end

#deployment_schedule(schedule) ⇒ Object

Set a deployment schedule

Parameters
  • schedule (IceCube::Schedule): The deployment schedule



189
190
191
192
193
194
# File 'lib/hybrid_platforms_conductor/config.rb', line 189

def deployment_schedule(schedule)
  @deployment_schedules << {
    schedule: schedule,
    nodes_selectors_stack: current_nodes_selectors_stack
  }
end

#expect_tests_to_fail(tests, reason) ⇒ Object

Mark some tests as expected failures.

Parameters
  • tests (Symbol or Array<Symbol>): List of tests expected to fail.

  • reason (String): Descriptive reason for the failure



152
153
154
155
156
157
158
# File 'lib/hybrid_platforms_conductor/config.rb', line 152

def expect_tests_to_fail(tests, reason)
  @expected_failures << {
    tests: tests.is_a?(Array) ? tests : [tests],
    nodes_selectors_stack: current_nodes_selectors_stack,
    reason: reason
  }
end

#for_nodes(nodes_selectors) ⇒ Object

Limit the scope of configuration to a given set of nodes

Parameters
  • nodes_selectors (Object): Nodes selectors, as defined by the NodesHandler#select_nodes method (check its signature for details)

Proc: DSL code called in the context of those selected nodes



137
138
139
140
141
142
143
144
# File 'lib/hybrid_platforms_conductor/config.rb', line 137

def for_nodes(nodes_selectors)
  @nodes_selectors_stack << nodes_selectors
  begin
    yield
  ensure
    @nodes_selectors_stack.pop
  end
end

#include_config_from(dsl_file) ⇒ Object

Include configuration from a DSL config file

Parameters
  • dsl_file (String): Path to the DSL file



106
107
108
109
# File 'lib/hybrid_platforms_conductor/config.rb', line 106

def include_config_from(dsl_file)
  log_debug "Include config from #{dsl_file}"
  self.evaluate_file(dsl_file)
end

#known_os_imagesObject

Get the list of known Docker images

Result
  • Array<Symbol>: List of known Docker images



239
240
241
# File 'lib/hybrid_platforms_conductor/config.rb', line 239

def known_os_images
  @os_images.keys
end

#os_image(image, dir) ⇒ Object

Register a new OS image

Parameters
  • image (Symbol): Name of the Docker image

  • dir (String): Directory containing the Dockerfile defining the image



117
118
119
120
# File 'lib/hybrid_platforms_conductor/config.rb', line 117

def os_image(image, dir)
  raise "OS image #{image} already defined to #{@os_images[image]}" if @os_images.key?(image)
  @os_images[image] = dir
end

#os_image_dir(image) ⇒ Object

Get the directory containing a Docker image

Parameters
  • image (Symbol): Image name

Result
  • String: Directory containing the Dockerfile of the image



249
250
251
# File 'lib/hybrid_platforms_conductor/config.rb', line 249

def os_image_dir(image)
  @os_images[image]
end

#retry_deploy_for_errors_on_stderr(errors) ⇒ Object

Mark some errors on stderr to be retriable during a deploy

Parameters
  • errors (String, Regexp or Array<String or Regexp>): Single (or list of) errors matching pattern (either as exact string match or using a regexp).



177
178
179
180
181
182
# File 'lib/hybrid_platforms_conductor/config.rb', line 177

def retry_deploy_for_errors_on_stderr(errors)
  @retriable_errors << {
    errors_on_stderr: errors.is_a?(Array) ? errors : [errors],
    nodes_selectors_stack: current_nodes_selectors_stack
  }
end

#retry_deploy_for_errors_on_stdout(errors) ⇒ Object

Mark some errors on stdout to be retriable during a deploy

Parameters
  • errors (String, Regexp or Array<String or Regexp>): Single (or list of) errors matching pattern (either as exact string match or using a regexp).



165
166
167
168
169
170
# File 'lib/hybrid_platforms_conductor/config.rb', line 165

def retry_deploy_for_errors_on_stdout(errors)
  @retriable_errors << {
    errors_on_stdout: errors.is_a?(Array) ? errors : [errors],
    nodes_selectors_stack: current_nodes_selectors_stack
  }
end

#tests_provisioner(provisioner) ⇒ Object

Set which provisioner should be used for tests

Parameters
  • provisioner (Symbol): Plugin ID of the provisioner to be used for tests



127
128
129
# File 'lib/hybrid_platforms_conductor/config.rb', line 127

def tests_provisioner(provisioner)
  @tests_provisioner = provisioner
end

#tests_provisioner_idObject

Name of the provisioner to be used for tests

Result
  • Symbol: Provisioner to be used for tests



257
258
259
# File 'lib/hybrid_platforms_conductor/config.rb', line 257

def tests_provisioner_id
  @tests_provisioner
end

#weekly_at(days, time, duration: 3000) ⇒ Object

Helper to get a weekly schedule at a given day and time

Parameters
  • days (Symbol or Array<Symbol>): Days for the weekly schedule (see IceCube::Rule documentation to know day names)

  • time (String): Time (UTC) for the weekly schedule

  • duration (Integer): Number of seconds of duration [default: 3000]

Result
  • IceCube::Schedule: Corresponding schedule



219
220
221
222
223
224
# File 'lib/hybrid_platforms_conductor/config.rb', line 219

def weekly_at(days, time, duration: 3000)
  days = [days] unless days.is_a?(Array)
  IceCube::Schedule.new(Time.parse("2020-01-01 #{time} UTC"), duration: duration) do |s|
    s.add_recurrence_rule(IceCube::Rule.weekly.day(*days))
  end
end