puppet 2.7.11 → 2.7.12
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 +188 -0
- data/conf/osx/createpackage.sh +1 -0
- data/conf/redhat/puppet.spec +12 -9
- data/conf/suse/puppet.spec +4 -1
- data/install.rb +9 -22
- data/lib/puppet.rb +1 -31
- data/lib/puppet/agent.rb +3 -5
- data/lib/puppet/agent/locker.rb +15 -1
- data/lib/puppet/application.rb +7 -4
- data/lib/puppet/application/agent.rb +4 -25
- data/lib/puppet/application/apply.rb +3 -3
- data/lib/puppet/application/device.rb +2 -16
- data/lib/puppet/application/doc.rb +2 -2
- data/lib/puppet/application/face_base.rb +22 -5
- data/lib/puppet/application/filebucket.rb +2 -0
- data/lib/puppet/application/inspect.rb +2 -1
- data/lib/puppet/application/kick.rb +25 -9
- data/lib/puppet/application/queue.rb +0 -23
- data/lib/puppet/configurer.rb +1 -0
- data/lib/puppet/configurer/downloader.rb +7 -3
- data/lib/puppet/defaults.rb +34 -29
- data/lib/puppet/face/ca.rb +1 -1
- data/lib/puppet/face/catalog.rb +1 -0
- data/lib/puppet/face/file/store.rb +1 -1
- data/lib/puppet/face/module/list.rb +23 -3
- data/lib/puppet/face/module/search.rb +21 -32
- data/lib/puppet/face/module/uninstall.rb +56 -15
- data/lib/puppet/file_bucket/dipper.rb +2 -2
- data/lib/puppet/file_serving/base.rb +6 -5
- data/lib/puppet/file_serving/configuration/parser.rb +1 -1
- data/lib/puppet/file_serving/content.rb +1 -1
- data/lib/puppet/forge.rb +153 -0
- data/lib/puppet/{module_tool → forge}/cache.rb +1 -2
- data/lib/puppet/{module_tool → forge}/repository.rb +46 -4
- data/lib/puppet/indirector/exec.rb +1 -1
- data/lib/puppet/indirector/file_bucket_file/file.rb +3 -3
- data/lib/puppet/interface/action.rb +6 -2
- data/lib/puppet/module.rb +70 -10
- data/lib/puppet/module_tool.rb +2 -38
- data/lib/puppet/module_tool/applications.rb +15 -11
- data/lib/puppet/module_tool/applications/application.rb +2 -5
- data/lib/puppet/module_tool/applications/cleaner.rb +1 -1
- data/lib/puppet/module_tool/applications/installer.rb +10 -45
- data/lib/puppet/module_tool/applications/searcher.rb +2 -26
- data/lib/puppet/module_tool/applications/uninstaller.rb +39 -13
- data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
- data/lib/puppet/module_tool/dependency.rb +1 -1
- data/lib/puppet/network/authconfig.rb +1 -1
- data/lib/puppet/network/handler/fileserver.rb +1 -1
- data/lib/puppet/network/http/handler.rb +4 -1
- data/lib/puppet/network/http/webrick.rb +4 -2
- data/lib/puppet/node/environment.rb +32 -6
- data/lib/puppet/parameter/path.rb +0 -4
- data/lib/puppet/parser/ast/relationship.rb +3 -16
- data/lib/puppet/parser/collector.rb +5 -3
- data/lib/puppet/parser/compiler.rb +2 -1
- data/lib/puppet/parser/functions/file.rb +1 -1
- data/lib/puppet/parser/functions/generate.rb +8 -2
- data/lib/puppet/parser/grammar.ra +16 -15
- data/lib/puppet/parser/parser.rb +959 -881
- data/lib/puppet/parser/relationship.rb +32 -15
- data/lib/puppet/parser/resource.rb +0 -1
- data/lib/puppet/parser/type_loader.rb +1 -2
- data/lib/puppet/provider/augeas/augeas.rb +17 -29
- data/lib/puppet/provider/exec/windows.rb +25 -3
- data/lib/puppet/provider/file/posix.rb +1 -1
- data/lib/puppet/provider/file/windows.rb +1 -1
- data/lib/puppet/provider/group/windows_adsi.rb +1 -1
- data/lib/puppet/provider/package/aix.rb +1 -1
- data/lib/puppet/provider/package/appdmg.rb +1 -1
- data/lib/puppet/provider/package/dpkg.rb +1 -1
- data/lib/puppet/provider/package/gem.rb +21 -23
- data/lib/puppet/provider/package/macports.rb +1 -1
- data/lib/puppet/provider/package/msi.rb +7 -1
- data/lib/puppet/provider/package/openbsd.rb +13 -16
- data/lib/puppet/provider/package/pacman.rb +1 -1
- data/lib/puppet/provider/package/pip.rb +3 -0
- data/lib/puppet/provider/package/pkg.rb +1 -1
- data/lib/puppet/provider/package/pkgdmg.rb +1 -1
- data/lib/puppet/provider/package/pkgutil.rb +1 -1
- data/lib/puppet/provider/package/portage.rb +2 -2
- data/lib/puppet/provider/package/rpm.rb +1 -1
- data/lib/puppet/provider/package/sun.rb +1 -1
- data/lib/puppet/provider/package/zypper.rb +35 -3
- data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +6 -2
- data/lib/puppet/provider/selmodule/semodule.rb +2 -2
- data/lib/puppet/provider/service/base.rb +1 -1
- data/lib/puppet/provider/service/launchd.rb +4 -0
- data/lib/puppet/provider/service/src.rb +2 -2
- data/lib/puppet/provider/service/upstart.rb +1 -1
- data/lib/puppet/provider/service/windows.rb +5 -4
- data/lib/puppet/provider/user/aix.rb +3 -3
- data/lib/puppet/provider/user/pw.rb +6 -0
- data/lib/puppet/provider/user/windows_adsi.rb +1 -1
- data/lib/puppet/resource/catalog.rb +6 -6
- data/lib/puppet/resource/type.rb +2 -0
- data/lib/puppet/ssl/certificate_request.rb +0 -70
- data/lib/puppet/transaction.rb +1 -1
- data/lib/puppet/transaction/report.rb +3 -2
- data/lib/puppet/type.rb +1 -1
- data/lib/puppet/type/cron.rb +5 -2
- data/lib/puppet/type/exec.rb +8 -0
- data/lib/puppet/type/file.rb +27 -18
- data/lib/puppet/type/file/checksum.rb +2 -2
- data/lib/puppet/type/file/content.rb +14 -9
- data/lib/puppet/type/file/ensure.rb +5 -4
- data/lib/puppet/type/file/group.rb +10 -2
- data/lib/puppet/type/file/mode.rb +46 -18
- data/lib/puppet/type/file/owner.rb +10 -2
- data/lib/puppet/type/file/source.rb +27 -40
- data/lib/puppet/type/file/target.rb +6 -6
- data/lib/puppet/type/group.rb +13 -9
- data/lib/puppet/type/k5login.rb +1 -1
- data/lib/puppet/type/package.rb +24 -8
- data/lib/puppet/type/scheduled_task.rb +77 -131
- data/lib/puppet/type/service.rb +22 -8
- data/lib/puppet/type/user.rb +29 -9
- data/lib/puppet/util.rb +24 -33
- data/lib/puppet/util/colors.rb +98 -0
- data/lib/puppet/util/diff.rb +3 -1
- data/lib/puppet/util/log.rb +5 -1
- data/lib/puppet/util/log/destinations.rb +37 -44
- data/lib/puppet/util/monkey_patches.rb +32 -0
- data/lib/puppet/util/pidlock.rb +70 -21
- data/lib/puppet/util/rdoc/parser.rb +4 -2
- data/lib/puppet/util/selinux.rb +1 -1
- data/lib/puppet/util/suidmanager.rb +2 -12
- data/lib/puppet/util/windows.rb +2 -0
- data/lib/puppet/util/windows/process.rb +33 -0
- data/lib/puppet/util/windows/security.rb +6 -4
- data/lib/puppet/util/windows/user.rb +44 -0
- data/lib/semver.rb +55 -4
- data/spec/fixtures/unit/provider/package/openbsd/pkginfo.detail +19 -0
- data/spec/fixtures/unit/provider/package/openbsd/pkginfo.list +10 -0
- data/spec/fixtures/unit/provider/package/openbsd/pkginfo.query +1 -0
- data/spec/fixtures/unit/provider/package/zypper/zypper-list-updates-SLES11sp1.out +369 -0
- data/spec/integration/defaults_spec.rb +10 -0
- data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
- data/spec/integration/module_tool_spec.rb +10 -12
- data/spec/integration/parser/compiler_spec.rb +147 -0
- data/spec/integration/type/file_spec.rb +1 -1
- data/spec/integration/util/windows/user_spec.rb +59 -0
- data/spec/lib/puppet/face/basetest.rb +5 -0
- data/spec/lib/puppet_spec/modules.rb +26 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/agent/locker_spec.rb +12 -0
- data/spec/unit/agent_backward_compatibility_spec.rb +152 -0
- data/spec/unit/agent_spec.rb +28 -8
- data/spec/unit/application/agent_spec.rb +4 -36
- data/spec/unit/application/device_spec.rb +55 -10
- data/spec/unit/application/face_base_spec.rb +32 -10
- data/spec/unit/application/filebucket_spec.rb +5 -0
- data/spec/unit/application/kick_spec.rb +6 -0
- data/spec/unit/application_spec.rb +8 -1
- data/spec/unit/configurer/downloader_spec.rb +4 -5
- data/spec/unit/face/ca_spec.rb +15 -4
- data/spec/unit/file_bucket/dipper_spec.rb +1 -1
- data/spec/unit/file_serving/base_spec.rb +60 -42
- data/spec/unit/file_serving/configuration/parser_spec.rb +5 -3
- data/spec/unit/file_serving/content_spec.rb +26 -27
- data/spec/unit/file_serving/metadata_spec.rb +22 -21
- data/spec/unit/forge/repository_spec.rb +86 -0
- data/spec/unit/forge_spec.rb +114 -0
- data/spec/unit/indirector/exec_spec.rb +8 -6
- data/spec/unit/indirector/facts/inventory_active_record_spec.rb +0 -1
- data/spec/unit/indirector/file_bucket_file/file_spec.rb +1 -1
- data/spec/unit/indirector/node/exec_spec.rb +1 -1
- data/spec/unit/indirector/resource/active_record_spec.rb +0 -4
- data/spec/unit/interface/action_builder_spec.rb +7 -5
- data/spec/unit/module_spec.rb +228 -9
- data/spec/unit/module_tool/application_spec.rb +3 -3
- data/spec/unit/module_tool/uninstaller_spec.rb +107 -27
- data/spec/unit/module_tool_spec.rb +0 -33
- data/spec/unit/network/authconfig_spec.rb +22 -21
- data/spec/unit/network/http/webrick_spec.rb +13 -9
- data/spec/unit/node/environment_spec.rb +159 -66
- data/spec/unit/parser/collector_spec.rb +16 -8
- data/spec/unit/parser/functions/generate_spec.rb +60 -18
- data/spec/unit/parser/resource_spec.rb +44 -0
- data/spec/unit/provider/augeas/augeas_spec.rb +160 -179
- data/spec/unit/provider/confine/feature_spec.rb +3 -5
- data/spec/unit/provider/package/dpkg_spec.rb +4 -2
- data/spec/unit/provider/package/gem_spec.rb +59 -43
- data/spec/unit/provider/package/openbsd_spec.rb +114 -0
- data/spec/unit/provider/package/pacman_spec.rb +1 -1
- data/spec/unit/provider/package/pip_spec.rb +10 -4
- data/spec/unit/provider/package/zypper_spec.rb +56 -14
- data/spec/unit/provider/selmodule_spec.rb +3 -3
- data/spec/unit/provider/service/launchd_spec.rb +22 -21
- data/spec/unit/provider/service/{upstart.rb → upstart_spec.rb} +7 -3
- data/spec/unit/provider/user/pw_spec.rb +19 -0
- data/spec/unit/resource/catalog_spec.rb +3 -3
- data/spec/unit/semver_spec.rb +117 -24
- data/spec/unit/transaction/report_spec.rb +11 -1
- data/spec/unit/type/cron_spec.rb +200 -213
- data/spec/unit/type/exec_spec.rb +7 -0
- data/spec/unit/type/file/content_spec.rb +2 -2
- data/spec/unit/type/file_spec.rb +12 -9
- data/spec/unit/type/package_spec.rb +25 -0
- data/spec/unit/type/schedule_spec.rb +31 -31
- data/spec/unit/util/diff_spec.rb +30 -0
- data/spec/unit/util/execution_stub_spec.rb +1 -2
- data/spec/unit/util/log/destinations_spec.rb +51 -0
- data/spec/unit/util/log_spec.rb +17 -1
- data/spec/unit/util/monkey_patches_spec.rb +119 -0
- data/spec/unit/util/rdoc/parser_spec.rb +25 -1
- data/spec/unit/util/selinux_spec.rb +2 -2
- data/spec/unit/util/suidmanager_spec.rb +6 -51
- data/spec/unit/util_spec.rb +82 -24
- data/test/lib/puppettest/certificates.rb +16 -0
- data/test/lib/puppettest/servertest.rb +4 -0
- data/test/util/pidlock.rb +125 -0
- metadata +23 -14
- data/ext/puppetstoredconfigclean.rb +0 -103
- data/lib/puppet/agent/disabler.rb +0 -27
- data/lib/puppet/util/anonymous_filelock.rb +0 -36
- data/spec/unit/agent/disabler_spec.rb +0 -60
- data/spec/unit/module_tool/repository_spec.rb +0 -52
- data/spec/unit/util/anonymous_filelock_spec.rb +0 -78
- data/spec/unit/util/pidlock_spec.rb +0 -208
data/spec/unit/util/log_spec.rb
CHANGED
@@ -14,6 +14,22 @@ describe Puppet::Util::Log do
|
|
14
14
|
message.should == "foo"
|
15
15
|
end
|
16
16
|
|
17
|
+
describe ".setup_default" do
|
18
|
+
it "should default to :syslog" do
|
19
|
+
Puppet.features.stubs(:syslog?).returns(true)
|
20
|
+
Puppet::Util::Log.expects(:newdestination).with(:syslog)
|
21
|
+
|
22
|
+
Puppet::Util::Log.setup_default
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should fall back to :file" do
|
26
|
+
Puppet.features.stubs(:syslog?).returns(false)
|
27
|
+
Puppet::Util::Log.expects(:newdestination).with(Puppet[:puppetdlog])
|
28
|
+
|
29
|
+
Puppet::Util::Log.setup_default
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
17
33
|
describe Puppet::Util::Log::DestConsole do
|
18
34
|
before do
|
19
35
|
@console = Puppet::Util::Log::DestConsole.new
|
@@ -34,7 +50,7 @@ describe Puppet::Util::Log do
|
|
34
50
|
it "should htmlize if Puppet[:color] is :html" do
|
35
51
|
Puppet[:color] = :html
|
36
52
|
|
37
|
-
@console.colorize(:alert, "abc").should == "<span style=\"color: FFA0A0\">abc</span>"
|
53
|
+
@console.colorize(:alert, "abc").should == "<span style=\"color: #FFA0A0\">abc</span>"
|
38
54
|
end
|
39
55
|
|
40
56
|
it "should do nothing if Puppet[:color] is false" do
|
@@ -53,3 +53,122 @@ describe "Array#combination" do
|
|
53
53
|
[1,2,3,4].combination(3).to_a.should == [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe IO do
|
58
|
+
include PuppetSpec::Files
|
59
|
+
|
60
|
+
let(:file) { tmpfile('io-binary') }
|
61
|
+
let(:content) { "\x01\x02\x03\x04" }
|
62
|
+
|
63
|
+
describe "::binread" do
|
64
|
+
it "should read in binary mode" do
|
65
|
+
File.open(file, 'wb') {|f| f.write(content) }
|
66
|
+
IO.binread(file).should == content
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should read with a length and offset" do
|
70
|
+
offset = 1
|
71
|
+
length = 2
|
72
|
+
File.open(file, 'wb') {|f| f.write(content) }
|
73
|
+
IO.binread(file, length, offset).should == content[offset..length]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should raise an error if the file doesn't exist" do
|
77
|
+
expect { IO.binread('/path/does/not/exist') }.to raise_error(Errno::ENOENT)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "::binwrite" do
|
82
|
+
it "should write in binary mode" do
|
83
|
+
IO.binwrite(file, content).should == content.length
|
84
|
+
File.open(file, 'rb') {|f| f.read.should == content }
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should write using an offset" do
|
88
|
+
offset = 1
|
89
|
+
IO.binwrite(file, content, offset).should == content.length - offset
|
90
|
+
File.open(file, 'rb') {|f| f.read.should == content[offset..-1] }
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should raise an error if the file doesn't exist" do
|
94
|
+
expect { IO.binwrite('/path/does/not/exist', 'foo') }.to raise_error(Errno::ENOENT)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe Range do
|
100
|
+
def do_test( range, other, expected )
|
101
|
+
result = range.intersection(other)
|
102
|
+
result.should == expected
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should return expected ranges for iterable things" do
|
106
|
+
iterable_tests = {
|
107
|
+
1 .. 4 => nil, # before
|
108
|
+
11 .. 15 => nil, # after
|
109
|
+
1 .. 6 => 5 .. 6, # overlap_begin
|
110
|
+
9 .. 15 => 9 .. 10, # overlap_end
|
111
|
+
1 .. 5 => 5 .. 5, # overlap_begin_edge
|
112
|
+
10 .. 15 => 10 .. 10, # overlap_end_edge
|
113
|
+
5 .. 10 => 5 .. 10, # overlap_all
|
114
|
+
6 .. 9 => 6 .. 9, # overlap_inner
|
115
|
+
|
116
|
+
1 ... 5 => nil, # before (exclusive range)
|
117
|
+
1 ... 7 => 5 ... 7, # overlap_begin (exclusive range)
|
118
|
+
1 ... 6 => 5 ... 6, # overlap_begin_edge (exclusive range)
|
119
|
+
5 ... 11 => 5 .. 10, # overlap_all (exclusive range)
|
120
|
+
6 ... 10 => 6 ... 10, # overlap_inner (exclusive range)
|
121
|
+
}
|
122
|
+
|
123
|
+
iterable_tests.each do |other, expected|
|
124
|
+
do_test( 5..10, other, expected )
|
125
|
+
do_test( other, 5..10, expected )
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should return expected ranges for noniterable things" do
|
130
|
+
inclusive_base_case = {
|
131
|
+
1.to_f .. 4.to_f => nil, # before
|
132
|
+
11.to_f .. 15.to_f => nil, # after
|
133
|
+
1.to_f .. 6.to_f => 5.to_f .. 6.to_f, # overlap_begin
|
134
|
+
9.to_f .. 15.to_f => 9.to_f .. 10.to_f, # overlap_end
|
135
|
+
1.to_f .. 5.to_f => 5.to_f .. 5.to_f, # overlap_begin_edge
|
136
|
+
10.to_f .. 15.to_f => 10.to_f .. 10.to_f, # overlap_end_edge
|
137
|
+
5.to_f .. 10.to_f => 5.to_f .. 10.to_f, # overlap_all
|
138
|
+
6.to_f .. 9.to_f => 6.to_f .. 9.to_f, # overlap_inner
|
139
|
+
|
140
|
+
1.to_f ... 5.to_f => nil, # before (exclusive range)
|
141
|
+
1.to_f ... 7.to_f => 5.to_f ... 7.to_f, # overlap_begin (exclusive range)
|
142
|
+
1.to_f ... 6.to_f => 5.to_f ... 6.to_f, # overlap_begin_edge (exclusive range)
|
143
|
+
5.to_f ... 11.to_f => 5.to_f .. 10.to_f, # overlap_all (exclusive range)
|
144
|
+
6.to_f ... 10.to_f => 6.to_f ... 10.to_f, # overlap_inner (exclusive range)
|
145
|
+
}
|
146
|
+
|
147
|
+
inclusive_base_case.each do |other, expected|
|
148
|
+
do_test( 5.to_f..10.to_f, other, expected )
|
149
|
+
do_test( other, 5.to_f..10.to_f, expected )
|
150
|
+
end
|
151
|
+
|
152
|
+
exclusive_base_case = {
|
153
|
+
1.to_f .. 4.to_f => nil, # before
|
154
|
+
11.to_f .. 15.to_f => nil, # after
|
155
|
+
1.to_f .. 6.to_f => 5.to_f .. 6.to_f, # overlap_begin
|
156
|
+
9.to_f .. 15.to_f => 9.to_f ... 10.to_f, # overlap_end
|
157
|
+
1.to_f .. 5.to_f => 5.to_f .. 5.to_f, # overlap_begin_edge
|
158
|
+
10.to_f .. 15.to_f => nil, # overlap_end_edge
|
159
|
+
5.to_f .. 10.to_f => 5.to_f ... 10.to_f, # overlap_all
|
160
|
+
6.to_f .. 9.to_f => 6.to_f .. 9.to_f, # overlap_inner
|
161
|
+
|
162
|
+
1.to_f ... 5.to_f => nil, # before (exclusive range)
|
163
|
+
1.to_f ... 7.to_f => 5.to_f ... 7.to_f, # overlap_begin (exclusive range)
|
164
|
+
1.to_f ... 6.to_f => 5.to_f ... 6.to_f, # overlap_begin_edge (exclusive range)
|
165
|
+
5.to_f ... 11.to_f => 5.to_f ... 10.to_f, # overlap_all (exclusive range)
|
166
|
+
6.to_f ... 10.to_f => 6.to_f ... 10.to_f, # overlap_inner (exclusive range)
|
167
|
+
}
|
168
|
+
|
169
|
+
exclusive_base_case.each do |other, expected|
|
170
|
+
do_test( 5.to_f...10.to_f, other, expected )
|
171
|
+
do_test( other, 5.to_f...10.to_f, expected )
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -75,7 +75,8 @@ describe RDoc::Parser, :'fails_on_ruby_1.9.2' => true do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should read any present README as module documentation" do
|
78
|
-
FileTest.stubs(:readable?).returns(true)
|
78
|
+
FileTest.stubs(:readable?).with("module/README").returns(true)
|
79
|
+
FileTest.stubs(:readable?).with("module/README.rdoc").returns(false)
|
79
80
|
File.stubs(:open).returns("readme")
|
80
81
|
@parser.stubs(:parse_elements)
|
81
82
|
|
@@ -84,6 +85,29 @@ describe RDoc::Parser, :'fails_on_ruby_1.9.2' => true do
|
|
84
85
|
@parser.scan_top_level(@topcontainer)
|
85
86
|
end
|
86
87
|
|
88
|
+
it "should read any present README.rdoc as module documentation" do
|
89
|
+
FileTest.stubs(:readable?).with("module/README.rdoc").returns(true)
|
90
|
+
FileTest.stubs(:readable?).with("module/README").returns(false)
|
91
|
+
File.stubs(:open).returns("readme")
|
92
|
+
@parser.stubs(:parse_elements)
|
93
|
+
|
94
|
+
@module.expects(:comment=).with("readme")
|
95
|
+
|
96
|
+
@parser.scan_top_level(@topcontainer)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should prefer README.rdoc over README as module documentation" do
|
100
|
+
FileTest.stubs(:readable?).with("module/README.rdoc").returns(true)
|
101
|
+
FileTest.stubs(:readable?).with("module/README").returns(true)
|
102
|
+
File.stubs(:open).with("module/README", "r").returns("readme")
|
103
|
+
File.stubs(:open).with("module/README.rdoc", "r").returns("readme.rdoc")
|
104
|
+
@parser.stubs(:parse_elements)
|
105
|
+
|
106
|
+
@module.expects(:comment=).with("readme.rdoc")
|
107
|
+
|
108
|
+
@parser.scan_top_level(@topcontainer)
|
109
|
+
end
|
110
|
+
|
87
111
|
it "should tell the container its module name" do
|
88
112
|
@parser.stubs(:parse_elements)
|
89
113
|
|
@@ -33,7 +33,7 @@ describe Puppet::Util::SELinux do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe "filesystem detection"
|
36
|
+
describe "filesystem detection" do
|
37
37
|
before :each do
|
38
38
|
fh = stub 'fh', :close => nil
|
39
39
|
File.stubs(:open).with("/proc/mounts").returns fh
|
@@ -192,7 +192,7 @@ describe Puppet::Util::SELinux do
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
-
describe "set_selinux_context"
|
195
|
+
describe "set_selinux_context" do
|
196
196
|
before :each do
|
197
197
|
fh = stub 'fh', :close => nil
|
198
198
|
File.stubs(:open).with("/proc/mounts").returns fh
|
@@ -248,61 +248,16 @@ describe Puppet::Util::SUIDManager do
|
|
248
248
|
end
|
249
249
|
|
250
250
|
describe "on Microsoft Windows", :if => Puppet.features.microsoft_windows? do
|
251
|
-
|
252
|
-
|
253
|
-
Facter.stubs(:value).with(:kernelmajversion).returns("5.2")
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should be root if user is a member of the Administrators group" do
|
257
|
-
Sys::Admin.stubs(:get_login).returns("Administrator")
|
258
|
-
Sys::Group.stubs(:members).returns(%w[Administrator])
|
259
|
-
|
260
|
-
Win32::Security.expects(:elevated_security?).never
|
261
|
-
Puppet::Util::SUIDManager.should be_root
|
262
|
-
end
|
263
|
-
|
264
|
-
it "should not be root if the process is running as Guest" do
|
265
|
-
Sys::Admin.stubs(:get_login).returns("Guest")
|
266
|
-
Sys::Group.stubs(:members).returns([])
|
251
|
+
it "should be root if user is privileged" do
|
252
|
+
Puppet::Util::Windows::User.stubs(:admin?).returns true
|
267
253
|
|
268
|
-
|
269
|
-
Puppet::Util::SUIDManager.should_not be_root
|
270
|
-
end
|
271
|
-
|
272
|
-
it "should raise an exception if the process fails to open the process token" do
|
273
|
-
Win32::Security.stubs(:elevated_security?).raises(Win32::Security::Error, "Access denied.")
|
274
|
-
Sys::Admin.stubs(:get_login).returns("Administrator")
|
275
|
-
Sys::Group.expects(:members).never
|
276
|
-
|
277
|
-
lambda { Puppet::Util::SUIDManager.should raise_error(Win32::Security::Error, /Access denied./) }
|
278
|
-
end
|
254
|
+
Puppet::Util::SUIDManager.should be_root
|
279
255
|
end
|
280
256
|
|
281
|
-
|
282
|
-
|
283
|
-
Facter.stubs(:value).with(:kernelmajversion).returns("6.0")
|
284
|
-
end
|
285
|
-
|
286
|
-
it "should be root if user is running with elevated privileges" do
|
287
|
-
Win32::Security.stubs(:elevated_security?).returns(true)
|
288
|
-
Sys::Admin.expects(:get_login).never
|
289
|
-
|
290
|
-
Puppet::Util::SUIDManager.should be_root
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should not be root if user is not running with elevated privileges" do
|
294
|
-
Win32::Security.stubs(:elevated_security?).returns(false)
|
295
|
-
Sys::Admin.expects(:get_login).never
|
257
|
+
it "should not be root if user is not privileged" do
|
258
|
+
Puppet::Util::Windows::User.stubs(:admin?).returns false
|
296
259
|
|
297
|
-
|
298
|
-
end
|
299
|
-
|
300
|
-
it "should raise an exception if the process fails to open the process token" do
|
301
|
-
Win32::Security.stubs(:elevated_security?).raises(Win32::Security::Error, "Access denied.")
|
302
|
-
Sys::Admin.expects(:get_login).never
|
303
|
-
|
304
|
-
lambda { Puppet::Util::SUIDManager.should raise_error(Win32::Security::Error, /Access denied./) }
|
305
|
-
end
|
260
|
+
Puppet::Util::SUIDManager.should_not be_root
|
306
261
|
end
|
307
262
|
end
|
308
263
|
end
|
data/spec/unit/util_spec.rb
CHANGED
@@ -177,8 +177,21 @@ describe Puppet::Util do
|
|
177
177
|
|
178
178
|
describe "execution methods" do
|
179
179
|
let(:pid) { 5501 }
|
180
|
+
let(:process_handle) { 0xDEADBEEF }
|
181
|
+
let(:thread_handle) { 0xCAFEBEEF }
|
182
|
+
let(:proc_info_stub) { stub 'processinfo', :process_handle => process_handle, :thread_handle => thread_handle, :process_id => pid}
|
180
183
|
let(:null_file) { Puppet.features.microsoft_windows? ? 'NUL' : '/dev/null' }
|
181
184
|
|
185
|
+
def stub_process_wait(exitstatus)
|
186
|
+
if Puppet.features.microsoft_windows?
|
187
|
+
Puppet::Util::Windows::Process.stubs(:wait_process).with(process_handle).returns(exitstatus)
|
188
|
+
Process.stubs(:CloseHandle).with(process_handle)
|
189
|
+
Process.stubs(:CloseHandle).with(thread_handle)
|
190
|
+
else
|
191
|
+
Process.stubs(:waitpid2).with(pid).returns([pid, stub('child_status', :exitstatus => exitstatus)])
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
182
195
|
describe "#execute_posix" do
|
183
196
|
before :each do
|
184
197
|
# Most of the things this method does are bad to do during specs. :/
|
@@ -251,12 +264,10 @@ describe Puppet::Util do
|
|
251
264
|
end
|
252
265
|
end
|
253
266
|
|
254
|
-
describe "#execute_windows" do
|
255
|
-
let(:proc_info_stub) { stub 'processinfo', :process_id => pid }
|
256
|
-
|
267
|
+
describe "#execute_windows", :if => Puppet.features.microsoft_windows? do
|
257
268
|
before :each do
|
258
269
|
Process.stubs(:create).returns(proc_info_stub)
|
259
|
-
|
270
|
+
stub_process_wait(0)
|
260
271
|
|
261
272
|
@stdin = File.open(null_file, 'r')
|
262
273
|
@stdout = Tempfile.new('stdout')
|
@@ -266,14 +277,15 @@ describe Puppet::Util do
|
|
266
277
|
it "should create a new process for the command" do
|
267
278
|
Process.expects(:create).with(
|
268
279
|
:command_line => "test command",
|
269
|
-
:startup_info => {:stdin => @stdin, :stdout => @stdout, :stderr => @stderr}
|
280
|
+
:startup_info => {:stdin => @stdin, :stdout => @stdout, :stderr => @stderr},
|
281
|
+
:close_handles => false
|
270
282
|
).returns(proc_info_stub)
|
271
283
|
|
272
284
|
Puppet::Util.execute_windows('test command', {}, @stdin, @stdout, @stderr)
|
273
285
|
end
|
274
286
|
|
275
|
-
it "should return the
|
276
|
-
Puppet::Util.execute_windows('test command', {}, @stdin, @stdout, @stderr).should ==
|
287
|
+
it "should return the process info of the child process" do
|
288
|
+
Puppet::Util.execute_windows('test command', {}, @stdin, @stdout, @stderr).should == proc_info_stub
|
277
289
|
end
|
278
290
|
|
279
291
|
it "should quote arguments containing spaces if command is specified as an array" do
|
@@ -287,7 +299,7 @@ describe Puppet::Util do
|
|
287
299
|
|
288
300
|
describe "#execute" do
|
289
301
|
before :each do
|
290
|
-
|
302
|
+
stub_process_wait(0)
|
291
303
|
end
|
292
304
|
|
293
305
|
describe "when an execution stub is specified" do
|
@@ -312,6 +324,7 @@ describe Puppet::Util do
|
|
312
324
|
describe "when setting up input and output files" do
|
313
325
|
include PuppetSpec::Files
|
314
326
|
let(:executor) { Puppet.features.microsoft_windows? ? 'execute_windows' : 'execute_posix' }
|
327
|
+
let(:rval) { Puppet.features.microsoft_windows? ? proc_info_stub : pid }
|
315
328
|
|
316
329
|
before :each do
|
317
330
|
Puppet::Util.stubs(:wait_for_output)
|
@@ -323,7 +336,7 @@ describe Puppet::Util do
|
|
323
336
|
|
324
337
|
Puppet::Util.expects(executor).with do |_,_,stdin,_,_|
|
325
338
|
stdin.path == input
|
326
|
-
end.returns(
|
339
|
+
end.returns(rval)
|
327
340
|
|
328
341
|
Puppet::Util.execute('test command', :stdinfile => input)
|
329
342
|
end
|
@@ -331,7 +344,7 @@ describe Puppet::Util do
|
|
331
344
|
it "should set stdin to the null file if not specified" do
|
332
345
|
Puppet::Util.expects(executor).with do |_,_,stdin,_,_|
|
333
346
|
stdin.path == null_file
|
334
|
-
end.returns(
|
347
|
+
end.returns(rval)
|
335
348
|
|
336
349
|
Puppet::Util.execute('test command')
|
337
350
|
end
|
@@ -340,7 +353,7 @@ describe Puppet::Util do
|
|
340
353
|
it "should set stdout and stderr to the null file" do
|
341
354
|
Puppet::Util.expects(executor).with do |_,_,_,stdout,stderr|
|
342
355
|
stdout.path == null_file and stderr.path == null_file
|
343
|
-
end.returns(
|
356
|
+
end.returns(rval)
|
344
357
|
|
345
358
|
Puppet::Util.execute('test command', :squelch => true)
|
346
359
|
end
|
@@ -353,7 +366,7 @@ describe Puppet::Util do
|
|
353
366
|
|
354
367
|
Puppet::Util.expects(executor).with do |_,_,_,stdout,_|
|
355
368
|
stdout.path == outfile.path
|
356
|
-
end.returns(
|
369
|
+
end.returns(rval)
|
357
370
|
|
358
371
|
Puppet::Util.execute('test command', :squelch => false)
|
359
372
|
end
|
@@ -364,7 +377,7 @@ describe Puppet::Util do
|
|
364
377
|
|
365
378
|
Puppet::Util.expects(executor).with do |_,_,_,stdout,stderr|
|
366
379
|
stdout.path == outfile.path and stderr.path == outfile.path
|
367
|
-
end.returns(
|
380
|
+
end.returns(rval)
|
368
381
|
|
369
382
|
Puppet::Util.execute('test command', :squelch => false, :combine => true)
|
370
383
|
end
|
@@ -375,28 +388,40 @@ describe Puppet::Util do
|
|
375
388
|
|
376
389
|
Puppet::Util.expects(executor).with do |_,_,_,stdout,stderr|
|
377
390
|
stdout.path == outfile.path and stderr.path == null_file
|
378
|
-
end.returns(
|
391
|
+
end.returns(rval)
|
379
392
|
|
380
393
|
Puppet::Util.execute('test command', :squelch => false, :combine => false)
|
381
394
|
end
|
382
395
|
end
|
383
396
|
end
|
397
|
+
|
398
|
+
describe "on Windows", :if => Puppet.features.microsoft_windows? do
|
399
|
+
it "should always close the process and thread handles" do
|
400
|
+
Puppet::Util.stubs(:execute_windows).returns(proc_info_stub)
|
401
|
+
|
402
|
+
Puppet::Util::Windows::Process.expects(:wait_process).with(process_handle).raises('whatever')
|
403
|
+
Process.expects(:CloseHandle).with(thread_handle)
|
404
|
+
Process.expects(:CloseHandle).with(process_handle)
|
405
|
+
|
406
|
+
expect { Puppet::Util.execute('test command') }.should raise_error(RuntimeError)
|
407
|
+
end
|
408
|
+
end
|
384
409
|
end
|
385
410
|
|
386
411
|
describe "after execution" do
|
387
|
-
let(:executor) { Puppet.features.microsoft_windows? ? 'execute_windows' : 'execute_posix' }
|
388
|
-
|
389
412
|
before :each do
|
390
|
-
|
413
|
+
stub_process_wait(0)
|
391
414
|
|
392
|
-
Puppet
|
415
|
+
if Puppet.features.microsoft_windows?
|
416
|
+
Puppet::Util.stubs(:execute_windows).returns(proc_info_stub)
|
417
|
+
else
|
418
|
+
Puppet::Util.stubs(:execute_posix).returns(pid)
|
419
|
+
end
|
393
420
|
end
|
394
421
|
|
395
422
|
it "should wait for the child process to exit" do
|
396
423
|
Puppet::Util.stubs(:wait_for_output)
|
397
424
|
|
398
|
-
Process.expects(:waitpid2).with(pid).returns([pid, process_status(0)])
|
399
|
-
|
400
425
|
Puppet::Util.execute('test command')
|
401
426
|
end
|
402
427
|
|
@@ -441,7 +466,7 @@ describe Puppet::Util do
|
|
441
466
|
end
|
442
467
|
|
443
468
|
it "should raise an error if failonfail is true and the child failed" do
|
444
|
-
|
469
|
+
stub_process_wait(1)
|
445
470
|
|
446
471
|
expect {
|
447
472
|
Puppet::Util.execute('fail command', :failonfail => true)
|
@@ -449,7 +474,7 @@ describe Puppet::Util do
|
|
449
474
|
end
|
450
475
|
|
451
476
|
it "should not raise an error if failonfail is false and the child failed" do
|
452
|
-
|
477
|
+
stub_process_wait(1)
|
453
478
|
|
454
479
|
expect {
|
455
480
|
Puppet::Util.execute('fail command', :failonfail => false)
|
@@ -457,8 +482,6 @@ describe Puppet::Util do
|
|
457
482
|
end
|
458
483
|
|
459
484
|
it "should not raise an error if failonfail is true and the child succeeded" do
|
460
|
-
Process.expects(:waitpid2).with(pid).returns([pid, process_status(0)])
|
461
|
-
|
462
485
|
expect {
|
463
486
|
Puppet::Util.execute('fail command', :failonfail => true)
|
464
487
|
}.not_to raise_error
|
@@ -466,6 +489,41 @@ describe Puppet::Util do
|
|
466
489
|
end
|
467
490
|
end
|
468
491
|
|
492
|
+
describe "#execpipe" do
|
493
|
+
let :instance do
|
494
|
+
instance = Class.new.new
|
495
|
+
instance.send(:extend, Puppet::Util)
|
496
|
+
instance
|
497
|
+
end
|
498
|
+
|
499
|
+
it "should execute a string as a string" do
|
500
|
+
instance.expects(:open).with('| echo hello 2>&1').returns('hello')
|
501
|
+
$CHILD_STATUS.expects(:==).with(0).returns(true)
|
502
|
+
instance.execpipe('echo hello').should == 'hello'
|
503
|
+
end
|
504
|
+
|
505
|
+
it "should execute an array by pasting together with spaces" do
|
506
|
+
instance.expects(:open).with('| echo hello 2>&1').returns('hello')
|
507
|
+
$CHILD_STATUS.expects(:==).with(0).returns(true)
|
508
|
+
instance.execpipe(['echo', 'hello']).should == 'hello'
|
509
|
+
end
|
510
|
+
|
511
|
+
it "should fail if asked to fail, and the child does" do
|
512
|
+
instance.stubs(:open).returns('error message')
|
513
|
+
$CHILD_STATUS.expects(:==).with(0).returns(false)
|
514
|
+
expect { instance.execpipe('echo hello') }.
|
515
|
+
to raise_error Puppet::ExecutionFailure, /error message/
|
516
|
+
end
|
517
|
+
|
518
|
+
it "should not fail if asked not to fail, and the child does" do
|
519
|
+
instance.stubs(:open).returns('error message')
|
520
|
+
$CHILD_STATUS.stubs(:==).with(0).returns(false)
|
521
|
+
expect do
|
522
|
+
instance.execpipe('echo hello', false).should == 'error message'
|
523
|
+
end.not_to raise_error
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
469
527
|
describe "#which" do
|
470
528
|
let(:base) { File.expand_path('/bin') }
|
471
529
|
let(:path) { File.join(base, 'foo') }
|