[PATCH conductor] BZ#753880 Catch exceptions on DC valid credentials request

Matt Wagner matt.wagner at redhat.com
Mon Feb 6 20:58:55 UTC 2012


On Mon, Feb 06, 2012 at 03:02:52PM -0500, Matt Wagner wrote:
> From: Martyn Taylor <mtaylor at redhat.com>
> 
> Signed-off-by: Matt Wagner <matt.wagner at redhat.com>
> ---
>  src/app/models/provider_account.rb       |    8 ++++++--
>  src/config/locales/en.yml                |    2 ++
>  src/features/provider_account.feature    |    2 +-
>  src/spec/models/provider_account_spec.rb |    8 ++++++++
>  4 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb
> index 89009aa..6a8cb35 100644
> --- a/src/app/models/provider_account.rb
> +++ b/src/app/models/provider_account.rb
> @@ -86,8 +86,12 @@ class ProviderAccount < ActiveRecord::Base
>    end
>  
>    def validate_credentials
> -    unless valid_credentials?
> -      errors.add(:base, "Login Credentials are Invalid for this Provider")
> +    begin
> +      unless valid_credentials?
> +        errors.add(:base, I18N.t('provider_accounts.errors.invalid_credentials'))
> +      end
> +    rescue
> +      errors.add(:base, I18n.t('provider_accounts.errors.exception_while_validating'))
>      end
>    end
>  
> diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
> index fe65336..3a0f746 100644
> --- a/src/config/locales/en.yml
> +++ b/src/config/locales/en.yml
> @@ -1101,6 +1101,8 @@ en:
>          must_select_account: "You must select some accounts first."
>          no_provider: "You don't have any provider yet"
>      errors:
> +      exception_while_validating: An error occurred when checking provider credentials. Please check your setup and try again.
> +      invalid_credentials: Login credentials are invalid for this provider.
>        populate_hardware_profiles_failed: "Failed to populate hardware_profiles: %{message}"
>        populate_realms_failed: "Failed to populate realms: %{message}"
>    config_servers:
> diff --git a/src/features/provider_account.feature b/src/features/provider_account.feature
> index 4ac6158..44f41cb 100644
> --- a/src/features/provider_account.feature
> +++ b/src/features/provider_account.feature
> @@ -56,7 +56,7 @@ Feature: Manage Provider Accounts
>      And I fill in "quota[maximum_running_instances]" with "13"
>      And I press "Save"
>      Then I should see "Cannot add the provider account."
> -    Then I should see "Login Credentials are Invalid for this Provider"
> +    Then I should see "An error occurred when checking provider credentials."
>  
>    Scenario: Delete a provider account
>      Given there is a provider named "testprovider"
> diff --git a/src/spec/models/provider_account_spec.rb b/src/spec/models/provider_account_spec.rb
> index 04b4b1e..a8c1074 100644
> --- a/src/spec/models/provider_account_spec.rb
> +++ b/src/spec/models/provider_account_spec.rb
> @@ -64,6 +64,14 @@ describe ProviderAccount do
>      provider_account.save.should == false
>    end
>  
> +  it "should add errors when testing credentials fails" do
> +    provider_account = Factory.build(:mock_provider_account)
> +    provider_account.credentials_hash = {'password' => "wrong_password"}
> +    provider_account.stub(:valid_credentials).and_raise("DeltacloudError")
> +    provider_account.save.should == false
> +    provider_account.errors[:base].should == [I18n.t('provider_accounts.errors.exception_while_validating')]
> +  end
> +
>    it "should fail to create a cloud account if fetching of hw profiles fails" do
>      provider_account = Factory.build(:mock_provider_account)
>      provider_account.stub(:populate_hardware_profiles).and_raise(ActiveRecord::RecordInvalid)
> -- 
> 1.7.6.5

I pushed this modified version of your patch.

My understanding from reviewing the BZ is that this patch improves
things, but that the BZ itself is not complete until an in-progress
Deltacloud patch lands as well. Ergo I haven't marked the BZ as modified
just yet, but let me know if I'm wrong for having not done so.

-- Matt



More information about the aeolus-devel mailing list