From: martyntaylor <[email protected]>

---
 src/app/controllers/cloud_accounts_controller.rb |   40 +++++++++++-------
 src/app/controllers/provider_controller.rb       |   26 +++++++++---
 src/app/views/provider/accounts.haml             |   14 ++----
 src/app/views/provider/show.haml                 |    8 ++--
 src/features/provider.feature                    |   49 +++++++++++++++++++++-
 src/features/support/custom.rb                   |    3 -
 6 files changed, 102 insertions(+), 38 deletions(-)

diff --git a/src/app/controllers/cloud_accounts_controller.rb 
b/src/app/controllers/cloud_accounts_controller.rb
index f1c55b6..2b4686a 100644
--- a/src/app/controllers/cloud_accounts_controller.rb
+++ b/src/app/controllers/cloud_accounts_controller.rb
@@ -31,30 +31,40 @@ class CloudAccountsController < ApplicationController
   def create
     @provider = Provider.find(params[:cloud_account][:provider_id])
     require_privilege(Privilege::ACCOUNT_MODIFY,@provider)
-    if not params[:cloud_account][:x509_cert_priv_file].nil?
+    if (not params[:cloud_account][:x509_cert_priv_file].nil?) && 
params[:cloud_account][:x509_cert_priv_file] != ""
       params[:cloud_account][:x509_cert_priv] = 
params[:cloud_account][:x509_cert_priv_file].read
     end
     params[:cloud_account].delete :x509_cert_priv_file
-    if not params[:cloud_account][:x509_cert_pub_file].nil?
+    if (not params[:cloud_account][:x509_cert_pub_file].nil?) && 
params[:cloud_account][:x509_cert_pub_file] != ""
       params[:cloud_account][:x509_cert_pub] = 
params[:cloud_account][:x509_cert_pub_file].read
     end
     params[:cloud_account].delete :x509_cert_pub_file
     @cloud_account = CloudAccount.new(params[:cloud_account])
-    unless @cloud_account.valid_credentials?
-      flash[:notice] = "The entered credential information is incorrect"
-      redirect_to :controller => "provider", :action => "accounts", :id => 
@provider
+
+    if params[:test_account]
+      if @cloud_account.valid_credentials?
+        flash[:notice] = "Test Connection Success: Valid Account Details"
+      else
+        flash[:notice] = "Test Connection Failed: Invalid Account Details"
+      end
+      redirect_to :controller => "provider", :action => "accounts", :id => 
@provider, :cloud_account => params[:cloud_account]
     else
-      quota = Quota.new
-      quota.maximum_running_instances = 
quota_from_string(params[:quota][:maximum_running_instances])
-      quota.save!
-      @cloud_account.quota_id = quota.id
-      @cloud_account.zones << Zone.default
-      @cloud_account.save!
-      if request.post? && @cloud_account.save && @cloud_account.populate_realms
-        flash[:notice] = "Provider account added."
+      unless @cloud_account.valid_credentials?
+        flash[:notice] = "The entered credential information is incorrect"
+        redirect_to :controller => "provider", :action => "accounts", :id => 
@provider
+      else
+        quota = Quota.new
+        quota.maximum_running_instances = 
quota_from_string(params[:quota][:maximum_running_instances])
+        quota.save!
+        @cloud_account.quota_id = quota.id
+        @cloud_account.zones << Zone.default
+        @cloud_account.save!
+        if request.post? && @cloud_account.save && 
@cloud_account.populate_realms
+          flash[:notice] = "Provider account added."
+        end
+        redirect_to :controller => "provider", :action => "accounts", :id => 
@provider
+        kick_condor
       end
-      redirect_to :controller => "provider", :action => "accounts", :id => 
@provider
-      kick_condor
     end
   end
 
diff --git a/src/app/controllers/provider_controller.rb 
b/src/app/controllers/provider_controller.rb
index 5e4d32c..fa266c8 100644
--- a/src/app/controllers/provider_controller.rb
+++ b/src/app/controllers/provider_controller.rb
@@ -53,14 +53,24 @@ class ProviderController < ApplicationController
   def create
     require_privilege(Privilege::PROVIDER_MODIFY)
     @provider = Provider.new(params[:provider])
-    if @provider.set_cloud_type && @provider.save &&
-      @provider.populate_hardware_profiles
-        flash[:notice] = "Provider added."
-        redirect_to :action => "show", :id => @provider
+    if params[:test_connection]
+      if @provider.connect
+        flash[:notice] = "Successfuly Connected to Provider"
+      else
+        flash[:notice] = "Failed to Connect to Provider"
+      end
+      provider_hash = {:name => @provider.name, :url => @provider.url}
+      redirect_to :action => "new", :provider => provider_hash
     else
-      render :action => "new"
+      if @provider.set_cloud_type && @provider.save &&
+        @provider.populate_hardware_profiles
+          flash[:notice] = "Provider added."
+          redirect_to :action => "show", :id => @provider
+      else
+        render :action => "new"
+      end
+      kick_condor
     end
-    kick_condor
   end
 
   def update
@@ -102,6 +112,10 @@ class ProviderController < ApplicationController
   def accounts
     @provider = Provider.find(:first, :conditions => {:id => params[:id]})
     require_privilege(Privilege::ACCOUNT_VIEW, @provider)
