Skip to content

Commit

Permalink
Merge pull request #18020 from yrudman/fixed-expression-with-tag-on-s…
Browse files Browse the repository at this point in the history
…ervice

Fixed MiqExpression evaluation on tagged Services
  • Loading branch information
gtanzillo authored Oct 1, 2018
2 parents 8489078 + 321c844 commit d670fe8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/models/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
# <registry>HKLM\Software\Microsoft\Windows\CurrentVersion\explorer\Shell Folders\Common AppData</registry> == 'C:\Documents and Settings\All Users\Application Data'
# <registry>HKLM\Software\Microsoft\Windows\CurrentVersion\explorer\Shell Folders : Common AppData</registry> == 'C:\Documents and Settings\All Users\Application Data'
Expand Down
8 changes: 8 additions & 0 deletions spec/models/condition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d670fe8

Please sign in to comment.