From: Greg Blomquist<gblomqui(a)redhat.com>
https://bugzilla.redhat.com/show_bug.cgi?id=785216
Launching a deployment should not fail if any of the provider accounts' priority
value is nil.
---
src/app/models/deployment.rb | 12 +++++++++++-
src/spec/models/deployment_spec.rb | 18 ++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletions(-)
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 68b5a57..8f6fac1 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -236,7 +236,17 @@ class Deployment< ActiveRecord::Base
return status
end
# grab the account with the best priority that can launch this deployment
- account = account_matches.keys.sort{|a,b| a.priority<=> b.priority}.first
+ account = account_matches.keys.sort do |a,b|
+ if a.priority.nil? and b.priority.nil?
+ 0
+ elsif a.priority.nil?
+ 1
+ elsif b.priority.nil?
+ -1
+ else
+ a.priority<=> b.priority
+ end
+ end.first
instances_matches = account_matches[account]
if deployable_xml.requires_config_server?
diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb
index 38b2b19..b8806e7 100644
--- a/src/spec/models/deployment_spec.rb
+++ b/src/spec/models/deployment_spec.rb
@@ -224,6 +224,24 @@ describe Deployment do
deployment2.instances[1].provider_account.should == @provider_account2
end
+ it "should not fail to launch if a provider account has a nil priority"
do
+ @deployment.save!
+ @deployment.instances.should be_empty
+
+ @provider_account1.priority = nil
+ @provider_account1.save!
+
+
Instance.any_instance.stub(:provider_images_for_match).and_return([@provider_image])
+ Taskomatic.stub!(:create_dcloud_instance).and_return(true)
+ Taskomatic.stub!(:handle_dcloud_error).and_return(true)
+ Taskomatic.stub!(:handle_instance_state).and_return(true)
+ @deployment.launch(@user_for_launch)[:errors].should be_empty
+ @deployment.reload
+ @deployment.instances.count.should == 2
+ @deployment.instances[0].provider_account.should == @provider_account2
+ @deployment.instances[1].provider_account.should == @provider_account2
+ end
+
it "should not launch instances if user has no access to hardware
profile" do
@deployment.save!
@deployment.instances.should be_empty