Discovery rule priority

Good day!

I've got a problem with priority of discovery rules. I've got a simple
setup of esxi vms.
So there'are two rules:
centos7 with priority 0 and query facts.memorysize_mb = 7984.34 and
facts.virtual = vmware
centos6 with priority 10 and query facts.virtual = vmware
Host boots from discovery image, send facts, and appears in Discovered
Hosts. I can find it in filter with the same rule as in discovery rule.
But everytime I click autoprovision a centos6 gets build

ruby193-rubygem-foreman_discovery-4.0.0-1.fm1_9.el7.noarch
FOREMAN: 1.9.3
RELEASE: CentOS Linux release 7.1.1503

logs
http://pastebin.com/iHRKw1T5

thanks!

> centos7 with priority 0 and query facts.memorysize_mb = 7984.34 and
> facts.virtual = vmware

According to the manual, priority must be greater than zero:

Priority puts the rules in order. Must be greater than zero and low
numbers go first. Rules are always matched by priority given.

Maybe try priority=1 ?

Thanks for help!

I'll try it and report tomorrow.

··· On Wednesday, 9 December 2015 20:24:03 UTC+3, Александр Костырев wrote: > > Good day! > > I've got a problem with priority of discovery rules. I've got a simple > setup of esxi vms. > So there'are two rules: > centos7 with priority 0 and query facts.memorysize_mb = 7984.34 and > facts.virtual = vmware > centos6 with priority 10 and query facts.virtual = vmware > Host boots from discovery image, send facts, and appears in Discovered > Hosts. I can find it in filter with the same rule as in discovery rule. > But everytime I click autoprovision a centos6 gets build > > ruby193-rubygem-foreman_discovery-4.0.0-1.fm1_9.el7.noarch > FOREMAN: 1.9.3 > RELEASE: CentOS Linux release 7.1.1503 > > logs > http://pastebin.com/iHRKw1T5 > > thanks! >

> centos7 with priority 0 and query facts.memorysize_mb = 7984.34 and

By the way, you never compare floats like that.

In programming, 1.0 is NOT equal to 1.0, never. Well there are
exceptions but it's a bad practice.

Use interval.

I also filed: Bug #12765: Inconsistent rule ordering in the UI - Discovery - Foreman but its rather
cosmetic issue.

LZ

··· -- Later, Lukas #lzap Zapletal

I did try setting priorities
5 for centos7
10 for centos6

the result is the same.

··· On 9 December 2015 at 22:48, Greg Sutcliffe wrote: >> centos7 with priority 0 and query facts.memorysize_mb = 7984.34 and >> facts.virtual = vmware > > According to the manual, priority must be greater than zero: > > Priority puts the rules in order. Must be greater than zero and low > numbers go first. Rules are always matched by priority given. > > Maybe try priority=1 ? > > -- > You received this message because you are subscribed to a topic in the Google Groups "Foreman users" group. > To unsubscribe from this topic, visit https://groups.google.com/d/topic/foreman-users/j_HTx9N8wlE/unsubscribe. > To unsubscribe from this group and all its topics, send an email to foreman-users+unsubscribe@googlegroups.com. > To post to this group, send email to foreman-users@googlegroups.com. > Visit this group at http://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout.

IIRC all fact values are currently stored as strings, which makes
integer comparison logic fail. I see
Feature #11150: Allow searching of facts as types other than string - Foreman scheduled for 1.10

Greg

··· On 10 December 2015 at 14:57, Lukas Zapletal wrote: >> centos7 with priority 0 and query facts.memorysize_mb = 7984.34 and > > By the way, you never compare floats like that. > > In programming, 1.0 is NOT equal to 1.0, never. Well there are > exceptions but it's a bad practice. > > Use interval.

I was wrong about priority, the manual is right.
Facts values are string but there are 4 facts that are saved as integers in
discovery:


so maybe search by memory instead of facts.memorysize_mb.

··· On Thu, Dec 10, 2015 at 5:32 PM, Greg Sutcliffe wrote:

On 10 December 2015 at 14:57, Lukas Zapletal lzap@redhat.com wrote:

centos7 with priority 0 and query facts.memorysize_mb = 7984.34 and

By the way, you never compare floats like that.

In programming, 1.0 is NOT equal to 1.0, never. Well there are
exceptions but it’s a bad practice.

Use interval.

IIRC all fact values are currently stored as strings, which makes
integer comparison logic fail. I see
Feature #11150: Allow searching of facts as types other than string - Foreman scheduled for 1.10

Greg


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

> IIRC all fact values are currently stored as strings, which makes
> integer comparison logic fail. I see
> Feature #11150: Allow searching of facts as types other than string - Foreman scheduled for 1.10

Oh right, you can only use the three mentioned facts for numeric
comparisons. We convert them, not the others. See the manual.

