From: Jozef Zigmund jzigmund@redhat.com
--- .../controllers/resources/instances_controller.rb | 3 ++- src/app/controllers/resources/pools_controller.rb | 3 ++- src/spec/controllers/instance_controller_spec.rb | 14 ++++++++++++++ src/spec/controllers/pools_controller_spec.rb | 3 ++- src/spec/factories/pool.rb | 1 + 5 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/app/controllers/resources/instances_controller.rb b/src/app/controllers/resources/instances_controller.rb index 75d6f96..efa9559 100644 --- a/src/app/controllers/resources/instances_controller.rb +++ b/src/app/controllers/resources/instances_controller.rb @@ -53,6 +53,7 @@ class Resources::InstancesController < ApplicationController require_privilege(Privilege::CREATE, Instance, Pool.find(@instance.pool_id)) free_quota = Quota.can_start_instance?(@instance, nil) + raise "Pool is not enabled" unless @instance.pool and @instance.pool.enabled @instance.transaction do @instance.save! # set owner permissions: @@ -190,7 +191,7 @@ class Resources::InstancesController < ApplicationController end
def init_new_instance_attrs - @pools = Pool.list_for_user(@current_user, Privilege::CREATE, :target_type => Instance) + @pools = Pool.list_for_user(@current_user, Privilege::CREATE, {:target_type => Instance,:conditions=>{ :enabled => true}}) @realms = FrontendRealm.all @hardware_profiles = HardwareProfile.all( :include => :architecture, diff --git a/src/app/controllers/resources/pools_controller.rb b/src/app/controllers/resources/pools_controller.rb index e557e91..af62592 100644 --- a/src/app/controllers/resources/pools_controller.rb +++ b/src/app/controllers/resources/pools_controller.rb @@ -118,7 +118,8 @@ class Resources::PoolsController < ApplicationController { :name => "Pool name", :sort_attr => :name }, { :name => "Quota (Instances)", :sort_attr => "quotas.total_instances"}, { :name => "% Quota used", :sortable => false }, - { :name => "Pool Family", :sort_attr => "pool_families.name" } + { :name => "Pool Family", :sort_attr => "pool_families.name" }, + { :name => "Enabled", :sort_attr => :enabled } ] end
diff --git a/src/spec/controllers/instance_controller_spec.rb b/src/spec/controllers/instance_controller_spec.rb index c2cfa64..ffed76d 100644 --- a/src/spec/controllers/instance_controller_spec.rb +++ b/src/spec/controllers/instance_controller_spec.rb @@ -66,4 +66,18 @@ describe Resources::InstancesController do {:name => 'mockinstance'}]).size.should == 0
end + + it "should not create instance in disabled pool" do + #instance = Factory.build(:new_instance) + #instance.pool.enabled = false + UserSession.create(@admin) + pool = Factory(:pool, :enabled => false) + template = Factory(:template) + hwp = Factory(:mock_hwp1) + post :create, :instance => { :name => 'mockinstance', + :pool_id => pool.id, + :template_id => template.id, + :hardware_profile_id => hwp.id } + response.flash[:warning].should == "Failed to launch instance: Pool is not enabled" + end end diff --git a/src/spec/controllers/pools_controller_spec.rb b/src/spec/controllers/pools_controller_spec.rb index ae84666..9c730c3 100644 --- a/src/spec/controllers/pools_controller_spec.rb +++ b/src/spec/controllers/pools_controller_spec.rb @@ -25,7 +25,8 @@ describe Resources::PoolsController do lambda do post :create, :pool => { :name => 'foopool', - :pool_family_id => PoolFamily.find_by_name('default').id + :pool_family_id => PoolFamily.find_by_name('default').id, + :enabled => true } end.should change(Pool, :count).by(1) id = Pool.find(:first, :conditions => ['name = ?', 'foopool']).id diff --git a/src/spec/factories/pool.rb b/src/spec/factories/pool.rb index 3b20f96..918335b 100644 --- a/src/spec/factories/pool.rb +++ b/src/spec/factories/pool.rb @@ -2,6 +2,7 @@ Factory.define :pool do |p| p.sequence(:name) { |n| "mypool#{n}" } p.pool_family { |p| PoolFamily.find_by_name('default') } p.association :quota + p.enabled true end
Factory.define :tpool, :parent => :pool do |p|