[PATCH] adding audrey deployable compatibility test

Jan Provaznik jprovazn at redhat.com
Tue Jun 12 12:58:07 UTC 2012


On 06/11/2012 04:54 PM, Dan Radez wrote:
> On 06/11/2012 10:18 AM, Jan Provaznik wrote:
>> On 06/08/2012 09:19 PM, Matt Wagner wrote:
>>> On Fri, Jun 08, 2012 at 03:17:17PM -0400, Dan Radez wrote:
>>>> ---
>>>>    src/app/models/deployable.rb |   38
>>>> ++++++++++++++++++++++++++++++++++++++
>>>>    src/config/locales/en.yml    |    1 +
>>>>    2 files changed, 39 insertions(+)
>>>>
>>>> diff --git a/src/app/models/deployable.rb b/src/app/models/deployable.rb
>>>> index 7659688..68e8c4b 100644
>>>> --- a/src/app/models/deployable.rb
>>>> +++ b/src/app/models/deployable.rb
>>>> @@ -192,6 +192,8 @@ class Deployable<   ActiveRecord::Base
>>>>            deployable_errors<<   "#{assembly_hash[:name]}: " +
>>>> I18n.t('deployables.error.attribute_not_exist')
>>>>          end
>>>>          assemblies_array<<   assembly_hash
>>>> +      audrey_error = check_audrey_api_compatibility(image, assembly)
>>>> +      deployable_errors<<   "#{assembly_hash[:name]}: " +
>>>> audrey_error if not audrey_error.nil?
>>>>        end
>>>>        [assemblies_array, images, missing_images, deployable_errors]
>>>>      end
>>>> @@ -245,6 +247,42 @@ class Deployable<   ActiveRecord::Base
>>>>        warnings
>>>>      end
>>>>
>>>> +  def check_audrey_api_compatibility(image, assembly)
>>>> +    # get icicle for agent
>>>> +    icicle_uuid =
>>>> image.latest_pushed_or_unpushed_build.target_images.first.icicle
>>>> rescue nil
>>>> +    icicle = Aeolus::Image::Warehouse::Icicle.find(icicle_uuid) if
>>>> icicle_uuid
>>>> +    agent_v = icicle ? icicle.packages.find_all { |p| p =~
>>>> /aeolus-audrey-agent(.*)/ } : ""
>>>> +    agent_v = agent_v.first.split('-')[3] if agent_v.present?
>>>> +
>>>> +    # calculate audrey api version
>>>> +    audrey_api_v = if agent_v>= "0.5.0"
>>
>> agent_v can be empty array, then this raises an exception:
>> undefined method `>=' for []:Array
>>
>
>
> I think I'm expecting audrey_v to be a string. probably should rewrite
> agent_v = agent_v.first.split('-')[3] if agent_v.present?
>
> to
>
> agent_v = agent_v.present? ? agent_v.first.split('-')[3] : ""
>
>
> Thoughts about that?
> I'll have a patch ready to go.
>
> Dan
>


Maybe the code could be simplified by putting more logic into Icicle 
model (which is in aeolus-image-rubygem component):

diff --git a/lib/aeolus_image/model/warehouse/icicle.rb 
b/lib/aeolus_image/model/warehouse/icicle.rb
index 1a11da8..0e33ee0 100644
--- a/lib/aeolus_image/model/warehouse/icicle.rb
+++ b/lib/aeolus_image/model/warehouse/icicle.rb
@@ -18,6 +18,11 @@ module Aeolus
        class Icicle < WarehouseModel
          @bucket_name = 'icicles'

+        def audrey_version
+          packages.each { return $1 if p =~ /aeolus-audrey-agent-(.*)/ }
+          nil
+        end
+
          def packages
            unless @packages
              begin
diff --git a/lib/aeolus_image/model/warehouse/target_image.rb 
b/lib/aeolus_image/model/warehouse/target_image.rb
index 5e6b84c..f1cb9ec 100644
--- a/lib/aeolus_image/model/warehouse/target_image.rb
+++ b/lib/aeolus_image/model/warehouse/target_image.rb
@@ -22,6 +22,10 @@ module Aeolus
            ImageBuild.find(@build) if @build
          end

+        def icicle
+          Icicle.find(@icicle) if @icicle
+        end
+
          def provider_images
            ProviderImage.where("($target_image == \"" + @uuid.to_s + "\")")
          end

then agent_v variable can be set by:
-    # get icicle for agent
-    icicle_uuid = 
image.latest_pushed_or_unpushed_build.target_images.first.icicle rescue nil
-    icicle = Aeolus::Image::Warehouse::Icicle.find(icicle_uuid) if 
icicle_uuid
-    agent_v = icicle ? icicle.packages.find_all { |p| p =~ 
/aeolus-audrey-agent(.*)/ } : ""
-    agent_v = agent_v.first.split('-')[3] if agent_v.present?
+    agent_v = image.latest_pushed_or_unpushed_build.
+                target_images.first.icicle.audrey_version.to_s rescue ''


(Thought I didn't test the code above)

Jan



More information about the aeolus-devel mailing list