v2 client sorts on name in wrong direction

Bug #1489941 reported by Stuart McLaren
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Won't Fix
Undecided
Kairat Kushaev
Glance Client
Won't Fix
Undecided
Unassigned

Bug Description

The v1 client sorts images by name alphabetically:

$ glance --os-image-api-version 1 image-list --sort-key name
+--------------------------------------+---------------------+-------------+------------------+-----------+----------------+
| ID | Name | Disk Format | Container Format | Size | Status |
+--------------------------------------+---------------------+-------------+------------------+-----------+----------------+
| 7d1923d7-68e8-4a8e-b23e-a7c77f8117fd | | raw | bare | 1034 | active |
| 5e9dc64e-7c05-431c-b81f-ae6a212353e8 | | qcow2 | bare | | queued |
| 6802e222-6eac-45c6-8c9f-0d62aed26406 | | qcow2 | bare | 145 | active |
| 7af0d66b-5b48-48a6-a6d9-c2cd3eafa83e | | | | | queued |
| dde89c3c-c8af-46a4-87b0-f39ed6c61c42 | | raw | bare | 2 | active |
| 262ac5aa-e580-4bec-a3b2-580924425fd5 | | raw | bare | 2 | active |
| 4cc5b305-43a7-495e-8e67-16d95629621e | | raw | bare | 2 | active |

The v2 client sorts in reverse alphabetical:

$ glance --os-image-api-version 2 image-list --sort-key name
+--------------------------------------+---------------------+
| ID | Name |
+--------------------------------------+---------------------+
| b16dbfb2-f435-40a8-aa08-2aadaee99cd1 | trusty2 |
| cc658de9-039a-46d7-829a-dc1f08cac153 | test1 |
| 2fa0f342-623e-423f-8faa-70f000b3e4cc | test1 |
| c95a4ee7-28d0-4fd5-86c6-fe9816fcef23 | test1 |
| d75354ed-ef63-4f41-9d53-a0d67394d1a3 | test1 |
| ecc24d0d-140c-484d-ae42-427e60be9270 | test1 |
| f3b996a9-469c-4882-864b-fef0cd24429d | test1 |

adding the sort dir gives the same result as v1:

$ glance --os-image-api-version 2 image-list --sort-key name --sort-dir asc
+--------------------------------------+---------------------+
| ID | Name |
+--------------------------------------+---------------------+
| 7d1923d7-68e8-4a8e-b23e-a7c77f8117fd | |
| 5e9dc64e-7c05-431c-b81f-ae6a212353e8 | |
| 6802e222-6eac-45c6-8c9f-0d62aed26406 | |
| 7af0d66b-5b48-48a6-a6d9-c2cd3eafa83e | |
| dde89c3c-c8af-46a4-87b0-f39ed6c61c42 | |
| 262ac5aa-e580-4bec-a3b2-580924425fd5 | |
| 4cc5b305-43a7-495e-8e67-16d95629621e | |

tags: added: 1.0.0-potential
Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

sorting is also reversed for:

status, id, size

(created_at, updated_at, container_format, disk_format are ok)

Changed in python-glanceclient:
assignee: nobody → Niall Bunting (niall-bunting)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-glanceclient (master)

Fix proposed to branch: master
Review: https://review.openstack.org/219205

Changed in python-glanceclient:
status: New → In Progress
Revision history for this message
Erno Kuvaja (jokke) wrote :

This is not a client bug. The default sorting direction was set to desc in: https://review.openstack.org/#/c/148326
https://review.openstack.org/#/c/148326

We should not mask server default behavior in the client, but rather change it in server if needed.

Changed in python-glanceclient:
status: In Progress → Invalid
Changed in glance:
status: New → Triaged
Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

It is a bug.

A user, when they execute:

glance image-list --sort-key name

will reasonably expect that

1) the sort direction is the same as it always has been
2) the names are sorted in alphabetical order

Changed in python-glanceclient:
status: Invalid → New
Revision history for this message
Ian Cordasco (icordasc) wrote :

The behaviour of the client has always relied on that of the service. That means that it defaults to the server-side sort, which makes this not a client bug STuart.

Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

> The behaviour of the client has always relied on that of the service.

How do you mean in this particular case?

