Foreman 1.4 - unable to filter on classes

Hi,

After update to 1.4.0 I can no longer filter host lists based on classes.
Regardless of which class i try to filter with, theforeman returns all
hosts as a result.

Example of query:
/hosts?search=class=cacti

should return one host but returns all hosts.

I filed a bug about this (Bug #4314: unable to filter on classes - Foreman) but
thought I check here also to see if this indeed is a foreman bug or if
something is wrong in my environment after the update.

Regards
Adam

I did try reproducing it when I saw your bug report, but was
unsuccessful. It'd be interesting if anybody else hits it, otherwise
I'd suggest turning on debug logs, doing the search and attaching the
output from production.log to the issue.

http://projects.theforeman.org/projects/foreman/wiki/Troubleshooting#How-do-I-enable-debugging

··· On 14/02/14 12:25, Adam Winberg wrote: > Hi, > > After update to 1.4.0 I can no longer filter host lists based on > classes. Regardless of which class i try to filter with, theforeman > returns all hosts as a result. > > Example of query: > /hosts?search=class=cacti > > should return one host but returns all hosts. > > I filed a bug about this (http://projects.theforeman.org/issues/4314) > but thought I check here also to see if this indeed is a foreman bug or > if something is wrong in my environment after the update.


Dominic Cleal
Red Hat Engineering

right, i enabled debug and reran the query, see output below. What really
stands out is the PGerror (i use postgresql as db):

··· --------------- PGError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list LINE 1: ..." WHERE (puppetclasses.name = 'foreman') ORDER BY hostgroups... ---------------

production.log full output:

Started GET “/hosts?utf8=%E2%9C%93&search=class+%3D+foreman” for
10.66.1.253 at 2014-02-14 12:38:23 +0000
Processing by HostsController#index as HTML
Parameters: {“utf8”=>“✓”, “search”=>“class = foreman”}
User Load (0.6ms) SELECT “users”.* FROM “users” WHERE “users”.“id” = $1
LIMIT 1 [[“id”, 2]]
Setting current user thread-local variable to a001329
Host::Managed Load (0.6ms) SELECT “hosts”.* FROM “hosts” WHERE
"hosts".“type” IN (‘Host::Managed’) LIMIT 1
Host::Managed Load (0.8ms) SELECT DISTINCT hosts.id FROM “hosts” INNER
JOIN “host_classes” ON “host_classes”.“host_id” = “hosts”.“id” INNER JOIN
"puppetclasses" ON “puppetclasses”.“id” = “host_classes”.“puppetclass_id"
WHERE “hosts”.“type” IN (‘Host::Managed’) AND (puppetclasses.name =
‘foreman’)
Hostgroup Load (0.6ms) SELECT DISTINCT hostgroups.id FROM “hostgroups"
INNER JOIN “hostgroup_classes” ON “hostgroup_classes”.“hostgroup_id” =
“hostgroups”.“id” INNER JOIN “puppetclasses” ON “puppetclasses”.“id” =
“hostgroup_classes”.“puppetclass_id” WHERE (puppetclasses.name = ‘foreman’)
ORDER BY hostgroups.label
PGError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in
select list
LINE 1: …” WHERE (puppetclasses.name = ‘foreman’) ORDER BY hostgroups…
^
: SELECT DISTINCT hostgroups.id FROM “hostgroups” INNER JOIN
"hostgroup_classes” ON “hostgroup_classes”.“hostgroup_id” =
“hostgroups”.“id” INNER JOIN “puppetclasses” ON “puppetclasses”.“id” =
“hostgroup_classes”.“puppetclass_id” WHERE (puppetclasses.name = ‘foreman’)
ORDER BY hostgroups.label
(0.4ms) SELECT COUNT() FROM “user_facts” WHERE “user_facts”.“user_id”
= 2
Host::Managed Load (0.6ms) SELECT “hosts”.
FROM “hosts” WHERE
"hosts".“type” IN (‘Host::Managed’) ORDER BY “hosts”.“name” ASC NULLS FIRST
LIMIT 20 OFFSET 0
Hostgroup Load (0.5ms) SELECT “hostgroups”.* FROM “hostgroups” WHERE
"hostgroups".“id” IN (7, 6) ORDER BY hostgroups.label
Operatingsystem Load (0.4ms) SELECT “operatingsystems”.* FROM
"operatingsystems" WHERE “operatingsystems”.“id” IN (2) ORDER BY
operatingsystems.name
Environment Load (0.6ms) SELECT “environments”.* FROM "environments"
WHERE “environments”.“id” IN (1) ORDER BY environments.name
Model Load (0.4ms) SELECT “models”.* FROM “models” WHERE “models”."id"
IN (1, 2) ORDER BY models.name
(0.4ms) SELECT MAX(“reports”.“id”) AS maximum_id, host_id AS host_id
FROM “reports” WHERE “reports”.“host_id” IN (2, 1) GROUP BY host_id
Rendered hosts/_list.html.erb (11.5ms)
Rendered hosts/index.html.erb within layouts/application (13.9ms)
Bookmark Load (0.6ms) SELECT “bookmarks”.* FROM “bookmarks” WHERE
(((bookmarks.public = ‘t’) OR (bookmarks.owner_id = 2 AND
bookmarks.owner_type = ‘User’))) AND (controller = ‘hosts’) ORDER BY name
Rendered common/_searchbar.html.erb (4.1ms)
Rendered home/_user_dropdown.html.erb (1.1ms)
Read fragment views/tabs_and_title_records-2 (0.1ms)
Rendered home/_topbar.html.erb (2.1ms)
Rendered layouts/base.html.erb (9.3ms)
Completed 200 OK in 48ms (Views: 28.1ms | ActiveRecord: 6.5ms)

//Adam

On 14 February 2014 13:27, Dominic Cleal dcleal@redhat.com wrote:

On 14/02/14 12:25, Adam Winberg wrote:

Hi,

After update to 1.4.0 I can no longer filter host lists based on
classes. Regardless of which class i try to filter with, theforeman
returns all hosts as a result.

Example of query:
/hosts?search=class=cacti

should return one host but returns all hosts.

I filed a bug about this (Bug #4314: unable to filter on classes - Foreman)
but thought I check here also to see if this indeed is a foreman bug or
if something is wrong in my environment after the update.

I did try reproducing it when I saw your bug report, but was
unsuccessful. It’d be interesting if anybody else hits it, otherwise
I’d suggest turning on debug logs, doing the search and attaching the
output from production.log to the issue.

Troubleshooting - Foreman


Dominic Cleal
Red Hat Engineering


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/groups/opt_out.

i guess the query should be altered to include the 'order by' field in the
select, like so:

SELECT DISTINCT hostgroups.id, hostgroups.label
FROM "hostgroups"
INNER JOIN "hostgroup_classes" ON "hostgroup_classes"."hostgroup_id" =
"hostgroups"."id"
INNER JOIN "puppetclasses" ON "puppetclasses"."id" =
"hostgroup_classes"."puppetclass_id"
WHERE (puppetclasses.name = 'foreman')
ORDER BY hostgroups.label

··· On 14 February 2014 13:42, Adam Winberg wrote:

right, i enabled debug and reran the query, see output below. What really
stands out is the PGerror (i use postgresql as db):

PGError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in
select list
LINE 1: …" WHERE (puppetclasses.name = ‘foreman’) ORDER BY hostgroups…

production.log full output:

Started GET “/hosts?utf8=%E2%9C%93&search=class+%3D+foreman” for
10.66.1.253 at 2014-02-14 12:38:23 +0000
Processing by HostsController#index as HTML
Parameters: {“utf8”=>“âoe”", “search”=>“class = foreman”}
User Load (0.6ms) SELECT “users”.* FROM “users” WHERE “users”.“id” = $1
LIMIT 1 [[“id”, 2]]
Setting current user thread-local variable to a001329
Host::Managed Load (0.6ms) SELECT “hosts”.* FROM “hosts” WHERE
"hosts".“type” IN (‘Host::Managed’) LIMIT 1
Host::Managed Load (0.8ms) SELECT DISTINCT hosts.id FROM “hosts” INNER
JOIN “host_classes” ON “host_classes”.“host_id” = “hosts”.“id” INNER JOIN
"puppetclasses" ON “puppetclasses”.“id” = “host_classes”.“puppetclass_id"
WHERE “hosts”.“type” IN (‘Host::Managed’) AND (puppetclasses.name =
‘foreman’)
Hostgroup Load (0.6ms) SELECT DISTINCT hostgroups.id FROM “hostgroups"
INNER JOIN “hostgroup_classes” ON “hostgroup_classes”.“hostgroup_id” =
“hostgroups”.“id” INNER JOIN “puppetclasses” ON “puppetclasses”.“id” =
“hostgroup_classes”.“puppetclass_id” WHERE (puppetclasses.name =
‘foreman’) ORDER BY hostgroups.label
PGError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in
select list
LINE 1: …” WHERE (puppetclasses.name = ‘foreman’) ORDER BY hostgroups…
^
: SELECT DISTINCT hostgroups.id FROM “hostgroups” INNER JOIN
"hostgroup_classes” ON “hostgroup_classes”.“hostgroup_id” =
“hostgroups”.“id” INNER JOIN “puppetclasses” ON “puppetclasses”.“id” =
“hostgroup_classes”.“puppetclass_id” WHERE (puppetclasses.name =
‘foreman’) ORDER BY hostgroups.label
(0.4ms) SELECT COUNT() FROM “user_facts” WHERE “user_facts”.“user_id”
= 2
Host::Managed Load (0.6ms) SELECT “hosts”.
FROM “hosts” WHERE
"hosts".“type” IN (‘Host::Managed’) ORDER BY “hosts”.“name” ASC NULLS FIRST
LIMIT 20 OFFSET 0
Hostgroup Load (0.5ms) SELECT “hostgroups”.* FROM “hostgroups” WHERE
"hostgroups".“id” IN (7, 6) ORDER BY hostgroups.label
Operatingsystem Load (0.4ms) SELECT “operatingsystems”.* FROM
"operatingsystems" WHERE “operatingsystems”.“id” IN (2) ORDER BY
operatingsystems.name
Environment Load (0.6ms) SELECT “environments”.* FROM "environments"
WHERE “environments”.“id” IN (1) ORDER BY environments.name
Model Load (0.4ms) SELECT “models”.* FROM “models” WHERE “models”."id"
IN (1, 2) ORDER BY models.name
(0.4ms) SELECT MAX(“reports”.“id”) AS maximum_id, host_id AS host_id
FROM “reports” WHERE “reports”.“host_id” IN (2, 1) GROUP BY host_id
Rendered hosts/_list.html.erb (11.5ms)
Rendered hosts/index.html.erb within layouts/application (13.9ms)
Bookmark Load (0.6ms) SELECT “bookmarks”.* FROM “bookmarks” WHERE
(((bookmarks.public = ‘t’) OR (bookmarks.owner_id = 2 AND
bookmarks.owner_type = ‘User’))) AND (controller = ‘hosts’) ORDER BY name
Rendered common/_searchbar.html.erb (4.1ms)
Rendered home/_user_dropdown.html.erb (1.1ms)
Read fragment views/tabs_and_title_records-2 (0.1ms)
Rendered home/_topbar.html.erb (2.1ms)
Rendered layouts/base.html.erb (9.3ms)
Completed 200 OK in 48ms (Views: 28.1ms | ActiveRecord: 6.5ms)

//Adam

On 14 February 2014 13:27, Dominic Cleal dcleal@redhat.com wrote:

On 14/02/14 12:25, Adam Winberg wrote:

Hi,

After update to 1.4.0 I can no longer filter host lists based on
classes. Regardless of which class i try to filter with, theforeman
returns all hosts as a result.

Example of query:
/hosts?search=class=cacti

should return one host but returns all hosts.

I filed a bug about this (Bug #4314: unable to filter on classes - Foreman)
but thought I check here also to see if this indeed is a foreman bug or
if something is wrong in my environment after the update.

I did try reproducing it when I saw your bug report, but was
unsuccessful. It’d be interesting if anybody else hits it, otherwise
I’d suggest turning on debug logs, doing the search and attaching the
output from production.log to the issue.

Troubleshooting - Foreman


Dominic Cleal
Red Hat Engineering


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/groups/opt_out.