summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2010-06-10 20:31:34 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit0b95a8528e554df07efe970c9ecfc34535d17c92 (patch)
tree42ac163a4ab9497e3fb9f676365c1b3da35c5c7d /spec/unit
parent4627b8fe11dc14bf42e98b84121b885df73c709e (diff)
downloadpuppet-0b95a8528e554df07efe970c9ecfc34535d17c92.tar.gz
puppet-0b95a8528e554df07efe970c9ecfc34535d17c92.tar.xz
puppet-0b95a8528e554df07efe970c9ecfc34535d17c92.zip
Working #3139 - scheduling moved to resource harness
We previously had the schedule checking code in Puppet::Type, but it's more of a transactional function, and in order to do proper auditing in the transactional area, we need the cache checking done there. Scheduling is one of the few functions that actually uses cached data currently. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/transaction.rb79
-rwxr-xr-xspec/unit/transaction/resource_harness.rb61
2 files changed, 123 insertions, 17 deletions
diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb
index b315eb124..0c3d901f5 100755
--- a/spec/unit/transaction.rb
+++ b/spec/unit/transaction.rb
@@ -241,39 +241,84 @@ describe Puppet::Transaction do
describe "when skipping a resource" do
before :each do
- @resource = stub_everything 'res'
+ @resource = Puppet::Type.type(:notify).new :name => "foo"
@catalog = Puppet::Resource::Catalog.new
+ @resource.catalog = @catalog
@transaction = Puppet::Transaction.new(@catalog)
end
it "should skip resource with missing tags" do
@transaction.stubs(:missing_tags?).returns(true)
- @transaction.skip?(@resource).should be_true
+ @transaction.should be_skip(@resource)
end
- it "should ask the resource if it's tagged with any of the tags" do
- tags = ['one', 'two']
- @transaction.stubs(:ignore_tags?).returns(false)
- @transaction.stubs(:tags).returns(tags)
-
- @resource.expects(:tagged?).with(*tags).returns(true)
-
- @transaction.missing_tags?(@resource).should be_false
- end
-
- it "should skip not scheduled resources" do
+ it "should skip unscheduled resources" do
@transaction.stubs(:scheduled?).returns(false)
- @transaction.skip?(@resource).should be_true
+ @transaction.should be_skip(@resource)
end
it "should skip resources with failed dependencies" do
- @transaction.stubs(:failed_dependencies?).returns(false)
- @transaction.skip?(@resource).should be_true
+ @transaction.stubs(:failed_dependencies?).returns(true)
+ @transaction.should be_skip(@resource)
end
it "should skip virtual resource" do
@resource.stubs(:virtual?).returns true
- @transaction.skip?(@resource).should be_true
+ @transaction.should be_skip(@resource)
+ end
+ end
+
+ describe "when determining if tags are missing" do
+ before :each do
+ @resource = Puppet::Type.type(:notify).new :name => "foo"
+ @catalog = Puppet::Resource::Catalog.new
+ @resource.catalog = @catalog
+ @transaction = Puppet::Transaction.new(@catalog)
+
+ @transaction.stubs(:ignore_tags?).returns false
+ end
+
+ it "should not be missing tags if tags are being ignored" do
+ @transaction.expects(:ignore_tags?).returns true
+
+ @resource.expects(:tagged?).never
+
+ @transaction.should_not be_missing_tags(@resource)
+ end
+
+ it "should not be missing tags if the transaction tags are empty" do
+ @transaction.tags = []
+ @resource.expects(:tagged?).never
+ @transaction.should_not be_missing_tags(@resource)
+ end
+
+ it "should otherwise let the resource determine if it is missing tags" do
+ tags = ['one', 'two']
+ @transaction.tags = tags
+ @resource.expects(:tagged?).with(*tags).returns(false)
+ @transaction.should be_missing_tags(@resource)
+ end
+ end
+
+ describe "when determining if a resource should be scheduled" do
+ before :each do
+ @resource = Puppet::Type.type(:notify).new :name => "foo"
+ @catalog = Puppet::Resource::Catalog.new
+ @resource.catalog = @catalog
+ @transaction = Puppet::Transaction.new(@catalog)
+ end
+
+ it "should always schedule resources if 'ignoreschedules' is set" do
+ @transaction.ignoreschedules = true
+ @transaction.resource_harness.expects(:scheduled?).never
+
+ @transaction.should be_scheduled(@resource)
+ end
+
+ it "should let the resource harness determine whether the resource should be scheduled" do
+ @transaction.resource_harness.expects(:scheduled?).with(@resource).returns "feh"
+
+ @transaction.scheduled?(@resource).should == "feh"
end
end
diff --git a/spec/unit/transaction/resource_harness.rb b/spec/unit/transaction/resource_harness.rb
index 3b9a42a38..334dbff77 100755
--- a/spec/unit/transaction/resource_harness.rb
+++ b/spec/unit/transaction/resource_harness.rb
@@ -265,4 +265,65 @@ describe Puppet::Transaction::ResourceHarness do
@harness.should_not be_allow_changes(@resource)
end
end
+
+ describe "when finding the schedule" do
+ before do
+ @catalog = Puppet::Resource::Catalog.new
+ @resource.catalog = @catalog
+ end
+
+ it "should warn and return nil if the resource has no catalog" do
+ @resource.catalog = nil
+ @resource.expects(:warning)
+
+ @harness.schedule(@resource).should be_nil
+ end
+
+ it "should return nil if the resource specifies no schedule" do
+ @harness.schedule(@resource).should be_nil
+ end
+
+ it "should fail if the named schedule cannot be found" do
+ @resource[:schedule] = "whatever"
+ @resource.expects(:fail)
+ @harness.schedule(@resource)
+ end
+
+ it "should return the named schedule if it exists" do
+ sched = Puppet::Type.type(:schedule).new(:name => "sched")
+ @catalog.add_resource(sched)
+ @resource[:schedule] = "sched"
+ @harness.schedule(@resource).to_s.should == sched.to_s
+ end
+ end
+
+ describe "when determining if a resource is scheduled" do
+ before do
+ @catalog = Puppet::Resource::Catalog.new
+ @resource.catalog = @catalog
+ end
+
+ it "should return true if 'ignoreschedules' is set" do
+ Puppet[:ignoreschedules] = true
+ @resource[:schedule] = "meh"
+ @harness.should be_scheduled(@resource)
+ end
+
+ it "should return true if the resource has no schedule set" do
+ @harness.should be_scheduled(@resource)
+ end
+
+ it "should return the result of matching the schedule with the cached 'checked' time if a schedule is set" do
+ t = Time.now
+ @resource.expects(:cached).with(:checked).returns(t)
+
+ sched = Puppet::Type.type(:schedule).new(:name => "sched")
+ @catalog.add_resource(sched)
+ @resource[:schedule] = "sched"
+
+ sched.expects(:match?).with(t.to_i).returns "feh"
+
+ @harness.scheduled?(@resource).should == "feh"
+ end
+ end
end