··· -- Later, Lukas #lzap Zapletal

When you search only for "facts.virtual = vmware" do you see your host?

When using auto provision the rules try to apply by priority and not by how
specific the rule is.
Both your queries have: facts.virtual = vmware so both of these rules can
be used to provision your host.
The rule with the higher priority will be used (centos6).

··· On Wed, Dec 9, 2015 at 10:57 PM, Александр Костырев wrote:

I did try setting priorities
5 for centos7
10 for centos6

the result is the same.

On 9 December 2015 at 22:48, Greg Sutcliffe greg.sutcliffe@gmail.com > wrote:

centos7 with priority 0 and query facts.memorysize_mb = 7984.34 and
facts.virtual = vmware

According to the manual, priority must be greater than zero:

Priority puts the rules in order. Must be greater than zero and low
numbers go first. Rules are always matched by priority given.

Maybe try priority=1 ?


You received this message because you are subscribed to a topic in the
Google Groups “Foreman users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/foreman-users/j_HTx9N8wlE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

> Facts values are string but there are 4 facts that are saved as integers in
> discovery:
> https://github.com/theforeman/foreman_discovery/blob/develop/app/models/discovery_attribute_set.rb
> so maybe search by memory instead of facts.memorysize_mb.

Yes, I just commented that. We have documented this.

··· -- Later, Lukas #lzap Zapletal

That's exactly why I didn't bother to set centos7 a higher priority.

··· On Thursday, 10 December 2015 12:33:43 UTC+3, Greg Sutcliffe wrote: > > > The rule with the higher priority will be used (centos6). > > If that's true, the manual is wrong. It states low numbers go first: > > "Priority puts the rules in order. Must be greater than zero and *low > numbers go first*. Rules are always matched by priority given." > (emphasis mine) > > Greg >

thanks!
but still no-go

So, OK now my rules are

Name Priority Query Host
group Hosts/limit Enabled
centos6 5 facts.virtual = vmware
QA_CentOS6 1 / 0 true
centos7 10 facts.memorysize_mb = 7984.34 and facts.virtual = vmware QA_CentOS7
0 / 0 true

I've created 4 VMs
2 with 8GB of memory and
2 with 9192MB

in discovered hosts I can find 2 vms with "facts.memorysize_mb = 7984.34
and facts.virtual = vmware" and 4 Vms with "facts.virtual = vmware"

but yet still with auto_provision they all get provisioned as centos6

··· On Thursday, 10 December 2015 11:37:48 UTC+3, Ori Rabin wrote: > > When you search only for "facts.virtual = vmware" do you see your host? > > When using auto provision the rules try to apply by priority and not by > how specific the rule is. > Both your queries have: facts.virtual = vmware so both of these rules can > be used to provision your host. > The rule with the higher priority will be used (centos6). > > On Wed, Dec 9, 2015 at 10:57 PM, Александр Костырев > wrote: > >> I did try setting priorities >> 5 for centos7 >> 10 for centos6 >> >> the result is the same. >> >> On 9 December 2015 at 22:48, Greg Sutcliffe > > wrote: >> >> centos7 with priority 0 and query facts.memorysize_mb = 7984.34 and >> >> facts.virtual = vmware >> > >> > According to the manual, priority must be greater than zero: >> > >> > Priority puts the rules in order. Must be greater than zero and low >> > numbers go first. Rules are always matched by priority given. >> > >> > Maybe try priority=1 ? >> > >> > -- >> > You received this message because you are subscribed to a topic in the >> Google Groups "Foreman users" group. >> > To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/foreman-users/j_HTx9N8wlE/unsubscribe. >> > To unsubscribe from this group and all its topics, send an email to >> foreman-user...@googlegroups.com . >> > To post to this group, send email to forema...@googlegroups.com >> . >> > Visit this group at http://groups.google.com/group/foreman-users. >> > For more options, visit https://groups.google.com/d/optout. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Foreman users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to foreman-user...@googlegroups.com . >> To post to this group, send email to forema...@googlegroups.com >> . >> Visit this group at http://groups.google.com/group/foreman-users. >> For more options, visit https://groups.google.com/d/optout. >> > >

> The rule with the higher priority will be used (centos6).

If that's true, the manual is wrong. It states low numbers go first:

"Priority puts the rules in order. Must be greater than zero and low
numbers go first
. Rules are always matched by priority given."
(emphasis mine)

Greg

> The rule with the higher priority will be used (centos6).

Hmmm, the way I see it:

Rules are sorted by priority (ascending) and the first rule to win is
applied. So it's actually bottom-top, on the page we sort them from
higher numbers to lowers which is confusing.

If you still have issues, put some Rails.logger.info statements in that
method and debug the rule list. Maybe you found a bug?

Make sure the taxonomy is set correctly if you enabled it!

··· -- Later, Lukas #lzap Zapletal