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



26
27
28
29
30
31
# File 'lib/beaker-puppet/helpers/host_helpers.rb', line 26

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



17
18
19
20
21
22
23
24
# File 'lib/beaker-puppet/helpers/host_helpers.rb', line 17

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



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

def ruby_command(host)
  "env PATH=\"#{host['privatebindir']}:${PATH}\" ruby"
end