+    if params[:cloud_account]
+      @cloud_account = CloudAccount.new(params[:cloud_account])
+      @quota = Quota.new(params[:quota])
+    end
   end
 
   def realms
diff --git a/src/app/views/provider/accounts.haml 
b/src/app/views/provider/accounts.haml
index d2b979e..eb5c9dc 100644
--- a/src/app/views/provider/accounts.haml
+++ b/src/app/views/provider/accounts.haml
@@ -62,10 +62,7 @@
           %a.button{ :href => remove_path, :name => "remove_acc_#{acct.id}", 
:class => "tiny #{'disabled' unless remove_path}" }
             = t(:remove)
           %span
-            &nbsp; (
-            %a{ :href => '' }<>
-              = t('.test_account')
-            )
+            %input{ :type => 'submit', :value => t('.test_account'), :name => 
'test_account', :id => 'test_account', :class => 'submit linkbutton' }
       %fieldset.clearfix.gap
         = submit_tag t(:reset), :name => 'reset_form', :class => 
"dialogbutton" unless @provider.cloud_accounts.empty?
         = submit_tag t(:save), :name => 'update_cloud_accounts', :class => 
"dialogbutton" unless @provider.cloud_accounts.empty?
@@ -117,11 +114,10 @@
         = file_field :cloud_account, :x509_cert_pub_file, :title => 
t('.account_public_cert')
       - remove_path = url_for :controller => 'cloud_accounts', :action => 
'destroy'
       .grid_3.omega
-        %span
-          (
-          %a{ :href => '' }<>
-            = t('.test_account')
-          )
+        (              (
+        %button.linkbutton.nospace{ :type => 'submit', :value => 
t('.test_account'), :name => 'test_account', :id => 'test_account' }<>
+          = t('.test_account')
+        )
     %fieldset.clearfix
       .grid_13.alpha.omega
         = submit_tag t(:add), :class => "ra nomargin dialogbutton"
diff --git a/src/app/views/provider/show.haml b/src/app/views/provider/show.haml
index 81e556b..70b5df8 100644
--- a/src/app/views/provider/show.haml
+++ b/src/app/views/provider/show.haml
@@ -27,10 +27,10 @@
         = hidden_field :provider, :id, :value => @provider.id
       .clear.prefix_4.grid_5.suffix_4.alpha.omega
         %span
-          (
-          %a{ :href => ''}<>
-            = t('.test_connection')
-          )
+        (
+        %button.linkbutton.nospace{ :type => 'submit', :value => 
t('.test_connection'), :name => 'test_connection', :id => 'test_connection' }<>
+          = t('.test_connection')
+        )
     - unless readonly
       %p.requirement
         %span.required
diff --git a/src/features/provider.feature b/src/features/provider.feature
index a544361..c332667 100644
--- a/src/features/provider.feature
+++ b/src/features/provider.feature
@@ -26,7 +26,6 @@ Feature: Manage Providers
     When I follow "testprovider"
     Then I should see "Provider Name"
     And I should see "Provider URL"
-    And I should see "Test Connection"
 
   Scenario: Create a new Provider
     Given I am on the providers page
@@ -39,3 +38,51 @@ Feature: Manage Providers
     Then I should be on the show provider page
     And I should see "Provider added"
     And I should have a provider named "testprovider"
+
+  Scenario: Test Provider Connection Successful
+    Given I am on the providers page
+    When I press "Add"
+    Then I should be on the new 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 providers page
+    When I press "Add"
+    Then I should be on the new 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"
+
+  Scenario: Test Account Connection Success
+    Given I am on the homepage
+    And there are these providers:
+    | name      |
+    | provider1 |
+    When I go to the providers page
+    And I follow "provider1"
+    And I follow "Provider Accounts"
+    And I fill in "cloud_account[label]" with "MockAccount"
+    And I fill in "cloud_account[username]" with "mockuser"
+    And I fill in "cloud_account[password]" with "mockpassword"
+    And I fill in "cloud_account[account_number]" with "12345678"
+    And I press "test_account"
+    Then I should see "Test Connection Success: Valid Account Details"
+
+  Scenario: Test Account Connection Failure
+    Given I am on the homepage
+    And there are these providers:
+    | name      |
+    | provider1 |
+    When I go to the providers page
+    And I follow "provider1"
+    And I follow "Provider Accounts"
+    And I fill in "cloud_account[label]" with "IncorrectAccount"
+    And I fill in "cloud_account[username]" with "incorrect_user"
+    And I fill in "cloud_account[password]" with "incorrect_password"
+    And I fill in "cloud_account[account_number]" with "12345678"
+    And I press "test_account"
+    Then I should see "Test Connection Failed: Invalid Account Details"
\ No newline at end of file
diff --git a/src/features/support/custom.rb b/src/features/support/custom.rb
index 46c618e..6e4e1ef 100644
--- a/src/features/support/custom.rb
+++ b/src/features/support/custom.rb
@@ -28,9 +28,6 @@ Provider.class_eval do
 end
 
 CloudAccount.class_eval do
-  def valid_credentials?
-    true
-  end
   
   alias :generate_cloud_account_key_original :generate_cloud_account_key 
 
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to