Class: Kitchen::Binding::Base

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/kitchen/binding/base.rb

Overview

Base class for a binding.

Author:

Direct Known Subclasses

PryRemote

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Base

Create a new Binding object using the provided configuration data which will be merged with any default configuration.

Parameters:

  • config (Hash) (defaults to: {})

    provided binding configuration



46
47
48
49
50
51
52
53
54
# File 'lib/kitchen/binding/base.rb', line 46

def initialize(config = {})
  # init_config(config) # Available in edge

  # Following not required in edge test-kitchen
  @config = LazyHash.new(config, self)
  self.class.defaults.each do |attr, value|
    @config[attr] = value unless @config.has_key?(attr)
  end
end

Instance Attribute Details

#instanceObject

Not required in edge



40
41
42
# File 'lib/kitchen/binding/base.rb', line 40

def instance
  @instance
end

#stateObject

Returns the value of attribute state.



38
39
40
# File 'lib/kitchen/binding/base.rb', line 38

def state
  @state
end

Instance Method Details

#connect_commandObject

Returns the command that will log into a remote interactive ruby shell.

Raises:

  • (ActionFailed)

    if the action could not be completed



80
81
# File 'lib/kitchen/binding/base.rb', line 80

def connect_command
end

#install_commandString

Returns the command that will install the remote interactive ruby shell.

Returns:

  • (String)

    the command to install the remote ruby shell

Raises:

  • (ActionFailed)

    if the action could not be completed



74
75
# File 'lib/kitchen/binding/base.rb', line 74

def install_command
end

#nameString

Returns the name of this transport, suitable for display in a CLI.

Returns:

  • (String)

    name of this transport



66
67
68
# File 'lib/kitchen/binding/base.rb', line 66

def name
  self.class.name.split('::').last.downcase
end

#sudo(script) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Conditionally prefixes a command with a sudo command.

Parameters:

  • command (String)

    command to be prefixed

Returns:

  • (String)

    the command, conditionaly prefixed with sudo



88
89
90
# File 'lib/kitchen/binding/base.rb', line 88

def sudo(script)
  config[:sudo] ? "sudo -E #{script}" : script
end

#test_connectiontrue, false

Test a remote port’s connectivity.

and false otherwise

Returns:

  • (true, false)

    a truthy value if the connection is ready



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/kitchen/binding/base.rb', line 96

def test_connection
  debug("Testing binding connection <#{hostname}:#{port}>")
  socket = TCPSocket.new(hostname, port)
  IO.select([socket], nil, nil, 5)
  true
rescue *SOCKET_EXCEPTIONS, Errno::EPERM, Errno::ETIMEDOUT
  debug("No binding server detected")
  sleep config[:binding_timeout] || 2
  false
ensure
  socket && socket.close
end