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
@@ -0,0 +1,53 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
$:.unshift '../../lib'
|
3
|
+
$:.unshift '..'
|
4
|
+
$puppetbase = "../.."
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'puppet/server'
|
9
|
+
require 'puppet/sslcertificates'
|
10
|
+
require 'test/unit'
|
11
|
+
require 'puppettest.rb'
|
12
|
+
|
13
|
+
# add the bin directory to our search path
|
14
|
+
ENV["PATH"] += ":" + File.join($puppetbase, "bin")
|
15
|
+
|
16
|
+
# and then the library directories
|
17
|
+
libdirs = $:.find_all { |dir|
|
18
|
+
dir =~ /puppet/ or dir =~ /\.\./
|
19
|
+
}
|
20
|
+
ENV["RUBYLIB"] = libdirs.join(":")
|
21
|
+
|
22
|
+
class TestPuppetBin < Test::Unit::TestCase
|
23
|
+
include ServerTest
|
24
|
+
def test_version
|
25
|
+
output = nil
|
26
|
+
assert_nothing_raised {
|
27
|
+
output = %x{puppet --version}.chomp
|
28
|
+
}
|
29
|
+
assert(output == Puppet.version)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_execution
|
33
|
+
file = mktestmanifest()
|
34
|
+
@@tmpfiles << "/tmp/puppetbintesting"
|
35
|
+
|
36
|
+
output = nil
|
37
|
+
cmd = "puppet"
|
38
|
+
cmd += " --verbose"
|
39
|
+
#cmd += " --fqdn %s" % fqdn
|
40
|
+
cmd += " --confdir %s" % Puppet[:puppetconf]
|
41
|
+
cmd += " --vardir %s" % Puppet[:puppetvar]
|
42
|
+
cmd += " --logdest %s" % "/dev/null"
|
43
|
+
|
44
|
+
assert_nothing_raised {
|
45
|
+
system(cmd + " " + file)
|
46
|
+
}
|
47
|
+
assert($? == 0, "Puppet exited with code %s" % $?.to_i)
|
48
|
+
|
49
|
+
assert(FileTest.exists?(@createdfile), "Failed to create config'ed file")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# $Id: $
|
@@ -0,0 +1,79 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
$:.unshift '../../lib'
|
3
|
+
$:.unshift '..'
|
4
|
+
$puppetbase = "../.."
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'puppet/server'
|
9
|
+
require 'puppet/sslcertificates'
|
10
|
+
require 'test/unit'
|
11
|
+
require 'puppettest.rb'
|
12
|
+
|
13
|
+
# $Id: puppetca.rb 724 2005-10-22 22:27:20Z luke $
|
14
|
+
|
15
|
+
# ok, we have to add the bin directory to our search path
|
16
|
+
ENV["PATH"] += ":" + File.join($puppetbase, "bin")
|
17
|
+
|
18
|
+
# and then the library directories
|
19
|
+
libdirs = $:.find_all { |dir|
|
20
|
+
dir =~ /puppet/ or dir =~ /\.\./
|
21
|
+
}
|
22
|
+
ENV["RUBYLIB"] = libdirs.join(":")
|
23
|
+
|
24
|
+
class TestPuppetCA < Test::Unit::TestCase
|
25
|
+
include ServerTest
|
26
|
+
def mkcert(hostname)
|
27
|
+
cert = nil
|
28
|
+
assert_nothing_raised {
|
29
|
+
cert = Puppet::SSLCertificates::Certificate.new(
|
30
|
+
:name => hostname
|
31
|
+
)
|
32
|
+
cert.mkcsr
|
33
|
+
}
|
34
|
+
|
35
|
+
return cert
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_signing
|
39
|
+
ca = nil
|
40
|
+
Puppet[:ssldir] = "/tmp/puppetcatest"
|
41
|
+
@@tmpfiles << Puppet[:ssldir]
|
42
|
+
Puppet[:autosign] = false
|
43
|
+
assert_nothing_raised {
|
44
|
+
ca = Puppet::Server::CA.new()
|
45
|
+
}
|
46
|
+
#Puppet.warning "SSLDir is %s" % Puppet[:ssldir]
|
47
|
+
#system("find %s" % Puppet[:ssldir])
|
48
|
+
|
49
|
+
cert = mkcert("host.test.com")
|
50
|
+
resp = nil
|
51
|
+
assert_nothing_raised {
|
52
|
+
# We need to use a fake name so it doesn't think the cert is from
|
53
|
+
# itself.
|
54
|
+
resp = ca.getcert(cert.csr.to_pem, "fakename", "127.0.0.1")
|
55
|
+
}
|
56
|
+
assert_equal(["",""], resp)
|
57
|
+
#Puppet.warning "SSLDir is %s" % Puppet[:ssldir]
|
58
|
+
#system("find %s" % Puppet[:ssldir])
|
59
|
+
|
60
|
+
output = nil
|
61
|
+
assert_nothing_raised {
|
62
|
+
output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]} 2>&1}.chomp.split("\n").reject { |line| line =~ /warning:/ } # stupid ssl.rb
|
63
|
+
}
|
64
|
+
#Puppet.warning "SSLDir is %s" % Puppet[:ssldir]
|
65
|
+
#system("find %s" % Puppet[:ssldir])
|
66
|
+
assert_equal($?,0)
|
67
|
+
assert_equal(%w{host.test.com}, output)
|
68
|
+
assert_nothing_raised {
|
69
|
+
output = %x{puppetca --sign -a --ssldir=#{Puppet[:ssldir]}}.chomp.split("\n")
|
70
|
+
}
|
71
|
+
assert_equal($?,0)
|
72
|
+
assert_equal([], output)
|
73
|
+
assert_nothing_raised {
|
74
|
+
output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]}}.chomp.split("\n")
|
75
|
+
}
|
76
|
+
assert_equal($?,0)
|
77
|
+
assert_equal([], output)
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
$:.unshift '../../lib'
|
3
|
+
$:.unshift '..'
|
4
|
+
$puppetbase = "../.."
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'puppet/server'
|
9
|
+
require 'test/unit'
|
10
|
+
require 'puppettest.rb'
|
11
|
+
require 'socket'
|
12
|
+
require 'facter'
|
13
|
+
|
14
|
+
# $Id: puppetd.rb 731 2005-10-26 04:44:25Z luke $
|
15
|
+
|
16
|
+
# ok, we have to add the bin directory to our search path
|
17
|
+
ENV["PATH"] += ":" + File.join($puppetbase, "bin")
|
18
|
+
|
19
|
+
# and then the library directories
|
20
|
+
libdirs = $:.find_all { |dir|
|
21
|
+
dir =~ /puppet/ or dir =~ /\.\./
|
22
|
+
}
|
23
|
+
ENV["RUBYLIB"] = libdirs.join(":")
|
24
|
+
|
25
|
+
class TestPuppetDExe < Test::Unit::TestCase
|
26
|
+
include ExeTest
|
27
|
+
def test_normalstart
|
28
|
+
# start the master
|
29
|
+
file = startmasterd
|
30
|
+
|
31
|
+
# create the client
|
32
|
+
client = Puppet::Client.new(:Server => "localhost", :Port => @@port)
|
33
|
+
|
34
|
+
# make a new fqdn
|
35
|
+
fqdn = client.fqdn.sub(/^\w+\./, "testing.")
|
36
|
+
|
37
|
+
cmd = "puppetd"
|
38
|
+
cmd += " --verbose"
|
39
|
+
#cmd += " --fqdn %s" % fqdn
|
40
|
+
cmd += " --port %s" % @@port
|
41
|
+
cmd += " --confdir %s" % Puppet[:puppetconf]
|
42
|
+
cmd += " --vardir %s" % Puppet[:puppetvar]
|
43
|
+
cmd += " --server localhost"
|
44
|
+
|
45
|
+
# and verify our daemon runs
|
46
|
+
assert_nothing_raised {
|
47
|
+
output = %x{#{cmd}}.chomp
|
48
|
+
puts output
|
49
|
+
}
|
50
|
+
sleep 1
|
51
|
+
assert($? == 0, "Puppetd exited with code %s" % $?)
|
52
|
+
|
53
|
+
assert(FileTest.exists?(@createdfile),
|
54
|
+
"Failed to create config'ed file")
|
55
|
+
|
56
|
+
# now verify that --noop works
|
57
|
+
File.unlink(@createdfile)
|
58
|
+
|
59
|
+
cmd += " --noop"
|
60
|
+
assert_nothing_raised {
|
61
|
+
output = %x{#{cmd}}.chomp
|
62
|
+
}
|
63
|
+
sleep 1
|
64
|
+
assert($? == 0, "Puppetd exited with code %s" % $?)
|
65
|
+
|
66
|
+
assert(! FileTest.exists?(@createdfile),
|
67
|
+
"Noop created config'ed file")
|
68
|
+
|
69
|
+
stopmasterd
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
$:.unshift '../../lib'
|
3
|
+
$:.unshift '..'
|
4
|
+
$puppetbase = "../.."
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'puppet/server'
|
9
|
+
require 'puppet/daemon'
|
10
|
+
require 'test/unit'
|
11
|
+
require 'puppettest.rb'
|
12
|
+
require 'socket'
|
13
|
+
require 'facter'
|
14
|
+
|
15
|
+
# $Id: puppetmasterd.rb 732 2005-10-28 05:39:59Z luke $
|
16
|
+
|
17
|
+
class TestPuppetMasterD < Test::Unit::TestCase
|
18
|
+
include ExeTest
|
19
|
+
def getcerts
|
20
|
+
include Puppet::Daemon
|
21
|
+
if self.readcerts
|
22
|
+
return [@cert, @key, @cacert, @cacertfile]
|
23
|
+
else
|
24
|
+
raise "Couldn't read certs"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# start the daemon and verify it responds and such
|
29
|
+
def test_normalstart
|
30
|
+
startmasterd
|
31
|
+
|
32
|
+
pidfile = File.join(Puppet[:puppetvar], "puppetmasterd.pid")
|
33
|
+
assert(FileTest.exists?(pidfile), "PID file does not exist")
|
34
|
+
|
35
|
+
sleep(1)
|
36
|
+
assert_nothing_raised {
|
37
|
+
socket = TCPSocket.new("127.0.0.1", @@port)
|
38
|
+
socket.close
|
39
|
+
}
|
40
|
+
|
41
|
+
client = nil
|
42
|
+
assert_nothing_raised() {
|
43
|
+
client = Puppet::Client::StatusClient.new(
|
44
|
+
:Server => "localhost",
|
45
|
+
:Port => @@port
|
46
|
+
)
|
47
|
+
}
|
48
|
+
|
49
|
+
# set our client up to auto-sign
|
50
|
+
assert(Puppet[:autosign] =~ /^#{File::SEPARATOR}/,
|
51
|
+
"Autosign is set to %s, not a file" % Puppet[:autosign])
|
52
|
+
|
53
|
+
FileUtils.mkdir_p(File.dirname(Puppet[:autosign]))
|
54
|
+
File.open(Puppet[:autosign], "w") { |f|
|
55
|
+
f.puts client.fqdn
|
56
|
+
}
|
57
|
+
|
58
|
+
retval = nil
|
59
|
+
|
60
|
+
# init the client certs
|
61
|
+
assert_nothing_raised() {
|
62
|
+
client.initcerts
|
63
|
+
}
|
64
|
+
|
65
|
+
# call status
|
66
|
+
assert_nothing_raised() {
|
67
|
+
retval = client.status
|
68
|
+
}
|
69
|
+
assert_equal(1, retval, "Status.status return value was %s" % retval)
|
70
|
+
|
71
|
+
# this client shoulduse the same certs
|
72
|
+
assert_nothing_raised() {
|
73
|
+
client = Puppet::Client::MasterClient.new(
|
74
|
+
:Server => "localhost",
|
75
|
+
:Port => @@port
|
76
|
+
)
|
77
|
+
}
|
78
|
+
assert_nothing_raised() {
|
79
|
+
#Puppet.notice "calling status"
|
80
|
+
#retval = client.call("status.status", "")
|
81
|
+
retval = client.getconfig
|
82
|
+
}
|
83
|
+
|
84
|
+
objects = nil
|
85
|
+
assert_instance_of(Puppet::TransBucket, retval,
|
86
|
+
"Retrieved non-transportable object")
|
87
|
+
stopmasterd
|
88
|
+
sleep(1)
|
89
|
+
end
|
90
|
+
|
91
|
+
# verify that we can run puppetmasterd in parse-only mode
|
92
|
+
def test_parseonly
|
93
|
+
startmasterd("--parseonly > /dev/null")
|
94
|
+
sleep(1)
|
95
|
+
|
96
|
+
pid = nil
|
97
|
+
ps = Facter["ps"].value || "ps -ef"
|
98
|
+
%x{#{ps}}.chomp.split(/\n/).each { |line|
|
99
|
+
if line =~ /puppetmasterd --manifest/
|
100
|
+
ary = line.split(" ")
|
101
|
+
pid = ary[1].to_i
|
102
|
+
end
|
103
|
+
}
|
104
|
+
|
105
|
+
assert($? == 0, "Puppetmasterd ended with non-zero exit status")
|
106
|
+
|
107
|
+
assert_nil(pid, "Puppetmasterd is still running after parseonly")
|
108
|
+
end
|
109
|
+
|
110
|
+
def disabled_test_sslconnection
|
111
|
+
#file = File.join($puppetbase, "examples", "code", "head")
|
112
|
+
#startmasterd("--manifest #{file}")
|
113
|
+
|
114
|
+
#assert_nothing_raised {
|
115
|
+
# socket = TCPSocket.new("127.0.0.1", Puppet[:masterport])
|
116
|
+
# socket.close
|
117
|
+
#}
|
118
|
+
|
119
|
+
client = nil
|
120
|
+
cert, key, cacert, cacertfile = getcerts()
|
121
|
+
|
122
|
+
assert_nothing_raised() {
|
123
|
+
client = Net::HTTP.new("localhost", Puppet[:masterport])
|
124
|
+
client.cert = cert
|
125
|
+
client.key = key
|
126
|
+
client.ca_file = cacertfile
|
127
|
+
client.use_ssl = true
|
128
|
+
client.start_immediately = true
|
129
|
+
}
|
130
|
+
retval = nil
|
131
|
+
|
132
|
+
assert_nothing_raised() {
|
133
|
+
retval = client.nothing
|
134
|
+
}
|
135
|
+
assert_equal(1, retval, "return value was %s" % retval)
|
136
|
+
facts = {}
|
137
|
+
Facter.each { |p,v|
|
138
|
+
facts[p] = v
|
139
|
+
}
|
140
|
+
textfacts = CGI.escape(Marshal::dump(facts))
|
141
|
+
assert_nothing_raised() {
|
142
|
+
#Puppet.notice "calling status"
|
143
|
+
#retval = client.call("status.status", "")
|
144
|
+
retval = client.call("puppetmaster.getconfig", textfacts)
|
145
|
+
}
|
146
|
+
|
147
|
+
objects = nil
|
148
|
+
assert_nothing_raised {
|
149
|
+
Marshal::load(CGI.unescape(retval))
|
150
|
+
}
|
151
|
+
#stopmasterd
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
$:.unshift '../../lib'
|
3
|
+
$:.unshift '..'
|
4
|
+
$puppetbase = "../.."
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'puppet/server'
|
9
|
+
require 'puppet/sslcertificates'
|
10
|
+
require 'test/unit'
|
11
|
+
require 'puppettest.rb'
|
12
|
+
|
13
|
+
# add the bin directory to our search path
|
14
|
+
ENV["PATH"] += ":" + File.join($puppetbase, "bin")
|
15
|
+
|
16
|
+
# and then the library directories
|
17
|
+
libdirs = $:.find_all { |dir|
|
18
|
+
dir =~ /puppet/ or dir =~ /\.\./
|
19
|
+
}
|
20
|
+
ENV["RUBYLIB"] = libdirs.join(":")
|
21
|
+
|
22
|
+
$module = File.join($puppetbase, "ext", "module:puppet")
|
23
|
+
|
24
|
+
class TestPuppetModule < Test::Unit::TestCase
|
25
|
+
include ServerTest
|
26
|
+
|
27
|
+
def test_execution
|
28
|
+
file = tempfile()
|
29
|
+
|
30
|
+
createdfile = tempfile()
|
31
|
+
|
32
|
+
File.open(file, "w") { |f|
|
33
|
+
f.puts "class yaytest { file { \"#{createdfile}\": create => true } }"
|
34
|
+
}
|
35
|
+
|
36
|
+
output = nil
|
37
|
+
cmd = $module
|
38
|
+
cmd += " --verbose"
|
39
|
+
#cmd += " --fqdn %s" % fqdn
|
40
|
+
cmd += " --confdir %s" % Puppet[:puppetconf]
|
41
|
+
cmd += " --vardir %s" % Puppet[:puppetvar]
|
42
|
+
if Puppet[:debug]
|
43
|
+
cmd += " --logdest %s" % "console"
|
44
|
+
else
|
45
|
+
cmd += " --logdest %s" % "/dev/null"
|
46
|
+
end
|
47
|
+
|
48
|
+
ENV["CFALLCLASSES"] = "yaytest:all"
|
49
|
+
|
50
|
+
Puppet.err :mark
|
51
|
+
assert_nothing_raised {
|
52
|
+
system(cmd + " " + file)
|
53
|
+
}
|
54
|
+
assert($? == 0, "Puppet module exited with code %s" % $?.to_i)
|
55
|
+
|
56
|
+
assert(FileTest.exists?(createdfile), "Failed to create config'ed file")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# $Id: puppetmodule.rb 746 2005-11-17 21:03:19Z luke $
|
@@ -0,0 +1,412 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
if __FILE__ == $0
|
4
|
+
$:.unshift '../../lib'
|
5
|
+
$:.unshift '..'
|
6
|
+
$puppetbase = "../.."
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'puppet'
|
10
|
+
require 'puppet/parser/interpreter'
|
11
|
+
require 'puppet/parser/parser'
|
12
|
+
require 'puppet/client'
|
13
|
+
require 'test/unit'
|
14
|
+
require 'puppettest'
|
15
|
+
|
16
|
+
class TestAST < Test::Unit::TestCase
|
17
|
+
include ParserTesting
|
18
|
+
|
19
|
+
# Test that classes behave like singletons
|
20
|
+
def test_classsingleton
|
21
|
+
parent = child1 = child2 = nil
|
22
|
+
children = []
|
23
|
+
|
24
|
+
# create the parent class
|
25
|
+
children << classobj("parent")
|
26
|
+
|
27
|
+
# Create child class one
|
28
|
+
children << classobj("child1", :parentclass => nameobj("parent"))
|
29
|
+
|
30
|
+
# Create child class two
|
31
|
+
children << classobj("child2", :parentclass => nameobj("parent"))
|
32
|
+
|
33
|
+
# Now call the two classes
|
34
|
+
assert_nothing_raised("Could not add AST nodes for calling") {
|
35
|
+
children << AST::ObjectDef.new(
|
36
|
+
:type => nameobj("child1"),
|
37
|
+
:name => nameobj("yayness"),
|
38
|
+
:params => astarray()
|
39
|
+
)
|
40
|
+
children << AST::ObjectDef.new(
|
41
|
+
:type => nameobj("child2"),
|
42
|
+
:name => nameobj("booness"),
|
43
|
+
:params => astarray()
|
44
|
+
)
|
45
|
+
}
|
46
|
+
|
47
|
+
top = nil
|
48
|
+
assert_nothing_raised("Could not create top object") {
|
49
|
+
top = AST::ASTArray.new(
|
50
|
+
:children => children
|
51
|
+
)
|
52
|
+
}
|
53
|
+
|
54
|
+
scope = nil
|
55
|
+
assert_nothing_raised("Could not evaluate") {
|
56
|
+
scope = Puppet::Parser::Scope.new()
|
57
|
+
objects = top.evaluate(scope)
|
58
|
+
}
|
59
|
+
|
60
|
+
assert_equal(1, scope.find_all { |child|
|
61
|
+
child.lookupobject("/parent", "file")
|
62
|
+
}.length, "Found incorrect number of '/parent' objects")
|
63
|
+
end
|
64
|
+
|
65
|
+
# Test that 'setobject' collects all of an object's parameters and stores
|
66
|
+
# them in one TransObject, rather than many. This is probably a bad idea.
|
67
|
+
def test_setobject
|
68
|
+
top = nil
|
69
|
+
children = [
|
70
|
+
fileobj("/etc", "owner" => "root"),
|
71
|
+
fileobj("/etc", "group" => "root")
|
72
|
+
]
|
73
|
+
assert_nothing_raised("Could not create top object") {
|
74
|
+
top = AST::ASTArray.new(
|
75
|
+
:children => children
|
76
|
+
)
|
77
|
+
}
|
78
|
+
|
79
|
+
scope = Puppet::Parser::Scope.new()
|
80
|
+
assert_nothing_raised("Could not evaluate") {
|
81
|
+
top.evaluate(scope)
|
82
|
+
}
|
83
|
+
|
84
|
+
obj = nil
|
85
|
+
assert_nothing_raised("Could not retrieve file object") {
|
86
|
+
obj = scope.lookupobject("/etc", "file")
|
87
|
+
}
|
88
|
+
|
89
|
+
assert(obj, "could not retrieve file object")
|
90
|
+
|
91
|
+
%w{owner group}.each { |param|
|
92
|
+
assert(obj.include?(param), "Object did not include %s" % param)
|
93
|
+
}
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
# Verify that objects can only have parents of the same type.
|
98
|
+
def test_validparent
|
99
|
+
parent = child1 = nil
|
100
|
+
children = []
|
101
|
+
|
102
|
+
# create the parent class
|
103
|
+
children << compobj("parent", :args => AST::ASTArray.new(:children => []))
|
104
|
+
|
105
|
+
# Create child class one
|
106
|
+
children << classobj("child1", :parentclass => nameobj("parent"))
|
107
|
+
|
108
|
+
# Now call the two classes
|
109
|
+
assert_nothing_raised("Could not add AST nodes for calling") {
|
110
|
+
children << AST::ObjectDef.new(
|
111
|
+
:type => nameobj("child1"),
|
112
|
+
:name => nameobj("yayness"),
|
113
|
+
:params => astarray()
|
114
|
+
)
|
115
|
+
}
|
116
|
+
|
117
|
+
top = nil
|
118
|
+
assert_nothing_raised("Could not create top object") {
|
119
|
+
top = AST::ASTArray.new(
|
120
|
+
:children => children
|
121
|
+
)
|
122
|
+
}
|
123
|
+
|
124
|
+
scope = nil
|
125
|
+
assert_raise(Puppet::ParseError, "Invalid parent type was allowed") {
|
126
|
+
scope = Puppet::Parser::Scope.new()
|
127
|
+
objects = top.evaluate(scope)
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
# Verify that classes are correctly defined in node scopes.
|
132
|
+
def test_nodeclasslookup
|
133
|
+
parent = child1 = nil
|
134
|
+
children = []
|
135
|
+
|
136
|
+
# create the parent class
|
137
|
+
children << classobj("parent")
|
138
|
+
|
139
|
+
# Create child class one
|
140
|
+
children << classobj("child1", :parentclass => nameobj("parent"))
|
141
|
+
|
142
|
+
# Now call the two classes
|
143
|
+
assert_nothing_raised("Could not add AST nodes for calling") {
|
144
|
+
children << AST::ObjectDef.new(
|
145
|
+
:type => nameobj("child1"),
|
146
|
+
:name => nameobj("yayness"),
|
147
|
+
:params => astarray()
|
148
|
+
)
|
149
|
+
}
|
150
|
+
|
151
|
+
# create the node
|
152
|
+
nodename = "mynodename"
|
153
|
+
node = nil
|
154
|
+
assert_nothing_raised("Could not create parent object") {
|
155
|
+
node = AST::NodeDef.new(
|
156
|
+
:names => nameobj(nodename),
|
157
|
+
:code => AST::ASTArray.new(
|
158
|
+
:children => children
|
159
|
+
)
|
160
|
+
)
|
161
|
+
}
|
162
|
+
|
163
|
+
# Create the wrapper object
|
164
|
+
top = nil
|
165
|
+
assert_nothing_raised("Could not create top object") {
|
166
|
+
top = AST::ASTArray.new(
|
167
|
+
:children => [node]
|
168
|
+
)
|
169
|
+
}
|
170
|
+
|
171
|
+
# Evaluate the parse tree
|
172
|
+
scope = nil
|
173
|
+
assert_nothing_raised("Could not evaluate node") {
|
174
|
+
scope = Puppet::Parser::Scope.new()
|
175
|
+
top.evaluate(scope)
|
176
|
+
}
|
177
|
+
|
178
|
+
# Verify that, well, nothing really happened, and especially verify
|
179
|
+
# that the top scope is not a node scope
|
180
|
+
assert(scope.topscope?, "Scope is not top scope")
|
181
|
+
assert(! scope.nodescope?, "Scope is mistakenly node scope")
|
182
|
+
assert(! scope.lookupclass("parent"), "Found parent class in top scope")
|
183
|
+
|
184
|
+
# verify we can find our node
|
185
|
+
assert(scope.node(nodename), "Could not find node")
|
186
|
+
|
187
|
+
# And verify that we can evaluate it okay
|
188
|
+
objects = nil
|
189
|
+
assert_nothing_raised("Could not retrieve node definition") {
|
190
|
+
objects = scope.evalnode([nodename], {})
|
191
|
+
}
|
192
|
+
assert(objects, "Could not retrieve node definition")
|
193
|
+
|
194
|
+
# Because node scopes are temporary (i.e., they get destroyed after the node's
|
195
|
+
# config is returned) we should not be able to find the node scope.
|
196
|
+
nodescope = nil
|
197
|
+
assert_nothing_raised {
|
198
|
+
nodescope = scope.find { |child|
|
199
|
+
child.nodescope?
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
assert_nil(nodescope, "Found nodescope")
|
204
|
+
|
205
|
+
# And now verify again that the top scope cannot find the node's definition
|
206
|
+
# of the parent class
|
207
|
+
assert(! scope.lookupclass("parent"), "Found parent class in top scope")
|
208
|
+
|
209
|
+
# Verify that we can evaluate the node twice
|
210
|
+
assert_nothing_raised("Could not retrieve node definition") {
|
211
|
+
scope.evalnode([nodename], {})
|
212
|
+
}
|
213
|
+
end
|
214
|
+
|
215
|
+
# Test that you can look a host up using multiple names, e.g., an FQDN and
|
216
|
+
# a short name
|
217
|
+
def test_multiplenodenames
|
218
|
+
children = []
|
219
|
+
|
220
|
+
# create a short-name node
|
221
|
+
shortname = "mynodename"
|
222
|
+
children << nodeobj(shortname)
|
223
|
+
|
224
|
+
# And a long-name node
|
225
|
+
longname = "node.domain.com"
|
226
|
+
children << nodeobj(longname)
|
227
|
+
|
228
|
+
# Create the wrapper object
|
229
|
+
top = nil
|
230
|
+
assert_nothing_raised("Could not create top object") {
|
231
|
+
top = AST::ASTArray.new(
|
232
|
+
:children => children
|
233
|
+
)
|
234
|
+
}
|
235
|
+
|
236
|
+
# Evaluate the parse tree
|
237
|
+
scope = nil
|
238
|
+
assert_nothing_raised("Could not evaluate node") {
|
239
|
+
scope = Puppet::Parser::Scope.new()
|
240
|
+
top.evaluate(scope)
|
241
|
+
}
|
242
|
+
|
243
|
+
# Verify we can find the node via a search list
|
244
|
+
objects = nil
|
245
|
+
assert_nothing_raised("Could not retrieve short node definition") {
|
246
|
+
objects = scope.evalnode(["%s.domain.com" % shortname, shortname], {})
|
247
|
+
}
|
248
|
+
assert(objects, "Could not retrieve short node definition")
|
249
|
+
|
250
|
+
# and then look for the long name
|
251
|
+
assert_nothing_raised("Could not retrieve long node definition") {
|
252
|
+
objects = scope.evalnode([longname.sub(/\..+/, ''), longname], {})
|
253
|
+
}
|
254
|
+
assert(objects, "Could not retrieve long node definition")
|
255
|
+
end
|
256
|
+
|
257
|
+
# Test that a node gets the entire configuration except for work meant for
|
258
|
+
# another node
|
259
|
+
def test_fullconfigwithnodes
|
260
|
+
children = []
|
261
|
+
|
262
|
+
children << fileobj("/testing")
|
263
|
+
|
264
|
+
# create a short-name node
|
265
|
+
name = "mynodename"
|
266
|
+
children << nodeobj(name)
|
267
|
+
|
268
|
+
# Create the wrapper object
|
269
|
+
top = nil
|
270
|
+
assert_nothing_raised("Could not create top object") {
|
271
|
+
top = AST::ASTArray.new(
|
272
|
+
:children => children
|
273
|
+
)
|
274
|
+
}
|
275
|
+
|
276
|
+
# Evaluate the parse tree
|
277
|
+
scope = nil
|
278
|
+
assert_nothing_raised("Could not evaluate node") {
|
279
|
+
scope = Puppet::Parser::Scope.new()
|
280
|
+
top.evaluate(scope)
|
281
|
+
}
|
282
|
+
|
283
|
+
# Verify we can find the node via a search list
|
284
|
+
objects = nil
|
285
|
+
assert_nothing_raised("Could not retrieve short node definition") {
|
286
|
+
objects = scope.evalnode([name], {})
|
287
|
+
}
|
288
|
+
assert(objects, "Could not retrieve short node definition")
|
289
|
+
|
290
|
+
# And now verify that we got both the top and node objects
|
291
|
+
assert_nothing_raised("Could not find top-declared object") {
|
292
|
+
assert_equal("/testing", objects[0][:name])
|
293
|
+
}
|
294
|
+
|
295
|
+
assert_nothing_raised("Could not find node-declared object") {
|
296
|
+
assert_equal("/%s" % name, objects[1][0][:name])
|
297
|
+
}
|
298
|
+
end
|
299
|
+
|
300
|
+
# Test that we can 'include' variables, not just normal strings.
|
301
|
+
def test_includevars
|
302
|
+
children = []
|
303
|
+
|
304
|
+
# Create our class for testin
|
305
|
+
klassname = "include"
|
306
|
+
children << classobj(klassname)
|
307
|
+
|
308
|
+
# Then add our variable assignment
|
309
|
+
children << varobj("klassvar", klassname)
|
310
|
+
|
311
|
+
# And finally add our calling of the variable
|
312
|
+
children << AST::ObjectDef.new(
|
313
|
+
:type => AST::Variable.new(:value => "klassvar"),
|
314
|
+
:params => astarray
|
315
|
+
)
|
316
|
+
|
317
|
+
# And then create our top object
|
318
|
+
top = AST::ASTArray.new(
|
319
|
+
:children => children
|
320
|
+
)
|
321
|
+
|
322
|
+
# Evaluate the parse tree
|
323
|
+
scope = nil
|
324
|
+
assert_nothing_raised("Could not evaluate node") {
|
325
|
+
scope = Puppet::Parser::Scope.new()
|
326
|
+
top.evaluate(scope)
|
327
|
+
}
|
328
|
+
|
329
|
+
# Verify we can find the node via a search list
|
330
|
+
objects = nil
|
331
|
+
assert_nothing_raised("Could not retrieve objects") {
|
332
|
+
objects = scope.to_trans
|
333
|
+
}
|
334
|
+
assert(objects, "Could not retrieve objects")
|
335
|
+
|
336
|
+
assert_nothing_raised("Could not find top-declared object") {
|
337
|
+
assert_equal("/%s" % klassname, objects[0][0][:name])
|
338
|
+
}
|
339
|
+
end
|
340
|
+
|
341
|
+
# Test that node inheritance works correctly
|
342
|
+
def test_znodeinheritance
|
343
|
+
children = []
|
344
|
+
|
345
|
+
# create the base node
|
346
|
+
name = "basenode"
|
347
|
+
children << nodeobj(name)
|
348
|
+
|
349
|
+
# and the sub node
|
350
|
+
name = "subnode"
|
351
|
+
children << AST::NodeDef.new(
|
352
|
+
:names => nameobj(name),
|
353
|
+
:parentclass => nameobj("basenode"),
|
354
|
+
:code => AST::ASTArray.new(
|
355
|
+
:children => [
|
356
|
+
varobj("%svar" % name, "%svalue" % name),
|
357
|
+
fileobj("/%s" % name)
|
358
|
+
]
|
359
|
+
)
|
360
|
+
)
|
361
|
+
#subnode = nodeobj(name)
|
362
|
+
#subnode.parentclass = "basenode"
|
363
|
+
|
364
|
+
#children << subnode
|
365
|
+
|
366
|
+
# and the top object
|
367
|
+
top = nil
|
368
|
+
assert_nothing_raised("Could not create top object") {
|
369
|
+
top = AST::ASTArray.new(
|
370
|
+
:children => children
|
371
|
+
)
|
372
|
+
}
|
373
|
+
|
374
|
+
# Evaluate the parse tree
|
375
|
+
scope = nil
|
376
|
+
assert_nothing_raised("Could not evaluate node") {
|
377
|
+
scope = Puppet::Parser::Scope.new()
|
378
|
+
top.evaluate(scope)
|
379
|
+
}
|
380
|
+
|
381
|
+
# Verify we can find the node via a search list
|
382
|
+
objects = nil
|
383
|
+
assert_nothing_raised("Could not retrieve node definition") {
|
384
|
+
objects = scope.evalnode([name], {})
|
385
|
+
}
|
386
|
+
assert(objects, "Could not retrieve node definition")
|
387
|
+
|
388
|
+
assert_nothing_raised {
|
389
|
+
inner = objects[0]
|
390
|
+
|
391
|
+
# And now verify that we got the subnode file
|
392
|
+
assert_nothing_raised("Could not find basenode file") {
|
393
|
+
base = inner[0]
|
394
|
+
assert_equal("/basenode", base[:name])
|
395
|
+
}
|
396
|
+
|
397
|
+
# and the parent node file
|
398
|
+
assert_nothing_raised("Could not find subnode file") {
|
399
|
+
sub = inner[1]
|
400
|
+
assert_equal("/subnode", sub[:name])
|
401
|
+
}
|
402
|
+
|
403
|
+
inner.each { |obj|
|
404
|
+
%w{basenode subnode}.each { |tag|
|
405
|
+
assert(obj.tags.include?(tag),
|
406
|
+
"%s did not include %s tag" % [obj[:name], tag]
|
407
|
+
)
|
408
|
+
}
|
409
|
+
}
|
410
|
+
}
|
411
|
+
end
|
412
|
+
end
|