beaker-puppet 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58336da53f9d99a2cf8cfdc1953cf93fcc44caae
|
4
|
+
data.tar.gz: 3475c0bda9886d60d226935501df00a66b152860
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5f343170c441d786f464f810b2f80c571a563de4e5e837a317afbae71fce33cb0196478b3735daa58d68341c2affb7f7f46d20788fccd15d8cfc2568e03ce12
|
7
|
+
data.tar.gz: 947b6b1cf35306b1ed9640ae3595713d2970ae1c25db77fe5aa6332b0a2e1e3d4321469c3cef3a7caac5e80944110d2bc51dc78a3ed3b7b3422b9263415ced64
|
@@ -0,0 +1,47 @@
|
|
1
|
+
test_name "dsl::helpers::host_helpers #create_tmpdir_on" do
|
2
|
+
step "#create_tmpdir_on returns a temporary directory on the remote system" do
|
3
|
+
tmpdir = create_tmpdir_on default
|
4
|
+
assert_match %r{/}, tmpdir
|
5
|
+
assert_equal 0, on(default, "touch #{tmpdir}/testfile").exit_code
|
6
|
+
end
|
7
|
+
|
8
|
+
step "#create_tmpdir_on uses the specified path prefix when provided" do
|
9
|
+
tmpdir = create_tmpdir_on(default, "mypathprefix")
|
10
|
+
assert_match %r{/mypathprefix}, tmpdir
|
11
|
+
assert_equal 0, on(default, "touch #{tmpdir}/testfile").exit_code
|
12
|
+
end
|
13
|
+
|
14
|
+
step "#create_tmpdir_on fails if a non-existent user is specified" do
|
15
|
+
assert_raises Beaker::Host::CommandFailure do
|
16
|
+
tmpdir = create_tmpdir_on default, '', 'fakeuser'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
step "#create_tmpdir_on sets the user if specified" do
|
21
|
+
default.user_present('tmpdirtestuser')
|
22
|
+
tmpdir = create_tmpdir_on(default, nil, 'tmpdirtestuser', nil)
|
23
|
+
assert_match /tmpdirtestuser/, on(default, "ls -ld #{tmpdir}").output
|
24
|
+
default.user_absent('tmpdirtestuser')
|
25
|
+
end
|
26
|
+
|
27
|
+
step "#create_tmpdir_on fails if a non-existent group is specified" do
|
28
|
+
assert_raises Beaker::Host::CommandFailure do
|
29
|
+
tmpdir = create_tmpdir_on default, '', nil, 'fakegroup'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
step "#create_tmpdir_on sets the group if specified" do
|
34
|
+
default.group_present('tmpdirtestgroup')
|
35
|
+
tmpdir = create_tmpdir_on(default, nil, nil, 'tmpdirtestgroup')
|
36
|
+
assert_match /testgroup/, on(default, "ls -ld #{tmpdir}").output
|
37
|
+
default.group_absent('tmpdirtestgroup')
|
38
|
+
end
|
39
|
+
|
40
|
+
step "#create_tmpdir_on operates on all hosts if given a hosts array" do
|
41
|
+
tmpdirs = create_tmpdir_on hosts
|
42
|
+
hosts.zip(tmpdirs).each do |(host, tmpdir)|
|
43
|
+
assert_match %r{/}, tmpdir
|
44
|
+
assert_equal 0, on(host, "touch #{tmpdir}/testfile").exit_code
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -865,6 +865,55 @@ module Beaker
|
|
865
865
|
sign_certificate_for(default)
|
866
866
|
end
|
867
867
|
|
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
|
+
|
868
917
|
# Create a temp directory on remote host with a user. Default user
|
869
918
|
# is puppet master user.
|
870
919
|
#
|
@@ -29,6 +29,98 @@ describe ClassMixedWithDSLHelpers do
|
|
29
29
|
let( :db ) { make_host( 'db', :roles => %w( database agent ) ) }
|
30
30
|
let( :hosts ) { [ master, agent, dash, db, custom ] }
|
31
31
|
|
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
|
32
124
|
|
33
125
|
describe '#create_tmpdir_for_user' do
|
34
126
|
let(:host) { {} }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaker-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -210,6 +210,7 @@ files:
|
|
210
210
|
- acceptance/pre_suite/pkg/install.rb
|
211
211
|
- acceptance/tests/README.md
|
212
212
|
- acceptance/tests/backwards_compatible.rb
|
213
|
+
- acceptance/tests/create_tmpdir_on_test.rb
|
213
214
|
- acceptance/tests/install_smoke_test.rb
|
214
215
|
- acceptance/tests/stub_host.rb
|
215
216
|
- acceptance/tests/web_helpers_test.rb
|