You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2011/10/10 19:26:41 UTC

svn commit: r1181084 - in /incubator/deltacloud/trunk: server/lib/deltacloud/drivers/mock/mock_driver.rb server/lib/deltacloud/hardware_profile.rb server/tests/drivers/mock/instances_test.rb tests/mock/hardware_profiles.feature

Author: mfojtik
Date: Mon Oct 10 17:26:41 2011
New Revision: 1181084

URL: http://svn.apache.org/viewvc?rev=1181084&view=rev
Log:
Core: Added validation for hardware profile properties type (Float, Fixnum)

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb
    incubator/deltacloud/trunk/server/tests/drivers/mock/instances_test.rb
    incubator/deltacloud/trunk/tests/mock/hardware_profiles.feature

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb?rev=1181084&r1=1181083&r2=1181084&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb Mon Oct 10 17:26:41 2011
@@ -55,7 +55,7 @@ module Deltacloud::Drivers::Mock
     end
 
     define_hardware_profile('m1-large') do
-      cpu                2
+      cpu                (1..6)
       memory           (7.5*1024 .. 15*1024), :default => 10 * 1024
       storage          [ 850, 1024 ]
       architecture     'x86_64'

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb?rev=1181084&r1=1181083&r2=1181084&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb Mon Oct 10 17:26:41 2011
@@ -69,6 +69,7 @@ module Deltacloud
       end
 
       def valid?(v)
+        v = convert_property_value_type(v)
         case kind
           # NOTE:
           # Currently we cannot validate fixed values because of UI
@@ -82,8 +83,8 @@ module Deltacloud
           #
           # when :fixed then (v == @default.to_s)
           when :fixed then true
-          when :range then ((first..last).include?(v.to_i))
-          when :enum then (values.include?(v.to_i))
+          when :range then match_type?(first, v) and (first..last).include?(v)
+          when :enum then match_type?(values.first, v) and values.include?(v)
           else false
         end
       end
@@ -99,6 +100,18 @@ module Deltacloud
           return values.include?(v)
         end
       end
+
+      private
+
+      def match_type?(reference, value)
+        true if reference.class == value.class
+      end
+
+      def convert_property_value_type(v)
+        return v.to_f if v =~ /(\d+)\.(\d+)/
+        return v.to_i if v =~ /(\d+)/
+        v.to_s
+      end
     end
 
     class << self

Modified: incubator/deltacloud/trunk/server/tests/drivers/mock/instances_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/drivers/mock/instances_test.rb?rev=1181084&r1=1181083&r2=1181084&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/drivers/mock/instances_test.rb (original)
+++ incubator/deltacloud/trunk/server/tests/drivers/mock/instances_test.rb Mon Oct 10 17:26:41 2011
@@ -114,9 +114,9 @@ module DeltacloudUnitTest
         :image_id => 'img1',
         :realm_id => '',
         :name => "unit_test_instance3",
-        :hwp_id => "m1-small",
-        :hwp_storage => '160',
-        :hwp_memory => '1740.8',
+        :hwp_id => "m1-large",
+        :hwp_storage => '850',
+        :hwp_memory => '7680.0',
         :hwp_cpu => "1.0",
       }
       post_url '/api/instances', params

Modified: incubator/deltacloud/trunk/tests/mock/hardware_profiles.feature
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/hardware_profiles.feature?rev=1181084&r1=1181083&r2=1181084&view=diff
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/hardware_profiles.feature (original)
+++ incubator/deltacloud/trunk/tests/mock/hardware_profiles.feature Mon Oct 10 17:26:41 2011
@@ -15,7 +15,7 @@ Feature: Accessing hardware profiles
     When client want to show 'm1-large' hardware_profile
     And client should get this hardware_profile
     And it should have a href attribute
-    And it should have a fixed property 'cpu'
+    And it should have a range property 'cpu'
     And it should have a range property 'memory'
     And it should have a enum property 'storage'
     And this URI should be available in XML, HTML, JSON format