Bug 1292620

Summary: Requirement for an additional sorting option in the REST API to perform case-insensitive sorting on a list
Product: Red Hat CloudForms Management Engine Reporter: Chris Pelland <cpelland>
Component: APIAssignee: Aparna Karve <akarve>
Status: CLOSED ERRATA QA Contact: Milan Falešník <mfalesni>
Severity: high Docs Contact:
Priority: high    
Version: 5.5.0CC: akarve, cpelland, dajohnso, dclarizi, gtanzill, jhardy, jkrocil, jprause, obarenbo, twade
Target Milestone: GAKeywords: ZStream
Target Release: 5.5.2   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: 5.5.2.1 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1291904 Environment:
Last Closed: 2016-02-10 15:29:40 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:
Bug Depends On: 1291904    
Bug Blocks:    

Comment 1 CFME Bot 2015-12-18 21:49:24 UTC
New commit detected on cfme/5.5.z:
https://code.engineering.redhat.com/gerrit/gitweb?p=cfme.git;a=commitdiff;h=afe99b6ced4219a546d190c3603731492db6cb9c

commit afe99b6ced4219a546d190c3603731492db6cb9c
Author:     Tim Wade <hello>
AuthorDate: Wed Dec 16 13:25:13 2015 -0800
Commit:     Aparna Karve <akarve>
CommitDate: Fri Dec 18 11:20:18 2015 -0800

    [api] Change `nocase` to `ignore_case`
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1292620

 app/controllers/api_controller/parameters.rb | 2 +-
 spec/requests/api/querying_spec.rb           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comment 2 CFME Bot 2015-12-18 21:49:29 UTC
New commit detected on cfme/5.5.z:
https://code.engineering.redhat.com/gerrit/gitweb?p=cfme.git;a=commitdiff;h=ce24397d32e87d4f9e1d89dd1068e9e0ba8ef1c6

commit ce24397d32e87d4f9e1d89dd1068e9e0ba8ef1c6
Merge: 1b7b4df afe99b6
Author:     Dan Clarizio <dclarizi>
AuthorDate: Fri Dec 18 16:46:20 2015 -0500
Commit:     Dan Clarizio <dclarizi>
CommitDate: Fri Dec 18 16:46:20 2015 -0500

    Merge branch 'api/case-insensitive-sorting' into '5.5.z'
    
    Api/case insensitive sorting
    
    Clean cherry-pick
    Upstream PR - https://github.com/ManageIQ/manageiq/pull/5871
    
    New sorting option added to the REST API for case insensitive sorting
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1292620
    
    See merge request !646

 app/controllers/api_controller/parameters.rb | 6 ++++--
 gems/cfme_client/bin/rest_api.rb             | 5 ++++-
 spec/requests/api/querying_spec.rb           | 9 +++++++++
 3 files changed, 17 insertions(+), 3 deletions(-)

Comment 8 Milan Falešník 2016-01-22 10:22:49 UTC
Verified in 5.5.2.1. Due to default case insensitive ordering I had to tinker with database config to verify that at least the query comes to the database as expected:

# vim /var/opt/rh/rh-postgresql94/lib/pgsql/data/postgresql.conf

Tweak the log_statement (all) and log_min_duration_statement (-1). Restart evmserverd and rh-postgresql94-postgresql.

In one window, do tail -fn0 /var/opt/rh/rh-postgresql94/lib/pgsql/data/pg_log/postgresql.log | fgrep ASC | fgrep LOWER

In other window, do:
# vmdb
# gems/cfme_client/bin/rest_api.rb get --expand=resources --attributes=name --sort-by=name --sort-order=asc --sort-options=ignore_case vms
# gems/cfme_client/bin/rest_api.rb get --expand=resources --attributes=name --sort-by=name --sort-order=asc vms

If you get load errors, install the required gem (should be faraday and faraday_middleware).

In the first call, something vms should appear in the tailed log. Many things come by, but you can recognize the right query, it looks like this:

