Permalink
Browse files

add min_size policy for the resource pool

Change-Id: I7a2e03c7dd2100d8cd5254997c086f16b44efae0
  • Loading branch information...
Glenn Oppegard & Patrick Bozeman
Glenn Oppegard & Patrick Bozeman committed Jan 29, 2013
1 parent 3635865 commit c071e15842a2aaca40a48d8df22cb27491d41377
Showing with 37 additions and 3 deletions.
  1. +1 −0 lib/cloud_controller/config.rb
  2. +11 −3 lib/cloud_controller/resource_pool.rb
  3. +25 −0 spec/resource_pool_spec.rb
@@ -95,6 +95,7 @@ class VCAP::CloudController::Config < VCAP::Config
:resource_pool => {
optional(:maximum_size) => Integer,
+ optional(:minimum_size) => Integer,
optional(:resource_directory_key) => String,
:fog_connection => {
:provider => String,
@@ -17,6 +17,7 @@ def configure(config = {})
opts = config[:resource_pool] || {}
@connection_config = opts[:fog_connection]
@resource_directory_key = opts[:resource_directory_key] || "cc-resources"
+ @minimum_size = opts[:minimum_size] || 0
@maximum_size = opts[:maximum_size] || 512 * 1024 * 1024 # MB
end
@@ -84,13 +85,20 @@ def logger
end
def resource_known?(descriptor)
- key = key_from_sha1(descriptor["sha1"])
- resource_dir.files.head(key)
+ size = descriptor["size"]
+ if size_allowed?(size)
+ key = key_from_sha1(descriptor["sha1"])
+ resource_dir.files.head(key)
+ end
end
def resource_allowed?(path)
stat = File.stat(path)
- File.file?(path) && !stat.symlink? && stat.size < maximum_size
+ File.file?(path) && !stat.symlink? && size_allowed?(stat.size)
+ end
+
+ def size_allowed?(size)
+ size && size > minimum_size && size < maximum_size
end
# Called after we sanity-check the input.
View
@@ -44,5 +44,30 @@ module VCAP::CloudController
ResourcePool.add_directory(@tmpdir)
end
end
+
+ describe "#size_allowed?" do
+ before do
+ @minimum_size = 5
+ @maximum_size = 7
+ ResourcePool.minimum_size = @minimum_size
+ ResourcePool.maximum_size = @maximum_size
+ end
+
+ it "should return true for a size between min and max size" do
+ ResourcePool.send(:size_allowed?, @minimum_size + 1).should be_true
+ end
+
+ it "should return false for a size < min size" do
+ ResourcePool.send(:size_allowed?, @minimum_size - 1).should be_false
+ end
+
+ it "should return false for a size > max size" do
+ ResourcePool.send(:size_allowed?, @maximum_size + 1).should be_false
+ end
+
+ it "should return false for a nil size" do
+ ResourcePool.send(:size_allowed?, nil).should be_false
+ end
+ end
end
end

0 comments on commit c071e15

Please sign in to comment.