sort options - -sort-key and - -sort-dir doesn't work in " manila list " command.

Bug #1777849 reported by Huabang Ding
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-manilaclient
Fix Released
Medium
Deepak Mourya

Bug Description

python-manilaclient version is 1.23.0

Problem:
When I use "manila list --sort-key name --sort-dir asc" command to sort the queried shares, sort options --sort-key and --sort-dir are not working. I have tried to sort by name but the list is always the same and sorted only according to ID.

Analyse:
The do_list() method in manilaclient/v2/shell.py file use cliutils.print_list(shares, list_of_keys) to output information of manila shares, which will always sort by "ID" filed.

manilaclient/v2/shell.py
-----
@cliutils.service_type('sharev2')
def do_list(cs, args):
    ...
    cliutils.print_list(shares, list_of_keys)
-----

and the definition of print_list()method is as below:
manilaclient/common/cliutils.py
-----
def print_list(objs, fields, formatters=None, sortby_index=0,
               mixed_case_fields=None, field_labels=None):
    """Print a list or objects as a table, one row per object.

    :param objs: iterable of :class:`Resource`
    :param fields: attributes that correspond to columns, in order
    :param formatters: `dict` of callables for field formatting
    :param sortby_index: index of the field for sorting table rows
    :param mixed_case_fields: fields corresponding to object attributes that
        have mixed case names (e.g., 'serverId')
    :param field_labels: Labels to use in the heading of the table, default to
        fields.
    """
    ...

    if sortby_index is None:
        kwargs = {}
    else:
        kwargs = {'sortby': field_labels[sortby_index]}
    pt = prettytable.PrettyTable(field_labels)
    pt.align = 'l'

    ....

    if six.PY3:
        print(encodeutils.safe_encode(pt.get_string(**kwargs)).decode())
    else:
        print(encodeutils.safe_encode(pt.get_string(**kwargs)))

-----

so the the value of sortby_index will fixed to 0, and the value of variable kwargs will fixed to "{'sortby': 'ID'}".

Huabang Ding (dinghb)
Changed in python-manilaclient (Ubuntu):
assignee: nobody → Huabang Ding (dinghb)
Revision history for this message
Corey Bryant (corey.bryant) wrote :

This appears to affect the upstream project as well as the Ubuntu package. I've targeted this at upstream python-manilaclient as well.

Changed in python-manilaclient:
assignee: nobody → Deepak Mourya (mourya007)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-manilaclient (master)

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

Changed in python-manilaclient:
status: New → In Progress
Revision history for this message
Tom Barron (tpb) wrote :

Does this issue affect other resources than shares?

Revision history for this message
Deepak Mourya (mourya007) wrote :

Hi Tom, I have checked this bug and resulted output is like:

manila list --sort_key name
+--------------------------------------+--------+------+-------------+--------+-----------+--------------------+------+-------------------+
| ID | Name | Size | Share Proto | Status | Is Public | Share Type Name | Host | Availability Zone |
+--------------------------------------+--------+------+-------------+--------+-----------+--------------------+------+-------------------+
| 5da4161b-6794-4ff5-a3ee-e482cc636337 | sp | 2 | NFS | error | False | generic_share_type | | None |
| e9fcaaf4-247e-4a60-8619-8072f96e6085 | share0 | 1 | NFS | error | False | generic_share_type | | None |
| cb4622cd-51f6-46ec-8ad1-af69dd1856ed | sa | 1 | NFS | error | False | generic_share_type | | None |
+--------------------------------------+--------+------+-------------+--------+-----------+--------------------+-----
so what is the issue you are about to point out.?

Changed in python-manilaclient:
importance: Undecided → Medium
milestone: none → rocky-3
James Page (james-page)
no longer affects: python-manilaclient (Ubuntu)
Revision history for this message
Deepak Mourya (mourya007) wrote :

Still behaving the same issue.

manila list --sort-key name --sort-dir asc
+--------------------------------------+------+------+-------------+--------+-----------+--------------------+------+-------------------+
| ID | Name | Size | Share Proto | Status | Is Public | Share Type Name | Host | Availability Zone |
+--------------------------------------+------+------+-------------+--------+-----------+--------------------+------+-------------------+
| 2e03f61a-1abe-495f-8e57-a9071c59de1d | ab | 1 | NFS | error | False | generic_share_type | | None |
| 98fa99be-0b87-4eda-88ec-40d3a7820eb7 | aab | 1 | NFS | error | False | generic_share_type | | None |
| a6f5990c-3775-4926-af1f-a436d3bc4d94 | abc | 1 | NFS | error | False | generic_share_type | | None |
+--------------------------------------+------+------+-------------+--------+-----------+--------------------+------+

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-manilaclient (master)

Reviewed: https://review.openstack.org/578744
Committed: https://git.openstack.org/cgit/openstack/python-manilaclient/commit/?id=7b816ceb03e84ad1b4a14a0e11b525a2c4b8baa1
Submitter: Zuul
Branch: master

commit 7b816ceb03e84ad1b4a14a0e11b525a2c4b8baa1
Author: deepak_mourya <email address hidden>
Date: Thu Jun 28 15:05:48 2018 +0530

    Fix sort options --sort-key and --sort-dir in list command.

    Previously manila list --sort_key name command sort on
    the basis of id instead of name. This PS will fix the
    issue and sort the list in terms of name key.

    Change-Id: If96162b5269a5a385de9c72c4cef2b335e5c24ff
    Closes-Bug: #1777849
    Closes-Bug: #1779935

Changed in python-manilaclient:
status: In Progress → Fix Released
Revision history for this message
Huabang Ding (dinghb) wrote :

@Deepak Mourya
I’m truly grateful for your help, By the way, I found that this fixed is not merged into python-manilaclient 1.24.1, so could you tell me when the next version release?

thanks.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-manilaclient 1.25.0

This issue was fixed in the openstack/python-manilaclient 1.25.0 release.

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.