Added Test button in Provider Properties tab.
---
.../admin/provider_accounts_controller.rb | 12 +-----
src/app/controllers/admin/providers_controller.rb | 43 +++++++++++---------
.../admin/provider_accounts/_provider_form.haml | 6 ---
src/app/views/admin/providers/_form.haml | 4 --
src/app/views/admin/providers/_properties.haml | 1 +
src/features/provider.feature | 20 +++------
src/features/provider_account.feature | 23 ++++-------
.../provider_accounts_controller_spec.rb | 9 ----
8 files changed, 41 insertions(+), 77 deletions(-)
diff --git a/src/app/controllers/admin/provider_accounts_controller.rb
b/src/app/controllers/admin/provider_accounts_controller.rb
index 49fced8..6835432 100644
--- a/src/app/controllers/admin/provider_accounts_controller.rb
+++ b/src/app/controllers/admin/provider_accounts_controller.rb
@@ -57,15 +57,10 @@ class Admin::ProviderAccountsController < ApplicationController
@provider_account.provider = @provider
@provider_account.quota = @quota = Quota.new
- if params.delete :test_account
- test_account(@provider_account)
- render :action => 'new' and return
- end
-
limit = params[:quota][:maximum_running_instances] if params[:quota]
@provider_account.quota.set_maximum_running_instances(limit)
- if @provider_account.invalid?
+ if @provider_account.invalid? || !(a)provider_account.valid_credentials?
flash[:error] = "Credentials are invalid!"
render :action => 'new' and return
end
@@ -96,11 +91,6 @@ class Admin::ProviderAccountsController < ApplicationController
@quota = @provider_account.quota
@providers = Provider.find(:all)
- if params.delete :test_account
- test_account(@provider_account)
- render :action => 'edit' and return
- end
-
limit = params[:quota][:maximum_running_instances] if params[:quota]
@provider_account.quota.set_maximum_running_instances(limit)
if @provider_account.update_attributes(params[:provider_account])
diff --git a/src/app/controllers/admin/providers_controller.rb
b/src/app/controllers/admin/providers_controller.rb
index 3f4e289..8a7c0c8 100644
--- a/src/app/controllers/admin/providers_controller.rb
+++ b/src/app/controllers/admin/providers_controller.rb
@@ -37,6 +37,11 @@ class Admin::ProvidersController < ApplicationController
require_privilege(Privilege::VIEW, @provider)
@tab_captions = ['Properties', 'HW Profiles', 'Realms',
'Provider Accounts', 'Services','History','Permissions']
@details_tab = params[:details_tab].blank? ? 'properties' :
params[:details_tab]
+
+ if params.delete :test_provider
+ test_connection(@provider)
+ end
+
respond_to do |format|
format.js do
if @url_params.delete :details_pane
@@ -56,9 +61,9 @@ class Admin::ProvidersController < ApplicationController
params[:provider][:provider_type_id] = provider_type.id
end
@provider = Provider.new(params[:provider])
- if params[:test_connection]
- test_connection(@provider)
- render :action => 'new'
+ if !(a)provider.connect
+ flash[:notice] = "Failed to connect to Provider"
+ render :action => "new"
else
if @provider.save && @provider.populate_hardware_profiles
@provider.assign_owner_roles(current_user)
@@ -73,22 +78,22 @@ class Admin::ProvidersController < ApplicationController
end
def update
- @provider = Provider.find_by_id(params[:id])
- require_privilege(Privilege::MODIFY, @provider)
- @provider.update_attributes(params[:provider])
- if params[:test_connection]
- test_connection(@provider)
- render :action => 'edit'
- else
- if @provider.errors.empty? and @provider.save
- flash[:notice] = "Provider updated."
- redirect_to admin_providers_path
- else
- flash[:notice] = "Cannot update the provider."
- render :action => 'edit'
- end
- kick_condor
- end
+ @provider = Provider.find_by_id(params[:id])
+ require_privilege(Privilege::MODIFY, @provider)
+ @provider.update_attributes(params[:provider])
+ if !(a)provider.connect
+ flash[:notice] = "Failed to connect to Provider"
+ render :action => "edit"
+ else
+ if @provider.errors.empty? and @provider.save
+ flash[:notice] = "Provider updated."
+ redirect_to admin_providers_path
+ else
+ flash[:notice] = "Cannot update the provider."
+ render :action => 'edit'
+ end
+ end
+ kick_condor
end
def multi_destroy
diff --git a/src/app/views/admin/provider_accounts/_provider_form.haml
b/src/app/views/admin/provider_accounts/_provider_form.haml
index d4c1462..182fc36 100644
--- a/src/app/views/admin/provider_accounts/_provider_form.haml
+++ b/src/app/views/admin/provider_accounts/_provider_form.haml
@@ -21,12 +21,6 @@
)
%fieldset.clear
-.grid_3.omega
- (
- %button.linkbutton.nospace{ :type => 'submit', :value =>
t('provider_accounts.form.test_account'), :name => 'test_account', :id
=> 'test_account' }<>
- = t('provider_accounts.form.test_account')
- )
-
:javascript
function set_unlimited_quota(elem_id) {
$("#" + elem_id)[0].value = "unlimited";
diff --git a/src/app/views/admin/providers/_form.haml
b/src/app/views/admin/providers/_form.haml
index df888dc..b400d00 100644
--- a/src/app/views/admin/providers/_form.haml
+++ b/src/app/views/admin/providers/_form.haml
@@ -7,10 +7,6 @@
%fieldset.clear
= form.label :url, 'Provider URL :'
= form.text_field :url, :title => 'provider_url', :value =>
@provider.url, :class => "grid_5"
- (
- %button.linkbutton.nospace{ :type => 'submit', :value =>
t('.test_connection'), :name => 'test_connection', :id =>
'test_connection' }
- Test connection
- )
%fieldset.clear
= form.label :provider_type
= form.select(:provider_type_id, ProviderType.all.collect {|provider_type|
[provider_type.name,provider_type.id] }, :prompt => "Select type of
provider")
diff --git a/src/app/views/admin/providers/_properties.haml
b/src/app/views/admin/providers/_properties.haml
index 163401e..044895a 100644
--- a/src/app/views/admin/providers/_properties.haml
+++ b/src/app/views/admin/providers/_properties.haml
@@ -2,3 +2,4 @@
Properties for
= @provider.name
= link_to "Edit", edit_admin_provider_path(@provider), {:class =>
'button'}
+= link_to "Test", admin_provider_path(@provider, {:test_provider => true}),
{ :class => 'button' }
diff --git a/src/features/provider.feature b/src/features/provider.feature
index 4b6c50c..34ab613 100644
--- a/src/features/provider.feature
+++ b/src/features/provider.feature
@@ -40,23 +40,17 @@ Feature: Manage Providers
And I should see "Provider added"
And I should have a provider named "testprovider"
- Scenario: Test Provider Connection Successful
+ Scenario: Create a new Provider failure when using wrong url
Given I am on the admin providers page
+ And there is not a provider named "testprovider"
When I follow "Create"
Then I should be on the new admin provider page
When I fill in "provider[name]" with "testprovider"
- And I fill in "provider[url]" with "http://localhost:3001/api"
- And I press "test_connection"
- Then I should see "Successfuly Connected to Provider"
-
- Scenario: Test Provider Connection Failure
- Given I am on the admin providers page
- When I follow "Create"
- Then I should be on the new admin provider page
- When I fill in "provider[name]" with "incorrect_provider"
- And I fill in "provider[url]" with
"http://incorrecthost:3001/api"
- And I press "test_connection"
- Then I should see "Failed to Connect to Provider"
+ And I fill in "provider[url]" with "http://localhost:3010/api"
+ And I select "Amazon EC2" from "provider_provider_type_id"
+ And I press "Save"
+ Then I should be on the admin providers page
+ And I should see "Failed to connect to Provider"
Scenario: Delete a provider
Given I am on the homepage
diff --git a/src/features/provider_account.feature
b/src/features/provider_account.feature
index 1702e8f..b4ce54a 100644
--- a/src/features/provider_account.feature
+++ b/src/features/provider_account.feature
@@ -33,27 +33,20 @@ Feature: Manage Provider Accounts
And I should see "Properties for testaccount"
And I should see "Running instances quota: 13"
- Scenario: Test Provider Account Connection Successful
- Given there is a provider named "testprovider"
- And there are no provider accounts
- And I am on the admin provider accounts page
- When I follow "New Account"
- Then I should be on the new admin provider account page
- When I fill in "provider_account[credentials_hash][username]" with
"mockuser"
- And I fill in "provider_account[credentials_hash][password]" with
"mockpassword"
- And I press "Test Account"
- Then I should see "Test Connection Success"
-
- Scenario: Test Provider Account Connection Failure
+ Scenario: Create a new Provider Account using wrong credentials
Given there is a provider named "testprovider"
And there are no provider accounts
And I am on the admin provider accounts page
When I follow "New Account"
Then I should be on the new admin provider account page
+ And I should see "New Account"
+ When I select "testprovider" from "provider_account_provider_id"
+ And I fill in "provider_account[label]" with "testaccount"
When I fill in "provider_account[credentials_hash][username]" with
"mockuser"
- And I fill in "provider_account[credentials_hash][password]" with
"wrong password"
- And I press "Test Account"
- Then I should see "Test Connection Failed"
+ And I fill in "provider_account[credentials_hash][password]" with
"wrongpassword"
+ And I fill in "quota[maximum_running_instances]" with "13"
+ And I press "Add"
+ Then I should see "Credentials are invalid!"
Scenario: Delete a provider account
Given there is a provider named "testprovider"
diff --git a/src/spec/controllers/provider_accounts_controller_spec.rb
b/src/spec/controllers/provider_accounts_controller_spec.rb
index 5327548..c6887cf 100644
--- a/src/spec/controllers/provider_accounts_controller_spec.rb
+++ b/src/spec/controllers/provider_accounts_controller_spec.rb
@@ -21,15 +21,6 @@ describe Admin::ProviderAccountsController do
response.should render_template("index")
end
- it "allows test account validity on create when passing test_account param"
do
- UserSession.create(@admin)
- @provider_account.credentials_hash = {}
- post :create, :provider_account => {:provider_id => @provider.id},
:test_account => true
- response.should be_success
- response.should render_template("new")
- response.flash[:error].should == "Test Connection Failed: Invalid Account
Details"
- end
-
it "doesn't allow to save provider's account if not valid
credentials" do
UserSession.create(@admin)
post :create, :provider_account => {:provider_id => @provider.id}
--
1.7.4