Class: Kitchen::LifecycleHook::Remote

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/lifecycle_hook/remote.rb

Instance Attribute Summary

Attributes inherited from Base

#hook, #lifecycle_hooks, #phase

Instance Method Summary collapse

Methods inherited from Base

#initialize, #logger, #should_run?

Constructor Details

This class inherits a constructor from Kitchen::LifecycleHook::Base

Instance Method Details

#runvoid

This method returns an undefined value.

Execute a specific remote command hook.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kitchen/lifecycle_hook/remote.rb', line 10

def run
  # Check if we're in a state that makes sense to even try.
  unless instance.last_action
    if hook[:skippable]
      # Just not even trying.
      return
    else
      raise UserError, "Cannot use remote lifecycle hooks during phases when the instance is not available"
    end
  end

  begin
    conn = instance.transport.connection(state_file.read)
    conn.execute(command)
  rescue Kitchen::Transport::SshFailed => e
    return if hook[:skippable] && e.message.match(/^SSH exited \(\d{1,3}\) for command: \[.+\]$/)

    raise
  end
end