class Kitchen::Terraform::InSpec::FailSlowWithHosts

FailSlowWithHosts is the class of objects which execute InSpec against multiple hosts and raise rescued errors after all hosts have been tested.

Attributes

hosts[RW]
messages[RW]
options[RW]
profile_locations[RW]

Public Class Methods

new(hosts:, options:, profile_locations:) click to toggle source

initialize prepares a new instance of the class.

@param hosts [Array<::String>] the names or addresses of hosts on which Inspec controls will be executed. @param options [Hash] options for execution. @param profile_locations [Array<::String>] the locations of the InSpec profiles which contain the controls

to be executed.

@return [Kitchen::Terraform::InSpec::FailSlowWithHosts]

# File lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb, line 47
def initialize(hosts:, options:, profile_locations:)
  self.hosts = hosts
  self.messages = []
  self.options = options
  self.profile_locations = profile_locations
end

Public Instance Methods

exec() click to toggle source

exec executes the InSpec controls of an InSpec profile.

@raise [Kitchen::TransientFailure] if the execution of InSpec fails. @return [self]

# File lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb, line 30
def exec
  hosts.each do |host|
    exec_and_continue host: host
  end

  raise ::Kitchen::TransientFailure, messages.join("\n\n") if !messages.empty?

  self
end

Private Instance Methods

exec_and_continue(host:) click to toggle source
# File lib/kitchen/terraform/inspec/fail_slow_with_hosts.rb, line 58
def exec_and_continue(host:)
  ::Kitchen::Terraform::InSpecRunner.new(
    options: options.merge(host: host),
    profile_locations: profile_locations,
  ).exec
rescue => error
  messages.push error.message
end