2016-01-22 10:14:44 GMT:[local]:56a1fdc7.5724:root@vmdb_production:[22308]:LOG:  execute <unnamed>: SELECT "vms".* FROM "vms" WHERE ((vms.id IN (147,309,316,140,102,15,22,189,118,21,65,256,224,281,302,700,272,787,786,295,296,298,8,12,970,335,336,334,332,331,330,328,326,327,267,213,5,3,98,333,329,325,201,790,270,702,701,232,104,88,163,36,222,806,713,10,732,1081,1080,746,812,815,644,1083,231,230,317,162,245,301,305,304,290,429,597,432,602,540,1088,626,572,47,142,553,816,821,631,822,589,548,584,824,630,607,610,1032,1095,87,243,168,266,215,204,107,137,287,234,166,285,655,108,799,615,616,844,641,989,823,436,643,440,461,645,991,2,444,827,462,647,828,30,992,445,479,467,453,485,472,233,836,459,854,448,651,818,663,851,639,984,997,845,441,1003,1000,993,454,668,657,463,456,481,468,473,487,664,838,994,846,176,985,640,464,1005,1001,998,670,442,658,852,855,652,449,455,820,460,513,92,719,1019,76,874,1025,483,882,707,493,129,515,907,1028,1023,521,731,894,722,499,530,512,1027,492,743,883,96,899,11,500,519,347,229,127,187,67,154,72,91,132,135,219,37,218,247,747,23,236,172,352,413,26,191,354,351,288,79,117,29,38,190,322,274,321,324,323,50,53,206,244,277,164,278,275,121,51,52,86,211,122,282,169,9,314,183,114,16,133,174,195,139,33,13,70,212,269,19,39,106,188,289,93,90,151,203,31,109,257,46,237,145,60,105,160,68,143,178,7,208,97,161,4,112,134,113,788,144,434,704,591,561,396,431,407,342,1093,613,387,451,795,587,649,420,671,393,337,559,1043,522,465,798,427,634,375,884,238,1099,504,601,437,654,426,380,987,1046,1055,624,365,721,710,447,477,843,425,604,831,386,421,41,235,217,847,628,585,933,1048,956,510,439,389,562,873,995,980,952,960,934,674,377,495,590,797,1092,507,516,1094,1036,546,1029,369,1056,484,443,709,1002,656,858,977,979,381,344,1052,1026,514,1062,577,408,912,996,648,959,1018,955,466,973,392,986,923,549,409,526,423,1024,538,422,659,974,1063,397,1086,482,593,497,909,848,475,430,511,1006,532,418,975,724,1071,925,564,1033,388,950,416,990,338,621,555,458,890,1011,534,877,967,509,1069,1042,1031,401,1022,435,864,953,968,470,947,1057,637,457,1014,525,595,978,489,373,976,889,1008,363,58,141,120,726,982,417,348,575,433,599,428,586,419,826,362,614,545,627,886,703,638,839,983,588,635,794,403,612,424,632,859,805,583,56,603,556,606,1096,1085,1090,1091,1087,1038,1040,807,739,830,349,809,796,210,699,791,792,155,279,312,941,1058,378,542,745,1059,353,611,939,376,198,921,543,636,819,642,438,835,480,981,517,879,502,706,1016,246,876,681,370,625,954,390,558,1075,623,361,552,385,1066,951,544,356,931,949,943,1060,1067,617,801,384,1064,358,938,804,945,547,1061,944,382,935,383,619,550,622,357,803,1070,1068,946,948,785,940,942,1074,1072,629,842,834,853,837,856,840,849,850,292,291,605,125,286,800,832,315,339,310,69,863,661,868,675,469,1013,861,471,829,450,494,474,666,669,103,860,1009,878,646,446,498,1012,488,1007,999,505,1004,653,870,490,501,865,177,476,452,496,683,833,1010,841,676,867,650,673,857,866,665,680,662,875,660,1045,888,551,717,359,486,554,520,508,367,744,1030,936,881,491,523,682,1041,737,872,929,557,225,893,400,308,394,568,311,711,964,1078,303,518,880,708,503,1017,892,720,1021,928,1053,598,911,371,537,735,897,733,94,343,904,730,742,916,738,618,734,740,608,741,915,905,620,908,729,728,901,609,727,736,900,402,412,965,578,1079,115,414,966,410,580,574,963,411,405,1077,119,1073,914,364,579,592,350,971,906,927,379,527,1047,887,560,366,565,895,346,1039,596,930,1035,922,374,1049,918,723,919,1037,716,372,581,917,913,718,563,714,898,903,582,1054,924,712,524,1050,533,685,920,705,576,340,896,1051,594,885,528,541,891,725,536,283,355,368,679,539,341,404,1076,1044,926,902,937,715,535,531,529,360,569,910,871,506,478,672,869,6,241,862,227,1015,684,345,600,226,817,810,783,789,99,784,1084,566,957,398,399,958,571,570,567,391,677,678,667,395,961,962,969,406,415,972,1082,573,932,802,1065,294,262,249,793,318,319,75,221,1,42,170,82,209,199,173,223,263,216,138,250,150,146,255,254,280,252,55,110,814,808,307,299,34,180,265,988)))  ORDER BY LOWER(name) ASC

Second call won't show up because it won't have the LOWER in the query, so this verifies that the intended query is issued although CFME seems to sort with case insensitivity by default.

Comment 9 errata-xmlrpc 2016-02-10 15:29:40 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/RHBA-2016:0159