Class: Serverspec::Backend::Ssh

Inherits:
Exec
  • Object
show all
Defined in:
lib/serverspec/backend/ssh.rb

Instance Method Summary collapse

Methods inherited from Exec

#check_executable, #check_monitored_by_monit, #check_mounted, #check_os, #check_readable, #check_routing_table, #check_running, #check_running_under_supervisor, #check_running_under_upstart, #check_writable, #check_zero, #commands, #method_missing, #set_commands, #set_example

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Serverspec::Backend::Exec

Instance Method Details

#add_pre_command(cmd) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/serverspec/backend/ssh.rb', line 25

def add_pre_command(cmd)
  cmd = super(cmd)
  user = RSpec.configuration.ssh.options[:user]
  pre_command = Serverspec.configuration.pre_command
  if pre_command && user != 'root'
    cmd = "sudo #{cmd}"
  end
  cmd
end

#build_command(cmd) ⇒ Object



19
20
21
22
23
# File 'lib/serverspec/backend/ssh.rb', line 19

def build_command(cmd)
  cmd = super(cmd)
  cmd = "sudo #{cmd}" if RSpec.configuration.ssh.options[:user] != 'root'
  cmd
end

#run_command(cmd, opt = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/serverspec/backend/ssh.rb', line 6

def run_command(cmd, opt={})
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)
  ret = ssh_exec!(cmd)

  if @example
    @example.[:command] = cmd
    @example.[:stdout]  = ret[:stdout]
  end

  ret
end