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
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'puppet/util/anonymous_filelock'
|
2
|
-
|
3
|
-
module Puppet::Agent::Disabler
|
4
|
-
# Let the daemon run again, freely in the filesystem.
|
5
|
-
def enable
|
6
|
-
disable_lockfile.unlock
|
7
|
-
end
|
8
|
-
|
9
|
-
# Stop the daemon from making any catalog runs.
|
10
|
-
def disable(msg='')
|
11
|
-
disable_lockfile.lock(msg)
|
12
|
-
end
|
13
|
-
|
14
|
-
def disable_lockfile
|
15
|
-
@disable_lockfile ||= Puppet::Util::AnonymousFilelock.new(lockfile_path+".disabled")
|
16
|
-
|
17
|
-
@disable_lockfile
|
18
|
-
end
|
19
|
-
|
20
|
-
def disabled?
|
21
|
-
disable_lockfile.locked?
|
22
|
-
end
|
23
|
-
|
24
|
-
def disable_message
|
25
|
-
disable_lockfile.message
|
26
|
-
end
|
27
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
|
2
|
-
class Puppet::Util::AnonymousFilelock
|
3
|
-
attr_reader :lockfile
|
4
|
-
|
5
|
-
def initialize(lockfile)
|
6
|
-
@lockfile = lockfile
|
7
|
-
end
|
8
|
-
|
9
|
-
def anonymous?
|
10
|
-
true
|
11
|
-
end
|
12
|
-
|
13
|
-
def lock(msg = '')
|
14
|
-
return false if locked?
|
15
|
-
|
16
|
-
File.open(@lockfile, 'w') { |fd| fd.print(msg) }
|
17
|
-
true
|
18
|
-
end
|
19
|
-
|
20
|
-
def unlock
|
21
|
-
if locked?
|
22
|
-
File.unlink(@lockfile)
|
23
|
-
true
|
24
|
-
else
|
25
|
-
false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def locked?
|
30
|
-
File.exists? @lockfile
|
31
|
-
end
|
32
|
-
|
33
|
-
def message
|
34
|
-
return File.read(@lockfile) if locked?
|
35
|
-
end
|
36
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rspec
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'puppet/agent'
|
4
|
-
require 'puppet/agent/locker'
|
5
|
-
|
6
|
-
class LockerTester
|
7
|
-
include Puppet::Agent::Disabler
|
8
|
-
end
|
9
|
-
|
10
|
-
describe Puppet::Agent::Disabler do
|
11
|
-
before do
|
12
|
-
@locker = LockerTester.new
|
13
|
-
@locker.stubs(:lockfile_path).returns "/my/lock"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should use an AnonymousFilelock instance as its disable_lockfile" do
|
17
|
-
@locker.disable_lockfile.should be_instance_of(Puppet::Util::AnonymousFilelock)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should use 'lockfile_path' to determine its disable_lockfile path" do
|
21
|
-
@locker.expects(:lockfile_path).returns "/my/lock"
|
22
|
-
lock = Puppet::Util::AnonymousFilelock.new("/my/lock")
|
23
|
-
Puppet::Util::AnonymousFilelock.expects(:new).with("/my/lock.disabled").returns lock
|
24
|
-
|
25
|
-
@locker.disable_lockfile
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should reuse the same lock file each time" do
|
29
|
-
@locker.disable_lockfile.should equal(@locker.disable_lockfile)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should lock the anonymous lock when disabled" do
|
33
|
-
@locker.disable_lockfile.expects(:lock)
|
34
|
-
|
35
|
-
@locker.disable
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should disable with a message" do
|
39
|
-
@locker.disable_lockfile.expects(:lock).with("disabled because")
|
40
|
-
|
41
|
-
@locker.disable("disabled because")
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should unlock the anonymous lock when enabled" do
|
45
|
-
@locker.disable_lockfile.expects(:unlock)
|
46
|
-
|
47
|
-
@locker.enable
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should check the lock if it is disabled" do
|
51
|
-
@locker.disable_lockfile.expects(:locked?)
|
52
|
-
|
53
|
-
@locker.disabled?
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should report the disable message when disabled" do
|
57
|
-
@locker.disable_lockfile.expects(:message).returns("message")
|
58
|
-
@locker.disable_message.should == "message"
|
59
|
-
end
|
60
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'net/http'
|
3
|
-
require 'puppet/module_tool'
|
4
|
-
|
5
|
-
describe Puppet::Module::Tool::Repository do
|
6
|
-
describe 'instances' do
|
7
|
-
before do
|
8
|
-
@repository = described_class.new('http://fake.com')
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#make_http_request' do
|
12
|
-
before do
|
13
|
-
# Do a mock of the Proxy call so we can do proper expects for
|
14
|
-
# Net::HTTP
|
15
|
-
Net::HTTP.expects(:Proxy).returns(Net::HTTP)
|
16
|
-
Net::HTTP.expects(:start)
|
17
|
-
end
|
18
|
-
context "when not given an :authenticate option" do
|
19
|
-
it "should authenticate" do
|
20
|
-
@repository.expects(:authenticate).never
|
21
|
-
@repository.make_http_request(nil)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
context "when given an :authenticate option" do
|
25
|
-
it "should authenticate" do
|
26
|
-
@repository.expects(:authenticate)
|
27
|
-
@repository.make_http_request(nil, :authenticate => true)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#authenticate' do
|
33
|
-
it "should set basic auth on the request" do
|
34
|
-
authenticated_request = stub
|
35
|
-
authenticated_request.expects(:basic_auth)
|
36
|
-
@repository.expects(:prompt).twice
|
37
|
-
@repository.authenticate(authenticated_request)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#retrieve' do
|
42
|
-
before do
|
43
|
-
@uri = URI.parse('http://some.url.com')
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should access the cache" do
|
47
|
-
@repository.cache.expects(:retrieve).with(@uri)
|
48
|
-
@repository.retrieve(@uri)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rspec
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
require 'puppet/util/anonymous_filelock'
|
5
|
-
|
6
|
-
describe Puppet::Util::AnonymousFilelock do
|
7
|
-
require 'puppet_spec/files'
|
8
|
-
include PuppetSpec::Files
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
@lockfile = tmpfile("lock")
|
12
|
-
@lock = Puppet::Util::AnonymousFilelock.new(@lockfile)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should be anonymous" do
|
16
|
-
@lock.should be_anonymous
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#lock" do
|
20
|
-
it "should return false if already locked" do
|
21
|
-
@lock.stubs(:locked?).returns(true)
|
22
|
-
@lock.lock.should be_false
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should return true if it successfully locked" do
|
26
|
-
@lock.lock.should be_true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should create a lock file" do
|
30
|
-
@lock.lock
|
31
|
-
|
32
|
-
File.should be_exists(@lockfile)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should create a lock file containing a message" do
|
36
|
-
@lock.lock("message")
|
37
|
-
|
38
|
-
File.read(@lockfile).should == "message"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#unlock" do
|
43
|
-
it "should return true when unlocking" do
|
44
|
-
@lock.lock
|
45
|
-
@lock.unlock.should be_true
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return false when not locked" do
|
49
|
-
@lock.unlock.should be_false
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should clear the lock file" do
|
53
|
-
File.open(@lockfile, 'w') { |fd| fd.print("locked") }
|
54
|
-
@lock.unlock
|
55
|
-
File.should_not be_exists(@lockfile)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should be locked when locked" do
|
60
|
-
@lock.lock
|
61
|
-
@lock.should be_locked
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should not be locked when not locked" do
|
65
|
-
@lock.should_not be_locked
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should not be locked when unlocked" do
|
69
|
-
@lock.lock
|
70
|
-
@lock.unlock
|
71
|
-
@lock.should_not be_locked
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should return the lock message" do
|
75
|
-
@lock.lock("lock message")
|
76
|
-
@lock.message.should == "lock message"
|
77
|
-
end
|
78
|
-
end
|
@@ -1,208 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rspec
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
require 'puppet/util/pidlock'
|
5
|
-
|
6
|
-
describe Puppet::Util::Pidlock do
|
7
|
-
require 'puppet_spec/files'
|
8
|
-
include PuppetSpec::Files
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
@lockfile = tmpfile("lock")
|
12
|
-
@lock = Puppet::Util::Pidlock.new(@lockfile)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should not be anonymous" do
|
16
|
-
@lock.should_not be_anonymous
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#lock" do
|
20
|
-
it "should not be locked at start" do
|
21
|
-
@lock.should_not be_locked
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should not be mine at start" do
|
25
|
-
@lock.should_not be_mine
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should become locked" do
|
29
|
-
@lock.lock
|
30
|
-
@lock.should be_locked
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should become mine" do
|
34
|
-
@lock.lock
|
35
|
-
@lock.should be_mine
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should be possible to lock multiple times" do
|
39
|
-
@lock.lock
|
40
|
-
lambda { @lock.lock }.should_not raise_error
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return true when locking" do
|
44
|
-
@lock.lock.should be_true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return true if locked by me" do
|
48
|
-
@lock.lock
|
49
|
-
@lock.lock.should be_true
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return false if locked by someone else" do
|
53
|
-
Process.stubs(:kill)
|
54
|
-
File.open(@lockfile, "w") { |fd| fd.print('0') }
|
55
|
-
|
56
|
-
@lock.lock.should be_false
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should create a lock file" do
|
60
|
-
@lock.lock
|
61
|
-
File.should be_exists(@lockfile)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should create a lock file containing our pid" do
|
65
|
-
@lock.lock
|
66
|
-
File.read(@lockfile).to_i.should == Process.pid.to_i
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#unlock" do
|
71
|
-
it "should not be locked anymore" do
|
72
|
-
@lock.lock
|
73
|
-
@lock.unlock
|
74
|
-
@lock.should_not be_locked
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should return false if not locked" do
|
78
|
-
@lock.unlock.should be_false
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should return true if properly unlocked" do
|
82
|
-
@lock.lock
|
83
|
-
@lock.unlock.should be_true
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should get rid of the lock file" do
|
87
|
-
@lock.lock
|
88
|
-
@lock.unlock
|
89
|
-
File.should_not be_exists(@lockfile)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should not warn if the lockfile was deleted by someone else" do
|
93
|
-
@lock.lock
|
94
|
-
File.unlink(@lockfile)
|
95
|
-
|
96
|
-
Puppet.expects(:err).never # meh
|
97
|
-
@lock.unlock
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should warn if the lockfile can't be deleted" do
|
101
|
-
@lock.lock
|
102
|
-
File.expects(:unlink).with(@lockfile).raises(Errno::EIO)
|
103
|
-
Puppet.expects(:err).with do |argument|
|
104
|
-
argument.should =~ /Input\/output error/
|
105
|
-
end
|
106
|
-
@lock.unlock
|
107
|
-
|
108
|
-
# This is necessary because our cleanup code uses File.unlink
|
109
|
-
File.unstub(:unlink)
|
110
|
-
@lock.unlock
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "#locked?" do
|
115
|
-
it "should return true if locked" do
|
116
|
-
@lock.lock
|
117
|
-
@lock.should be_locked
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "with a stale lock" do
|
122
|
-
before(:each) do
|
123
|
-
Process.stubs(:kill).with(0, 6789)
|
124
|
-
Process.stubs(:kill).with(0, 1234).raises(Errno::ESRCH)
|
125
|
-
Process.stubs(:pid).returns(6789)
|
126
|
-
File.open(@lockfile, 'w') { |fd| fd.write("1234") }
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should not be locked" do
|
130
|
-
@lock.should_not be_locked
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "#lock" do
|
134
|
-
it "should clear stale locks" do
|
135
|
-
@lock.locked?
|
136
|
-
File.should_not be_exists(@lockfile)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should replace with new locks" do
|
140
|
-
@lock.lock
|
141
|
-
File.should be_exists(@lockfile)
|
142
|
-
@lock.lock_pid.should == 6789
|
143
|
-
@lock.should be_mine
|
144
|
-
@lock.should be_locked
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "#unlock" do
|
149
|
-
it "should not be allowed" do
|
150
|
-
@lock.unlock.should be_false
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should not remove the lock file" do
|
154
|
-
@lock.unlock
|
155
|
-
File.should be_exists(@lockfile)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "with another process lock" do
|
161
|
-
before(:each) do
|
162
|
-
Process.stubs(:kill).with(0, 6789)
|
163
|
-
Process.stubs(:kill).with(0, 1234)
|
164
|
-
Process.stubs(:pid).returns(6789)
|
165
|
-
File.open(@lockfile, 'w') { |fd| fd.write("1234") }
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should be locked" do
|
169
|
-
@lock.should be_locked
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should not be mine" do
|
173
|
-
@lock.should_not be_mine
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "#lock" do
|
177
|
-
it "should not be possible" do
|
178
|
-
@lock.lock.should be_false
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should not overwrite the lock" do
|
182
|
-
@lock.lock
|
183
|
-
@lock.should_not be_mine
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
describe "#unlock" do
|
188
|
-
it "should not be possible" do
|
189
|
-
@lock.unlock.should be_false
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should not remove the lock file" do
|
193
|
-
@lock.unlock
|
194
|
-
File.should be_exists(@lockfile)
|
195
|
-
end
|
196
|
-
|
197
|
-
it "should still not be our lock" do
|
198
|
-
@lock.unlock
|
199
|
-
@lock.should_not be_mine
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should not warn" do
|
203
|
-
Puppet.expects(:err).never
|
204
|
-
@lock.unlock
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|