class Kitchen::Driver::Dummy
Dummy
driver for Kitchen
. This driver does nothing but report what would happen if this driver did anything of consequence. As a result it may be a useful driver to use when debugging or developing new features or plugins.
@author Fletcher Nichol <fnichol@nichol.ca>
Public Instance Methods
(see Base#create
)
# File lib/kitchen/driver/dummy.rb, line 37 def create(state) # Intentionally not calling `super` to avoid pre_create_command. state[:my_id] = "#{instance.name}-#{Time.now.to_i}" report(:create, state) end
(see Base#destroy
)
# File lib/kitchen/driver/dummy.rb, line 54 def destroy(state) report(:destroy, state) state.delete(:my_id) end
(see Base#setup)
# File lib/kitchen/driver/dummy.rb, line 44 def setup(state) report(:setup, state) end
(see Base#verify)
# File lib/kitchen/driver/dummy.rb, line 49 def verify(state) report(:verify, state) end
Private Instance Methods
Simulate a failure in an action, if set in the config.
@param action [Symbol] the action currently taking place @api private
# File lib/kitchen/driver/dummy.rb, line 86 def failure_if_set(action) if config[:"fail_#{action}"] debug("[Dummy] Failure for action ##{action}.") raise ActionFailed, "Action ##{action} failed for #{instance.to_str}." elsif config[:random_failure] && randomly_fail? debug("[Dummy] Random failure for action ##{action}.") raise ActionFailed, "Action ##{action} failed for #{instance.to_str}." end end
Determine whether or not to randomly fail.
@return [true, false] @api private
# File lib/kitchen/driver/dummy.rb, line 100 def randomly_fail? [true, false].sample end
Report what action is taking place, sleeping if so configured, and possibly fail randomly.
@param action [Symbol] the action currently taking place @param state [Hash] the state hash @api private
# File lib/kitchen/driver/dummy.rb, line 67 def report(action, state) what = action.capitalize info("[Dummy] #{what} on instance=#{instance} with state=#{state}") sleep_if_set failure_if_set(action) debug("[Dummy] #{what} completed (#{config[:sleep]}s).") end
Sleep for a period of time, if a value is set in the config.
@api private
# File lib/kitchen/driver/dummy.rb, line 78 def sleep_if_set sleep(config[:sleep].to_f) if config[:sleep].to_f > 0.0 end