Class: DopCommon::Step

Inherits:
Object
  • Object
show all
Includes:
RunOptions, Validator
Defined in:
lib/dop_common/step.rb

Instance Method Summary collapse

Methods included from RunOptions

#canary_host, #max_in_flight, #max_per_role, #valitdate_shared_options

Methods included from Validator

#log_validation_method, #set_not_valid, #try_validate_obj, #valid?

Constructor Details

#initialize(hash) ⇒ Step

Returns a new instance of Step.



10
11
12
13
# File 'lib/dop_common/step.rb', line 10

def initialize(hash)
  @hash = HashParser.symbolize_keys(hash)
  HashParser.key_aliases(@hash, :commands, [:command])
end

Instance Method Details

#commandsObject



64
65
66
# File 'lib/dop_common/step.rb', line 64

def commands
  @commands ||= commands_valid? ? create_commands : nil
end

#delete_plugin_defaultsObject



73
74
75
76
# File 'lib/dop_common/step.rb', line 73

def delete_plugin_defaults
  @delete_plugin_defaults ||= delete_plugin_defaults_valid? ?
    parse_plugin_pattern_array(:delete_plugin_defaults) : []
end

#exclude_nodesObject



39
40
41
42
# File 'lib/dop_common/step.rb', line 39

def exclude_nodes
  @exclude_nodes ||= exclude_nodes_valid? ?
    HashParser.parse_pattern_list(@hash, :exclude_nodes) : []
end

#exclude_nodes_by_configObject



49
50
51
52
# File 'lib/dop_common/step.rb', line 49

def exclude_nodes_by_config
  @exclude_nodes_by_config ||= exclude_nodes_by_config_valid? ?
    HashParser.parse_hash_of_pattern_lists(@hash, :exclude_nodes_by_config) : {}
end

#exclude_rolesObject



59
60
61
62
# File 'lib/dop_common/step.rb', line 59

def exclude_roles
  @exclude_roles ||= exclude_roles_valid? ?
    HashParser.parse_pattern_list(@hash, :exclude_roles) : []
end

#nameObject



15
16
17
18
# File 'lib/dop_common/step.rb', line 15

def name
  @name ||= @hash[:name] or
    raise PlanParsingError, "Every step needs to have a 'name' key defined"
end

#nodesObject



34
35
36
37
# File 'lib/dop_common/step.rb', line 34

def nodes
  @nodes ||= nodes_valid? ?
    HashParser.parse_pattern_list(@hash, :nodes) : []
end

#nodes_by_configObject



44
45
46
47
# File 'lib/dop_common/step.rb', line 44

def nodes_by_config
  @nodes_by_config ||= nodes_by_config_valid? ?
    HashParser.parse_hash_of_pattern_lists(@hash, :nodes_by_config) : {}
end

#rolesObject



54
55
56
57
# File 'lib/dop_common/step.rb', line 54

def roles
  @roles ||= roles_valid? ?
    HashParser.parse_pattern_list(@hash, :roles) : []
end

#set_plugin_defaultsObject



68
69
70
71
# File 'lib/dop_common/step.rb', line 68

def set_plugin_defaults
  @set_plugin_defaults ||= set_plugin_defaults_valid? ?
    parse_plugin_pattern_array(:set_plugin_defaults) : []
end

#validateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dop_common/step.rb', line 20

def validate
  valitdate_shared_options
  log_validation_method('name')
  log_validation_method('nodes_valid?')
  log_validation_method('exclude_nodes_valid?')
  log_validation_method('nodes_by_config_valid?')
  log_validation_method('exclude_nodes_by_config_valid?')
  log_validation_method('roles_valid?')
  log_validation_method('exclude_roles_valid?')
  log_validation_method('commands_valid?')
  r_name = @name || 'unknown' # name may not be set because of a previous error
  try_validate_obj("Step #{r_name}: Can't validate the commands part because of a previous error"){commands}
end