Skip to content

Commit da363b4

Browse files
author
Branan Riley
authored
Merge pull request #57 from puppetlabs/revert-56-BKR-496
Revert "(BKR-496) Move create_tmpdir_on from beaker"
2 parents 2c21779 + dcf3654 commit da363b4

File tree

3 files changed

+0
-188
lines changed

3 files changed

+0
-188
lines changed

acceptance/tests/create_tmpdir_on_test.rb

Lines changed: 0 additions & 47 deletions
This file was deleted.

lib/beaker-puppet/helpers/puppet_helpers.rb

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -865,55 +865,6 @@ def sign_certificate
865865
sign_certificate_for(default)
866866
end
867867

868-
# Create a temp directory on remote host, optionally owned by specified user and group.
869-
#
870-
# @param [Host, Array<Host>, String, Symbol] hosts One or more hosts to act upon,
871-
# or a role (String or Symbol) that identifies one or more hosts.
872-
# @param [String] path_prefix A remote path prefix for the new temp directory.
873-
# @param [String] user The name of user that should own the temp directory. If
874-
# not specified, uses default permissions from tmpdir creation.
875-
# @param [String] group The name of group that should own the temp directory.
876-
# If not specified, uses default permissions from tmpdir creation.
877-
#
878-
# @return [String, Array<String>] Returns the name of the newly-created dir, or
879-
# an array of names of newly-created dirs per-host
880-
#
881-
# @note While tempting, this method should not be "optimized" to coalesce calls to
882-
# chown user:group when both options are passed, as doing so will muddy the spec.
883-
def create_tmpdir_on(hosts, path_prefix = '', user = nil, group = nil)
884-
block_on hosts do | host |
885-
# create the directory
886-
dir = host.tmpdir(path_prefix)
887-
# only chown if explicitly passed; don't make assumptions about perms
888-
# only `chown user` for cleaner codepaths
889-
if user
890-
# ensure user exists
891-
if not host.user_get(user).success?
892-
# clean up
893-
host.rm_rf("#{dir}")
894-
raise "User #{user} does not exist on #{host}."
895-
end
896-
# chown only user
897-
host.chown(user, dir)
898-
# on host, "chown #{user} #{dir}"
899-
end
900-
# only chgrp if explicitly passed; don't make assumptions about perms
901-
if group
902-
# ensure group exists
903-
if not host.group_get(group).success?
904-
# clean up
905-
# on host, "rmdir #{dir}"
906-
host.rm_rf(dir)
907-
raise "Group #{group} does not exist on #{host}."
908-
end
909-
# chgrp
910-
# on host, "chgrp #{group} #{dir}"
911-
host.chgrp(group, dir)
912-
end
913-
dir
914-
end
915-
end
916-
917868
# Create a temp directory on remote host with a user. Default user
918869
# is puppet master user.
919870
#

spec/beaker-puppet/helpers/puppet_helpers_spec.rb

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -29,98 +29,6 @@ def logger
2929
let( :db ) { make_host( 'db', :roles => %w( database agent ) ) }
3030
let( :hosts ) { [ master, agent, dash, db, custom ] }
3131

32-
describe '#create_tmpdir_on' do
33-
let(:host) { {'user' => 'puppet', 'group' => 'muppets'} }
34-
let(:result_success) { double.as_null_object }
35-
let(:result_failure) { double.as_null_object }
36-
let(:tmpdir) { '/tmp/beaker.XXXXXX/' }
37-
38-
before :each do
39-
allow( host ).to receive( :tmpdir ).and_return( tmpdir )
40-
allow( host ).to receive( :result ).and_return( result_success )
41-
allow( result_success ).to receive( :success? ).and_return( true )
42-
allow( result_success ).to receive( :stdout ).and_return( 'puppet' )
43-
allow( result_failure ).to receive( :success? ).and_return( false )
44-
end
45-
46-
context 'with the path_prefix argument' do
47-
it 'passes path_prefix to host.tmpdir' do
48-
expect( host ).to receive( :tmpdir ).with( 'beaker' )
49-
subject.create_tmpdir_on( host, 'beaker' )
50-
end
51-
end
52-
53-
context 'with the user argument' do
54-
it 'calls chown when a user is specified' do
55-
expect( host ).to receive( :user_get ).and_return( result_success )
56-
expect( host ).to receive( :chown ).with( host['user'], tmpdir )
57-
58-
subject.create_tmpdir_on( host, 'beaker', host['user'] )
59-
end
60-
61-
it 'does not call chown when a user is not specified' do
62-
expect( host ).to_not receive( :chown )
63-
64-
subject.create_tmpdir_on( host, 'beaker' )
65-
end
66-
67-
it 'does not call chown and cleans up when the user does not exist on the host' do
68-
expect( host ).to receive( :user_get ).and_return( result_failure )
69-
expect( host ).to receive( :rm_rf ).with( tmpdir )
70-
71-
expect{
72-
subject.create_tmpdir_on( host, 'beaker', 'invalid.user' )
73-
}.to raise_error( RuntimeError, /User invalid.user does not exist on / )
74-
end
75-
end
76-
77-
context 'with the group argument' do
78-
it 'calls chgrp when a group is specified' do
79-
expect( host ).to receive( :group_get ).and_return( result_success )
80-
expect( host ).to receive( :chgrp ).with( host['group'], tmpdir )
81-
82-
subject.create_tmpdir_on( host, 'beaker', nil, host['group'] )
83-
end
84-
85-
it 'does not call chgrp when a group is not specified' do
86-
expect( subject ).to_not receive( :chgrp )
87-
88-
subject.create_tmpdir_on( host, 'beaker' )
89-
end
90-
91-
it 'does not call chgrp and cleans up when the group does not exist on the host' do
92-
expect( host ).to receive( :group_get ).and_return( result_failure )
93-
expect( host ).to receive( :rm_rf ).with( tmpdir )
94-
95-
expect{
96-
subject.create_tmpdir_on( host, 'beaker', nil, 'invalid.group' )
97-
}.to raise_error( RuntimeError, /Group invalid.group does not exist on / )
98-
end
99-
end
100-
101-
context 'with user and group arguments' do
102-
# don't coalesce the group into chown, i.e. `chown user:group`
103-
# this keeps execution paths simple, clean, and discrete
104-
it 'calls chown and chgrp separately' do
105-
expect( host ).to receive( :user_get ).and_return( result_success )
106-
expect( host ).to receive( :group_get ).and_return( result_success )
107-
expect( host ).to receive( :chown ).with( host['user'], tmpdir )
108-
expect( host ).to receive( :chgrp ).with( host['group'], tmpdir )
109-
110-
subject.create_tmpdir_on( host, 'beaker', host['user'], host['group'] )
111-
end
112-
113-
it 'does not pass group to chown' do
114-
allow( host ).to receive( :user_get ).and_return( result_success )
115-
allow( host ).to receive( :chgrp ).with( host['group'], tmpdir )
116-
117-
expect( host ).to receive( :group_get ).and_return( result_success )
118-
expect( host ).to receive( :chown ).with( host['user'], tmpdir )
119-
120-
subject.create_tmpdir_on( host, 'beaker', host['user'], host['group'] )
121-
end
122-
end
123-
end
12432

12533
describe '#create_tmpdir_for_user' do
12634
let(:host) { {} }

0 commit comments

Comments
 (0)