Resolves
https://bugzilla.redhat.com/show_bug.cgi?id=741711
If a front-end HWP has a nil value and the back-end value is a range,
HardwareProfile.generate_override_property_values will now return
the back-end's "value" paramter instead of the nil value from the
front-end property.
---
src/app/models/hardware_profile.rb | 2 +-
src/spec/factories/hardware_profile.rb | 18 ++++++++++++++++++
src/spec/factories/hardware_profile_property.rb | 16 ++++++++++++++++
src/spec/models/hardware_profile_spec.rb | 8 ++++++++
4 files changed, 43 insertions(+), 1 deletions(-)
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb
index 4d067f8..2a5268e 100644
--- a/src/app/models/hardware_profile.rb
+++ b/src/app/models/hardware_profile.rb
@@ -177,7 +177,7 @@ class HardwareProfile < ActiveRecord::Base
when "fixed"
return back_end_property.value
when "range"
- return front_end_property.value
+ return front_end_property.value.present? ? front_end_property.value :
back_end_property.value
when "enum"
create_array_from_property(back_end_property).sort!.each do |value|
if BigDecimal.new(value) >= BigDecimal.new(front_end_property.value)
diff --git a/src/spec/factories/hardware_profile.rb
b/src/spec/factories/hardware_profile.rb
index 80c9a45..d505838 100644
--- a/src/spec/factories/hardware_profile.rb
+++ b/src/spec/factories/hardware_profile.rb
@@ -75,4 +75,22 @@ FactoryGirl.define do
external_key 'front_hwp3_key'
end
+ factory :back_hwp_ranged_cpu, :parent => :hardware_profile do
+ memory { |p| p.association(:front_hwp1_memory) }
+ storage { |p| p.association(:front_hwp1_storage) }
+ cpu { |p| p.association(:hwpp_ranged_cpu) }
+ architecture { |p| p.association(:front_hwp1_arch) }
+ name 'cpu_range'
+ external_key 'cpu_range'
+ end
+
+ factory :front_end_nil_cpu, :parent => :hardware_profile do
+ memory { |p| p.association(:front_hwp3_memory) }
+ storage { |p| p.association(:front_hwp3_storage) }
+ cpu { |p| p.association(:hwpp_nil_cpu) }
+ architecture { |p| p.association(:front_hwp3_arch) }
+ name 'front_nil_cpu'
+ external_key 'front_nil_cpu'
+ end
+
end
diff --git a/src/spec/factories/hardware_profile_property.rb
b/src/spec/factories/hardware_profile_property.rb
index 56183db..9ddde28 100644
--- a/src/spec/factories/hardware_profile_property.rb
+++ b/src/spec/factories/hardware_profile_property.rb
@@ -227,4 +227,20 @@ FactoryGirl.define do
value 'x86_64'
end
+ factory :hwpp_ranged_cpu, :parent => :hardware_profile_property do
+ name 'cpu'
+ kind 'range'
+ unit 'count'
+ range_first 1
+ range_last 32
+ value 2
+ end
+
+ factory :hwpp_nil_cpu, :parent => :hardware_profile_property do
+ name 'cpu'
+ kind 'fixed'
+ unit 'count'
+ value nil
+ end
+
end
diff --git a/src/spec/models/hardware_profile_spec.rb
b/src/spec/models/hardware_profile_spec.rb
index a958906..fcf9296 100644
--- a/src/spec/models/hardware_profile_spec.rb
+++ b/src/spec/models/hardware_profile_spec.rb
@@ -208,6 +208,14 @@ describe HardwareProfile do
HardwareProfile.match_hardware_profile_property(front_end_cpu,
back_end_cpu_fail).should == false
end
+ it "should handle nils in ranged values in generate_override_property_values"
do
+ fe_hwp = Factory.create(:front_end_nil_cpu)
+ be_hwp = Factory.create(:back_hwp_ranged_cpu)
+ overrides = HardwareProfile.generate_override_property_values(fe_hwp, be_hwp)
+ overrides[:cpu].should_not be_blank
+ end
+
+
def create_hwpp_enum(value_array, properties = {})
hwpp_enum = FactoryGirl.create(:hwpp_enum, properties)
value_array.each do |value|
--
1.7.6.2