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



43
44
45
46
47
48
49
50
51
# File 'lib/kitchen/binding/base.rb', line 43

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



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

def instance
  @instance
end

#stateObject

Returns the value of attribute state.



35
36
37
# File 'lib/kitchen/binding/base.rb', line 35

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



77
78
# File 'lib/kitchen/binding/base.rb', line 77

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



71
72
# File 'lib/kitchen/binding/base.rb', line 71

def install_command
end

#nameString

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

Returns:

  • (String)

    name of this transport



63
64
65
# File 'lib/kitchen/binding/base.rb', line 63

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



85
86
87
# File 'lib/kitchen/binding/base.rb', line 85

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



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/kitchen/binding/base.rb', line 93

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