[Bug 1777849] [NEW] sort options - -sort-key and - -sort-dir doesn't work in " manila list " command.

Huabang Ding 1777849 at bugs.launchpad.net
Wed Jun 20 10:12:10 UTC 2018


Public bug reported:

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'}".

** Affects: python-manilaclient (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
OpenStack, which is subscribed to python-manilaclient in Ubuntu.
https://bugs.launchpad.net/bugs/1777849

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

Status in python-manilaclient package in Ubuntu:
  New

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'}".

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-manilaclient/+bug/1777849/+subscriptions



More information about the Ubuntu-openstack-bugs mailing list