puppet 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +0 -0
- data/COPYING +340 -0
- data/LICENSE +17 -0
- data/README +24 -0
- data/Rakefile +294 -0
- data/TODO +4 -0
- data/bin/cf2puppet +186 -0
- data/bin/puppet +176 -0
- data/bin/puppetca +213 -0
- data/bin/puppetd +246 -0
- data/bin/puppetdoc +184 -0
- data/bin/puppetmasterd +258 -0
- data/examples/code/allatonce +13 -0
- data/examples/code/assignments +11 -0
- data/examples/code/classing +35 -0
- data/examples/code/components +73 -0
- data/examples/code/execs +16 -0
- data/examples/code/failers/badclassnoparam +10 -0
- data/examples/code/failers/badclassparam +10 -0
- data/examples/code/failers/badcompnoparam +9 -0
- data/examples/code/failers/badcompparam +9 -0
- data/examples/code/failers/badtypeparam +3 -0
- data/examples/code/file.bl +11 -0
- data/examples/code/filedefaults +10 -0
- data/examples/code/fileparsing +116 -0
- data/examples/code/filerecursion +15 -0
- data/examples/code/functions +3 -0
- data/examples/code/groups +7 -0
- data/examples/code/head +30 -0
- data/examples/code/importing +8 -0
- data/examples/code/nodes +20 -0
- data/examples/code/one +8 -0
- data/examples/code/relationships +34 -0
- data/examples/code/selectors +28 -0
- data/examples/code/simpletests +11 -0
- data/examples/code/snippets/argumentdefaults +14 -0
- data/examples/code/snippets/casestatement +39 -0
- data/examples/code/snippets/classheirarchy.pp +15 -0
- data/examples/code/snippets/classincludes.pp +17 -0
- data/examples/code/snippets/classpathtest +11 -0
- data/examples/code/snippets/dirchmod +19 -0
- data/examples/code/snippets/failmissingexecpath.pp +13 -0
- data/examples/code/snippets/falsevalues.pp +3 -0
- data/examples/code/snippets/filecreate +11 -0
- data/examples/code/snippets/implicititeration +15 -0
- data/examples/code/snippets/multipleinstances +7 -0
- data/examples/code/snippets/namevartest +9 -0
- data/examples/code/snippets/scopetest +13 -0
- data/examples/code/snippets/selectorvalues.pp +22 -0
- data/examples/code/snippets/simpledefaults +5 -0
- data/examples/code/snippets/simpleselector +38 -0
- data/examples/code/svncommit +13 -0
- data/examples/root/bin/sleeper +69 -0
- data/examples/root/etc/configfile +0 -0
- data/examples/root/etc/debian-passwd +29 -0
- data/examples/root/etc/debian-syslog.conf +71 -0
- data/examples/root/etc/init.d/sleeper +65 -0
- data/examples/root/etc/otherfile +0 -0
- data/examples/root/etc/puppet/fileserver.conf +3 -0
- data/examples/root/etc/puppet/puppetmasterd.conf +10 -0
- data/ext/module:puppet +195 -0
- data/install.rb +270 -0
- data/lib/puppet.rb +249 -0
- data/lib/puppet/base64.rb +19 -0
- data/lib/puppet/client.rb +519 -0
- data/lib/puppet/config.rb +49 -0
- data/lib/puppet/daemon.rb +208 -0
- data/lib/puppet/element.rb +71 -0
- data/lib/puppet/event.rb +259 -0
- data/lib/puppet/log.rb +321 -0
- data/lib/puppet/metric.rb +250 -0
- data/lib/puppet/parsedfile.rb +38 -0
- data/lib/puppet/parser/ast.rb +1560 -0
- data/lib/puppet/parser/interpreter.rb +150 -0
- data/lib/puppet/parser/lexer.rb +226 -0
- data/lib/puppet/parser/parser.rb +1354 -0
- data/lib/puppet/parser/scope.rb +755 -0
- data/lib/puppet/server.rb +170 -0
- data/lib/puppet/server/authstore.rb +227 -0
- data/lib/puppet/server/ca.rb +140 -0
- data/lib/puppet/server/filebucket.rb +147 -0
- data/lib/puppet/server/fileserver.rb +477 -0
- data/lib/puppet/server/logger.rb +43 -0
- data/lib/puppet/server/master.rb +103 -0
- data/lib/puppet/server/servlet.rb +247 -0
- data/lib/puppet/sslcertificates.rb +737 -0
- data/lib/puppet/statechange.rb +150 -0
- data/lib/puppet/storage.rb +95 -0
- data/lib/puppet/transaction.rb +179 -0
- data/lib/puppet/transportable.rb +151 -0
- data/lib/puppet/type.rb +1354 -0
- data/lib/puppet/type/component.rb +141 -0
- data/lib/puppet/type/cron.rb +543 -0
- data/lib/puppet/type/exec.rb +316 -0
- data/lib/puppet/type/group.rb +152 -0
- data/lib/puppet/type/nameservice.rb +3 -0
- data/lib/puppet/type/nameservice/netinfo.rb +173 -0
- data/lib/puppet/type/nameservice/objectadd.rb +146 -0
- data/lib/puppet/type/nameservice/posix.rb +200 -0
- data/lib/puppet/type/package.rb +420 -0
- data/lib/puppet/type/package/apt.rb +70 -0
- data/lib/puppet/type/package/dpkg.rb +108 -0
- data/lib/puppet/type/package/rpm.rb +81 -0
- data/lib/puppet/type/package/sun.rb +117 -0
- data/lib/puppet/type/package/yum.rb +58 -0
- data/lib/puppet/type/pfile.rb +569 -0
- data/lib/puppet/type/pfile/checksum.rb +219 -0
- data/lib/puppet/type/pfile/create.rb +108 -0
- data/lib/puppet/type/pfile/group.rb +129 -0
- data/lib/puppet/type/pfile/mode.rb +131 -0
- data/lib/puppet/type/pfile/source.rb +264 -0
- data/lib/puppet/type/pfile/type.rb +31 -0
- data/lib/puppet/type/pfile/uid.rb +166 -0
- data/lib/puppet/type/pfilebucket.rb +80 -0
- data/lib/puppet/type/pprocess.rb +97 -0
- data/lib/puppet/type/service.rb +347 -0
- data/lib/puppet/type/service/base.rb +17 -0
- data/lib/puppet/type/service/debian.rb +50 -0
- data/lib/puppet/type/service/init.rb +145 -0
- data/lib/puppet/type/service/smf.rb +29 -0
- data/lib/puppet/type/state.rb +182 -0
- data/lib/puppet/type/symlink.rb +183 -0
- data/lib/puppet/type/tidy.rb +183 -0
- data/lib/puppet/type/typegen.rb +149 -0
- data/lib/puppet/type/typegen/filerecord.rb +243 -0
- data/lib/puppet/type/typegen/filetype.rb +316 -0
- data/lib/puppet/type/user.rb +290 -0
- data/lib/puppet/util.rb +138 -0
- data/test/certmgr/certmgr.rb +265 -0
- data/test/client/client.rb +203 -0
- data/test/executables/puppetbin.rb +53 -0
- data/test/executables/puppetca.rb +79 -0
- data/test/executables/puppetd.rb +71 -0
- data/test/executables/puppetmasterd.rb +153 -0
- data/test/executables/puppetmodule.rb +60 -0
- data/test/language/ast.rb +412 -0
- data/test/language/interpreter.rb +71 -0
- data/test/language/scope.rb +412 -0
- data/test/language/snippets.rb +445 -0
- data/test/other/events.rb +111 -0
- data/test/other/log.rb +195 -0
- data/test/other/metrics.rb +92 -0
- data/test/other/overrides.rb +115 -0
- data/test/other/parsedfile.rb +31 -0
- data/test/other/relationships.rb +113 -0
- data/test/other/state.rb +106 -0
- data/test/other/storage.rb +39 -0
- data/test/other/transactions.rb +235 -0
- data/test/parser/lexer.rb +120 -0
- data/test/parser/parser.rb +180 -0
- data/test/puppet/conffiles.rb +104 -0
- data/test/puppet/defaults.rb +100 -0
- data/test/puppet/error.rb +23 -0
- data/test/puppet/utiltest.rb +120 -0
- data/test/puppettest.rb +774 -0
- data/test/server/authstore.rb +209 -0
- data/test/server/bucket.rb +227 -0
- data/test/server/ca.rb +201 -0
- data/test/server/fileserver.rb +710 -0
- data/test/server/logger.rb +175 -0
- data/test/server/master.rb +150 -0
- data/test/server/server.rb +130 -0
- data/test/tagging/tagging.rb +80 -0
- data/test/test +51 -0
- data/test/types/basic.rb +119 -0
- data/test/types/component.rb +272 -0
- data/test/types/cron.rb +261 -0
- data/test/types/exec.rb +273 -0
- data/test/types/file.rb +616 -0
- data/test/types/filebucket.rb +167 -0
- data/test/types/fileignoresource.rb +287 -0
- data/test/types/filesources.rb +587 -0
- data/test/types/filetype.rb +162 -0
- data/test/types/group.rb +271 -0
- data/test/types/package.rb +205 -0
- data/test/types/query.rb +101 -0
- data/test/types/service.rb +100 -0
- data/test/types/symlink.rb +93 -0
- data/test/types/tidy.rb +124 -0
- data/test/types/type.rb +135 -0
- data/test/types/user.rb +371 -0
- metadata +243 -0
data/test/types/cron.rb
ADDED
@@ -0,0 +1,261 @@
|
|
1
|
+
# Test cron job creation, modification, and destruction
|
2
|
+
|
3
|
+
if __FILE__ == $0
|
4
|
+
$:.unshift '..'
|
5
|
+
$:.unshift '../../lib'
|
6
|
+
$puppetbase = "../../../../language/trunk"
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'puppettest'
|
10
|
+
require 'puppet'
|
11
|
+
require 'puppet/type/cron'
|
12
|
+
require 'test/unit'
|
13
|
+
require 'facter'
|
14
|
+
|
15
|
+
class TestExec < Test::Unit::TestCase
|
16
|
+
include TestPuppet
|
17
|
+
def setup
|
18
|
+
super
|
19
|
+
# retrieve the user name
|
20
|
+
id = %x{id}.chomp
|
21
|
+
if id =~ /uid=\d+\(([^\)]+)\)/
|
22
|
+
@me = $1
|
23
|
+
else
|
24
|
+
puts id
|
25
|
+
end
|
26
|
+
unless defined? @me
|
27
|
+
raise "Could not retrieve user name; 'id' did not work"
|
28
|
+
end
|
29
|
+
# god i'm lazy
|
30
|
+
@crontype = Puppet::Type::Cron
|
31
|
+
end
|
32
|
+
|
33
|
+
# Back up the user's existing cron tab if they have one.
|
34
|
+
def cronback
|
35
|
+
tab = nil
|
36
|
+
assert_nothing_raised {
|
37
|
+
tab = Puppet::Type::Cron.crontype.read(@me)
|
38
|
+
}
|
39
|
+
|
40
|
+
if $? == 0
|
41
|
+
@currenttab = tab
|
42
|
+
else
|
43
|
+
@currenttab = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Restore the cron tab to its original form.
|
48
|
+
def cronrestore
|
49
|
+
assert_nothing_raised {
|
50
|
+
if @currenttab
|
51
|
+
@crontype.crontype.write(@me, @currenttab)
|
52
|
+
else
|
53
|
+
@crontype.crontype.remove(@me)
|
54
|
+
end
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
# Create a cron job with all fields filled in.
|
59
|
+
def mkcron(name)
|
60
|
+
cron = nil
|
61
|
+
assert_nothing_raised {
|
62
|
+
cron = @crontype.create(
|
63
|
+
:command => "date > %s/crontest%s" % [tmpdir(), name],
|
64
|
+
:name => name,
|
65
|
+
:user => @me,
|
66
|
+
:minute => rand(59),
|
67
|
+
:month => "1",
|
68
|
+
:monthday => "1",
|
69
|
+
:hour => "1"
|
70
|
+
)
|
71
|
+
}
|
72
|
+
|
73
|
+
return cron
|
74
|
+
end
|
75
|
+
|
76
|
+
# Run the cron through its paces -- install it then remove it.
|
77
|
+
def cyclecron(cron)
|
78
|
+
name = cron.name
|
79
|
+
comp = newcomp(name, cron)
|
80
|
+
|
81
|
+
trans = assert_events(comp, [:cron_created], name)
|
82
|
+
cron.retrieve
|
83
|
+
assert(cron.insync?)
|
84
|
+
trans = assert_events(comp, [], name)
|
85
|
+
cron[:command] = :notfound
|
86
|
+
trans = assert_events(comp, [:cron_deleted], name)
|
87
|
+
# the cron should no longer exist, not even in the comp
|
88
|
+
trans = assert_events(comp, [], name)
|
89
|
+
|
90
|
+
assert(!comp.include?(cron),
|
91
|
+
"Cron is still a member of comp, after being deleted")
|
92
|
+
end
|
93
|
+
|
94
|
+
# A simple test to see if we can load the cron from disk.
|
95
|
+
def test_load
|
96
|
+
assert_nothing_raised {
|
97
|
+
@crontype.retrieve(@me)
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
# Test that a cron job turns out as expected, by creating one and generating
|
102
|
+
# it directly
|
103
|
+
def test_simple_to_cron
|
104
|
+
cron = nil
|
105
|
+
# make the cron
|
106
|
+
name = "yaytest"
|
107
|
+
assert_nothing_raised {
|
108
|
+
cron = @crontype.create(
|
109
|
+
:name => name,
|
110
|
+
:command => "date",
|
111
|
+
:user => @me
|
112
|
+
)
|
113
|
+
}
|
114
|
+
str = nil
|
115
|
+
# generate the text
|
116
|
+
assert_nothing_raised {
|
117
|
+
str = cron.to_cron
|
118
|
+
}
|
119
|
+
assert_equal(str, "# Puppet Name: #{name}\n* * * * * date",
|
120
|
+
"Cron did not generate correctly")
|
121
|
+
end
|
122
|
+
|
123
|
+
# Test that comments are correctly retained
|
124
|
+
def test_retain_comments
|
125
|
+
str = "# this is a comment\n#and another comment\n"
|
126
|
+
user = "fakeuser"
|
127
|
+
assert_nothing_raised {
|
128
|
+
@crontype.parse(user, str)
|
129
|
+
}
|
130
|
+
|
131
|
+
assert_nothing_raised {
|
132
|
+
newstr = @crontype.tab(user)
|
133
|
+
assert_equal(str, newstr, "Cron comments were changed or lost")
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
# Test that a specified cron job will be matched against an existing job
|
138
|
+
# with no name, as long as all fields match
|
139
|
+
def test_matchcron
|
140
|
+
str = "0,30 * * * * date\n"
|
141
|
+
|
142
|
+
assert_nothing_raised {
|
143
|
+
@crontype.parse(@me, str)
|
144
|
+
}
|
145
|
+
|
146
|
+
assert_nothing_raised {
|
147
|
+
cron = @crontype.create(
|
148
|
+
:name => "yaycron",
|
149
|
+
:minute => [0, 30],
|
150
|
+
:command => "date",
|
151
|
+
:user => @me
|
152
|
+
)
|
153
|
+
}
|
154
|
+
|
155
|
+
modstr = "# Puppet Name: yaycron\n%s" % str
|
156
|
+
|
157
|
+
assert_nothing_raised {
|
158
|
+
newstr = @crontype.tab(@me)
|
159
|
+
assert_equal(modstr, newstr, "Cron was not correctly matched")
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
# Test adding a cron when there is currently no file.
|
164
|
+
def test_mkcronwithnotab
|
165
|
+
cronback
|
166
|
+
Puppet::Type::Cron.crontype.remove(@me)
|
167
|
+
|
168
|
+
cron = mkcron("testwithnotab")
|
169
|
+
cyclecron(cron)
|
170
|
+
cronrestore
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_mkcronwithtab
|
174
|
+
cronback
|
175
|
+
Puppet::Type::Cron.crontype.remove(@me)
|
176
|
+
Puppet::Type::Cron.crontype.write(@me,
|
177
|
+
"1 1 1 1 * date > %s/crontesting\n" % testdir()
|
178
|
+
)
|
179
|
+
|
180
|
+
cron = mkcron("testwithtab")
|
181
|
+
cyclecron(cron)
|
182
|
+
cronrestore
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_makeandretrievecron
|
186
|
+
cronback
|
187
|
+
Puppet::Type::Cron.crontype.remove(@me)
|
188
|
+
|
189
|
+
name = "storeandretrieve"
|
190
|
+
cron = mkcron(name)
|
191
|
+
comp = newcomp(name, cron)
|
192
|
+
trans = assert_events(comp, [:cron_created], name)
|
193
|
+
|
194
|
+
cron = nil
|
195
|
+
|
196
|
+
Puppet::Type::Cron.clear
|
197
|
+
Puppet::Type::Cron.retrieve(@me)
|
198
|
+
|
199
|
+
assert(cron = Puppet::Type::Cron[name], "Could not retrieve named cron")
|
200
|
+
assert_instance_of(Puppet::Type::Cron, cron)
|
201
|
+
cronrestore
|
202
|
+
end
|
203
|
+
|
204
|
+
# Do input validation testing on all of the parameters.
|
205
|
+
def test_arguments
|
206
|
+
values = {
|
207
|
+
:monthday => {
|
208
|
+
:valid => [ 1, 13, "1,30" ],
|
209
|
+
:invalid => [ -1, 0, 32 ]
|
210
|
+
},
|
211
|
+
:weekday => {
|
212
|
+
:valid => [ 0, 3, 6, "1,2", "tue", "wed",
|
213
|
+
"Wed", "MOnday", "SaTurday" ],
|
214
|
+
:invalid => [ -1, 7, "1, 3", "tues", "teusday", "thurs" ]
|
215
|
+
},
|
216
|
+
:hour => {
|
217
|
+
:valid => [ 0, 21, 23 ],
|
218
|
+
:invalid => [ -1, 24 ]
|
219
|
+
},
|
220
|
+
:minute => {
|
221
|
+
:valid => [ 0, 34, 59 ],
|
222
|
+
:invalid => [ -1, 60 ]
|
223
|
+
},
|
224
|
+
:month => {
|
225
|
+
:valid => [ 1, 11, 12, "mar", "March", "apr", "October", "DeCeMbEr" ],
|
226
|
+
:invalid => [ 0, 13, "marc", "sept" ]
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
cron = mkcron("valtesting")
|
231
|
+
values.each { |param, hash|
|
232
|
+
hash.each { |type, values|
|
233
|
+
values.each { |value|
|
234
|
+
case type
|
235
|
+
when :valid:
|
236
|
+
assert_nothing_raised {
|
237
|
+
cron[param] = value
|
238
|
+
}
|
239
|
+
|
240
|
+
if value.is_a?(Integer)
|
241
|
+
assert_equal([value], cron[param],
|
242
|
+
"Cron value was not set correctly")
|
243
|
+
end
|
244
|
+
when :invalid:
|
245
|
+
assert_raise(Puppet::Error, "%s is incorrectly a valid %s" %
|
246
|
+
[value, param]) {
|
247
|
+
cron[param] = value
|
248
|
+
}
|
249
|
+
end
|
250
|
+
|
251
|
+
if value.is_a?(Integer)
|
252
|
+
value = value.to_s
|
253
|
+
redo
|
254
|
+
end
|
255
|
+
}
|
256
|
+
}
|
257
|
+
}
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
# $Id: cron.rb 742 2005-11-16 17:12:11Z luke $
|
data/test/types/exec.rb
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
$:.unshift '..'
|
3
|
+
$:.unshift '../../lib'
|
4
|
+
$puppetbase = "../.."
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'puppettest'
|
9
|
+
require 'test/unit'
|
10
|
+
require 'facter'
|
11
|
+
|
12
|
+
# $Id: exec.rb 742 2005-11-16 17:12:11Z luke $
|
13
|
+
|
14
|
+
class TestExec < Test::Unit::TestCase
|
15
|
+
include TestPuppet
|
16
|
+
def test_execution
|
17
|
+
command = nil
|
18
|
+
output = nil
|
19
|
+
assert_nothing_raised {
|
20
|
+
command = Puppet::Type::Exec.create(
|
21
|
+
:command => "/bin/echo"
|
22
|
+
)
|
23
|
+
}
|
24
|
+
assert_nothing_raised {
|
25
|
+
command.evaluate
|
26
|
+
}
|
27
|
+
assert_nothing_raised {
|
28
|
+
output = command.sync
|
29
|
+
}
|
30
|
+
assert_equal([:executed_command],output)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_numvsstring
|
34
|
+
command = nil
|
35
|
+
output = nil
|
36
|
+
assert_nothing_raised {
|
37
|
+
command = Puppet::Type::Exec.create(
|
38
|
+
:command => "/bin/echo",
|
39
|
+
:returns => 0
|
40
|
+
)
|
41
|
+
}
|
42
|
+
assert_nothing_raised {
|
43
|
+
command.evaluate
|
44
|
+
}
|
45
|
+
assert_nothing_raised {
|
46
|
+
output = command.sync
|
47
|
+
}
|
48
|
+
Puppet::Type::Exec.clear
|
49
|
+
assert_nothing_raised {
|
50
|
+
command = Puppet::Type::Exec.create(
|
51
|
+
:command => "/bin/echo",
|
52
|
+
:returns => "0"
|
53
|
+
)
|
54
|
+
}
|
55
|
+
assert_nothing_raised {
|
56
|
+
command.evaluate
|
57
|
+
}
|
58
|
+
assert_nothing_raised {
|
59
|
+
output = command.sync
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_path_or_qualified
|
64
|
+
command = nil
|
65
|
+
output = nil
|
66
|
+
assert_nothing_raised {
|
67
|
+
command = Puppet::Type::Exec.create(
|
68
|
+
:command => "echo"
|
69
|
+
)
|
70
|
+
assert_nil(command)
|
71
|
+
}
|
72
|
+
Puppet::Type::Exec.clear
|
73
|
+
assert_nothing_raised {
|
74
|
+
command = Puppet::Type::Exec.create(
|
75
|
+
:command => "echo",
|
76
|
+
:path => "/usr/bin:/bin:/usr/sbin:/sbin"
|
77
|
+
)
|
78
|
+
}
|
79
|
+
Puppet::Type::Exec.clear
|
80
|
+
assert_nothing_raised {
|
81
|
+
command = Puppet::Type::Exec.create(
|
82
|
+
:command => "/bin/echo"
|
83
|
+
)
|
84
|
+
}
|
85
|
+
Puppet::Type::Exec.clear
|
86
|
+
assert_nothing_raised {
|
87
|
+
command = Puppet::Type::Exec.create(
|
88
|
+
:command => "/bin/echo",
|
89
|
+
:path => "/usr/bin:/bin:/usr/sbin:/sbin"
|
90
|
+
)
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_nonzero_returns
|
95
|
+
assert_nothing_raised {
|
96
|
+
command = Puppet::Type::Exec.create(
|
97
|
+
:command => "mkdir /this/directory/does/not/exist",
|
98
|
+
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
99
|
+
:returns => 1
|
100
|
+
)
|
101
|
+
}
|
102
|
+
assert_nothing_raised {
|
103
|
+
command = Puppet::Type::Exec.create(
|
104
|
+
:command => "touch /etc",
|
105
|
+
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
106
|
+
:returns => 1
|
107
|
+
)
|
108
|
+
}
|
109
|
+
assert_nothing_raised {
|
110
|
+
command = Puppet::Type::Exec.create(
|
111
|
+
:command => "thiscommanddoesnotexist",
|
112
|
+
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
113
|
+
:returns => 127
|
114
|
+
)
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_cwdsettings
|
119
|
+
command = nil
|
120
|
+
dir = "/tmp"
|
121
|
+
wd = Dir.chdir(dir) {
|
122
|
+
Dir.getwd
|
123
|
+
}
|
124
|
+
assert_nothing_raised {
|
125
|
+
command = Puppet::Type::Exec.create(
|
126
|
+
:command => "pwd",
|
127
|
+
:cwd => dir,
|
128
|
+
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
129
|
+
:returns => 0
|
130
|
+
)
|
131
|
+
}
|
132
|
+
assert_nothing_raised {
|
133
|
+
command.evaluate
|
134
|
+
}
|
135
|
+
assert_nothing_raised {
|
136
|
+
command.sync
|
137
|
+
}
|
138
|
+
assert_equal(wd,command.output.chomp)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_refreshonly
|
142
|
+
file = nil
|
143
|
+
cmd = nil
|
144
|
+
tmpfile = "/tmp/exectesting"
|
145
|
+
@@tmpfiles.push tmpfile
|
146
|
+
trans = nil
|
147
|
+
File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of|
|
148
|
+
of.puts rand(100)
|
149
|
+
}
|
150
|
+
file = Puppet::Type::PFile.create(
|
151
|
+
:path => tmpfile,
|
152
|
+
:checksum => "md5"
|
153
|
+
)
|
154
|
+
assert_nothing_raised {
|
155
|
+
cmd = Puppet::Type::Exec.create(
|
156
|
+
:command => "pwd",
|
157
|
+
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
158
|
+
:subscribe => [[file.class.name,file.name]],
|
159
|
+
:refreshonly => true
|
160
|
+
)
|
161
|
+
}
|
162
|
+
|
163
|
+
comp = Puppet::Type::Component.create(:name => "RefreshTest")
|
164
|
+
[file,cmd].each { |obj|
|
165
|
+
comp.push obj
|
166
|
+
}
|
167
|
+
events = nil
|
168
|
+
assert_nothing_raised {
|
169
|
+
trans = comp.evaluate
|
170
|
+
|
171
|
+
sum = file.state(:checksum)
|
172
|
+
assert_equal(sum.is, sum.should)
|
173
|
+
events = trans.evaluate.collect { |event|
|
174
|
+
event.event
|
175
|
+
}
|
176
|
+
}
|
177
|
+
# the first checksum shouldn't result in a changed file
|
178
|
+
assert_equal([],events)
|
179
|
+
File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of|
|
180
|
+
of.puts rand(100)
|
181
|
+
of.puts rand(100)
|
182
|
+
of.puts rand(100)
|
183
|
+
}
|
184
|
+
assert_nothing_raised {
|
185
|
+
trans = comp.evaluate
|
186
|
+
sum = file.state(:checksum)
|
187
|
+
events = trans.evaluate.collect { |event| event.event }
|
188
|
+
}
|
189
|
+
|
190
|
+
# verify that only the file_changed event was kicked off, not the
|
191
|
+
# command_executed
|
192
|
+
assert_equal(
|
193
|
+
[:file_modified],
|
194
|
+
events
|
195
|
+
)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_creates
|
199
|
+
file = tempfile()
|
200
|
+
exec = nil
|
201
|
+
assert_nothing_raised {
|
202
|
+
exec = Puppet::Type::Exec.create(
|
203
|
+
:command => "touch %s" % file,
|
204
|
+
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
205
|
+
:creates => file
|
206
|
+
)
|
207
|
+
}
|
208
|
+
|
209
|
+
comp = newcomp("createstest", exec)
|
210
|
+
assert_events(comp, [:executed_command], "creates")
|
211
|
+
assert_events(comp, [], "creates")
|
212
|
+
end
|
213
|
+
|
214
|
+
if Process.uid == 0
|
215
|
+
# Verify that we can execute commands as a special user
|
216
|
+
def mknverify(file, user, group = nil, id = true)
|
217
|
+
args = {
|
218
|
+
:command => "touch %s" % file,
|
219
|
+
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
220
|
+
}
|
221
|
+
|
222
|
+
if user
|
223
|
+
#Puppet.warning "Using user %s" % user.name
|
224
|
+
if id
|
225
|
+
# convert to a string, because that's what the object expects
|
226
|
+
args[:user] = user.uid.to_s
|
227
|
+
else
|
228
|
+
args[:user] = user.name
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
if group
|
233
|
+
#Puppet.warning "Using group %s" % group.name
|
234
|
+
if id
|
235
|
+
args[:group] = group.gid.to_s
|
236
|
+
else
|
237
|
+
args[:group] = group.name
|
238
|
+
end
|
239
|
+
end
|
240
|
+
exec = nil
|
241
|
+
assert_nothing_raised {
|
242
|
+
exec = Puppet::Type::Exec.create(args)
|
243
|
+
}
|
244
|
+
|
245
|
+
comp = newcomp("usertest", exec)
|
246
|
+
assert_events(comp, [:executed_command], "usertest")
|
247
|
+
|
248
|
+
assert(FileTest.exists?(file), "File does not exist")
|
249
|
+
if user
|
250
|
+
assert_equal(user.uid, File.stat(file).uid, "File UIDs do not match")
|
251
|
+
end
|
252
|
+
|
253
|
+
# We can't actually test group ownership, unfortunately, because
|
254
|
+
# behaviour changes wildlly based on platform.
|
255
|
+
Puppet::Type.allclear
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_userngroup
|
259
|
+
file = tempfile()
|
260
|
+
[
|
261
|
+
[nonrootuser()], # just user, by name
|
262
|
+
[nonrootuser(), nil, true], # user, by uid
|
263
|
+
[nil, nonrootgroup()], # just group
|
264
|
+
[nil, nonrootgroup(), true], # just group, by id
|
265
|
+
[nonrootuser(), nonrootgroup()], # user and group, by name
|
266
|
+
[nonrootuser(), nonrootgroup(), true], # user and group, by id
|
267
|
+
].each { |ary|
|
268
|
+
mknverify(file, *ary) {
|
269
|
+
}
|
270
|
+
}
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|