Class: Cucumber::Chef::Bootstrap

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/chef/bootstrap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout = STDOUT, stderr = STDERR, stdin = STDIN) ⇒ Bootstrap

Returns a new instance of Bootstrap.



32
33
34
35
36
37
38
39
# File 'lib/cucumber/chef/bootstrap.rb', line 32

def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN)
  @stdout, @stderr, @stdin = stdout, stderr, stdin
  @stdout.sync = true if @stdout.respond_to?(:sync=)

  @ssh = Cucumber::Chef::SSH.new(@stdout, @stderr, @stdin)
  @config = Hash.new(nil)
  @config[:context] = Hash.new(nil)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



28
29
30
# File 'lib/cucumber/chef/bootstrap.rb', line 28

def config
  @config
end

#stderrObject

Returns the value of attribute stderr.



28
29
30
# File 'lib/cucumber/chef/bootstrap.rb', line 28

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



28
29
30
# File 'lib/cucumber/chef/bootstrap.rb', line 28

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



28
29
30
# File 'lib/cucumber/chef/bootstrap.rb', line 28

def stdout
  @stdout
end

Instance Method Details

#runObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cucumber/chef/bootstrap.rb', line 43

def run
  $logger.debug { "config(#{@config.inspect})" }

  if !@config[:template_file]
    message = "You must supply a 'template_file' option."
    $logger.fatal { message }
    raise BootstrapError, message
  end

  if !@config[:host]
    message = "You must supply a 'host' option."
    $logger.fatal { message }
    raise BootstrapError, message
  end

  if !@config[:ssh_user]
    message = "You must supply a 'ssh_user' option."
    $logger.fatal { message }
    raise BootstrapError, message
  end

  if (!@config[:ssh_password] && !@config[:identity_file])
    message = "You must supply a 'ssh_password' or 'identity_file' option."
    $logger.fatal { message }
    raise BootstrapError, message
  end

  $logger.debug { "prepare(#{@config[:host]})" }

  @ssh.config[:host] = @config[:host]
  @ssh.config[:ssh_user] = @config[:ssh_user]
  @ssh.config[:ssh_password] = @config[:ssh_password]
  @ssh.config[:identity_file] = @config[:identity_file]
  @ssh.config[:timeout] = 5

  $logger.debug { "template_file(#{@config[:template_file]})" }
  command = Cucumber::Chef::Template.render(@config[:template_file], @config[:context])
  command = "sudo #{command}" if @config[:use_sudo]

  $logger.debug { "begin(#{@config[:host]})" }
  @ssh.exec(command, :silence => true)
  $logger.debug { "end(#{@config[:host]})" }
end