Sha256: 5b3247a9215777f88e12e832a3d9caa9876f1bdc8a3f63ed6cd189df13db7367

Contents?: true

Size: 968 Bytes

Versions: 18

Compression:

Stored size: 968 Bytes

Contents

require_relative "base"
require_relative "../errors"

module Kitchen
  class LifecycleHook
    class Remote < Base
      # Execute a specific remote command hook.
      #
      # @return [void]
      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

      private

      # return [String]
      def command
        hook.fetch(:remote)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
test-kitchen-3.7.0 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.6.0 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.5.1 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.5.0 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.4.0 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.3.2 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.3.1 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.3.0 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.2.2 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.2.1 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.2.0 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.1.1 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.1.0 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-rsync-3.0.0.pre.3 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-rsync-3.0.0.pre.2 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-rsync-3.0.0.pre.1 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-3.0.0 lib/kitchen/lifecycle_hook/remote.rb
test-kitchen-2.12.0 lib/kitchen/lifecycle_hook/remote.rb