Bug 1678300

Summary: Rename default search definition for templates
Product: Red Hat Satellite Reporter: Ranjan Kumar <rankumar>
Component: SearchAssignee: Marek Hulan <mhulan>
Status: CLOSED ERRATA QA Contact: Omkar Khatavkar <okhatavk>
Severity: low Docs Contact:
Priority: unspecified    
Version: 6.5.0CC: c.mcgregor, egolov, kgaikwad, mhulan, rankumar
Target Milestone: 6.6.0Keywords: Reopened, Triaged
Target Release: Unused   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: foreman-1.22.0-0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-10-22 19:48:20 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Ranjan Kumar 2019-02-18 13:05:12 UTC
Description of problem: Searching template for string "default" returns the wrong result

→  hammer --no-headers --csv template list --search "TEST defaul"
137,TEST default,provision

→  hammer --no-headers --csv template list --search "TEST default"
No Result

Other test result
--------
Satellite 6.5
----
→ hammer --no-headers --csv template list --search "default" | wc -l
93

→  hammer --no-headers --csv template list --search "defaul" | wc -l
61

Satellite 6.3(Correct result)
---
→ hammer  --csv template list --search "default" | wc -l
122
    
→ hammer  --csv template list --search "defaul" | wc -l
122


Version-Release number of selected component (if applicable):6.5.0


How reproducible: Always


Additional info:
Sql Query in Satellite 6.3

Satellite 6.3:
------
 SELECT COUNT(DISTINCT "templates"."id") FROM "templates" LEFT OUTER JOIN "operatingsystems_provisioning_templates" ON "operatingsystems_provisioning_templates"."provisioning_template_id" = "templates"."id" LEFT OUTER JOIN "operatingsystems" ON "operatingsystems"."id" = "operatingsystems_provisioning_templates"."operatingsystem_id" LEFT OUTER JOIN "template_combinations" ON "template_combinations"."provisioning_template_id" = "templates"."id" LEFT OUTER JOIN "environments" ON "environments"."id" = "template_combinations"."environment_id" LEFT OUTER JOIN "template_combinations" "template_combinations_templates_join" ON "template_combinations_templates_join"."provisioning_template_id" = "templates"."id" LEFT OUTER JOIN "hostgroups" ON "hostgroups"."id" = "template_combinations_templates_join"."hostgroup_id" LEFT OUTER JOIN "template_kinds" ON "template_kinds"."id" = "templates"."template_kind_id" WHERE "templates"."type" IN ('ProvisioningTemplate') AND ((("templates"."name" ILIKE '%UNSW%' OR "templates"."template" ILIKE '%UNSW%' OR "operatingsystems"."name" ILIKE '%UNSW%' OR "environments"."name" ILIKE '%UNSW%' OR "hostgroups"."name" ILIKE '%UNSW%' OR "template_kinds"."name" ILIKE '%UNSW%') AND ("templates"."name" ILIKE '%default%' OR "templates"."template" ILIKE '%default%' OR "operatingsystems"."name" ILIKE '%default%' OR "environments"."name" ILIKE '%default%' OR "hostgroups"."name" ILIKE '%default%' OR "template_kinds"."name" ILIKE '%default%')))

Satellite 6.5:
-------
irb(main):010:0> ProvisioningTemplate.search_for("UNSW default").count
D, [2019-02-18T16:39:01.316511 #28441] DEBUG -- :    (14.2ms)  SELECT COUNT(DISTINCT "templates"."id") FROM "templates" LEFT OUTER JOIN "operatingsystems_provisioning_templates" ON "operatingsystems_provisioning_templates"."provisioning_template_id" = "templates"."id" LEFT OUTER JOIN "operatingsystems" ON "operatingsystems"."id" = "operatingsystems_provisioning_templates"."operatingsystem_id" LEFT OUTER JOIN "template_combinations" ON "template_combinations"."provisioning_template_id" = "templates"."id" LEFT OUTER JOIN "environments" ON "environments"."id" = "template_combinations"."environment_id" LEFT OUTER JOIN "template_combinations" "template_combinations_templates_join" ON "template_combinations_templates_join"."provisioning_template_id" = "templates"."id" LEFT OUTER JOIN "hostgroups" ON "hostgroups"."id" = "template_combinations_templates_join"."hostgroup_id" LEFT OUTER JOIN "template_kinds" ON "template_kinds"."id" = "templates"."template_kind_id" WHERE "templates"."type" IN ('ProvisioningTemplate') AND ((("templates"."name" ILIKE '%UNSW%' OR "templates"."template" ILIKE '%UNSW%' OR "operatingsystems"."name" ILIKE '%UNSW%' OR "environments"."name" ILIKE '%UNSW%' OR "hostgroups"."name" ILIKE '%UNSW%' OR "template_kinds"."name" ILIKE '%UNSW%') AND (("templates"."default" <> 'f'))))

In Satellite 6.5: the sql query search only in the default template
AND (("templates"."default" <> 'f'))

Workaround:  Set default = true in the template

Comment 1 Marek Hulan 2019-02-18 14:00:00 UTC
Does it work if you search like 'name ~ "TEST default"'? Note that default here relates also to "default" checkbox. You need to be a bit more explicit in the search syntax in this case.

Comment 2 Ranjan Kumar 2019-02-18 15:11:27 UTC
Marek,

But the same works fine in Satellite 6.3.5 and the "default" checkbox is also present in 6.3.5

Comment 4 Marek Hulan 2019-02-19 09:01:36 UTC
> But the same works fine in Satellite 6.3.5 and the "default" checkbox is also present in 6.3.5

because by that time, we didn't have the default attribute available for searching, it's not always a bug if something behaved differently in previous version :-)

In your example

> hammer template list --search 'UNSW def'

it defacto means search "name ~ UNSW or name ~ def" which obviously works

in your second example 

> hammer template list --search 'UNSW default'

the default is a new keyword, referring to value of "default" checkbox of a template. If you want to search for templates that contain either UNSW or default word in their name, do it this way

> hammer template list --search 'name ~ UNSW or name ~ default'

if you wanted to find all templates that contain "UNSW default" in their name, do it this way

> hammer template list --search 'name ~ "UNSW default"'

I tested all above and it works just fine. I don't think there's any bug here, so I'm closing this. Please let me know if I missed something.

Comment 5 Marek Hulan 2019-02-19 11:51:16 UTC
After a discussion with Ranjan, I'm reopening. Because people usually don't search based on default attribute but rather name, it's still advised to be explicit and use "name ~ value", but it's probably worth aliasing the "default" attribute to default_template. That way generic search term like "Kickstart default" would work correctly.

Comment 6 Marek Hulan 2019-02-19 11:51:48 UTC
Created redmine issue https://projects.theforeman.org/issues/26083 from this bug

Comment 7 Bryan Kearney 2019-04-03 08:06:16 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue https://projects.theforeman.org/issues/26083 has been resolved.

Comment 8 Omkar Khatavkar 2019-05-28 04:56:06 UTC
> hammer --no-headers --csv template list --search "default" | wc -l
62
> hammer --no-headers --csv template list --search "defaul" | wc -l
62

> hammer template list --search 'Kickstart default' | wc -l
18
> hammer template list --search 'Kickstart default' | wc -l 
18

Verified with Satellite 6.5 with Snap4. It's working fine 'defaul' and 'default' keywords.

Comment 9 Omkar Khatavkar 2019-05-28 04:57:01 UTC
Sorry, It was Satellite 6.6 with Snap4

Comment 11 Bryan Kearney 2019-10-22 19:48:20 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:3172