summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-10-04 20:11:56 -0700
committerJesse Wolfe <jes5199@gmail.com>2010-10-04 21:46:59 -0700
commit7bdbd132634f61d91aeee401de15248d936ce71e (patch)
tree146bb43d90478d373f9bb1c5ed3e04bd9d04dbbc /spec
parent163ec172e06a2b8aab9f9c9247dd45bc0dea3f72 (diff)
parent917c520f1abc0c72d7065531cffcef88259e32e0 (diff)
downloadpuppet-7bdbd132634f61d91aeee401de15248d936ce71e.tar.gz
puppet-7bdbd132634f61d91aeee401de15248d936ce71e.tar.xz
puppet-7bdbd132634f61d91aeee401de15248d936ce71e.zip
Merge commit '2.6.2rc1' into next
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/yaml/report0.25.x.yaml64
-rw-r--r--spec/fixtures/yaml/report2.6.x.yaml190
-rwxr-xr-xspec/integration/parser/compiler_spec.rb21
-rw-r--r--spec/spec_helper.rb1
-rwxr-xr-xspec/unit/indirector/node/active_record_spec.rb1
-rwxr-xr-xspec/unit/parser/lexer_spec.rb8
-rwxr-xr-xspec/unit/provider/service/launchd_spec.rb13
-rw-r--r--spec/unit/provider/user/user_role_add_spec.rb19
-rwxr-xr-xspec/unit/provider/user/useradd_spec.rb19
-rw-r--r--spec/unit/reports/rrdgraph_spec.rb31
-rwxr-xr-xspec/unit/type/user_spec.rb20
-rwxr-xr-x[-rw-r--r--]spec/unit/util/zaml_spec.rb3
12 files changed, 381 insertions, 9 deletions
diff --git a/spec/fixtures/yaml/report0.25.x.yaml b/spec/fixtures/yaml/report0.25.x.yaml
new file mode 100644
index 000000000..ce6a64286
--- /dev/null
+++ b/spec/fixtures/yaml/report0.25.x.yaml
@@ -0,0 +1,64 @@
+--- !ruby/object:Puppet::Transaction::Report
+ host: mattmac.local
+ logs:
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym info
+ message: Applying configuration version '1285283846'
+ source: Puppet
+ tags:
+ - info
+ time: 2010-09-23 16:17:26.977750 -07:00
+ metrics:
+ time: !ruby/object:Puppet::Util::Metric
+ label: Time
+ name: time
+ values:
+ - - !ruby/sym config_retrieval
+ - Config retrieval
+ - 0.955046892166138
+ - - !ruby/sym schedule
+ - Schedule
+ - 0.00123691558837891
+ - - !ruby/sym total
+ - Total
+ - 0.956486701965332
+ - - !ruby/sym filebucket
+ - Filebucket
+ - 0.00020289421081543
+ resources: !ruby/object:Puppet::Util::Metric
+ label: Resources
+ name: resources
+ values:
+ - - !ruby/sym skipped
+ - Skipped
+ - 0
+ - - !ruby/sym scheduled
+ - Scheduled
+ - 7
+ - - !ruby/sym applied
+ - Applied
+ - 0
+ - - !ruby/sym restarted
+ - Restarted
+ - 0
+ - - !ruby/sym total
+ - Total
+ - 10
+ - - !ruby/sym failed_restarts
+ - Failed restarts
+ - 0
+ - - !ruby/sym out_of_sync
+ - Out of sync
+ - 0
+ - - !ruby/sym failed
+ - Failed
+ - 0
+ changes: !ruby/object:Puppet::Util::Metric
+ label: Changes
+ name: changes
+ values:
+ - - !ruby/sym total
+ - Total
+ - 0
+ records: {}
+ time: 2010-09-23 16:17:26.987789 -07:00 \ No newline at end of file
diff --git a/spec/fixtures/yaml/report2.6.x.yaml b/spec/fixtures/yaml/report2.6.x.yaml
new file mode 100644
index 000000000..dd4c3814e
--- /dev/null
+++ b/spec/fixtures/yaml/report2.6.x.yaml
@@ -0,0 +1,190 @@
+--- !ruby/object:Puppet::Transaction::Report
+ external_times:
+ !ruby/sym config_retrieval: 0.170313835144043
+ host: ubuntu1004desktop.localdomain
+ logs:
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Using cached certificate for ca
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.244173 -07:00
+ version: &id001 2.6.1
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Using cached certificate for ubuntu1004desktop.localdomain
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.244764 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Using cached certificate_revocation_list for ca
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.245677 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: "catalog supports formats: b64_zlib_yaml dot marshal pson raw yaml; using pson"
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.247069 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym info
+ message: Caching catalog for ubuntu1004desktop.localdomain
+ source: Puppet
+ tags:
+ - info
+ time: 2010-09-23 15:44:06.409109 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Creating default schedules
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.418755 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym debug
+ message: Loaded state in 0.00 seconds
+ source: Puppet
+ tags:
+ - debug
+ time: 2010-09-23 15:44:06.427441 -07:00
+ version: *id001
+ - !ruby/object:Puppet::Util::Log
+ level: !ruby/sym info
+ message: Applying configuration version '1285281846'
+ source: Puppet
+ tags:
+ - info
+ time: 2010-09-23 15:44:06.429532 -07:00
+ version: *id001
+ metrics:
+ time: !ruby/object:Puppet::Util::Metric
+ label: Time
+ name: time
+ values:
+ - - config_retrieval
+ - Config retrieval
+ - 0.170313835144043
+ - - schedule
+ - Schedule
+ - 0.00077
+ - - filebucket
+ - Filebucket
+ - 0.000166
+ resources: !ruby/object:Puppet::Util::Metric
+ label: Resources
+ name: resources
+ values:
+ - - !ruby/sym total
+ - Total
+ - 7
+ events: !ruby/object:Puppet::Util::Metric
+ label: Events
+ name: events
+ values:
+ - - !ruby/sym total
+ - Total
+ - 0
+ changes: !ruby/object:Puppet::Util::Metric
+ label: Changes
+ name: changes
+ values:
+ - - !ruby/sym total
+ - Total
+ - 0
+ resource_statuses:
+ "Schedule[monthly]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000121
+ events: []
+ file:
+ line:
+ resource: "Schedule[monthly]"
+ source_description: "/Schedule[monthly]"
+ tags:
+ - schedule
+ - monthly
+ time: 2010-09-23 15:44:06.430577 -07:00
+ version: 1285281846
+ "Filebucket[puppet]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000166
+ events: []
+ file:
+ line:
+ resource: "Filebucket[puppet]"
+ source_description: "/Filebucket[puppet]"
+ tags:
+ - filebucket
+ - puppet
+ time: 2010-09-23 15:44:06.430998 -07:00
+ version: 1285281846
+ "Schedule[never]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000119
+ events: []
+ file:
+ line:
+ resource: "Schedule[never]"
+ source_description: "/Schedule[never]"
+ tags:
+ - schedule
+ - never
+ time: 2010-09-23 15:44:06.433034 -07:00
+ version: 1285281846
+ "Schedule[weekly]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000118
+ events: []
+ file:
+ line:
+ resource: "Schedule[weekly]"
+ source_description: "/Schedule[weekly]"
+ tags:
+ - schedule
+ - weekly
+ time: 2010-09-23 15:44:06.431443 -07:00
+ version: 1285281846
+ "Schedule[puppet]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000129
+ events: []
+ file:
+ line:
+ resource: "Schedule[puppet]"
+ source_description: "/Schedule[puppet]"
+ tags:
+ - schedule
+ - puppet
+ time: 2010-09-23 15:44:06.432626 -07:00
+ version: 1285281846
+ "Schedule[daily]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000154
+ events: []
+ file:
+ line:
+ resource: "Schedule[daily]"
+ source_description: "/Schedule[daily]"
+ tags:
+ - schedule
+ - daily
+ time: 2010-09-23 15:44:06.430130 -07:00
+ version: 1285281846
+ "Schedule[hourly]": !ruby/object:Puppet::Resource::Status
+ evaluation_time: 0.000129
+ events: []
+ file:
+ line:
+ resource: "Schedule[hourly]"
+ source_description: "/Schedule[hourly]"
+ tags:
+ - schedule
+ - hourly
+ time: 2010-09-23 15:44:06.432185 -07:00
+ version: 1285281846
+ time: 2010-09-23 15:44:05.894401 -07:00 \ No newline at end of file
diff --git a/spec/integration/parser/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb
index df310ac07..f731692b3 100755
--- a/spec/integration/parser/compiler_spec.rb
+++ b/spec/integration/parser/compiler_spec.rb
@@ -27,6 +27,27 @@ describe Puppet::Parser::Compiler do
@compiler.catalog.version.should == version
end
+ it "should not create duplicate resources when a class is referenced both directly and indirectly by the node classifier (4792)" do
+ Puppet[:code] = <<-PP
+ class foo
+ {
+ notify { foo_notify: }
+ include bar
+ }
+ class bar
+ {
+ notify { bar_notify: }
+ }
+ PP
+
+ @node.stubs(:classes).returns(['foo', 'bar'])
+
+ catalog = Puppet::Parser::Compiler.compile(@node)
+
+ catalog.resource("Notify[foo_notify]").should_not be_nil
+ catalog.resource("Notify[bar_notify]").should_not be_nil
+ end
+
describe "when resolving class references" do
it "should favor local scope, even if there's an included class in topscope" do
Puppet[:code] = <<-PP
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2fe0c36a3..b5b273857 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -20,6 +20,7 @@ module PuppetSpec
FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
end
+require 'spec/lib/puppet_spec/files'
require 'monkey_patches/alias_should_to_must'
require 'monkey_patches/add_confine_and_runnable_to_rspec_dsl'
require 'monkey_patches/publicize_methods'
diff --git a/spec/unit/indirector/node/active_record_spec.rb b/spec/unit/indirector/node/active_record_spec.rb
index 6cc3f5132..3540ef738 100755
--- a/spec/unit/indirector/node/active_record_spec.rb
+++ b/spec/unit/indirector/node/active_record_spec.rb
@@ -3,7 +3,6 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/node'
-require 'spec/lib/puppet_spec/files.rb'
describe "Puppet::Node::ActiveRecord" do
include PuppetSpec::Files
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index b27980bf2..2d67bf357 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -30,6 +30,14 @@ describe Puppet::Parser::Lexer do
@lexer.line.should == 10
end
+
+ it "should not think the terminator is escaped, when preceeded by an even number of backslashes" do
+ @lexer.line = 10
+ @lexer.string = "here\nis\nthe\nstring\\\\'with\nextra\njunk"
+ @lexer.slurpstring("'")
+
+ @lexer.line.should == 13
+ end
end
end
diff --git a/spec/unit/provider/service/launchd_spec.rb b/spec/unit/provider/service/launchd_spec.rb
index 320ee3ace..43e4cba8e 100755
--- a/spec/unit/provider/service/launchd_spec.rb
+++ b/spec/unit/provider/service/launchd_spec.rb
@@ -98,19 +98,22 @@ describe provider_class do
it "should return true if the job plist says disabled is true and the global overrides says disabled is false" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
@provider.stubs(:plist_from_label).returns(["foo", {"Disabled" => true}])
- Plist.stubs(:parse_xml).returns({@resource[:name] => {"Disabled" => false}})
+ @provider.class.stubs(:read_plist).returns({@resource[:name] => {"Disabled" => false}})
+ FileTest.expects(:file?).with(Launchd_Overrides).returns(true)
@provider.enabled?.should == :true
end
it "should return false if the job plist says disabled is false and the global overrides says disabled is true" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
@provider.stubs(:plist_from_label).returns(["foo", {"Disabled" => false}])
- Plist.stubs(:parse_xml).returns({@resource[:name] => {"Disabled" => true}})
+ @provider.class.stubs(:read_plist).returns({@resource[:name] => {"Disabled" => true}})
+ FileTest.expects(:file?).with(Launchd_Overrides).returns(true)
@provider.enabled?.should == :false
end
it "should return true if the job plist and the global overrides have no disabled keys" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
@provider.stubs(:plist_from_label).returns(["foo", {}])
- Plist.stubs(:parse_xml).returns({})
+ @provider.class.stubs(:read_plist).returns({})
+ FileTest.expects(:file?).with(Launchd_Overrides).returns(true)
@provider.enabled?.should == :true
end
end
@@ -182,7 +185,7 @@ describe provider_class do
describe "when enabling the service on OS X 10.6" do
it "should write to the global launchd overrides file once" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
- Plist.stubs(:parse_xml).returns({})
+ @provider.class.stubs(:read_plist).returns({})
Plist::Emit.expects(:save_plist).once
@provider.enable
end
@@ -191,7 +194,7 @@ describe provider_class do
describe "when disabling the service on OS X 10.6" do
it "should write to the global launchd overrides file once" do
provider_class.stubs(:get_macosx_version_major).returns("10.6")
- Plist.stubs(:parse_xml).returns({})
+ @provider.class.stubs(:read_plist).returns({})
Plist::Emit.expects(:save_plist).once
@provider.enable
end
diff --git a/spec/unit/provider/user/user_role_add_spec.rb b/spec/unit/provider/user/user_role_add_spec.rb
index 211f4260a..b3244f19d 100644
--- a/spec/unit/provider/user/user_role_add_spec.rb
+++ b/spec/unit/provider/user/user_role_add_spec.rb
@@ -56,7 +56,7 @@ describe provider_class do
it "should use the add command when the user is not a role" do
@provider.stubs(:is_role?).returns(false)
@provider.expects(:addcmd).returns("useradd")
- @provider.expects(:run)
+ @provider.expects(:run).at_least_once
@provider.create
end
@@ -66,6 +66,15 @@ describe provider_class do
@provider.expects(:run)
@provider.create
end
+
+ it "should set password age rules" do
+ @resource = Puppet::Type.type(:user).new :name => "myuser", :password_min_age => 5, :password_max_age => 10, :provider => :user_role_add
+ @provider = provider_class.new(@resource)
+ @provider.stubs(:user_attributes)
+ @provider.stubs(:execute)
+ @provider.expects(:execute).with { |cmd, *args| args == ["-m", 5, "-M", 10, "myuser"] }
+ @provider.create
+ end
end
describe "when calling destroy" do
@@ -107,6 +116,7 @@ describe provider_class do
before do
@resource.expects(:allowdupe?).returns true
@provider.stubs(:is_role?).returns(false)
+ @provider.stubs(:execute)
@provider.expects(:execute).with { |args| args.include?("-o") }
end
@@ -246,4 +256,11 @@ describe provider_class do
@provider.password=("hashedpassword")
end
end
+
+ describe "#shadow_entry" do
+ it "should return the line for the right user" do
+ File.stubs(:readlines).returns(["someuser:!:10:5:20:7:1::\n", "fakeval:*:20:10:30:7:2::\n", "testuser:*:30:15:40:7:3::\n"])
+ @provider.shadow_entry.should == ["fakeval", "*", "20", "10", "30", "7", "2"]
+ end
+ end
end
diff --git a/spec/unit/provider/user/useradd_spec.rb b/spec/unit/provider/user/useradd_spec.rb
index 6eb9717b8..26367c584 100755
--- a/spec/unit/provider/user/useradd_spec.rb
+++ b/spec/unit/provider/user/useradd_spec.rb
@@ -15,6 +15,7 @@ describe provider_class do
# #1360
it "should add -o when allowdupe is enabled and the user is being created" do
@resource.expects(:allowdupe?).returns true
+ @provider.stubs(:execute)
@provider.expects(:execute).with { |args| args.include?("-o") }
@provider.create
end
@@ -26,6 +27,15 @@ describe provider_class do
@provider.uid = 150
end
+ it "should set password age rules" do
+ provider_class.has_feature :manages_password_age
+ @resource = Puppet::Type.type(:user).new :name => "myuser", :password_min_age => 5, :password_max_age => 10, :provider => :useradd
+ @provider = provider_class.new(@resource)
+ @provider.stubs(:execute)
+ @provider.expects(:execute).with { |cmd, *args| args == ["-m", 5, "-M", 10, "myuser"] }
+ @provider.create
+ end
+
describe "when checking to add allow dup" do
it "should check allow dup" do
@resource.expects(:allowdupe?)
@@ -109,6 +119,15 @@ describe provider_class do
@provider.stubs(:command).with(:add).returns("useradd")
@provider.stubs(:add_properties).returns(["-G", "somegroup"])
@resource.stubs(:[]).with(:name).returns("someuser")
+ @resource.stubs(:[]).with(:expiry).returns("somedate")
+ @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", '-e somedate', "someuser"]
+ end
+
+ it "should return an array without -e if expery is undefined full command" do
+ @provider.stubs(:command).with(:add).returns("useradd")
+ @provider.stubs(:add_properties).returns(["-G", "somegroup"])
+ @resource.stubs(:[]).with(:name).returns("someuser")
+ @resource.stubs(:[]).with(:expiry).returns nil
@provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", "someuser"]
end
end
diff --git a/spec/unit/reports/rrdgraph_spec.rb b/spec/unit/reports/rrdgraph_spec.rb
new file mode 100644
index 000000000..ce2cf7905
--- /dev/null
+++ b/spec/unit/reports/rrdgraph_spec.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/reports'
+
+processor = Puppet::Reports.report(:rrdgraph)
+
+describe processor do
+ include PuppetSpec::Files
+ before do
+ Puppet[:rrddir] = tmpdir('rrdgraph')
+ Puppet.settings.use :master
+ end
+
+ after do
+ FileUtils.rm_rf(Puppet[:rrddir])
+ end
+
+ it "should not error on 0.25.x report format" do
+ report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report0.25.x.yaml')).extend processor
+ report.expects(:mkhtml)
+ lambda{ report.process }.should_not raise_error
+ end
+
+ it "should not error on 2.6.x report format" do
+ report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml')).extend processor
+ report.expects(:mkhtml)
+ lambda{ report.process }.should_not raise_error
+ end
+end
diff --git a/spec/unit/type/user_spec.rb b/spec/unit/type/user_spec.rb
index 4c6eb1150..ccea9ee4c 100755
--- a/spec/unit/type/user_spec.rb
+++ b/spec/unit/type/user_spec.rb
@@ -35,6 +35,14 @@ describe user do
user.provider_feature(:manages_solaris_rbac).should_not be_nil
end
+ it "should have a manages_expiry feature" do
+ user.provider_feature(:manages_expiry).should_not be_nil
+ end
+
+ it "should have a manages_password_age feature" do
+ user.provider_feature(:manages_password_age).should_not be_nil
+ end
+
describe "instances" do
it "should have a valid provider" do
user.new(:name => "foo").provider.class.ancestors.should be_include(Puppet::Provider)
@@ -47,7 +55,7 @@ describe user do
end
end
- properties = [:ensure, :uid, :gid, :home, :comment, :shell, :password, :groups, :roles, :auths, :profiles, :project, :keys]
+ properties = [:ensure, :uid, :gid, :home, :comment, :shell, :password, :password_min_age, :password_max_age, :groups, :roles, :auths, :profiles, :project, :keys, :expiry]
properties.each do |property|
it "should have a #{property} property" do
@@ -227,6 +235,16 @@ describe user do
end
end
+ describe "when managing expiry" do
+ before do
+ @expiry = user.attrclass(:expiry).new(:resource => @resource)
+ end
+
+ it "should fail if given an invalid date" do
+ lambda { @expiry.should = "200-20-20" }.should raise_error(Puppet::Error)
+ end
+ end
+
describe "when managing passwords" do
before do
@password = user.attrclass(:password).new(:resource => @resource, :should => "mypass")
diff --git a/spec/unit/util/zaml_spec.rb b/spec/unit/util/zaml_spec.rb
index 14cf94f36..b223f89d4 100644..100755
--- a/spec/unit/util/zaml_spec.rb
+++ b/spec/unit/util/zaml_spec.rb
@@ -11,7 +11,8 @@ describe "Pure ruby yaml implementation" do
'test' => "--- test",
[] => "--- []",
:symbol => "--- !ruby/sym symbol",
- {:a => "A"} => "--- \n !ruby/sym a: A"
+ {:a => "A"} => "--- \n !ruby/sym a: A",
+ {:a => "x\ny"} => "--- \n !ruby/sym a: |-\n x\n y"
}.each { |o,y|
it "should convert the #{o.class} #{o.inspect} to yaml" do
o.to_yaml.should == y