ACK
The commit message probably needs some updating -- I expect you wrote this just as a message for anyone testing this.
It worked for me in that it did the push correctly.
I still can't create any instances as the provider_image.provider_image_key value is not being set correctly, but that's a different issue and probably deserves its own patch.
Thomas
On 03/21/2011 10:37 PM, Jason Guiditta wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=688924
To try this out, you will need a successful build of a base image sitting in your conductor setup. In the UI, this will likely be a bullet under builds with a 'completed' and the a second line beneathe it with nothing. Spin up the rails console for your env, likely prod (src/script/console) and find the ec2 Image. Assuming an id of 5: i=Image.find(5) i.provider_images.each{|k| k.destroy} i=Image.find(5) i.status="anything" i.save i.status="complete" i.save
This should kick off another attempt at a push.
aeolus-conductor.spec.in | 1 + .../image_factory_connector.rb | 2 + .../image_factory_connector/spec/connector_spec.rb | 9 +++- src/app/models/provider_account.rb | 2 +- src/app/models/push_job.rb | 58 +++++++------------- src/config/environment.rb | 1 + src/spec/factories/push_job.rb | 4 -- src/spec/models/provider_account_spec.rb | 2 +- src/spec/models/push_job_spec.rb | 6 ++- 9 files changed, 40 insertions(+), 45 deletions(-)
diff --git a/aeolus-conductor.spec.in b/aeolus-conductor.spec.in index 73c46d0..96744e0 100644 --- a/aeolus-conductor.spec.in +++ b/aeolus-conductor.spec.in @@ -27,6 +27,7 @@ Requires: rubygem(compass) Requires: rubygem(compass-960-plugin) Requires: rubygem(simple-navigation) Requires: rubygem(typhoeus) +Requires: rubygem(rest-client) Requires: rubygem(rb-inotify) Requires: rubygem(builder) Requires: rubygem(json) diff --git a/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb b/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb index ce7446e..98a7a32 100644 --- a/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb +++ b/services/image_factory/image_factory_connector/lib/image_factory_connector/image_factory_connector.rb @@ -60,11 +60,13 @@ class ImageFactoryConnector< Sinatra::Base end
post "/build" do
puts "build method called with #{params.inspect}" @b=settings.console.build_image("#{params[:template]}", "#{params[:target]}") builder :image end
post "/push" do
puts "push method called with #{params.inspect}" @b=settings.console.push_image("#{params[:image_id]}", "#{params[:provider]}", "#{params[:credentials]}") builder :image end
diff --git a/services/image_factory/image_factory_connector/spec/connector_spec.rb b/services/image_factory/image_factory_connector/spec/connector_spec.rb index bbf10c9..44badef 100644 --- a/services/image_factory/image_factory_connector/spec/connector_spec.rb +++ b/services/image_factory/image_factory_connector/spec/connector_spec.rb @@ -53,6 +53,14 @@ describe 'image_factory_connector app' do last_response.body.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<image>\n<uuid>#{@b.image_id}</uuid>\n</image>\n" end
- it 'receives complex xml properly' do
- creds="<?xml version=\"1.0\"?>\n<provider_credentials>\n<ec2_credentials>\n<account_number>1234-5678-9150</account_number>\n<access_key>BLAHBLAHBLAH</access_key>\n<secret_access_key>FROBNOSTICATOR</secret_access_key>\n<certificate>-----BEGIN CERTIFICATE-----\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\n-----END CERTIFICATE-----\n</certificate>\n<key>-----BEGIN PRIVATE KEY-----
\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\n5F4VAX2kWheWeepocDVyrHak+CMQ7vnWPgdio8d9Q+va5v+rU2NhPluXtXVOGqSqXmE7HvVhR4i0
\nKJHKEL5748CBSIODF4T789JGLS47DFGHS\n-----END PRIVATE KEY-----</key>\n</ec2_credentials>\n</provider_credentials>\n"
- provider="ec2-us-east-1"
- uuid="6669978e-97a3-4381-92cb-2fbc160b49c7"
- app.console.stub!(:push_image).and_return(@b)
- post 'push', {:image_id => uuid, :provider => provider, :credentials => creds}
- last_response.body.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<image>\n<uuid>#{@b.image_id}</uuid>\n</image>\n"
- end it 'calls the console push_image method and returns xml response with uuid' do app.console.stub(:push_image).and_return(@b) post 'push', {:image_id => @b.image_id, :provider => 'mock', :credentials => 'some creds'}
@@ -76,5 +84,4 @@ describe 'image_factory_connector app' do last_response.should be_ok last_response.body.should == "Console connection closed" end
- end
diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb index 6ed677b..ce67a51 100644 --- a/src/app/models/provider_account.rb +++ b/src/app/models/provider_account.rb @@ -198,7 +198,7 @@ EOT node.at_xpath('./secret_access_key').content = password node.at_xpath('./certificate').content = x509_cert_pub node.at_xpath('./key').content = x509_cert_priv
- return xml.to_s
xml end
def generate_auth_key
diff --git a/src/app/models/push_job.rb b/src/app/models/push_job.rb index 50f0d53..9983953 100644 --- a/src/app/models/push_job.rb +++ b/src/app/models/push_job.rb @@ -16,7 +16,7 @@ # MA 02110-1301, USA. A copy of the GNU General Public License is # also available at http://www.gnu.org/copyleft/gpl.html.
-require 'typhoeus' +require 'rest_client' require 'nokogiri'
class PushJob< Struct.new(:provider_image_id, :hydra) @@ -24,43 +24,27 @@ class PushJob< Struct.new(:provider_image_id, :hydra) @logger = Delayed::Worker.logger @logger.info "--- start ---" @logger.info "PushJob for provider_image_id: #{provider_image_id}"
- begin
@hydra = hydra
if (@hydra == nil)
@hydra = Typhoeus::Hydra.new
end
provider_image = ProviderImage.find(provider_image_id)
# TODO: what if a provider has multiple accounts
# for now pick first account
provider_account = provider_image.provider.provider_accounts.first
request = Typhoeus::Request.new(YAML.load_file("#{RAILS_ROOT}/config/image_factory_console.yml")['pushurl'],
:method => :post,
:timeout => 60*1000, # in milliseconds
:params => {
:image_id => provider_image.image.uuid,
:provider => provider_image.provider.name,
:credentials => provider_account.build_credentials
})
request.on_complete do |response|
if response.success?
@logger.info "success "
xml = Nokogiri::XML(response.body)
@return_uuid = xml.xpath('//image/uuid').first.text
provider_image.uuid = @return_uuid
provider_image.save
@logger.info "uuid: #{@return_uuid}"
else
@logger.error "failure"
@logger.error response.body
end
end
@hydra.queue(request)
@hydra.run
- rescue Exception => e
@logger.error "Exception: "
@logger.error e
- provider_image = ProviderImage.find(provider_image_id)
- # 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.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
)
- if response.code==200
@logger.info "success "
xml = Nokogiri::XML(response.body)
@return_uuid = xml.xpath('//image/uuid').first.text
provider_image.uuid = @return_uuid
provider_image.save
@logger.info "uuid: #{@return_uuid}"
- else
@logger.error "failure"
@logger.error response.body
# TODO: raise an error and capture it somewhere end
- @logger.info "--- done ---" @return_uuid end end
diff --git a/src/config/environment.rb b/src/config/environment.rb index 22300a2..0b08e04 100644 --- a/src/config/environment.rb +++ b/src/config/environment.rb @@ -51,6 +51,7 @@ Rails::Initializer.run do |config| config.gem "compass-960-plugin", :lib => "ninesixty" config.gem "simple-navigation" config.gem "typhoeus"
- config.gem 'rest-client', :version => '>= 1.6.1' config.gem "rb-inotify" config.gem 'rack-restful_submit', :version => '1.1.2' config.gem 'sunspot_rails', :lib => 'sunspot/rails'
diff --git a/src/spec/factories/push_job.rb b/src/spec/factories/push_job.rb index b3d82f0..7110339 100644 --- a/src/spec/factories/push_job.rb +++ b/src/spec/factories/push_job.rb @@ -1,7 +1,3 @@ Factory.define :push_job do |p|
- hydra = Typhoeus::Hydra.new
- response = Typhoeus::Response.new(:code => 200, :headers => "", :body => "<?xml version="1.0" encoding="UTF-8"><image><uuid>push-job-stub-uuid</uuid></image>", :time => 0.1)
- hydra.stub(:post, YAML.load_file("#{RAILS_ROOT}/config/image_factory_console.yml")['pushurl']).and_return(response) p.provider_image_id { Factory.create(:provider_image, :provider => Factory.create(:mock_provider_account).provider).id }
- p.hydra hydra end
diff --git a/src/spec/models/provider_account_spec.rb b/src/spec/models/provider_account_spec.rb index 09cf674..943bee9 100644 --- a/src/spec/models/provider_account_spec.rb +++ b/src/spec/models/provider_account_spec.rb @@ -76,6 +76,6 @@ EOT :x509_cert_priv => 'priv_key', :x509_cert_pub => 'cert' )
- provider_account.build_credentials.should eql(expected_xml)
- provider_account.build_credentials.to_s.should eql(expected_xml) end end
diff --git a/src/spec/models/push_job_spec.rb b/src/spec/models/push_job_spec.rb index 48348e7..c4fb9e5 100644 --- a/src/spec/models/push_job_spec.rb +++ b/src/spec/models/push_job_spec.rb @@ -2,8 +2,12 @@ require 'spec_helper'
describe PushJob do it "should match request and parse stubbed xml" do
- image_id="6669978e-97a3-4381-92cb-2fbc160b49c7"
- response = RestClient::Response.create("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<image>\n<uuid>#{image_id}</uuid>\n</image>\n", 200, {})
- response.stub(:code).and_return(200)
- RestClient.stub(:post).and_return(response) job = Factory.build(:push_job) uuid = job.perform
- uuid.should == "push-job-stub-uuid"
- uuid.should == image_id end end