Module: Beaker::DSL::Helpers::HostHelpers

Included in:
BeakerPuppet
Defined in:
lib/beaker-puppet/helpers/host_helpers.rb

Overview

Methods that help you interact with your facter installation, facter must be installed for these methods to execute correctly

Instance Method Summary collapse

Instance Method Details

#assert_ownership_permissions(host, location, expected_user, expected_group, expected_permissions) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/beaker-puppet/helpers/host_helpers.rb', line 31

def assert_ownership_permissions(host, location, expected_user, expected_group, expected_permissions)
  permissions = beaker_stat(host, location)
  assert_equal(expected_user, permissions[0],
               "Owner #{permissions[0]} does not match expected #{expected_user}")
  assert_equal(expected_group, permissions[1],
               "Group #{permissions[1]} does not match expected #{expected_group}")
  assert_equal(expected_permissions, permissions[2],
               "Permissions  #{permissions[2]} does not match expected #{expected_permissions}")
end

#beaker_stat(host, path) ⇒ Object

Returns an array containing the owner, group and mode of the file specified by path. The returned mode is an integer value containing only the file mode, excluding the type, e.g S_IFDIR 0040000



20
21
22
23
24
25
26
27
28
29
# File 'lib/beaker-puppet/helpers/host_helpers.rb', line 20

def beaker_stat(host, path)
  ruby = ruby_command(host)
  owner = on(host,
             "#{ruby} -e 'require \"etc\"; puts (Etc.getpwuid(File.stat(\"#{path}\").uid).name)'").stdout.chomp
  group = on(host,
             "#{ruby} -e 'require \"etc\"; puts (Etc.getgrgid(File.stat(\"#{path}\").gid).name)'").stdout.chomp
  mode  = on(host, "#{ruby} -e 'puts (File.stat(\"#{path}\").mode & 0777).to_s(8)'").stdout.chomp.to_i

  [owner, group, mode]
end

#ruby_command(host) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/beaker-puppet/helpers/host_helpers.rb', line 8

def ruby_command(host)
  if host['platform'] =~ /windows/ && !host.is_cygwin?
    "cmd /V /C \"set PATH=#{host['privatebindir']};!PATH! && ruby\""
  else
    "env PATH=\"#{host['privatebindir']}:${PATH}\" ruby"
  end
end