Class: HybridPlatformsConductor::Config
- Inherits:
-
Object
- Object
- HybridPlatformsConductor::Config
- 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
-
.mixin_initializers ⇒ Object
Array<Symbol>: List of mixin initializers to call.
Instance Attribute Summary collapse
-
#deployment_schedules ⇒ Object
readonly
List of deployment schedules.
-
#expected_failures ⇒ Object
readonly
List of expected failures info.
-
#hybrid_platforms_dir ⇒ Object
readonly
Directory of the definition of the platforms String.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
-
#current_nodes_selectors_stack ⇒ Object
Get the current nodes selector stack.
-
#daily_at(time, duration: 3000) ⇒ Object
Helper to get a daily schedule at a given time.
-
#deployment_schedule(schedule) ⇒ Object
Set a deployment schedule.
-
#expect_tests_to_fail(tests, reason) ⇒ Object
Mark some tests as expected failures.
-
#for_nodes(nodes_selectors) ⇒ Object
Limit the scope of configuration to a given set of nodes.
-
#include_config_from(dsl_file) ⇒ Object
Include configuration from a DSL config file.
-
#initialize(logger: Logger.new($stdout), logger_stderr: Logger.new($stderr)) ⇒ Config
constructor
Constructor.
-
#known_os_images ⇒ Object
Get the list of known Docker images.
-
#os_image(image, dir) ⇒ Object
Register a new OS image.
-
#os_image_dir(image) ⇒ Object
Get the directory containing a Docker image.
-
#tests_provisioner(provisioner) ⇒ Object
Set which provisioner should be used for tests.
-
#tests_provisioner_id ⇒ Object
Name of the provisioner to be used for tests.
-
#weekly_at(days, time, duration: 3000) ⇒ Object
Helper to get a weekly schedule at a given day and time.
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 |
# 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.(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 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| send(mixin_init_method) end include_config_from "#{@hybrid_platforms_dir}/hpc_config.rb" end |
Class Attribute Details
.mixin_initializers ⇒ Object
Array<Symbol>: List of mixin initializers to call
19 20 21 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 19 def mixin_initializers @mixin_initializers end |
Instance Attribute Details
#deployment_schedules ⇒ Object (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_failures ⇒ Object (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>
51 52 53 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 51 def expected_failures @expected_failures end |
#hybrid_platforms_dir ⇒ Object (readonly)
Directory of the definition of the platforms
String
42 43 44 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 42 def hybrid_platforms_dir @hybrid_platforms_dir 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]
27 28 29 30 31 32 33 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 27 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_stack ⇒ Object
Get the current nodes selector stack.
- Result
-
Array<Object>: Nodes selectors stack
203 204 205 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 203 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
176 177 178 179 180 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 176 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
161 162 163 164 165 166 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 161 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
148 149 150 151 152 153 154 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 148 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
133 134 135 136 137 138 139 140 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 133 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
101 102 103 104 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 101 def include_config_from(dsl_file) log_debug "Include config from #{dsl_file}" evaluate_file(dsl_file) end |
#known_os_images ⇒ Object
Get the list of known Docker images
- Result
-
Array<Symbol>: List of known Docker images
211 212 213 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 211 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
112 113 114 115 116 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 112 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
221 222 223 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 221 def os_image_dir(image) @os_images[image] 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
123 124 125 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 123 def tests_provisioner(provisioner) @tests_provisioner = provisioner end |
#tests_provisioner_id ⇒ Object
Name of the provisioner to be used for tests
- Result
-
Symbol: Provisioner to be used for tests
229 230 231 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 229 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
191 192 193 194 195 196 |
# File 'lib/hybrid_platforms_conductor/config.rb', line 191 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 |