puppet 0.9.2 → 0.13.0
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 +58 -0
- data/README +21 -18
- data/Rakefile +176 -36
- data/bin/puppet +34 -48
- data/bin/puppetca +41 -28
- data/bin/puppetd +87 -65
- data/bin/puppetdoc +99 -23
- data/bin/puppetmasterd +72 -91
- data/conf/redhat/client.init +80 -0
- data/conf/redhat/client.sysconfig +11 -0
- data/conf/redhat/fileserver.conf +12 -0
- data/conf/redhat/puppet.spec +130 -0
- data/conf/redhat/server.init +89 -0
- data/conf/redhat/server.sysconfig +9 -0
- data/examples/code/allatonce +2 -2
- data/examples/code/assignments +1 -1
- data/examples/code/classing +2 -2
- data/examples/code/components +2 -2
- data/examples/code/file.bl +5 -5
- data/examples/code/filedefaults +2 -2
- data/examples/code/fileparsing +1 -1
- data/examples/code/filerecursion +1 -1
- data/examples/code/functions +1 -1
- data/examples/code/groups +1 -1
- data/examples/code/importing +1 -1
- data/examples/code/nodes +1 -1
- data/examples/code/one +1 -1
- data/examples/code/relationships +2 -2
- data/examples/code/simpletests +5 -5
- data/examples/code/snippets/argumentdefaults +2 -2
- data/examples/code/snippets/casestatement +16 -8
- data/examples/code/snippets/classheirarchy.pp +4 -4
- data/examples/code/snippets/classincludes.pp +4 -4
- data/examples/code/snippets/classpathtest +2 -2
- data/examples/code/snippets/componentmetaparams.pp +11 -0
- data/examples/code/snippets/dirchmod +5 -5
- data/examples/code/snippets/emptyclass.pp +9 -0
- data/examples/code/snippets/failmissingexecpath.pp +1 -1
- data/examples/code/snippets/falsevalues.pp +1 -1
- data/examples/code/snippets/filecreate +5 -5
- data/examples/code/snippets/implicititeration +5 -5
- data/examples/code/snippets/multipleinstances +4 -4
- data/examples/code/snippets/namevartest +3 -3
- data/examples/code/snippets/scopetest +1 -1
- data/examples/code/snippets/selectorvalues.pp +3 -3
- data/examples/code/snippets/simpledefaults +2 -2
- data/examples/code/snippets/simpleselector +5 -5
- data/examples/code/snippets/singleary.pp +19 -0
- data/examples/root/etc/init.d/sleeper +3 -2
- data/ext/emacs/puppet-mode-init.el +6 -0
- data/ext/emacs/puppet-mode.el +189 -0
- data/ext/ldap/puppet.schema +17 -0
- data/ext/{module:puppet → module_puppet} +30 -31
- data/ext/vim/filetype.vim +9 -0
- data/ext/vim/puppet.vim +87 -0
- data/install.rb +63 -30
- data/lib/puppet.rb +216 -122
- data/lib/puppet/client.rb +51 -416
- data/lib/puppet/client/ca.rb +17 -0
- data/lib/puppet/client/dipper.rb +78 -0
- data/lib/puppet/client/file.rb +20 -0
- data/lib/puppet/client/log.rb +17 -0
- data/lib/puppet/client/master.rb +246 -0
- data/lib/puppet/client/proxy.rb +27 -0
- data/lib/puppet/client/status.rb +7 -0
- data/lib/puppet/config.rb +563 -13
- data/lib/puppet/daemon.rb +50 -22
- data/lib/puppet/element.rb +4 -4
- data/lib/puppet/event-loop.rb +1 -0
- data/lib/puppet/event-loop/better-definers.rb +367 -0
- data/lib/puppet/event-loop/event-loop.rb +355 -0
- data/lib/puppet/event-loop/signal-system.rb +220 -0
- data/lib/puppet/event.rb +9 -11
- data/lib/puppet/filetype.rb +195 -0
- data/lib/puppet/log.rb +35 -12
- data/lib/puppet/metric.rb +2 -2
- data/lib/puppet/networkclient.rb +145 -0
- data/lib/puppet/parameter.rb +335 -0
- data/lib/puppet/parser/ast.rb +42 -1453
- data/lib/puppet/parser/ast/astarray.rb +88 -0
- data/lib/puppet/parser/ast/branch.rb +47 -0
- data/lib/puppet/parser/ast/caseopt.rb +66 -0
- data/lib/puppet/parser/ast/casestatement.rb +78 -0
- data/lib/puppet/parser/ast/classdef.rb +78 -0
- data/lib/puppet/parser/ast/compdef.rb +111 -0
- data/lib/puppet/parser/ast/component.rb +105 -0
- data/lib/puppet/parser/ast/hostclass.rb +82 -0
- data/lib/puppet/parser/ast/leaf.rb +86 -0
- data/lib/puppet/parser/ast/node.rb +103 -0
- data/lib/puppet/parser/ast/nodedef.rb +68 -0
- data/lib/puppet/parser/ast/objectdef.rb +336 -0
- data/lib/puppet/parser/ast/objectparam.rb +30 -0
- data/lib/puppet/parser/ast/objectref.rb +76 -0
- data/lib/puppet/parser/ast/selector.rb +60 -0
- data/lib/puppet/parser/ast/typedefaults.rb +45 -0
- data/lib/puppet/parser/ast/vardef.rb +44 -0
- data/lib/puppet/parser/interpreter.rb +31 -14
- data/lib/puppet/parser/lexer.rb +2 -4
- data/lib/puppet/parser/parser.rb +332 -242
- data/lib/puppet/parser/scope.rb +55 -38
- data/lib/puppet/server.rb +43 -44
- data/lib/puppet/server/authstore.rb +3 -6
- data/lib/puppet/server/ca.rb +5 -2
- data/lib/puppet/server/filebucket.rb +2 -4
- data/lib/puppet/server/fileserver.rb +28 -12
- data/lib/puppet/server/logger.rb +15 -4
- data/lib/puppet/server/master.rb +62 -7
- data/lib/puppet/sslcertificates.rb +41 -607
- data/lib/puppet/sslcertificates/ca.rb +291 -0
- data/lib/puppet/sslcertificates/certificate.rb +283 -0
- data/lib/puppet/statechange.rb +6 -1
- data/lib/puppet/storage.rb +67 -56
- data/lib/puppet/transaction.rb +25 -9
- data/lib/puppet/transportable.rb +102 -22
- data/lib/puppet/type.rb +1096 -315
- data/lib/puppet/type/component.rb +30 -21
- data/lib/puppet/type/cron.rb +409 -448
- data/lib/puppet/type/exec.rb +234 -174
- data/lib/puppet/type/group.rb +65 -82
- data/lib/puppet/type/nameservice.rb +247 -3
- data/lib/puppet/type/nameservice/netinfo.rb +29 -40
- data/lib/puppet/type/nameservice/objectadd.rb +52 -66
- data/lib/puppet/type/nameservice/posix.rb +6 -194
- data/lib/puppet/type/package.rb +447 -295
- data/lib/puppet/type/package/apt.rb +51 -50
- data/lib/puppet/type/package/bsd.rb +82 -0
- data/lib/puppet/type/package/dpkg.rb +85 -88
- data/lib/puppet/type/package/rpm.rb +67 -63
- data/lib/puppet/type/package/sun.rb +119 -98
- data/lib/puppet/type/package/yum.rb +41 -37
- data/lib/puppet/type/parsedtype.rb +295 -0
- data/lib/puppet/type/parsedtype/host.rb +143 -0
- data/lib/puppet/type/parsedtype/port.rb +232 -0
- data/lib/puppet/type/parsedtype/sshkey.rb +129 -0
- data/lib/puppet/type/pfile.rb +484 -460
- data/lib/puppet/type/pfile/checksum.rb +237 -181
- data/lib/puppet/type/pfile/content.rb +67 -0
- data/lib/puppet/type/pfile/ensure.rb +212 -0
- data/lib/puppet/type/pfile/group.rb +106 -105
- data/lib/puppet/type/pfile/mode.rb +98 -101
- data/lib/puppet/type/pfile/source.rb +228 -209
- data/lib/puppet/type/pfile/type.rb +18 -21
- data/lib/puppet/type/pfile/uid.rb +127 -130
- data/lib/puppet/type/pfilebucket.rb +68 -63
- data/lib/puppet/type/schedule.rb +341 -0
- data/lib/puppet/type/service.rb +351 -255
- data/lib/puppet/type/service/base.rb +9 -14
- data/lib/puppet/type/service/debian.rb +32 -38
- data/lib/puppet/type/service/init.rb +130 -130
- data/lib/puppet/type/service/smf.rb +48 -20
- data/lib/puppet/type/state.rb +229 -16
- data/lib/puppet/type/symlink.rb +51 -63
- data/lib/puppet/type/tidy.rb +105 -102
- data/lib/puppet/type/user.rb +118 -180
- data/lib/puppet/util.rb +100 -6
- data/test/certmgr/certmgr.rb +0 -1
- data/test/client/client.rb +4 -4
- data/test/executables/puppetbin.rb +7 -14
- data/test/executables/puppetca.rb +18 -24
- data/test/executables/puppetd.rb +7 -16
- data/test/executables/puppetmasterd.rb +7 -9
- data/test/executables/puppetmodule.rb +11 -16
- data/test/language/ast.rb +11 -7
- data/test/language/interpreter.rb +1 -1
- data/test/language/scope.rb +2 -0
- data/test/language/snippets.rb +30 -5
- data/test/language/transportable.rb +77 -0
- data/test/other/config.rb +316 -0
- data/test/other/events.rb +22 -21
- data/test/other/log.rb +14 -14
- data/test/other/metrics.rb +4 -8
- data/test/other/overrides.rb +5 -5
- data/test/other/relationships.rb +4 -2
- data/test/other/storage.rb +64 -3
- data/test/other/transactions.rb +20 -20
- data/test/parser/parser.rb +7 -4
- data/test/puppet/conffiles.rb +12 -12
- data/test/puppet/defaults.rb +13 -11
- data/test/puppet/utiltest.rb +14 -11
- data/test/puppettest.rb +156 -48
- data/test/server/bucket.rb +2 -2
- data/test/server/fileserver.rb +6 -6
- data/test/server/logger.rb +19 -11
- data/test/server/master.rb +33 -4
- data/test/server/server.rb +2 -7
- data/test/types/basic.rb +5 -7
- data/test/types/component.rb +22 -18
- data/test/types/cron.rb +111 -44
- data/test/types/exec.rb +116 -59
- data/test/types/file.rb +262 -137
- data/test/types/filebucket.rb +13 -15
- data/test/types/fileignoresource.rb +12 -16
- data/test/types/filesources.rb +73 -48
- data/test/types/filetype.rb +13 -15
- data/test/types/group.rb +15 -13
- data/test/types/host.rb +146 -0
- data/test/types/package.rb +74 -63
- data/test/types/port.rb +139 -0
- data/test/types/query.rb +8 -8
- data/test/types/schedule.rb +335 -0
- data/test/types/service.rb +137 -21
- data/test/types/sshkey.rb +140 -0
- data/test/types/symlink.rb +3 -5
- data/test/types/tidy.rb +5 -14
- data/test/types/type.rb +67 -11
- data/test/types/user.rb +25 -23
- metadata +186 -122
- data/lib/puppet/type/pfile/create.rb +0 -108
- data/lib/puppet/type/pprocess.rb +0 -97
- data/lib/puppet/type/typegen.rb +0 -149
- data/lib/puppet/type/typegen/filerecord.rb +0 -243
- data/lib/puppet/type/typegen/filetype.rb +0 -316
- data/test/other/state.rb +0 -106
data/test/types/cron.rb
CHANGED
@@ -8,11 +8,18 @@ end
|
|
8
8
|
|
9
9
|
require 'puppettest'
|
10
10
|
require 'puppet'
|
11
|
-
require 'puppet/type/cron'
|
12
11
|
require 'test/unit'
|
13
12
|
require 'facter'
|
14
13
|
|
15
|
-
|
14
|
+
|
15
|
+
# Here we just want to unit-test our cron type, to verify that
|
16
|
+
#class TestCronType < Test::Unit::TestCase
|
17
|
+
# include TestPuppet
|
18
|
+
#
|
19
|
+
#
|
20
|
+
#end
|
21
|
+
|
22
|
+
class TestCron < Test::Unit::TestCase
|
16
23
|
include TestPuppet
|
17
24
|
def setup
|
18
25
|
super
|
@@ -26,15 +33,24 @@ class TestExec < Test::Unit::TestCase
|
|
26
33
|
unless defined? @me
|
27
34
|
raise "Could not retrieve user name; 'id' did not work"
|
28
35
|
end
|
36
|
+
|
29
37
|
# god i'm lazy
|
30
|
-
@crontype = Puppet
|
38
|
+
@crontype = Puppet.type(:cron)
|
39
|
+
@oldfiletype = @crontype.filetype
|
40
|
+
@fakefiletype = Puppet::FileType.filetype(:ram)
|
41
|
+
@crontype.filetype = @fakefiletype
|
42
|
+
end
|
43
|
+
|
44
|
+
def teardown
|
45
|
+
@crontype.filetype = @oldfiletype
|
46
|
+
super
|
31
47
|
end
|
32
48
|
|
33
49
|
# Back up the user's existing cron tab if they have one.
|
34
50
|
def cronback
|
35
51
|
tab = nil
|
36
52
|
assert_nothing_raised {
|
37
|
-
tab = Puppet
|
53
|
+
tab = Puppet.type(:cron).filetype.read(@me)
|
38
54
|
}
|
39
55
|
|
40
56
|
if $? == 0
|
@@ -48,9 +64,9 @@ class TestExec < Test::Unit::TestCase
|
|
48
64
|
def cronrestore
|
49
65
|
assert_nothing_raised {
|
50
66
|
if @currenttab
|
51
|
-
@crontype.
|
67
|
+
@crontype.filetype.new(@me).write(@currenttab)
|
52
68
|
else
|
53
|
-
@crontype.
|
69
|
+
@crontype.filetype.new(@me).remove
|
54
70
|
end
|
55
71
|
}
|
56
72
|
end
|
@@ -78,17 +94,21 @@ class TestExec < Test::Unit::TestCase
|
|
78
94
|
name = cron.name
|
79
95
|
comp = newcomp(name, cron)
|
80
96
|
|
81
|
-
|
97
|
+
assert_events([:cron_created], comp)
|
98
|
+
cron.retrieve
|
99
|
+
|
100
|
+
assert(cron.insync?)
|
101
|
+
|
102
|
+
assert_events([], comp)
|
103
|
+
|
104
|
+
cron[:ensure] = :absent
|
105
|
+
|
106
|
+
assert_events([:cron_removed], comp)
|
107
|
+
|
82
108
|
cron.retrieve
|
109
|
+
|
83
110
|
assert(cron.insync?)
|
84
|
-
|
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")
|
111
|
+
assert_events([], comp)
|
92
112
|
end
|
93
113
|
|
94
114
|
# A simple test to see if we can load the cron from disk.
|
@@ -107,18 +127,66 @@ class TestExec < Test::Unit::TestCase
|
|
107
127
|
assert_nothing_raised {
|
108
128
|
cron = @crontype.create(
|
109
129
|
:name => name,
|
110
|
-
:command => "date",
|
130
|
+
:command => "date > /dev/null",
|
111
131
|
:user => @me
|
112
132
|
)
|
113
133
|
}
|
114
134
|
str = nil
|
115
135
|
# generate the text
|
116
136
|
assert_nothing_raised {
|
117
|
-
str = cron.
|
137
|
+
str = cron.to_record
|
118
138
|
}
|
119
|
-
|
139
|
+
|
140
|
+
assert_equal(str, "# Puppet Name: #{name}\n* * * * * date > /dev/null",
|
120
141
|
"Cron did not generate correctly")
|
121
142
|
end
|
143
|
+
|
144
|
+
# Test that changing any field results in the cron tab being rewritten.
|
145
|
+
# it directly
|
146
|
+
def test_any_field_changes
|
147
|
+
cron = nil
|
148
|
+
# make the cron
|
149
|
+
name = "yaytest"
|
150
|
+
assert_nothing_raised {
|
151
|
+
cron = @crontype.create(
|
152
|
+
:name => name,
|
153
|
+
:command => "date > /dev/null",
|
154
|
+
:month => "May",
|
155
|
+
:user => @me
|
156
|
+
)
|
157
|
+
}
|
158
|
+
assert(cron, "Cron did not get created")
|
159
|
+
comp = newcomp(cron)
|
160
|
+
assert_events([:cron_created], comp)
|
161
|
+
|
162
|
+
assert_nothing_raised {
|
163
|
+
cron[:month] = "June"
|
164
|
+
}
|
165
|
+
|
166
|
+
cron.retrieve
|
167
|
+
|
168
|
+
assert_events([:cron_changed], comp)
|
169
|
+
end
|
170
|
+
|
171
|
+
# Test that a cron job with spaces at the end doesn't get rewritten
|
172
|
+
def test_trailingspaces
|
173
|
+
cron = nil
|
174
|
+
# make the cron
|
175
|
+
name = "yaytest"
|
176
|
+
assert_nothing_raised {
|
177
|
+
cron = @crontype.create(
|
178
|
+
:name => name,
|
179
|
+
:command => "date > /dev/null ",
|
180
|
+
:month => "May",
|
181
|
+
:user => @me
|
182
|
+
)
|
183
|
+
}
|
184
|
+
comp = newcomp(cron)
|
185
|
+
|
186
|
+
assert_events([:cron_created], comp, "did not create cron job")
|
187
|
+
cron.retrieve
|
188
|
+
assert_events([], comp, "cron job got rewritten")
|
189
|
+
end
|
122
190
|
|
123
191
|
# Test that comments are correctly retained
|
124
192
|
def test_retain_comments
|
@@ -130,7 +198,7 @@ class TestExec < Test::Unit::TestCase
|
|
130
198
|
|
131
199
|
assert_nothing_raised {
|
132
200
|
newstr = @crontype.tab(user)
|
133
|
-
|
201
|
+
assert(newstr.include?(str), "Comments were lost")
|
134
202
|
}
|
135
203
|
end
|
136
204
|
|
@@ -156,62 +224,59 @@ class TestExec < Test::Unit::TestCase
|
|
156
224
|
|
157
225
|
assert_nothing_raised {
|
158
226
|
newstr = @crontype.tab(@me)
|
159
|
-
|
227
|
+
assert(newstr.include?(modstr),
|
228
|
+
"Cron was not correctly matched")
|
160
229
|
}
|
161
230
|
end
|
162
231
|
|
163
232
|
# Test adding a cron when there is currently no file.
|
164
233
|
def test_mkcronwithnotab
|
165
|
-
|
166
|
-
|
234
|
+
tab = @fakefiletype.new(@me)
|
235
|
+
tab.remove
|
167
236
|
|
168
237
|
cron = mkcron("testwithnotab")
|
169
238
|
cyclecron(cron)
|
170
|
-
cronrestore
|
171
239
|
end
|
172
240
|
|
173
241
|
def test_mkcronwithtab
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
"1 1 1 1 * date > %s/crontesting\n" %
|
242
|
+
tab = @fakefiletype.new(@me)
|
243
|
+
tab.remove
|
244
|
+
tab.write(
|
245
|
+
"1 1 1 1 * date > %s/crontesting\n" % tstdir()
|
178
246
|
)
|
179
247
|
|
180
248
|
cron = mkcron("testwithtab")
|
181
249
|
cyclecron(cron)
|
182
|
-
cronrestore
|
183
250
|
end
|
184
251
|
|
185
252
|
def test_makeandretrievecron
|
186
|
-
|
187
|
-
|
253
|
+
tab = @fakefiletype.new(@me)
|
254
|
+
tab.remove
|
188
255
|
|
189
256
|
name = "storeandretrieve"
|
190
257
|
cron = mkcron(name)
|
191
258
|
comp = newcomp(name, cron)
|
192
|
-
trans = assert_events(
|
259
|
+
trans = assert_events([:cron_created], comp, name)
|
193
260
|
|
194
261
|
cron = nil
|
195
262
|
|
196
|
-
Puppet
|
197
|
-
Puppet::Type::Cron.retrieve(@me)
|
263
|
+
Puppet.type(:cron).retrieve(@me)
|
198
264
|
|
199
|
-
assert(cron = Puppet
|
200
|
-
assert_instance_of(Puppet
|
201
|
-
cronrestore
|
265
|
+
assert(cron = Puppet.type(:cron)[name], "Could not retrieve named cron")
|
266
|
+
assert_instance_of(Puppet.type(:cron), cron)
|
202
267
|
end
|
203
268
|
|
204
269
|
# Do input validation testing on all of the parameters.
|
205
270
|
def test_arguments
|
206
271
|
values = {
|
207
272
|
:monthday => {
|
208
|
-
:valid => [ 1, 13, "1
|
273
|
+
:valid => [ 1, 13, "1" ],
|
209
274
|
:invalid => [ -1, 0, 32 ]
|
210
275
|
},
|
211
276
|
:weekday => {
|
212
|
-
:valid => [ 0, 3, 6, "1
|
277
|
+
:valid => [ 0, 3, 6, "1", "tue", "wed",
|
213
278
|
"Wed", "MOnday", "SaTurday" ],
|
214
|
-
:invalid => [ -1, 7, "
|
279
|
+
:invalid => [ -1, 7, "13", "tues", "teusday", "thurs" ]
|
215
280
|
},
|
216
281
|
:hour => {
|
217
282
|
:valid => [ 0, 21, 23 ],
|
@@ -223,14 +288,16 @@ class TestExec < Test::Unit::TestCase
|
|
223
288
|
},
|
224
289
|
:month => {
|
225
290
|
:valid => [ 1, 11, 12, "mar", "March", "apr", "October", "DeCeMbEr" ],
|
226
|
-
:invalid => [ 0, 13, "marc", "sept" ]
|
291
|
+
:invalid => [ -1, 0, 13, "marc", "sept" ]
|
227
292
|
}
|
228
293
|
}
|
229
294
|
|
230
295
|
cron = mkcron("valtesting")
|
231
296
|
values.each { |param, hash|
|
232
|
-
|
233
|
-
|
297
|
+
# We have to test the valid ones first, because otherwise the
|
298
|
+
# state will fail to create at all.
|
299
|
+
[:valid, :invalid].each { |type|
|
300
|
+
hash[type].each { |value|
|
234
301
|
case type
|
235
302
|
when :valid:
|
236
303
|
assert_nothing_raised {
|
@@ -238,7 +305,7 @@ class TestExec < Test::Unit::TestCase
|
|
238
305
|
}
|
239
306
|
|
240
307
|
if value.is_a?(Integer)
|
241
|
-
assert_equal(
|
308
|
+
assert_equal(value.to_s, cron.should(param),
|
242
309
|
"Cron value was not set correctly")
|
243
310
|
end
|
244
311
|
when :invalid:
|
@@ -258,4 +325,4 @@ class TestExec < Test::Unit::TestCase
|
|
258
325
|
end
|
259
326
|
end
|
260
327
|
|
261
|
-
# $Id: cron.rb
|
328
|
+
# $Id: cron.rb 831 2006-01-16 20:01:20Z luke $
|
data/test/types/exec.rb
CHANGED
@@ -9,7 +9,7 @@ require 'puppettest'
|
|
9
9
|
require 'test/unit'
|
10
10
|
require 'facter'
|
11
11
|
|
12
|
-
# $Id: exec.rb
|
12
|
+
# $Id: exec.rb 832 2006-01-17 07:11:50Z luke $
|
13
13
|
|
14
14
|
class TestExec < Test::Unit::TestCase
|
15
15
|
include TestPuppet
|
@@ -17,46 +17,29 @@ class TestExec < Test::Unit::TestCase
|
|
17
17
|
command = nil
|
18
18
|
output = nil
|
19
19
|
assert_nothing_raised {
|
20
|
-
command = Puppet
|
20
|
+
command = Puppet.type(:exec).create(
|
21
21
|
:command => "/bin/echo"
|
22
22
|
)
|
23
23
|
}
|
24
24
|
assert_nothing_raised {
|
25
25
|
command.evaluate
|
26
26
|
}
|
27
|
-
|
28
|
-
output = command.sync
|
29
|
-
}
|
30
|
-
assert_equal([:executed_command],output)
|
27
|
+
assert_events([:executed_command], command)
|
31
28
|
end
|
32
29
|
|
33
30
|
def test_numvsstring
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
command =
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
31
|
+
[0, "0"].each { |val|
|
32
|
+
Puppet.type(:exec).clear
|
33
|
+
Puppet.type(:component).clear
|
34
|
+
command = nil
|
35
|
+
output = nil
|
36
|
+
assert_nothing_raised {
|
37
|
+
command = Puppet.type(:exec).create(
|
38
|
+
:command => "/bin/echo",
|
39
|
+
:returns => val
|
40
|
+
)
|
41
|
+
}
|
42
|
+
assert_events([:executed_command], command)
|
60
43
|
}
|
61
44
|
end
|
62
45
|
|
@@ -64,27 +47,27 @@ class TestExec < Test::Unit::TestCase
|
|
64
47
|
command = nil
|
65
48
|
output = nil
|
66
49
|
assert_nothing_raised {
|
67
|
-
command = Puppet
|
50
|
+
command = Puppet.type(:exec).create(
|
68
51
|
:command => "echo"
|
69
52
|
)
|
70
53
|
assert_nil(command)
|
71
54
|
}
|
72
|
-
Puppet
|
55
|
+
Puppet.type(:exec).clear
|
73
56
|
assert_nothing_raised {
|
74
|
-
command = Puppet
|
57
|
+
command = Puppet.type(:exec).create(
|
75
58
|
:command => "echo",
|
76
59
|
:path => "/usr/bin:/bin:/usr/sbin:/sbin"
|
77
60
|
)
|
78
61
|
}
|
79
|
-
Puppet
|
62
|
+
Puppet.type(:exec).clear
|
80
63
|
assert_nothing_raised {
|
81
|
-
command = Puppet
|
64
|
+
command = Puppet.type(:exec).create(
|
82
65
|
:command => "/bin/echo"
|
83
66
|
)
|
84
67
|
}
|
85
|
-
Puppet
|
68
|
+
Puppet.type(:exec).clear
|
86
69
|
assert_nothing_raised {
|
87
|
-
command = Puppet
|
70
|
+
command = Puppet.type(:exec).create(
|
88
71
|
:command => "/bin/echo",
|
89
72
|
:path => "/usr/bin:/bin:/usr/sbin:/sbin"
|
90
73
|
)
|
@@ -93,21 +76,21 @@ class TestExec < Test::Unit::TestCase
|
|
93
76
|
|
94
77
|
def test_nonzero_returns
|
95
78
|
assert_nothing_raised {
|
96
|
-
command = Puppet
|
79
|
+
command = Puppet.type(:exec).create(
|
97
80
|
:command => "mkdir /this/directory/does/not/exist",
|
98
81
|
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
99
82
|
:returns => 1
|
100
83
|
)
|
101
84
|
}
|
102
85
|
assert_nothing_raised {
|
103
|
-
command = Puppet
|
86
|
+
command = Puppet.type(:exec).create(
|
104
87
|
:command => "touch /etc",
|
105
88
|
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
106
89
|
:returns => 1
|
107
90
|
)
|
108
91
|
}
|
109
92
|
assert_nothing_raised {
|
110
|
-
command = Puppet
|
93
|
+
command = Puppet.type(:exec).create(
|
111
94
|
:command => "thiscommanddoesnotexist",
|
112
95
|
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
113
96
|
:returns => 127
|
@@ -122,37 +105,33 @@ class TestExec < Test::Unit::TestCase
|
|
122
105
|
Dir.getwd
|
123
106
|
}
|
124
107
|
assert_nothing_raised {
|
125
|
-
command = Puppet
|
108
|
+
command = Puppet.type(:exec).create(
|
126
109
|
:command => "pwd",
|
127
110
|
:cwd => dir,
|
128
111
|
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
129
112
|
:returns => 0
|
130
113
|
)
|
131
114
|
}
|
132
|
-
|
133
|
-
command.evaluate
|
134
|
-
}
|
135
|
-
assert_nothing_raised {
|
136
|
-
command.sync
|
137
|
-
}
|
115
|
+
assert_events([:executed_command], command)
|
138
116
|
assert_equal(wd,command.output.chomp)
|
139
117
|
end
|
140
118
|
|
141
119
|
def test_refreshonly
|
142
120
|
file = nil
|
143
121
|
cmd = nil
|
144
|
-
tmpfile =
|
122
|
+
tmpfile = tempfile()
|
145
123
|
@@tmpfiles.push tmpfile
|
146
124
|
trans = nil
|
147
125
|
File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of|
|
148
126
|
of.puts rand(100)
|
149
127
|
}
|
150
|
-
file = Puppet
|
128
|
+
file = Puppet.type(:file).create(
|
151
129
|
:path => tmpfile,
|
152
130
|
:checksum => "md5"
|
153
131
|
)
|
132
|
+
assert_instance_of(Puppet.type(:file), file)
|
154
133
|
assert_nothing_raised {
|
155
|
-
cmd = Puppet
|
134
|
+
cmd = Puppet.type(:exec).create(
|
156
135
|
:command => "pwd",
|
157
136
|
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
158
137
|
:subscribe => [[file.class.name,file.name]],
|
@@ -160,7 +139,9 @@ class TestExec < Test::Unit::TestCase
|
|
160
139
|
)
|
161
140
|
}
|
162
141
|
|
163
|
-
|
142
|
+
assert_instance_of(Puppet.type(:exec), cmd)
|
143
|
+
|
144
|
+
comp = Puppet.type(:component).create(:name => "RefreshTest")
|
164
145
|
[file,cmd].each { |obj|
|
165
146
|
comp.push obj
|
166
147
|
}
|
@@ -190,7 +171,7 @@ class TestExec < Test::Unit::TestCase
|
|
190
171
|
# verify that only the file_changed event was kicked off, not the
|
191
172
|
# command_executed
|
192
173
|
assert_equal(
|
193
|
-
[:
|
174
|
+
[:file_changed],
|
194
175
|
events
|
195
176
|
)
|
196
177
|
end
|
@@ -198,8 +179,9 @@ class TestExec < Test::Unit::TestCase
|
|
198
179
|
def test_creates
|
199
180
|
file = tempfile()
|
200
181
|
exec = nil
|
182
|
+
assert(! FileTest.exists?(file), "File already exists")
|
201
183
|
assert_nothing_raised {
|
202
|
-
exec = Puppet
|
184
|
+
exec = Puppet.type(:exec).create(
|
203
185
|
:command => "touch %s" % file,
|
204
186
|
:path => "/usr/bin:/bin:/usr/sbin:/sbin",
|
205
187
|
:creates => file
|
@@ -207,8 +189,83 @@ class TestExec < Test::Unit::TestCase
|
|
207
189
|
}
|
208
190
|
|
209
191
|
comp = newcomp("createstest", exec)
|
210
|
-
assert_events(
|
211
|
-
assert_events(
|
192
|
+
assert_events([:executed_command], comp, "creates")
|
193
|
+
assert_events([], comp, "creates")
|
194
|
+
end
|
195
|
+
|
196
|
+
# Verify that we can download the file that we're going to execute.
|
197
|
+
def test_retrievethenmkexe
|
198
|
+
exe = tempfile()
|
199
|
+
oexe = tempfile()
|
200
|
+
sh = %x{which sh}
|
201
|
+
File.open(exe, "w") { |f| f.puts "#!#{sh}\necho yup" }
|
202
|
+
|
203
|
+
file = Puppet.type(:file).create(
|
204
|
+
:name => oexe,
|
205
|
+
:source => exe,
|
206
|
+
:mode => 0755
|
207
|
+
)
|
208
|
+
|
209
|
+
exec = Puppet.type(:exec).create(
|
210
|
+
:name => oexe,
|
211
|
+
:require => [:file, oexe]
|
212
|
+
)
|
213
|
+
|
214
|
+
comp = newcomp("Testing", file, exec)
|
215
|
+
|
216
|
+
assert_events([:file_created, :executed_command], comp)
|
217
|
+
end
|
218
|
+
|
219
|
+
# Verify that we auto-require any managed scripts.
|
220
|
+
def test_autorequire
|
221
|
+
exe = tempfile()
|
222
|
+
oexe = tempfile()
|
223
|
+
sh = %x{which sh}
|
224
|
+
File.open(exe, "w") { |f| f.puts "#!#{sh}\necho yup" }
|
225
|
+
|
226
|
+
file = Puppet.type(:file).create(
|
227
|
+
:name => oexe,
|
228
|
+
:source => exe,
|
229
|
+
:mode => 755
|
230
|
+
)
|
231
|
+
|
232
|
+
basedir = File.dirname(oexe)
|
233
|
+
baseobj = Puppet.type(:file).create(
|
234
|
+
:name => basedir,
|
235
|
+
:source => exe,
|
236
|
+
:mode => 755
|
237
|
+
)
|
238
|
+
|
239
|
+
ofile = Puppet.type(:file).create(
|
240
|
+
:name => exe,
|
241
|
+
:mode => 755
|
242
|
+
)
|
243
|
+
|
244
|
+
exec = Puppet.type(:exec).create(
|
245
|
+
:name => oexe,
|
246
|
+
:path => ENV["PATH"],
|
247
|
+
:cwd => basedir
|
248
|
+
)
|
249
|
+
|
250
|
+
cat = Puppet.type(:exec).create(
|
251
|
+
:name => "cat %s %s" % [exe, oexe],
|
252
|
+
:path => ENV["PATH"]
|
253
|
+
)
|
254
|
+
|
255
|
+
Puppet::Type.finalize
|
256
|
+
|
257
|
+
# Verify we get the script itself
|
258
|
+
assert(exec.requires?(file), "Exec did not autorequire file")
|
259
|
+
|
260
|
+
# Verify we catch the cwd
|
261
|
+
assert(exec.requires?(baseobj), "Exec did not autorequire cwd")
|
262
|
+
|
263
|
+
# Verify we don't require ourselves
|
264
|
+
assert(!exec.requires?(ofile), "Exec incorrectly required file")
|
265
|
+
|
266
|
+
# Verify that we catch inline files
|
267
|
+
assert(cat.requires?(ofile), "Exec did not catch second inline file")
|
268
|
+
assert(cat.requires?(file), "Exec did not catch inline file")
|
212
269
|
end
|
213
270
|
|
214
271
|
if Process.uid == 0
|
@@ -239,11 +296,11 @@ class TestExec < Test::Unit::TestCase
|
|
239
296
|
end
|
240
297
|
exec = nil
|
241
298
|
assert_nothing_raised {
|
242
|
-
exec = Puppet
|
299
|
+
exec = Puppet.type(:exec).create(args)
|
243
300
|
}
|
244
301
|
|
245
302
|
comp = newcomp("usertest", exec)
|
246
|
-
assert_events(
|
303
|
+
assert_events([:executed_command], comp, "usertest")
|
247
304
|
|
248
305
|
assert(FileTest.exists?(file), "File does not exist")
|
249
306
|
if user
|