As noted in the subject, this is not the complete fix (no tests, updated
deps, etc), but in local testing, this general changed worked for me.
It seems that typhoeus was not handling the xml properly, even when I tried
to send it as html_safe, so I tried rest_client, which worked out of the box.
If anyone want to give this a go, you may need a little tweaking, but manually
runnning the RestClient command in this patch in a nearly identical
configuration (just not in the job or with the response block) successfully sent
the request to the connecotr, whereas the typhoeus version did nothing.
To try this out, you will need a successful build of a base image sitting in your
conductor setup. In the UI, this will like be a bullet under builds with a
'completed'
and the a second line beneather it with nothing. Spin up the rails console for your
env, likely prod (src/script/console) and fine 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.
I have included a puts in the push method of the connector, just to make it easier
to see that it was called. If this nominally work for someone early monday, I'll
clean it up when I get in, add deps, tests, etc.
-j
---
.../image_factory_connector.rb | 4 +-
src/app/models/provider_account.rb | 2 +-
src/app/models/push_job.rb | 56 +++++++------------
3 files changed, 25 insertions(+), 37 deletions(-)
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..af83be5 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,12 +60,14 @@ 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
- @b=settings.console.push_image("#{params[:image_id]}",
"#{params[:provider]}", "#{params[:credentials]}")
+ 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/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..9b2d798 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,29 @@ 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 => {
+ 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
+ RestClient.post('http://localhost:2003/push', :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
+ :credentials => cred_block
+ }) {|response, request, result, block|
+ case response.code
+ when 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
end
- @hydra.queue(request)
- @hydra.run
- rescue Exception => e
- @logger.error "Exception: "
- @logger.error e
- end
- @logger.info "--- done ---"
+ }
@return_uuid
end
end
--
1.7.4