Sha256: cd63660b986f60ed7714c721de709e4da8a72b43eb6b0d054b88c530dd69f087

Contents?: true

Size: 1.6 KB

Versions: 33

Compression:

Stored size: 1.6 KB

Contents

module Beaker
  module DSL
    module Helpers
      # Methods that help you interact with your facter installation, facter must be installed
      # for these methods to execute correctly
      #
      module HostHelpers

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

        # 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
        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

        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
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
beaker-puppet-1.19.1 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.19.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.15 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.14 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.13 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.12 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.11 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.10 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.9 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.8 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.7 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.6 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.5 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.4 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.3 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.2 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.1 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.18.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.17.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.16.0 lib/beaker-puppet/helpers/host_helpers.rb