lib/beaker-puppet/helpers/puppet_helpers.rb in beaker-puppet-0.16.0 vs lib/beaker-puppet/helpers/puppet_helpers.rb in beaker-puppet-0.17.0
- old
+ new
@@ -863,9 +863,58 @@
#@see #sign_certificate_for
def sign_certificate
sign_certificate_for(default)
end
+ # Create a temp directory on remote host, optionally owned by specified user and group.
+ #
+ # @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
+ # or a role (String or Symbol) that identifies one or more hosts.
+ # @param [String] path_prefix A remote path prefix for the new temp directory.
+ # @param [String] user The name of user that should own the temp directory. If
+ # not specified, uses default permissions from tmpdir creation.
+ # @param [String] group The name of group that should own the temp directory.
+ # If not specified, uses default permissions from tmpdir creation.
+ #
+ # @return [String, Array<String>] Returns the name of the newly-created dir, or
+ # an array of names of newly-created dirs per-host
+ #
+ # @note While tempting, this method should not be "optimized" to coalesce calls to
+ # chown user:group when both options are passed, as doing so will muddy the spec.
+ def create_tmpdir_on(hosts, path_prefix = '', user = nil, group = nil)
+ block_on hosts do | host |
+ # create the directory
+ dir = host.tmpdir(path_prefix)
+ # only chown if explicitly passed; don't make assumptions about perms
+ # only `chown user` for cleaner codepaths
+ if user
+ # ensure user exists
+ if not host.user_get(user).success?
+ # clean up
+ host.rm_rf("#{dir}")
+ raise "User #{user} does not exist on #{host}."
+ end
+ # chown only user
+ host.chown(user, dir)
+ # on host, "chown #{user} #{dir}"
+ end
+ # only chgrp if explicitly passed; don't make assumptions about perms
+ if group
+ # ensure group exists
+ if not host.group_get(group).success?
+ # clean up
+ # on host, "rmdir #{dir}"
+ host.rm_rf(dir)
+ raise "Group #{group} does not exist on #{host}."
+ end
+ # chgrp
+ # on host, "chgrp #{group} #{dir}"
+ host.chgrp(group, dir)
+ end
+ dir
+ end
+ end
+
# Create a temp directory on remote host with a user. Default user
# is puppet master user.
#
# @param [Host] host A single remote host on which to create and adjust
# the ownership of a temp directory.