Sha256: 5a80bc76b7293f3ba535b23679dce4955a827a6cf51c26803fef7b06fbcab1e1

Contents?: true

Size: 1.76 KB

Versions: 16

Compression:

Stored size: 1.76 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)
          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

        # 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

16 entries across 16 versions & 1 rubygems

Version Path
beaker-puppet-1.29.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.28.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.27.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.26.3 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.26.2 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.26.1 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.26.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.25.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.24.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.23.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.22.2 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.22.1 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.22.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.21.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.20.0 lib/beaker-puppet/helpers/host_helpers.rb
beaker-puppet-1.19.2 lib/beaker-puppet/helpers/host_helpers.rb