puppet 2.7.9 → 2.7.11
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 +413 -0
- data/README_DEVELOPER.md +28 -0
- data/conf/redhat/puppet.spec +10 -1
- data/conf/solaris/pkginfo +1 -1
- data/conf/suse/puppet.spec +7 -4
- data/ext/envpuppet.bat +13 -0
- data/ext/rack/files/apache2.conf +4 -0
- data/install.rb +4 -8
- data/lib/puppet.rb +1 -1
- data/lib/puppet/agent.rb +7 -0
- data/lib/puppet/agent/disabler.rb +27 -0
- data/lib/puppet/agent/locker.rb +0 -10
- data/lib/puppet/application.rb +3 -0
- data/lib/puppet/application/agent.rb +13 -3
- data/lib/puppet/application/apply.rb +6 -6
- data/lib/puppet/application/cert.rb +5 -5
- data/lib/puppet/application/instrumentation_data.rb +4 -0
- data/lib/puppet/application/instrumentation_listener.rb +4 -0
- data/lib/puppet/application/instrumentation_probe.rb +4 -0
- data/lib/puppet/configurer.rb +3 -1
- data/lib/puppet/configurer/downloader.rb +4 -2
- data/lib/puppet/configurer/fact_handler.rb +0 -21
- data/lib/puppet/daemon.rb +3 -4
- data/lib/puppet/defaults.rb +2 -2
- data/lib/puppet/face/instrumentation_data.rb +28 -0
- data/lib/puppet/face/instrumentation_listener.rb +96 -0
- data/lib/puppet/face/instrumentation_probe.rb +77 -0
- data/lib/puppet/face/module/list.rb +64 -0
- data/lib/puppet/face/module/uninstall.rb +50 -0
- data/lib/puppet/face/node/clean.rb +1 -4
- data/lib/puppet/feature/base.rb +1 -0
- data/lib/puppet/file_serving/content.rb +1 -1
- data/lib/puppet/indirector/facts/facter.rb +20 -7
- data/lib/puppet/indirector/facts/inventory_active_record.rb +14 -11
- data/lib/puppet/indirector/indirection.rb +7 -0
- data/lib/puppet/indirector/instrumentation_data.rb +3 -0
- data/lib/puppet/indirector/instrumentation_data/local.rb +19 -0
- data/lib/puppet/indirector/instrumentation_data/rest.rb +5 -0
- data/lib/puppet/indirector/instrumentation_listener.rb +3 -0
- data/lib/puppet/indirector/instrumentation_listener/local.rb +23 -0
- data/lib/puppet/indirector/instrumentation_listener/rest.rb +5 -0
- data/lib/puppet/indirector/instrumentation_probe.rb +3 -0
- data/lib/puppet/indirector/instrumentation_probe/local.rb +24 -0
- data/lib/puppet/indirector/instrumentation_probe/rest.rb +5 -0
- data/lib/puppet/indirector/rest.rb +1 -1
- data/lib/puppet/module.rb +13 -17
- data/lib/puppet/module_tool/applications.rb +1 -0
- data/lib/puppet/module_tool/applications/uninstaller.rb +33 -0
- data/lib/puppet/module_tool/contents_description.rb +1 -1
- data/lib/puppet/network/server.rb +2 -3
- data/lib/puppet/node/environment.rb +16 -3
- data/lib/puppet/parser/ast/leaf.rb +1 -1
- data/lib/puppet/parser/functions/create_resources.rb +1 -1
- data/lib/puppet/parser/type_loader.rb +1 -1
- data/lib/puppet/property.rb +46 -14
- data/lib/puppet/provider.rb +13 -4
- data/lib/puppet/provider/augeas/augeas.rb +6 -4
- data/lib/puppet/provider/group/pw.rb +24 -10
- data/lib/puppet/provider/nameservice/directoryservice.rb +146 -37
- data/lib/puppet/provider/package/pip.rb +1 -1
- data/lib/puppet/provider/package/yum.rb +1 -2
- data/lib/puppet/provider/service/debian.rb +14 -0
- data/lib/puppet/provider/service/launchd.rb +1 -1
- data/lib/puppet/provider/service/smf.rb +2 -2
- data/lib/puppet/provider/user/pw.rb +56 -2
- data/lib/puppet/provider/user/user_role_add.rb +32 -22
- data/lib/puppet/provider/user/windows_adsi.rb +1 -0
- data/lib/puppet/rails/benchmark.rb +1 -1
- data/lib/puppet/reports/store.rb +8 -1
- data/lib/puppet/resource/catalog.rb +5 -1
- data/lib/puppet/simple_graph.rb +11 -14
- data/lib/puppet/transaction.rb +10 -4
- data/lib/puppet/transaction/report.rb +9 -3
- data/lib/puppet/type.rb +19 -7
- data/lib/puppet/type/exec.rb +1 -1
- data/lib/puppet/type/file.rb +4 -1
- data/lib/puppet/type/file/ensure.rb +5 -1
- data/lib/puppet/type/file/mode.rb +45 -10
- data/lib/puppet/type/file/source.rb +4 -0
- data/lib/puppet/type/host.rb +17 -3
- data/lib/puppet/type/k5login.rb +3 -2
- data/lib/puppet/type/schedule.rb +3 -2
- data/lib/puppet/util.rb +83 -27
- data/lib/puppet/util/anonymous_filelock.rb +36 -0
- data/lib/puppet/util/docs.rb +18 -2
- data/lib/puppet/util/instrumentation.rb +173 -0
- data/lib/puppet/util/instrumentation/data.rb +34 -0
- data/lib/puppet/util/instrumentation/indirection_probe.rb +29 -0
- data/lib/puppet/util/instrumentation/instrumentable.rb +143 -0
- data/lib/puppet/util/instrumentation/listener.rb +60 -0
- data/lib/puppet/util/instrumentation/listeners/log.rb +29 -0
- data/lib/puppet/util/instrumentation/listeners/performance.rb +30 -0
- data/lib/puppet/util/monkey_patches.rb +8 -0
- data/lib/puppet/util/pidlock.rb +21 -25
- data/lib/puppet/util/rdoc/parser.rb +2 -2
- data/lib/puppet/util/reference.rb +8 -23
- data/lib/puppet/util/retryaction.rb +48 -0
- data/lib/puppet/util/suidmanager.rb +70 -39
- data/lib/puppet/util/symbolic_file_mode.rb +140 -0
- data/spec/integration/configurer_spec.rb +5 -0
- data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
- data/spec/integration/indirector/file_content/file_server_spec.rb +7 -7
- data/spec/integration/provider/package_spec.rb +7 -0
- data/spec/unit/agent/disabler_spec.rb +60 -0
- data/spec/unit/agent/locker_spec.rb +0 -12
- data/spec/unit/agent_spec.rb +8 -0
- data/spec/unit/application/agent_spec.rb +38 -1
- data/spec/unit/application/apply_spec.rb +34 -40
- data/spec/unit/application/cert_spec.rb +1 -1
- data/spec/unit/application_spec.rb +6 -0
- data/spec/unit/configurer/downloader_spec.rb +29 -10
- data/spec/unit/configurer/fact_handler_spec.rb +5 -29
- data/spec/unit/configurer_spec.rb +8 -8
- data/spec/unit/daemon_spec.rb +12 -26
- data/spec/unit/face/instrumentation_data.rb +7 -0
- data/spec/unit/face/instrumentation_listener.rb +38 -0
- data/spec/unit/face/instrumentation_probe.rb +21 -0
- data/spec/unit/face/node_spec.rb +111 -111
- data/spec/unit/file_serving/content_spec.rb +2 -2
- data/spec/unit/indirector/facts/facter_spec.rb +25 -3
- data/spec/unit/indirector/facts/inventory_active_record_spec.rb +14 -4
- data/spec/unit/indirector/instrumentation_data/local_spec.rb +52 -0
- data/spec/unit/indirector/instrumentation_data/rest_spec.rb +11 -0
- data/spec/unit/indirector/instrumentation_listener/local_spec.rb +65 -0
- data/spec/unit/indirector/instrumentation_listener/rest_spec.rb +11 -0
- data/spec/unit/indirector/instrumentation_probe/local_spec.rb +65 -0
- data/spec/unit/indirector/instrumentation_probe/rest_spec.rb +11 -0
- data/spec/unit/module_spec.rb +39 -125
- data/spec/unit/module_tool/uninstaller_spec.rb +44 -0
- data/spec/unit/network/server_spec.rb +2 -20
- data/spec/unit/node/environment_spec.rb +76 -58
- data/spec/unit/parser/ast/asthash_spec.rb +1 -2
- data/spec/unit/parser/ast/leaf_spec.rb +16 -0
- data/spec/unit/property/keyvalue_spec.rb +5 -2
- data/spec/unit/property_spec.rb +260 -159
- data/spec/unit/provider/augeas/augeas_spec.rb +2 -2
- data/spec/unit/provider/group/pw_spec.rb +81 -0
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +102 -0
- data/spec/unit/provider/package/pip_spec.rb +7 -0
- data/spec/unit/provider/package/yum_spec.rb +45 -1
- data/spec/unit/provider/service/debian_spec.rb +15 -0
- data/spec/unit/provider/service/launchd_spec.rb +48 -43
- data/spec/unit/provider/service/smf_spec.rb +3 -3
- data/spec/unit/provider/user/pw_spec.rb +183 -0
- data/spec/unit/provider/user/user_role_add_spec.rb +46 -39
- data/spec/unit/provider/user/windows_adsi_spec.rb +1 -0
- data/spec/unit/provider_spec.rb +32 -0
- data/spec/unit/reports/store_spec.rb +19 -1
- data/spec/unit/simple_graph_spec.rb +34 -19
- data/spec/unit/ssl/certificate_factory_spec.rb +3 -3
- data/spec/unit/transaction/report_spec.rb +29 -1
- data/spec/unit/transaction_spec.rb +32 -46
- data/spec/unit/type/file/mode_spec.rb +1 -1
- data/spec/unit/type/file/source_spec.rb +28 -3
- data/spec/unit/type/file_spec.rb +17 -16
- data/spec/unit/type/host_spec.rb +527 -0
- data/spec/unit/type/k5login_spec.rb +115 -0
- data/spec/unit/type/schedule_spec.rb +6 -6
- data/spec/unit/type_spec.rb +51 -0
- data/spec/unit/util/anonymous_filelock_spec.rb +78 -0
- data/spec/unit/util/execution_stub_spec.rb +2 -1
- data/spec/unit/util/instrumentation/data_spec.rb +44 -0
- data/spec/unit/util/instrumentation/indirection_probe_spec.rb +19 -0
- data/spec/unit/util/instrumentation/instrumentable_spec.rb +186 -0
- data/spec/unit/util/instrumentation/listener_spec.rb +100 -0
- data/spec/unit/util/instrumentation/listeners/log_spec.rb +34 -0
- data/spec/unit/util/instrumentation/listeners/performance_spec.rb +36 -0
- data/spec/unit/util/instrumentation_spec.rb +181 -0
- data/spec/unit/util/pidlock_spec.rb +208 -0
- data/spec/unit/util/rdoc/parser_spec.rb +1 -1
- data/spec/unit/util/reference_spec.rb +16 -6
- data/spec/unit/util/retryaction_spec.rb +62 -0
- data/spec/unit/util/suidmanager_spec.rb +101 -83
- data/spec/unit/util/symbolic_file_mode_spec.rb +182 -0
- data/spec/unit/util_spec.rb +126 -0
- data/tasks/rake/apple.rake +176 -0
- data/tasks/rake/templates/prototype.plist.erb +38 -0
- metadata +61 -13
- data/lib/puppet/application/module.rb +0 -3
- data/lib/puppet/face/module.rb +0 -12
- data/spec/unit/face/module/build_spec.rb +0 -30
- data/spec/unit/face/module/changes_spec.rb +0 -30
- data/spec/unit/face/module/clean_spec.rb +0 -30
- data/spec/unit/face/module/generate_spec.rb +0 -30
- data/spec/unit/face/module/install_spec.rb +0 -75
- data/spec/unit/face/module/search_spec.rb +0 -40
- data/test/util/pidlock.rb +0 -126
data/lib/puppet/face/module.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'puppet/face'
|
2
|
-
require 'puppet/module_tool'
|
3
|
-
|
4
|
-
Puppet::Face.define(:module, '1.0.0') do
|
5
|
-
copyright "Puppet Labs", 2011
|
6
|
-
license "Apache 2 license; see COPYING"
|
7
|
-
|
8
|
-
summary "Creates, installs and searches for modules on the Puppet Forge."
|
9
|
-
description <<-EOT
|
10
|
-
Creates, installs and searches for modules on the Puppet Forge.
|
11
|
-
EOT
|
12
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet/face'
|
3
|
-
|
4
|
-
describe "puppet module build" do
|
5
|
-
subject { Puppet::Face[:module, :current] }
|
6
|
-
|
7
|
-
describe "option validation" do
|
8
|
-
context "without any options" do
|
9
|
-
it "should require a path" do
|
10
|
-
pattern = /wrong number of arguments/
|
11
|
-
expect { subject.build }.to raise_error ArgumentError, pattern
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "inline documentation" do
|
17
|
-
subject { Puppet::Face[:module, :current].get_action :build }
|
18
|
-
|
19
|
-
its(:summary) { should =~ /build.*module/im }
|
20
|
-
its(:description) { should =~ /build.*module/im }
|
21
|
-
its(:returns) { should =~ /pathname/i }
|
22
|
-
its(:examples) { should_not be_empty }
|
23
|
-
|
24
|
-
%w{ license copyright summary description returns examples }.each do |doc|
|
25
|
-
context "of the" do
|
26
|
-
its(doc.to_sym) { should_not =~ /(FIXME|REVISIT|TODO)/ }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet/face'
|
3
|
-
|
4
|
-
describe "puppet module changes" do
|
5
|
-
subject { Puppet::Face[:module, :current] }
|
6
|
-
|
7
|
-
describe "option validation" do
|
8
|
-
context "without any options" do
|
9
|
-
it "should require a path" do
|
10
|
-
pattern = /wrong number of arguments/
|
11
|
-
expect { subject.changes }.to raise_error ArgumentError, pattern
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "inline documentation" do
|
17
|
-
subject { Puppet::Face[:module, :current].get_action :changes }
|
18
|
-
|
19
|
-
its(:summary) { should =~ /modified.*module/im }
|
20
|
-
its(:description) { should =~ /modified.*module/im }
|
21
|
-
its(:returns) { should =~ /array/i }
|
22
|
-
its(:examples) { should_not be_empty }
|
23
|
-
|
24
|
-
%w{ license copyright summary description returns examples }.each do |doc|
|
25
|
-
context "of the" do
|
26
|
-
its(doc.to_sym) { should_not =~ /(FIXME|REVISIT|TODO)/ }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet/face'
|
3
|
-
|
4
|
-
describe "puppet module clean" do
|
5
|
-
subject { Puppet::Face[:module, :current] }
|
6
|
-
|
7
|
-
describe "option validation" do
|
8
|
-
context "without any options" do
|
9
|
-
it "should not require any arguments" do
|
10
|
-
Puppet::Module::Tool::Applications::Cleaner.expects(:run).once
|
11
|
-
subject.clean
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "inline documentation" do
|
17
|
-
subject { Puppet::Face[:module, :current].get_action :clean }
|
18
|
-
|
19
|
-
its(:summary) { should =~ /clean.*module/im }
|
20
|
-
its(:description) { should =~ /clean.*module/im }
|
21
|
-
its(:returns) { should =~ /hash/i }
|
22
|
-
its(:examples) { should_not be_empty }
|
23
|
-
|
24
|
-
%w{ license copyright summary description returns examples }.each do |doc|
|
25
|
-
context "of the" do
|
26
|
-
its(doc.to_sym) { should_not =~ /(FIXME|REVISIT|TODO)/ }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet/face'
|
3
|
-
|
4
|
-
describe "puppet module generate" do
|
5
|
-
subject { Puppet::Face[:module, :current] }
|
6
|
-
|
7
|
-
describe "option validation" do
|
8
|
-
context "without any options" do
|
9
|
-
it "should require name" do
|
10
|
-
pattern = /wrong number of arguments/
|
11
|
-
expect { subject.generate }.to raise_error ArgumentError, pattern
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "inline documentation" do
|
17
|
-
subject { Puppet::Face[:module, :current].get_action :generate }
|
18
|
-
|
19
|
-
its(:summary) { should =~ /generate.*module/im }
|
20
|
-
its(:description) { should =~ /generate.*module/im }
|
21
|
-
its(:returns) { should =~ /array/i }
|
22
|
-
its(:examples) { should_not be_empty }
|
23
|
-
|
24
|
-
%w{ license copyright summary description returns examples }.each do |doc|
|
25
|
-
context "of the" do
|
26
|
-
its(doc.to_sym) { should_not =~ /(FIXME|REVISIT|TODO)/ }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet/face'
|
3
|
-
require 'puppet/module_tool'
|
4
|
-
|
5
|
-
describe "puppet module install" do
|
6
|
-
subject { Puppet::Face[:module, :current] }
|
7
|
-
|
8
|
-
let(:options) do
|
9
|
-
{}
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "option validation" do
|
13
|
-
let(:expected_options) do
|
14
|
-
{
|
15
|
-
:install_dir => File.expand_path("/dev/null/modules"),
|
16
|
-
:module_repository => "http://forge.puppetlabs.com",
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
context "without any options" do
|
21
|
-
it "should require a name" do
|
22
|
-
pattern = /wrong number of arguments/
|
23
|
-
expect { subject.install }.to raise_error ArgumentError, pattern
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should not require any options" do
|
27
|
-
Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
|
28
|
-
subject.install("puppetlabs-apache")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should accept the --force option" do
|
33
|
-
options[:force] = true
|
34
|
-
expected_options.merge!(options)
|
35
|
-
Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
|
36
|
-
subject.install("puppetlabs-apache", options)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should accept the --install-dir option" do
|
40
|
-
options[:install_dir] = "/foo/puppet/modules"
|
41
|
-
expected_options.merge!(options)
|
42
|
-
Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
|
43
|
-
subject.install("puppetlabs-apache", options)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should accept the --module-repository option" do
|
47
|
-
options[:module_repository] = "http://forge.example.com"
|
48
|
-
expected_options.merge!(options)
|
49
|
-
Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
|
50
|
-
subject.install("puppetlabs-apache", options)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should accept the --version option" do
|
54
|
-
options[:version] = "0.0.1"
|
55
|
-
expected_options.merge!(options)
|
56
|
-
Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once
|
57
|
-
subject.install("puppetlabs-apache", options)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "inline documentation" do
|
62
|
-
subject { Puppet::Face[:module, :current].get_action :install }
|
63
|
-
|
64
|
-
its(:summary) { should =~ /install.*module/im }
|
65
|
-
its(:description) { should =~ /install.*module/im }
|
66
|
-
its(:returns) { should =~ /pathname/i }
|
67
|
-
its(:examples) { should_not be_empty }
|
68
|
-
|
69
|
-
%w{ license copyright summary description returns examples }.each do |doc|
|
70
|
-
context "of the" do
|
71
|
-
its(doc.to_sym) { should_not =~ /(FIXME|REVISIT|TODO)/ }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet/face'
|
3
|
-
|
4
|
-
describe "puppet module search" do
|
5
|
-
subject { Puppet::Face[:module, :current] }
|
6
|
-
|
7
|
-
let(:options) do
|
8
|
-
{}
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "option validation" do
|
12
|
-
context "without any options" do
|
13
|
-
it "should require a search term" do
|
14
|
-
pattern = /wrong number of arguments/
|
15
|
-
expect { subject.search }.to raise_error ArgumentError, pattern
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should accept the --module-repository option" do
|
20
|
-
options[:module_repository] = "http://forge.example.com"
|
21
|
-
Puppet::Module::Tool::Applications::Searcher.expects(:run).with("puppetlabs-apache", options).once
|
22
|
-
subject.search("puppetlabs-apache", options)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "inline documentation" do
|
27
|
-
subject { Puppet::Face[:module, :current].get_action :search }
|
28
|
-
|
29
|
-
its(:summary) { should =~ /search.*module/im }
|
30
|
-
its(:description) { should =~ /search.*module/im }
|
31
|
-
its(:returns) { should =~ /array/i }
|
32
|
-
its(:examples) { should_not be_empty }
|
33
|
-
|
34
|
-
%w{ license copyright summary description returns examples }.each do |doc|
|
35
|
-
context "of the" do
|
36
|
-
its(doc.to_sym) { should_not =~ /(FIXME|REVISIT|TODO)/ }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/test/util/pidlock.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest')
|
2
|
-
|
3
|
-
require 'puppet/util/pidlock'
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
# This is *fucked* *up*
|
7
|
-
Puppet.debug = false
|
8
|
-
|
9
|
-
class TestPuppetUtilPidlock < Test::Unit::TestCase
|
10
|
-
include PuppetTest
|
11
|
-
|
12
|
-
def setup
|
13
|
-
super
|
14
|
-
@workdir = tstdir
|
15
|
-
end
|
16
|
-
|
17
|
-
def teardown
|
18
|
-
super
|
19
|
-
FileUtils.rm_rf(@workdir)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_00_basic_create
|
23
|
-
l = nil
|
24
|
-
assert_nothing_raised { l = Puppet::Util::Pidlock.new(@workdir + '/nothingmuch') }
|
25
|
-
|
26
|
-
assert_equal Puppet::Util::Pidlock, l.class
|
27
|
-
|
28
|
-
assert_equal @workdir + '/nothingmuch', l.lockfile
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_10_uncontended_lock
|
32
|
-
l = Puppet::Util::Pidlock.new(@workdir + '/test_lock')
|
33
|
-
|
34
|
-
assert !l.locked?
|
35
|
-
assert !l.mine?
|
36
|
-
assert l.lock
|
37
|
-
assert l.locked?
|
38
|
-
assert l.mine?
|
39
|
-
assert !l.anonymous?
|
40
|
-
# It's OK to call lock multiple times
|
41
|
-
assert l.lock
|
42
|
-
assert l.unlock
|
43
|
-
assert !l.locked?
|
44
|
-
assert !l.mine?
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_20_someone_elses_lock
|
48
|
-
childpid = nil
|
49
|
-
l = Puppet::Util::Pidlock.new(@workdir + '/someone_elses_lock')
|
50
|
-
|
51
|
-
# First, we need a PID that's guaranteed to be (a) used, (b) someone
|
52
|
-
# else's, and (c) around for the life of this test.
|
53
|
-
childpid = fork { loop do; sleep 10; end }
|
54
|
-
|
55
|
-
File.open(l.lockfile, 'w') { |fd| fd.write(childpid) }
|
56
|
-
|
57
|
-
assert l.locked?
|
58
|
-
assert !l.mine?
|
59
|
-
assert !l.lock
|
60
|
-
assert l.locked?
|
61
|
-
assert !l.mine?
|
62
|
-
assert !l.unlock
|
63
|
-
assert l.locked?
|
64
|
-
assert !l.mine?
|
65
|
-
ensure
|
66
|
-
Process.kill("KILL", childpid) unless childpid.nil?
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_30_stale_lock
|
70
|
-
# This is a bit hard to guarantee, but we need a PID that is definitely
|
71
|
-
# unused, and will stay so for the the life of this test. Our best
|
72
|
-
# bet is to create a process, get it's PID, let it die, and *then*
|
73
|
-
# lock on it.
|
74
|
-
childpid = fork { exit }
|
75
|
-
|
76
|
-
# Now we can't continue until we're sure that the PID is dead
|
77
|
-
Process.wait(childpid)
|
78
|
-
|
79
|
-
l = Puppet::Util::Pidlock.new(@workdir + '/stale_lock')
|
80
|
-
|
81
|
-
# locked? should clear the lockfile
|
82
|
-
File.open(l.lockfile, 'w') { |fd| fd.write(childpid) }
|
83
|
-
assert File.exists?(l.lockfile)
|
84
|
-
assert !l.locked?
|
85
|
-
assert !File.exists?(l.lockfile)
|
86
|
-
|
87
|
-
# lock should replace the lockfile with our own
|
88
|
-
File.open(l.lockfile, 'w') { |fd| fd.write(childpid) }
|
89
|
-
assert File.exists?(l.lockfile)
|
90
|
-
assert l.lock
|
91
|
-
assert l.locked?
|
92
|
-
assert l.mine?
|
93
|
-
|
94
|
-
# unlock should fail, and should *not* molest the existing lockfile,
|
95
|
-
# despite it being stale
|
96
|
-
File.open(l.lockfile, 'w') { |fd| fd.write(childpid) }
|
97
|
-
assert File.exists?(l.lockfile)
|
98
|
-
assert !l.unlock
|
99
|
-
assert File.exists?(l.lockfile)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_40_not_locked_at_all
|
103
|
-
l = Puppet::Util::Pidlock.new(@workdir + '/not_locked')
|
104
|
-
|
105
|
-
assert !l.locked?
|
106
|
-
# We can't unlock if we don't hold the lock
|
107
|
-
assert !l.unlock
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_50_anonymous_lock
|
111
|
-
l = Puppet::Util::Pidlock.new(@workdir + '/anonymous_lock')
|
112
|
-
|
113
|
-
assert !l.locked?
|
114
|
-
assert l.lock(:anonymous => true)
|
115
|
-
assert l.locked?
|
116
|
-
assert l.anonymous?
|
117
|
-
assert !l.mine?
|
118
|
-
assert "", File.read(l.lockfile)
|
119
|
-
assert !l.unlock
|
120
|
-
assert l.locked?
|
121
|
-
assert l.anonymous?
|
122
|
-
assert l.unlock(:anonymous => true)
|
123
|
-
assert !File.exists?(l.lockfile)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|