[PATCH conductor] BZ 790860 - re-enable provider availability

jprovazn at redhat.com jprovazn at redhat.com
Tue Feb 21 14:39:54 UTC 2012


From: Jan Provaznik <jprovazn at redhat.com>

If a provider was unavailable, it was never set as avaialable again.
---
 src/app/models/provider.rb       |   16 +++++++++++-----
 src/spec/factories/provider.rb   |    4 ++++
 src/spec/models/instance_spec.rb |    6 +++++-
 src/spec/models/provider_spec.rb |   17 +++++++++++++++++
 4 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index 1cbd99f..22e4e95 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -134,13 +134,19 @@ class Provider < ActiveRecord::Base
   def populate_realms
     reload
 
+    self.available = valid_framework?
+    if self.available_changed?
+      if self.available
+        logger.warn "provider #{name} is now available"
+        save!
+      else
+        logger.warn "provider #{name} is not available"
+        update_attribute(:available, false)
+      end
+    end
     # if the provider is not running, mark as unavailable and don't refresh its
     # realms
-    unless valid_framework?
-      update_attribute(:available, false)
-      logger.warn "provider #{name} is not available"
-      return
-    end
+    return unless self.available
 
     conductor_acct_realms = {}
     conductor_acct_realm_ids = {}
diff --git a/src/spec/factories/provider.rb b/src/spec/factories/provider.rb
index e8a8889..de6092d 100644
--- a/src/spec/factories/provider.rb
+++ b/src/spec/factories/provider.rb
@@ -61,4 +61,8 @@ FactoryGirl.define do
     name "mock"
     after_create { |p| p.provider_accounts << FactoryGirl.create(:mock_provider_account, :provider => p) }
   end
+
+  factory :unavailable_mock_provider, :parent => :mock_provider do
+    available false
+  end
 end
diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb
index 66b1365..8af85b1 100644
--- a/src/spec/models/instance_spec.rb
+++ b/src/spec/models/instance_spec.rb
@@ -216,10 +216,14 @@ describe Instance do
 
   it "shouldn't match frontend realms mapped to unavailable providers" do
     build = @instance.image_build || @instance.image.latest_pushed_build
-    provider = FactoryGirl.create(:mock_provider, :name => build.provider_images.first.provider_name, :available => false)
+    provider = FactoryGirl.create(:mock_provider, :name => build.provider_images.first.provider_name)
     realm_target = FactoryGirl.create(:realm_backend_target, :realm_or_provider => provider)
     @instance.frontend_realm = realm_target.frontend_realm
     @pool.pool_family.provider_accounts = [FactoryGirl.create(:mock_provider_account, :label => 'testaccount', :provider => provider)]
+    # provider's available flag can be changed when a provider account is
+    # created (populate_realms is called from after_create callback)
+    provider.available = false
+    provider.save!
     @instance.matches.last.should include(I18n.t('instances.errors.provider_not_available', :account_name => 'testaccount'))
   end
 
diff --git a/src/spec/models/provider_spec.rb b/src/spec/models/provider_spec.rb
index ca6843e..11cf71e 100644
--- a/src/spec/models/provider_spec.rb
+++ b/src/spec/models/provider_spec.rb
@@ -148,6 +148,23 @@ describe Provider do
     it "should return empty list of not terminated instances when disabled" do
       @provider.disable(nil)[:failed_to_terminate].should be_empty
     end
+
+    it "should mark provider as unavailable if inaccessible" do
+      @provider.available.should be_true
+      @provider.populate_realms
+      @provider.available.should be_false
+    end
+  end
+
+  context "(unavailable provider)" do
+    before(:each) do
+      @provider = FactoryGirl.create(:unavailable_mock_provider)
+    end
+
+    it "should mark provider as available if it becomes accessible" do
+      @provider.populate_realms
+      @provider.available.should be_true
+    end
   end
 
 end
-- 
1.7.7.6




More information about the aeolus-devel mailing list