Class: Kitchen::Transport::Train::Connection

Inherits:
Base::Connection
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/kitchen/transport/train.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Connection

Returns a new instance of Connection.

Yields:

  • (_self)

Yield Parameters:



32
33
34
35
36
37
38
39
40
# File 'lib/kitchen/transport/train.rb', line 32

def initialize(options = {})
  @options = options
  @logger = Kitchen.logger

  @backend = ::Train.create(options[:backend], options)
  @connection = @backend.connection

  yield self if block_given?
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



30
31
32
# File 'lib/kitchen/transport/train.rb', line 30

def logger
  @logger
end

Instance Method Details

#credentials_fileObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/kitchen/transport/train.rb', line 46

def credentials_file
  instance_name = @connection.transport_options[:instance_name]

  config = @backend.instance_variable_get(:@connection_options)
  config.compact!
  config.transform_values! { |v| v.is_a?(Symbol) ? v.to_s : v }

  # Some configuration variables vary between transports
  config[:host] = config[:hostname] = @connection.transport_options[:host]
  config[:key_files] = @connection.transport_options[:key_files]

  # Due to a long-standing bug in TestKitchen, standard platforms will override
  # kitchen.yml `user` settings, so this transport introduces an "train_user" override.
  # See https://github.com/test-kitchen/kitchen-ec2/pull/273
  config[:user] = config[:username] = @connection.transport_options[:train_user] || @connection.transport_options[:user]

  require "toml-rb" unless defined?(TomlRB)

  "['#{instance_name}']\n" + TomlRB.dump(config)
end

#execute(command) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/kitchen/transport/train.rb', line 67

def execute(command)
  return if command.nil?

  logger.debug("[Train/#{options[:backend]}] Execute (#{command})")

  command_result = @connection.run_command(command)

  if command_result.exit_status == 0
    logger.info(command_result.stdout)
  else
    logger.error(command_result.stderr)

    raise Transport::ConnectionFailed.new(
      "Train/#{options[:backend]} exited (#{command_result.exit_status}) for command: [#{command}]",
      command_result.exit_status
    )
  end
end

#login_commandObject

Raises:

  • (::Kitchen::UserError)


86
87
88
# File 'lib/kitchen/transport/train.rb', line 86

def 
  raise ::Kitchen::UserError, "Interactive shells are not possible with the Train transport"
end

#train_uriObject



42
43
44
# File 'lib/kitchen/transport/train.rb', line 42

def train_uri
  @connection.uri
end