[PATCH conductor] Image building compatible with ActiveResource 3.2

jstransk at redhat.com jstransk at redhat.com
Mon Aug 20 15:52:32 UTC 2012


From: Jiri Stransky <jstransk at redhat.com>

Right now we have ActiveResource 3.2 in our Gemfile.lock, but Conductor
was not compatible with it. Building images did not work. This commit
fixes it.

When doing:

    image = Aeolus::Image::Factory::Image.new(:id => some_id)
    image.save!

ActiveResource 3.0 would make a PUT request to
.../images/some_id
but ActiveResource >= 3.1 would make a POST request to
.../images

This caused miscommunication between Conductor and ImageFactory when
using ActiveResource 3.2. The image that we wanted to build would remain
untouched (without any build or target image linked to it), but a new,
redundant image would be created and built. After this commit everything
works fine.

Unfortunately, there does not seem to be a way to fix this without
explicitly asking for ActiveResource version (as long as we want to
support both ActiveResource 3.0 and 3.2 at the same time). After
ActiveResource 3.0 is obsoleted from Conductor, we can remove the
version check and use the code for 3.2.
---
 src/app/controllers/api/images_controller.rb    | 10 +++++++++-
 src/app/controllers/images_controller.rb        | 11 ++++++++++-
 src/app/controllers/target_images_controller.rb | 14 ++++++++++++--
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/app/controllers/api/images_controller.rb b/src/app/controllers/api/images_controller.rb
index 332e873..b72092e 100644
--- a/src/app/controllers/api/images_controller.rb
+++ b/src/app/controllers/api/images_controller.rb
@@ -89,7 +89,15 @@ module Api
             :template => @tpl.uuid,
             :environment => @pool_family.name
           })
-          @image = Aeolus::Image::Factory::Image.new(:id => iwhd_image.id)
+
+          # TODO: Remove the 'else' branch when ActiveResource 3.0 is obsoleted
+          @image = if ActiveResource::VERSION::MAJOR >= 3 &&
+                      ActiveResource::VERSION::MINOR >= 1
+            Aeolus::Image::Factory::Image.new({ :id => iwhd_image.id },
+                                              true) # persisted
+          else
+            Aeolus::Image::Factory::Image.new(:id => iwhd_image.id)
+          end
           @image.targets = req[:params][:targets]
           @image.template = req[:params][:template]
           @image.save!
diff --git a/src/app/controllers/images_controller.rb b/src/app/controllers/images_controller.rb
index d9ab289..d5d2e01 100644
--- a/src/app/controllers/images_controller.rb
+++ b/src/app/controllers/images_controller.rb
@@ -122,7 +122,16 @@ class ImagesController < ApplicationController
     check_permissions
     targets = @environment.build_targets
     unless targets.empty?
-      factory_image = Aeolus::Image::Factory::Image.new(:id => @image.id)
+
+      # TODO: Remove the 'else' branch when ActiveResource 3.0 is obsoleted
+      factory_image = if ActiveResource::VERSION::MAJOR >= 3 &&
+                         ActiveResource::VERSION::MINOR >= 1
+        Aeolus::Image::Factory::Image.new({ :id => @image.id },
+                                          true) # persisted
+      else
+        Aeolus::Image::Factory::Image.new(:id => @image.id)
+      end
+
       factory_image.targets = targets.join(',')
       factory_image.template = @image.template_xml.to_s
       factory_image.save!
diff --git a/src/app/controllers/target_images_controller.rb b/src/app/controllers/target_images_controller.rb
index a647315..90a19c1 100644
--- a/src/app/controllers/target_images_controller.rb
+++ b/src/app/controllers/target_images_controller.rb
@@ -23,12 +23,22 @@ class TargetImagesController < ApplicationController
     require_privilege(Privilege::USE, @environment)
 
     begin
-      timage = Aeolus::Image::Factory::Image.new(
+      timage_params = {
         :id => params[:image_id],
         :template => wh_image.template_xml.to_s,
         :build_id => params[:build_id],
         :targets => params[:target]
-      )
+      }
+
+      # TODO: Remove the 'else' branch when ActiveResource 3.0 is obsoleted
+      timage = if ActiveResource::VERSION::MAJOR >= 3 &&
+                  ActiveResource::VERSION::MINOR >= 1
+        Aeolus::Image::Factory::Image.new(timage_params,
+                                          true) # persisted
+      else
+        Aeolus::Image::Factory::Image.new(timage_params)
+      end
+
       timage.save!
     rescue
       logger.error $!.message
-- 
1.7.11.4




More information about the aeolus-devel mailing list