puppet 2.6.4 → 2.6.5
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 +147 -0
- data/LICENSE +2 -2
- data/Rakefile +3 -4
- data/lib/puppet.rb +1 -1
- data/lib/puppet/application.rb +22 -5
- data/lib/puppet/application/apply.rb +2 -18
- data/lib/puppet/application/doc.rb +1 -4
- data/lib/puppet/application/inspect.rb +178 -0
- data/lib/puppet/configurer.rb +9 -11
- data/lib/puppet/configurer/plugin_handler.rb +0 -2
- data/lib/puppet/defaults.rb +12 -3
- data/lib/puppet/external/pson/pure/generator.rb +1 -22
- data/lib/puppet/file_bucket/dipper.rb +9 -3
- data/lib/puppet/file_bucket/file.rb +14 -94
- data/lib/puppet/indirector.rb +4 -0
- data/lib/puppet/indirector/catalog/active_record.rb +1 -1
- data/lib/puppet/indirector/file_bucket_file/file.rb +64 -75
- data/lib/puppet/indirector/indirection.rb +18 -8
- data/lib/puppet/indirector/resource/ral.rb +7 -2
- data/lib/puppet/indirector/rest.rb +19 -2
- data/lib/puppet/network/http/api/v1.rb +3 -0
- data/lib/puppet/network/http/handler.rb +16 -1
- data/lib/puppet/network/http/rack/rest.rb +1 -3
- data/lib/puppet/network/rest_authconfig.rb +4 -12
- data/lib/puppet/network/rights.rb +28 -14
- data/lib/puppet/parser/ast.rb +4 -0
- data/lib/puppet/parser/compiler.rb +18 -3
- data/lib/puppet/parser/functions/defined.rb +28 -6
- data/lib/puppet/parser/functions/fqdn_rand.rb +6 -3
- data/lib/puppet/parser/templatewrapper.rb +1 -0
- data/lib/puppet/property.rb +16 -1
- data/lib/puppet/property/keyvalue.rb +0 -2
- data/lib/puppet/property/list.rb +0 -2
- data/lib/puppet/provider/file/posix.rb +1 -3
- data/lib/puppet/provider/file/win32.rb +1 -3
- data/lib/puppet/provider/maillist/mailman.rb +3 -5
- data/lib/puppet/provider/mount.rb +2 -0
- data/lib/puppet/provider/nameservice/directoryservice.rb +2 -2
- data/lib/puppet/provider/package/freebsd.rb +2 -2
- data/lib/puppet/provider/zone/solaris.rb +1 -1
- data/lib/puppet/reference/configuration.rb +2 -2
- data/lib/puppet/reference/function.rb +4 -0
- data/lib/puppet/relationship.rb +4 -0
- data/lib/puppet/reports/store.rb +1 -19
- data/lib/puppet/resource.rb +11 -2
- data/lib/puppet/resource/status.rb +24 -3
- data/lib/puppet/resource/type.rb +24 -16
- data/lib/puppet/resource/type_collection.rb +4 -1
- data/lib/puppet/simple_graph.rb +4 -0
- data/lib/puppet/transaction.rb +1 -28
- data/lib/puppet/transaction/event.rb +9 -4
- data/lib/puppet/transaction/report.rb +42 -22
- data/lib/puppet/transaction/resource_harness.rb +99 -71
- data/lib/puppet/type.rb +22 -9
- data/lib/puppet/type/cron.rb +1 -5
- data/lib/puppet/type/exec.rb +4 -34
- data/lib/puppet/type/file.rb +19 -26
- data/lib/puppet/type/file/checksum.rb +1 -1
- data/lib/puppet/type/file/content.rb +2 -1
- data/lib/puppet/type/file/ctime.rb +18 -0
- data/lib/puppet/type/file/ensure.rb +1 -1
- data/lib/puppet/type/file/mode.rb +10 -44
- data/lib/puppet/type/file/mtime.rb +17 -0
- data/lib/puppet/type/file/owner.rb +1 -1
- data/lib/puppet/type/file/source.rb +0 -1
- data/lib/puppet/type/file/target.rb +1 -1
- data/lib/puppet/type/file/type.rb +5 -12
- data/lib/puppet/type/host.rb +1 -1
- data/lib/puppet/type/mount.rb +2 -2
- data/lib/puppet/type/package.rb +0 -2
- data/lib/puppet/type/service.rb +11 -5
- data/lib/puppet/type/user.rb +7 -9
- data/lib/puppet/type/yumrepo.rb +2 -2
- data/lib/puppet/type/zpool.rb +0 -4
- data/lib/puppet/util/checksums.rb +24 -1
- data/lib/puppet/util/command_line.rb +6 -2
- data/lib/puppet/util/command_line/puppet +5 -1
- data/lib/puppet/util/command_line/puppetca +2 -2
- data/lib/puppet/util/command_line/puppetd +11 -9
- data/lib/puppet/util/command_line/puppetdoc +2 -2
- data/lib/puppet/util/command_line/puppetmasterd +5 -0
- data/lib/puppet/util/log.rb +15 -8
- data/lib/puppet/util/log/destinations.rb +2 -0
- data/lib/puppet/util/log_paths.rb +1 -1
- data/lib/puppet/util/logging.rb +1 -1
- data/lib/puppet/util/metric.rb +1 -0
- data/lib/puppet/util/reference.rb +1 -10
- data/lib/puppet/util/settings.rb +1 -1
- data/lib/puppet/util/zaml.rb +30 -31
- data/spec/fixtures/unit/provider/mount/mount-output.aix.txt +7 -0
- data/spec/integration/application/apply_spec.rb +1 -2
- data/spec/integration/defaults_spec.rb +1 -0
- data/spec/integration/indirector/catalog/queue_spec.rb +1 -4
- data/spec/integration/indirector/report/rest_spec.rb +13 -17
- data/spec/integration/network/formats_spec.rb +2 -5
- data/spec/integration/network/server/mongrel_spec.rb +1 -2
- data/spec/integration/provider/mailalias/aliases_spec.rb +0 -1
- data/spec/integration/provider/package_spec.rb +1 -3
- data/spec/integration/provider/service/init_spec.rb +3 -9
- data/spec/integration/reference/providers_spec.rb +2 -2
- data/spec/integration/resource/catalog_spec.rb +1 -2
- data/spec/integration/transaction/report_spec.rb +1 -1
- data/spec/monkey_patches/alias_should_to_must.rb +2 -0
- data/spec/shared_behaviours/file_server_terminus.rb +1 -1
- data/spec/shared_behaviours/file_serving.rb +1 -1
- data/spec/shared_behaviours/memory_terminus.rb +1 -1
- data/spec/spec_helper.rb +8 -6
- data/spec/unit/application/agent_spec.rb +1 -0
- data/spec/unit/application/apply_spec.rb +7 -7
- data/spec/unit/application/doc_spec.rb +2 -2
- data/spec/unit/application/filebucket_spec.rb +1 -0
- data/spec/unit/application/inspect_spec.rb +278 -0
- data/spec/unit/application/kick_spec.rb +1 -3
- data/spec/unit/application/master_spec.rb +1 -3
- data/spec/unit/application/queue_spec.rb +1 -0
- data/spec/unit/application_spec.rb +63 -5
- data/spec/unit/configurer/plugin_handler_spec.rb +5 -1
- data/spec/unit/configurer_spec.rb +33 -49
- data/spec/unit/file_bucket/dipper_spec.rb +69 -77
- data/spec/unit/file_bucket/file_spec.rb +12 -127
- data/spec/unit/file_serving/fileset_spec.rb +1 -0
- data/spec/unit/file_serving/metadata_spec.rb +4 -4
- data/spec/unit/indirector/active_record_spec.rb +1 -0
- data/spec/unit/indirector/catalog/active_record_spec.rb +29 -13
- data/spec/unit/indirector/facts/active_record_spec.rb +2 -3
- data/spec/unit/indirector/facts/couch_spec.rb +1 -2
- data/spec/unit/indirector/file_bucket_file/file_spec.rb +202 -218
- data/spec/unit/indirector/file_server_spec.rb +6 -7
- data/spec/unit/indirector/indirection_spec.rb +71 -2
- data/spec/unit/indirector/ldap_spec.rb +2 -6
- data/spec/unit/indirector/node/active_record_spec.rb +1 -3
- data/spec/unit/indirector/queue_spec.rb +1 -3
- data/spec/unit/indirector/rest_spec.rb +37 -1
- data/spec/unit/indirector/ssl_file_spec.rb +5 -5
- data/spec/unit/indirector_spec.rb +6 -1
- data/spec/unit/module_spec.rb +1 -3
- data/spec/unit/network/formats_spec.rb +2 -5
- data/spec/unit/network/http/api/v1_spec.rb +4 -0
- data/spec/unit/network/http/compression_spec.rb +1 -3
- data/spec/unit/network/http/handler_spec.rb +39 -0
- data/spec/unit/network/http/mongrel/rest_spec.rb +1 -2
- data/spec/unit/network/http/mongrel_spec.rb +3 -9
- data/spec/unit/network/http/rack/rest_spec.rb +1 -3
- data/spec/unit/network/http/rack/xmlrpc_spec.rb +2 -3
- data/spec/unit/network/http/rack_spec.rb +2 -3
- data/spec/unit/network/http/webrick_spec.rb +1 -0
- data/spec/unit/network/rest_authconfig_spec.rb +1 -1
- data/spec/unit/network/rights_spec.rb +43 -23
- data/spec/unit/network/xmlrpc/client_spec.rb +1 -0
- data/spec/unit/parameter_spec.rb +1 -2
- data/spec/unit/parser/collector_spec.rb +3 -6
- data/spec/unit/parser/compiler_spec.rb +90 -5
- data/spec/unit/parser/lexer_spec.rb +3 -2
- data/spec/unit/parser/templatewrapper_spec.rb +1 -0
- data/spec/unit/property/keyvalue_spec.rb +5 -5
- data/spec/unit/property/list_spec.rb +7 -7
- data/spec/unit/provider/mount/parsed_spec.rb +1 -2
- data/spec/unit/provider/mount_spec.rb +8 -0
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +38 -0
- data/spec/unit/provider/package/freebsd_spec.rb +55 -0
- data/spec/unit/provider/service/init_spec.rb +2 -0
- data/spec/unit/rails/host_spec.rb +1 -3
- data/spec/unit/rails/param_value_spec.rb +2 -3
- data/spec/unit/rails/resource_spec.rb +2 -3
- data/spec/unit/rails_spec.rb +5 -15
- data/spec/unit/relationship_spec.rb +2 -6
- data/spec/unit/reports/http_spec.rb +1 -1
- data/spec/unit/reports/store_spec.rb +31 -0
- data/spec/unit/reports/tagmail_spec.rb +1 -1
- data/spec/unit/resource/catalog_spec.rb +2 -6
- data/spec/unit/resource/status_spec.rb +53 -3
- data/spec/unit/resource/type_collection_spec.rb +0 -8
- data/spec/unit/resource/type_spec.rb +50 -4
- data/spec/unit/resource_spec.rb +10 -6
- data/spec/unit/ssl/certificate_authority/interface_spec.rb +1 -1
- data/spec/unit/transaction/event_spec.rb +21 -2
- data/spec/unit/transaction/report_spec.rb +91 -35
- data/spec/unit/transaction/resource_harness_spec.rb +289 -208
- data/spec/unit/transaction_spec.rb +1 -6
- data/spec/unit/type/augeas_spec.rb +1 -3
- data/spec/unit/type/file/content_spec.rb +63 -10
- data/spec/unit/type/file/ctime.rb +35 -0
- data/spec/unit/type/file/ensure_spec.rb +8 -7
- data/spec/unit/type/file/group_spec.rb +5 -5
- data/spec/unit/type/file/mtime.rb +35 -0
- data/spec/unit/type/file/owner_spec.rb +7 -7
- data/spec/unit/type/file/selinux_spec.rb +2 -2
- data/spec/unit/type/file/source_spec.rb +3 -3
- data/spec/unit/type/file/type.rb +20 -0
- data/spec/unit/type/file_spec.rb +131 -8
- data/spec/unit/type/mount_spec.rb +4 -4
- data/spec/unit/type/package_spec.rb +3 -3
- data/spec/unit/type/ssh_authorized_key_spec.rb +1 -1
- data/spec/unit/type/user_spec.rb +31 -3
- data/spec/unit/type/zpool_spec.rb +12 -12
- data/spec/unit/type_spec.rb +2 -2
- data/spec/unit/util/checksums_spec.rb +9 -1
- data/spec/unit/util/command_line_spec.rb +29 -0
- data/spec/unit/util/log/destinations_spec.rb +13 -0
- data/spec/unit/util/log_spec.rb +24 -12
- data/spec/unit/util/logging_spec.rb +1 -1
- data/spec/unit/util/metric_spec.rb +7 -7
- data/spec/unit/util/pson_spec.rb +15 -0
- data/spec/unit/util/queue/stomp_spec.rb +2 -6
- data/spec/unit/util/settings/file_setting_spec.rb +1 -3
- data/spec/unit/util/zaml_spec.rb +51 -0
- data/test/language/snippets.rb +3 -0
- data/test/lib/puppettest/fileparsing.rb +2 -0
- data/test/lib/puppettest/reporttesting.rb +1 -1
- data/test/lib/puppettest/support/utils.rb +1 -1
- data/test/network/server/mongrel_test.rb +0 -6
- data/test/other/report.rb +1 -1
- data/test/ral/providers/cron/crontab.rb +4 -1
- data/test/ral/type/file.rb +1 -1
- data/test/ral/type/filesources.rb +1 -4
- metadata +1119 -1113
- data/lib/puppet/transaction/change.rb +0 -87
- data/spec/Rakefile +0 -91
- data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +0 -46
- data/spec/spec_specs/runnable_spec.rb +0 -95
- data/spec/unit/transaction/change_spec.rb +0 -193
@@ -6,9 +6,7 @@ describe "Package Provider" do
|
|
6
6
|
Puppet::Type.type(:package).providers.each do |name|
|
7
7
|
provider = Puppet::Type.type(:package).provider(name)
|
8
8
|
|
9
|
-
describe name do
|
10
|
-
confine "Provider #{name} is not suitable" => provider.suitable?
|
11
|
-
|
9
|
+
describe name, :if => provider.suitable? do
|
12
10
|
it "should fail when asked to install an invalid package" do
|
13
11
|
pending("This test hangs forever with recent versions of RubyGems") if provider.name == :gem
|
14
12
|
pkg = Puppet::Type.newpackage :name => "nosuch#{provider.name}", :provider => provider.name
|
@@ -6,25 +6,19 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
|
|
6
6
|
provider = Puppet::Type.type(:service).provider(:init)
|
7
7
|
|
8
8
|
describe provider do
|
9
|
-
describe "when running on FreeBSD" do
|
10
|
-
confine "Not running on FreeBSD" => (Facter.value(:operatingsystem) == "FreeBSD")
|
11
|
-
|
9
|
+
describe "when running on FreeBSD", :if => (Facter.value(:operatingsystem) == "FreeBSD") do
|
12
10
|
it "should set its default path to include /etc/init.d and /usr/local/etc/init.d" do
|
13
11
|
provider.defpath.should == ["/etc/rc.d", "/usr/local/etc/rc.d"]
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
17
|
-
describe "when running on HP-UX" do
|
18
|
-
confine "Not running on HP-UX" => (Facter.value(:operatingsystem) == "HP-UX")
|
19
|
-
|
15
|
+
describe "when running on HP-UX", :if => (Facter.value(:operatingsystem) == "HP-UX")do
|
20
16
|
it "should set its default path to include /sbin/init.d" do
|
21
17
|
provider.defpath.should == "/sbin/init.d"
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
25
|
-
describe "when not running on FreeBSD or HP-UX" do
|
26
|
-
confine "Running on HP-UX or FreeBSD" => (! %w{HP-UX FreeBSD}.include?(Facter.value(:operatingsystem)))
|
27
|
-
|
21
|
+
describe "when not running on FreeBSD or HP-UX", :if => (! %w{HP-UX FreeBSD}.include?(Facter.value(:operatingsystem))) do
|
28
22
|
it "should set its default path to include /etc/init.d" do
|
29
23
|
provider.defpath.should == "/etc/init.d"
|
30
24
|
end
|
@@ -11,7 +11,7 @@ describe reference do
|
|
11
11
|
reference.should_not be_nil
|
12
12
|
end
|
13
13
|
|
14
|
-
it "should be able to be rendered as
|
15
|
-
lambda { reference.
|
14
|
+
it "should be able to be rendered as markdown" do
|
15
|
+
lambda { reference.to_markdown }.should_not raise_error
|
16
16
|
end
|
17
17
|
end
|
@@ -6,8 +6,7 @@
|
|
6
6
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
7
7
|
|
8
8
|
describe Puppet::Resource::Catalog do
|
9
|
-
describe "when pson is available" do
|
10
|
-
confine "PSON library is missing" => Puppet.features.pson?
|
9
|
+
describe "when pson is available", :if => Puppet.features.pson? do
|
11
10
|
it "should support pson" do
|
12
11
|
Puppet::Resource::Catalog.supported_formats.should be_include(:pson)
|
13
12
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# Created by Luke Kanies on 2007-10-18.
|
4
4
|
# Copyright (c) 2007. All rights reserved.
|
5
5
|
|
6
|
-
|
6
|
+
shared_examples_for "Puppet::Indirector::FileServerTerminus" do
|
7
7
|
# This only works if the shared behaviour is included before
|
8
8
|
# the 'before' block in the including context.
|
9
9
|
before do
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# Created by Luke Kanies on 2007-10-18.
|
4
4
|
# Copyright (c) 2007. All rights reserved.
|
5
5
|
|
6
|
-
|
6
|
+
shared_examples_for "Puppet::FileServing::Files" do
|
7
7
|
it "should use the rest terminus when the 'puppet' URI scheme is used and a host name is present" do
|
8
8
|
uri = "puppet://myhost/fakemod/my/file"
|
9
9
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# Created by Luke Kanies on 2008-4-8.
|
3
3
|
# Copyright (c) 2008. All rights reserved.
|
4
4
|
|
5
|
-
|
5
|
+
shared_examples_for "A Memory Terminus" do
|
6
6
|
it "should find no instances by default" do
|
7
7
|
@searcher.find(@request).should be_nil
|
8
8
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,29 +6,31 @@ dir = File.expand_path(File.dirname(__FILE__))
|
|
6
6
|
$LOAD_PATH.unshift("#{dir}/")
|
7
7
|
$LOAD_PATH.unshift("#{dir}/lib") # a spec-specific test lib dir
|
8
8
|
$LOAD_PATH.unshift("#{dir}/../lib")
|
9
|
+
$LOAD_PATH.unshift("#{dir}/../test/lib")
|
9
10
|
|
10
11
|
# Don't want puppet getting the command line arguments for rake or autotest
|
11
12
|
ARGV.clear
|
12
13
|
|
13
14
|
require 'puppet'
|
14
15
|
require 'mocha'
|
15
|
-
gem 'rspec', '>=
|
16
|
-
require 'spec/autorun'
|
16
|
+
gem 'rspec', '>=2.0.0'
|
17
17
|
|
18
18
|
# So everyone else doesn't have to include this base constant.
|
19
19
|
module PuppetSpec
|
20
20
|
FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
|
21
21
|
end
|
22
22
|
|
23
|
+
module PuppetTest
|
24
|
+
end
|
25
|
+
|
23
26
|
require 'lib/puppet_spec/files'
|
24
27
|
require 'monkey_patches/alias_should_to_must'
|
25
|
-
require 'monkey_patches/add_confine_and_runnable_to_rspec_dsl'
|
26
28
|
require 'monkey_patches/publicize_methods'
|
27
29
|
|
28
|
-
|
30
|
+
RSpec.configure do |config|
|
29
31
|
config.mock_with :mocha
|
30
32
|
|
31
|
-
config.
|
33
|
+
config.after :each do
|
32
34
|
Puppet.settings.clear
|
33
35
|
Puppet::Node::Environment.clear
|
34
36
|
Puppet::Util::Storage.clear
|
@@ -58,7 +60,7 @@ Spec::Runner.configure do |config|
|
|
58
60
|
Puppet::Util::Log.close_all
|
59
61
|
end
|
60
62
|
|
61
|
-
config.
|
63
|
+
config.before :each do
|
62
64
|
# these globals are set by Application
|
63
65
|
$puppet_application_mode = nil
|
64
66
|
$puppet_application_name = nil
|
@@ -4,6 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
4
4
|
|
5
5
|
require 'puppet/application/apply'
|
6
6
|
require 'puppet/file_bucket/dipper'
|
7
|
+
require 'puppet/configurer'
|
7
8
|
|
8
9
|
describe Puppet::Application::Apply do
|
9
10
|
before :each do
|
@@ -194,6 +195,9 @@ describe Puppet::Application::Apply do
|
|
194
195
|
@catalog.stubs(:apply).returns(@transaction)
|
195
196
|
|
196
197
|
@apply.stubs(:exit)
|
198
|
+
|
199
|
+
Puppet::Util::Storage.stubs(:load)
|
200
|
+
Puppet::Configurer.any_instance.stubs(:save_last_run_summary) # to prevent it from trying to write files
|
197
201
|
end
|
198
202
|
|
199
203
|
it "should set the code to run from --code" do
|
@@ -302,11 +306,8 @@ describe Puppet::Application::Apply do
|
|
302
306
|
end
|
303
307
|
|
304
308
|
it "should call the prerun and postrun commands on a Configurer instance" do
|
305
|
-
|
306
|
-
|
307
|
-
Puppet::Configurer.expects(:new).returns configurer
|
308
|
-
configurer.expects(:execute_prerun_command)
|
309
|
-
configurer.expects(:execute_postrun_command)
|
309
|
+
Puppet::Configurer.any_instance.expects(:execute_prerun_command)
|
310
|
+
Puppet::Configurer.any_instance.expects(:execute_postrun_command)
|
310
311
|
|
311
312
|
@apply.main
|
312
313
|
end
|
@@ -321,8 +322,7 @@ describe Puppet::Application::Apply do
|
|
321
322
|
it "should exit with report's computed exit status" do
|
322
323
|
Puppet.stubs(:[]).with(:noop).returns(false)
|
323
324
|
@apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
|
324
|
-
|
325
|
-
@transaction.stubs(:report).returns(report)
|
325
|
+
Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666)
|
326
326
|
@apply.expects(:exit).with(666)
|
327
327
|
|
328
328
|
@apply.main
|
@@ -48,10 +48,10 @@ describe Puppet::Application::Doc do
|
|
48
48
|
@doc.options[:mode].should == :text
|
49
49
|
end
|
50
50
|
|
51
|
-
it "should init format to
|
51
|
+
it "should init format to to_markdown" do
|
52
52
|
@doc.preinit
|
53
53
|
|
54
|
-
@doc.options[:format].should == :
|
54
|
+
@doc.options[:format].should == :to_markdown
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -0,0 +1,278 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
|
+
|
5
|
+
require 'puppet/application/inspect'
|
6
|
+
require 'puppet/resource/catalog'
|
7
|
+
require 'puppet/indirector/catalog/yaml'
|
8
|
+
require 'puppet/indirector/report/rest'
|
9
|
+
require 'puppet/indirector/file_bucket_file/rest'
|
10
|
+
|
11
|
+
describe Puppet::Application::Inspect do
|
12
|
+
include PuppetSpec::Files
|
13
|
+
|
14
|
+
before :each do
|
15
|
+
@inspect = Puppet::Application[:inspect]
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "during setup" do
|
19
|
+
it "should print its configuration if asked" do
|
20
|
+
Puppet[:configprint] = "all"
|
21
|
+
|
22
|
+
Puppet.settings.expects(:print_configs).returns(true)
|
23
|
+
lambda { @inspect.setup }.should raise_error(SystemExit)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should fail if reporting is turned off" do
|
27
|
+
Puppet[:report] = false
|
28
|
+
lambda { @inspect.setup }.should raise_error(/report=true/)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when executing" do
|
33
|
+
before :each do
|
34
|
+
Puppet[:report] = true
|
35
|
+
@inspect.options[:logset] = true
|
36
|
+
Puppet::Transaction::Report::Rest.any_instance.stubs(:save)
|
37
|
+
@inspect.setup
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should retrieve the local catalog" do
|
41
|
+
Puppet::Resource::Catalog::Yaml.any_instance.expects(:find).with {|request| request.key == Puppet[:certname] }.returns(Puppet::Resource::Catalog.new)
|
42
|
+
|
43
|
+
@inspect.run_command
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should save the report to REST" do
|
47
|
+
Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(Puppet::Resource::Catalog.new)
|
48
|
+
Puppet::Transaction::Report::Rest.any_instance.expects(:save).with {|request| request.instance.host == Puppet[:certname] }
|
49
|
+
|
50
|
+
@inspect.run_command
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should audit the specified properties" do
|
54
|
+
catalog = Puppet::Resource::Catalog.new
|
55
|
+
file = Tempfile.new("foo")
|
56
|
+
file.puts("file contents")
|
57
|
+
file.close
|
58
|
+
resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"})
|
59
|
+
catalog.add_resource(resource)
|
60
|
+
Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
|
61
|
+
|
62
|
+
events = nil
|
63
|
+
|
64
|
+
Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
|
65
|
+
events = request.instance.resource_statuses.values.first.events
|
66
|
+
end
|
67
|
+
|
68
|
+
@inspect.run_command
|
69
|
+
|
70
|
+
properties = events.inject({}) do |property_values, event|
|
71
|
+
property_values.merge(event.property => event.previous_value)
|
72
|
+
end
|
73
|
+
properties["ensure"].should == :file
|
74
|
+
properties["content"].should == "{md5}#{Digest::MD5.hexdigest("file contents\n")}"
|
75
|
+
properties.has_key?("target").should == false
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should set audited to true for all events" do
|
79
|
+
catalog = Puppet::Resource::Catalog.new
|
80
|
+
file = Tempfile.new("foo")
|
81
|
+
resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"})
|
82
|
+
catalog.add_resource(resource)
|
83
|
+
Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
|
84
|
+
|
85
|
+
events = nil
|
86
|
+
|
87
|
+
Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
|
88
|
+
events = request.instance.resource_statuses.values.first.events
|
89
|
+
end
|
90
|
+
|
91
|
+
@inspect.run_command
|
92
|
+
|
93
|
+
events.each do |event|
|
94
|
+
event.audited.should == true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should not report irrelevent attributes if the resource is absent" do
|
99
|
+
catalog = Puppet::Resource::Catalog.new
|
100
|
+
file = Tempfile.new("foo")
|
101
|
+
resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"})
|
102
|
+
file.delete
|
103
|
+
catalog.add_resource(resource)
|
104
|
+
Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
|
105
|
+
|
106
|
+
events = nil
|
107
|
+
|
108
|
+
Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
|
109
|
+
events = request.instance.resource_statuses.values.first.events
|
110
|
+
end
|
111
|
+
|
112
|
+
@inspect.run_command
|
113
|
+
|
114
|
+
properties = events.inject({}) do |property_values, event|
|
115
|
+
property_values.merge(event.property => event.previous_value)
|
116
|
+
end
|
117
|
+
properties.should == {"ensure" => :absent}
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "when archiving to a bucket" do
|
121
|
+
before :each do
|
122
|
+
Puppet[:archive_files] = true
|
123
|
+
Puppet[:archive_file_server] = "filebucketserver"
|
124
|
+
@catalog = Puppet::Resource::Catalog.new
|
125
|
+
Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(@catalog)
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "when auditing files" do
|
129
|
+
before :each do
|
130
|
+
@file = tmpfile("foo")
|
131
|
+
@resource = Puppet::Resource.new(:file, @file, :parameters => {:audit => "content"})
|
132
|
+
@catalog.add_resource(@resource)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should send an existing file to the file bucket" do
|
136
|
+
File.open(@file, 'w') { |f| f.write('stuff') }
|
137
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:head).with do |request|
|
138
|
+
request.server == Puppet[:archive_file_server]
|
139
|
+
end.returns(false)
|
140
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:save).with do |request|
|
141
|
+
request.server == Puppet[:archive_file_server] and request.instance.contents == 'stuff'
|
142
|
+
end
|
143
|
+
@inspect.run_command
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should not send unreadable files" do
|
147
|
+
File.open(@file, 'w') { |f| f.write('stuff') }
|
148
|
+
File.chmod(0, @file)
|
149
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
|
150
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
|
151
|
+
@inspect.run_command
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should not try to send non-existent files" do
|
155
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
|
156
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
|
157
|
+
@inspect.run_command
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should not try to send files whose content we are not auditing" do
|
161
|
+
@resource[:audit] = "group"
|
162
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
|
163
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
|
164
|
+
@inspect.run_command
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should continue if bucketing a file fails" do
|
168
|
+
File.open(@file, 'w') { |f| f.write('stuff') }
|
169
|
+
Puppet::FileBucketFile::Rest.any_instance.stubs(:head).returns false
|
170
|
+
Puppet::FileBucketFile::Rest.any_instance.stubs(:save).raises "failure"
|
171
|
+
Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
|
172
|
+
@report = request.instance
|
173
|
+
end
|
174
|
+
|
175
|
+
@inspect.run_command
|
176
|
+
|
177
|
+
@report.logs.first.should_not == nil
|
178
|
+
@report.logs.first.message.should =~ /Could not back up/
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "when auditing non-files" do
|
183
|
+
before :each do
|
184
|
+
Puppet::Type.newtype(:stub_type) do
|
185
|
+
newparam(:name) do
|
186
|
+
desc "The name var"
|
187
|
+
isnamevar
|
188
|
+
end
|
189
|
+
|
190
|
+
newproperty(:content) do
|
191
|
+
desc "content"
|
192
|
+
def retrieve
|
193
|
+
:whatever
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
@resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
|
199
|
+
@catalog.add_resource(@resource)
|
200
|
+
end
|
201
|
+
|
202
|
+
after :each do
|
203
|
+
Puppet::Type.rmtype(:stub_type)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should not try to send non-files" do
|
207
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
|
208
|
+
Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
|
209
|
+
@inspect.run_command
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "when there are failures" do
|
215
|
+
before :each do
|
216
|
+
Puppet::Type.newtype(:stub_type) do
|
217
|
+
newparam(:name) do
|
218
|
+
desc "The name var"
|
219
|
+
isnamevar
|
220
|
+
end
|
221
|
+
|
222
|
+
newproperty(:content) do
|
223
|
+
desc "content"
|
224
|
+
def retrieve
|
225
|
+
raise "failed"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
@catalog = Puppet::Resource::Catalog.new
|
231
|
+
Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(@catalog)
|
232
|
+
|
233
|
+
Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
|
234
|
+
@report = request.instance
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
after :each do
|
239
|
+
Puppet::Type.rmtype(:stub_type)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should mark the report failed and create failed events for each property" do
|
243
|
+
@resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
|
244
|
+
@catalog.add_resource(@resource)
|
245
|
+
|
246
|
+
@inspect.run_command
|
247
|
+
|
248
|
+
@report.status.should == "failed"
|
249
|
+
@report.logs.select{|log| log.message =~ /Could not inspect/}.count.should == 1
|
250
|
+
@report.resource_statuses.count.should == 1
|
251
|
+
@report.resource_statuses['Stub_type[foo]'].events.count.should == 1
|
252
|
+
|
253
|
+
event = @report.resource_statuses['Stub_type[foo]'].events.first
|
254
|
+
event.property.should == "content"
|
255
|
+
event.status.should == "failure"
|
256
|
+
event.audited.should == true
|
257
|
+
event.instance_variables.should_not include("@previous_value")
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should continue to the next resource" do
|
261
|
+
@resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
|
262
|
+
@other_resource = Puppet::Resource.new(:stub_type, 'bar', :parameters => {:audit => "all"})
|
263
|
+
@catalog.add_resource(@resource)
|
264
|
+
@catalog.add_resource(@other_resource)
|
265
|
+
|
266
|
+
@inspect.run_command
|
267
|
+
|
268
|
+
@report.resource_statuses.count.should == 2
|
269
|
+
@report.resource_statuses.keys.should =~ ['Stub_type[foo]', 'Stub_type[bar]']
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
after :all do
|
275
|
+
Puppet::Resource::Catalog.indirection.reset_terminus_class
|
276
|
+
Puppet::Transaction::Report.indirection.terminus_class = :processor
|
277
|
+
end
|
278
|
+
end
|