When we do a regular 'glance image-list' the client explicitly requests the sort order:

v1:

glance image-list results in:
GET /v1/images/detail?sort_key=name&sort_dir=asc&limit=20 HTTP/1.1.

v2:

glance image-list results in:
T 10.0.0.85:34641 -> 10.0.0.85:9292 [AP]
GET /v2/images?limit=20&sort=name:asc HTTP/1.1.

So, for example both v1 and v2 list alphabetically by default:

$ glance --os-image-api-version 1 image-list
+--------------------------------------+------+-------------+------------------+------+--------+
| ID | Name | Disk Format | Container Format | Size | Status |
+--------------------------------------+------+-------------+------------------+------+--------+
| 04b25ad3-20b4-461a-b36e-578bc8d64813 | abc | | | | queued |
| 94e8af26-06f4-4fa7-bbc3-1624b754038e | xyz | | | | queued |
+--------------------------------------+------+-------------+------------------+------+--------+

$ glance --os-image-api-version 2 image-list
+--------------------------------------+------+
| ID | Name |
+--------------------------------------+------+
| 04b25ad3-20b4-461a-b36e-578bc8d64813 | abc |
| 94e8af26-06f4-4fa7-bbc3-1624b754038e | xyz |
+--------------------------------------+------+

When we add the sort key for v1 this also explicitly sets the order:
GET /v1/images/detail?sort_key=name&sort_dir=asc&limit=20 HTTP/1.1.

$ glance --os-image-api-version 1 image-list --sort-key name
+--------------------------------------+------+-------------+------------------+------+--------+
| ID | Name | Disk Format | Container Format | Size | Status |
+--------------------------------------+------+-------------+------------------+------+--------+
| 04b25ad3-20b4-461a-b36e-578bc8d64813 | abc | | | | queued |
| 94e8af26-06f4-4fa7-bbc3-1624b754038e | xyz | | | | queued |
+--------------------------------------+------+-------------+------------------+------+--------+

But the v2 client doesn't explicity set the order when using '--sort-key':

GET /v2/images?limit=20&sort_key=name HTTP/1.1.

$ glance --os-image-api-version 2 image-list --sort-key name
+--------------------------------------+------+
| ID | Name |
+--------------------------------------+------+
| 94e8af26-06f4-4fa7-bbc3-1624b754038e | xyz |
| 04b25ad3-20b4-461a-b36e-578bc8d64813 | abc |
+--------------------------------------+------+

Doesn't it make sense to add 'sort_dir=asc' in all four cases rather than three out of four?
If we want to rely on the server behaviour should a basic 'image-list' return images in reverse order? (I don't think so)

Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

Also, as far as I can tell, there has been no server side change between v1 and v2 in terms of default sort ordering with respect to name:

$ curl -s -H 'x-auth-token: xxx' 'http://localhost:9292/v1/images?sort_key=name' | python -mjson.tool | grep name
            "name": "xyz",
            "name": "abc",

$ curl -s -H 'x-auth-token: xxx' 'http://localhost:9292/v2/images?sort_key=name' | python -mjson.tool | grep name
            "name": "xyz",
            "name": "abc",

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on python-glanceclient (master)

Change abandoned by Niall Bunting (<email address hidden>) on branch: master
Review: https://review.openstack.org/219205
Reason: This will confuse users.

Changed in python-glanceclient:
assignee: Niall Bunting (niall-bunting) → nobody
Changed in glance:
assignee: nobody → Kairat Kushaev (kkushaev)
status: Triaged → In Progress
Revision history for this message
Kairat Kushaev (kkushaev) wrote :

If this will be accepted in glance then we need to remove default sorting from glanceclient because we don't need it anymore.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on glance (master)

Change abandoned by Brian Rosmaita (<email address hidden>) on branch: master
Review: https://review.openstack.org/275120
Reason: The consensus was to do nothing, so let's officially abandon this change.

Revision history for this message
Kairat Kushaev (kkushaev) wrote :

Marked as Won't fix. See reason in comment #10. Also python-glanceclient is going to be deprecated in favor of openstackclient. So the bug marked as won't fix for glanceclient too.

Changed in glance:
status: In Progress → Won't Fix
Changed in python-glanceclient:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.