From: Tomas Sedovic <tsedovic(a)redhat.com>
When an instance was being launched, there was a problem when its hardware
profile contained `nil` value for the `enum` type.
`nil` in that context means "match anything", so that's what it does now.
---
src/app/models/hardware_profile.rb | 15 ++++++++++++---
src/spec/models/hardware_profile_spec.rb | 9 +++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index 57d5fd8..2dde0ba 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -150,7 +150,7 @@ class HardwareProfile < ActiveRecord::Base
matched_hwp = hwp
end
when "enum"
- values = create_array_from_property(hwp.memory.to_s).sort
+ values = create_array_from_property(hwp.memory.to_s)
if BigDecimal.new(value.last) < BigDecimal.new(value.to_s)
value = values.last
matched_hwp = hwp
@@ -177,7 +177,15 @@ class HardwareProfile < ActiveRecord::Base
when "range"
return front_end_property.value
when "enum"
- create_array_from_property(back_end_property).sort!.each do |value|
+ backend_values = create_array_from_property(back_end_property)
+ if front_end_property.value.nil?
+ if back_end_property.value.blank?
+ return backend_values.first
+ else
+ return back_end_property.value
+ end
+ end
+ backend_values.each do |value|
if BigDecimal.new(value) >= BigDecimal.new(front_end_property.value)
return value
end
@@ -235,7 +243,8 @@ class HardwareProfile < ActiveRecord::Base
return [p.value]
when 'enum'
- return p.property_enum_entries.map { |enum| enum.value }
+ backend_values = p.property_enum_entries.map { |enum| enum.value }
+ return backend_values.sort {|a,b| BigDecimal.new(a) <=> BigDecimal.new(b) }
end
end
diff --git a/src/spec/models/hardware_profile_spec.rb
b/src/spec/models/hardware_profile_spec.rb
index 7e3fa79..2ff5d93 100644
--- a/src/spec/models/hardware_profile_spec.rb
+++ b/src/spec/models/hardware_profile_spec.rb
@@ -133,6 +133,15 @@ describe HardwareProfile do
HardwareProfile.generate_override_property_value(front_end_cpu, back_end_cpu).should
== '2'
end
+ it "should generate override property values for nil frontend values" do
+ front_end_storage = FactoryGirl.create(:hwpp_fixed, :name => 'storage',
:unit => 'GB', :value => nil)
+ back_end_storage = create_hwpp_enum(['500', '1500', '2000'],
{:name => 'storage', :unit => 'GB', :value => '1500'})
+ HardwareProfile.generate_override_property_value(front_end_storage,
back_end_storage).should == '1500'
+
+ back_end_property_without_value = create_hwpp_enum(['500', '1500',
'2000'], {:name => 'storage', :unit => 'GB', :value =>
''})
+ HardwareProfile.generate_override_property_value(front_end_storage,
back_end_property_without_value).should == '500'
+ end
+
it "should correctly match a front end hardware profile with a back end hardware
profile" do
front_end_memory = FactoryGirl.create(:hwpp_fixed, :name => 'memory',
:unit => 'MB', :value => '2048')
front_end_storage = FactoryGirl.create(:hwpp_fixed, :name => 'storage',
:unit => 'GB', :value => '850')
--
1.7.6
Show replies by date