From: Jan Provaznik <jprovazn(a)redhat.com>
task #1623 (
https://www.aeolusproject.org/redmine/issues/1623)
---
.../controllers/provider_accounts_controller.rb | 5 ++
src/app/models/provider_account.rb | 2 +-
src/app/models/push_job.rb | 2 +-
src/features/provider_account.feature | 13 ++++++
.../step_definitions/provider_account_steps.rb | 44 ++++++++++++++++++++
5 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/src/app/controllers/provider_accounts_controller.rb
b/src/app/controllers/provider_accounts_controller.rb
index 9ae24c9..4dcd48d 100644
--- a/src/app/controllers/provider_accounts_controller.rb
+++ b/src/app/controllers/provider_accounts_controller.rb
@@ -13,6 +13,11 @@ class ProviderAccountsController < ApplicationController
end
@accounts = search.results
end
+
+ respond_to do |format|
+ format.html
+ format.xml { render :partial => 'list.xml' }
+ end
end
def show
diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb
index b1c1bb8..88ebe5b 100644
--- a/src/app/models/provider_account.rb
+++ b/src/app/models/provider_account.rb
@@ -183,7 +183,7 @@ class ProviderAccount < ActiveRecord::Base
element.content = h[:value]
credential_node << element
end
- doc.to_xml
+ doc
end
def creds_label_hash
diff --git a/src/app/models/push_job.rb b/src/app/models/push_job.rb
index e028b84..9983953 100644
--- a/src/app/models/push_job.rb
+++ b/src/app/models/push_job.rb
@@ -28,7 +28,7 @@ class PushJob < Struct.new(:provider_image_id, :hydra)
# TODO: what if a provider has multiple accounts
# for now pick first account
provider_account = provider_image.provider.provider_accounts.first
- cred_block = provider_account.build_credentials.html_safe
+ cred_block = provider_account.build_credentials.to_xml.html_safe
response =
RestClient.post(YAML.load_file("#{RAILS_ROOT}/config/image_factory_console.yml")['pushurl'],
:image_id => provider_image.image.uuid,
:provider => provider_image.provider.name,
:credentials => cred_block
diff --git a/src/features/provider_account.feature
b/src/features/provider_account.feature
index 3e6c8c9..97048b5 100644
--- a/src/features/provider_account.feature
+++ b/src/features/provider_account.feature
@@ -15,6 +15,19 @@ Feature: Manage Provider Accounts
Then I should see "New Account"
And there should be no provider accounts
+ Scenario: List providers in XML format
+ Given I accept XML
+ And there is ec2 provider account "ec2_account"
+ And there is mock provider account "mock_account"
+ When I go to the provider accounts page
+ Then I should get a XML document
+ And there should be these mock provider accounts:
+ | name | provider | provider_type | username | password |
+ | mock_account | provider1 | mock |||
+ And there should be these ec2 provider accounts:
+ | name | provider | provider_type | access_key | secret_access_key |
+ | ec2_account | amazon-ec2 | ec2 |||
+
Scenario: Create a new Provider Account
Given there is a provider named "testprovider"
And there are no provider accounts
diff --git a/src/features/step_definitions/provider_account_steps.rb
b/src/features/step_definitions/provider_account_steps.rb
index 2b6c49c..60fd8f4 100644
--- a/src/features/step_definitions/provider_account_steps.rb
+++ b/src/features/step_definitions/provider_account_steps.rb
@@ -51,3 +51,47 @@ Given /^that there are these provider accounts:$/ do |table|
Factory.create(:provider_account, :name => hash['name'], :username =>
hash['username'])
end
end
+
+Given /^there is ec2 provider account "([^"]*)"$/ do |arg1|
+ Factory(:ec2_provider_account, :label => arg1)
+end
+
+Given /^there is mock provider account "([^"]*)"$/ do |arg1|
+ Factory(:mock_provider_account, :label => arg1)
+end
+
+Then /^there should be these mock provider accounts:$/ do |table|
+ accounts = @xml_response.root.xpath('/provider_accounts/provider_account').map
do |n|
+ {:name => n.xpath('name').text,
+ :provider => n.xpath('provider').text,
+ :username => n.xpath('username').text,
+ :password => n.xpath('password').text,
+ :provider_type => n.xpath('provider_type').text}
+ end
+ table.hashes.each do |hash|
+ p = accounts.find {|n| n[:name] == hash[:name]}
+ p.should_not be_nil
+ p[:provider].should == hash[:provider]
+ p[:username].should == hash[:username]
+ p[:password].should == hash[:password]
+ p[:provider_type].should == hash[:provider_type]
+ end
+end
+
+Then /^there should be these ec2 provider accounts:$/ do |table|
+ accounts = @xml_response.root.xpath('/provider_accounts/provider_account').map
do |n|
+ {:name => n.xpath('name').text,
+ :provider => n.xpath('provider').text,
+ :access_key => n.xpath('access_key').text,
+ :secret_access_key => n.xpath('secret_access_key').text,
+ :provider_type => n.xpath('provider_type').text}
+ end
+ table.hashes.each do |hash|
+ p = accounts.find {|n| n[:name] == hash[:name]}
+ p.should_not be_nil
+ p[:provider].should == hash[:provider]
+ p[:access_key].should == hash[:access_key]
+ p[:secret_access_key].should == hash[:secret_access_key]
+ p[:provider_type].should == hash[:provider_type]
+ end
+end
--
1.7.4