From b74e3df296c80520a0469adaba4a7c131105e8e0 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Tue, 25 Sep 2018 17:13:20 -0400 Subject: [PATCH 1/2] MiqExpression defined on Service does not evaluate tag correctly when instance of class descendent from Service passed: class descendent from Service has `service` method and string "service" passed to MiqExpression as reference, so MiqExpression trying to obtaine 'real' object using passed reference by invoking `service` method on instance of class descendent from Service, which is wrong. Passed object should not be subsrituted using reference if reference is "service" and object < ... < Service Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1628727 --- app/models/condition.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/condition.rb b/app/models/condition.rb index a18f42b0495..2c1adc59fb8 100644 --- a/app/models/condition.rb +++ b/app/models/condition.rb @@ -220,7 +220,7 @@ def self.options2hash(opts, rec) attr, val = o.split("=") ohash[attr.strip.downcase.to_sym] = val.strip.downcase end - if ohash[:ref] != rec.class.to_s.downcase + if ohash[:ref] != rec.class.to_s.downcase && !exclude_from_object_ref_substitution(ohash[:ref], rec) ref = rec.send(val) if val && rec.respond_to?(val) end @@ -232,6 +232,13 @@ def self.options2hash(opts, rec) return ohash, ref, object end + def self.exclude_from_object_ref_substitution(reference, rec) + case reference + when "service" + rec.kind_of?(Service) + end + end + def self.registry_data(ref, name, ohash) # HKLM\Software\Microsoft\Windows\CurrentVersion\explorer\Shell Folders\Common AppData == 'C:\Documents and Settings\All Users\Application Data' # HKLM\Software\Microsoft\Windows\CurrentVersion\explorer\Shell Folders : Common AppData == 'C:\Documents and Settings\All Users\Application Data' From 321c84445905e578b658ac95a8a4082e74e868e1 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Wed, 26 Sep 2018 09:47:12 -0400 Subject: [PATCH 2/2] added test to cover .options2hash in cases when reference is 'ref=service' and passed object is descendant from Service class --- spec/models/condition_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/models/condition_spec.rb b/spec/models/condition_spec.rb index 9b135b1959d..09dd035f448 100644 --- a/spec/models/condition_spec.rb +++ b/spec/models/condition_spec.rb @@ -164,4 +164,12 @@ expect(condition.expression.exp).to eq("not" => {">" => {"field" => "Vm-cpu_num", "value" => 2}}) end end + + describe ".options2hash" do + it 'returns the same record if it is descendant from Service class and passed reference is "service" ' do + record = ServiceContainerTemplate.new + _, result_record, _ = described_class.options2hash("ref=service", record) + expect(result_record).to be(record) + end + end end