Can not sort audit templates list with goal

Bug #1662887 reported by Eric Xie
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
watcher
Fix Released
Medium
Egor Panfilov

Bug Description

Description
===========
Failed to list audit templates with the sort key 'goal_name' or 'Goal'.

Steps to reproduce
==================
* openstack optimize audittemplate list --sort-key goal_id
goal_id is an invalid field for sorting, valid values for --sort-key are: ['uuid', 'name', 'UUID', 'goal_name', 'Strategy', 'strategy_name', 'Name', 'Goal']
* openstack optimize audittemplate list --sort-key goal_name
Sort key supplied is invalid: goal_name (HTTP 500)

Expected result
===============
Sort audit templates list successfully

Actual result
=============
Got invalid sort key.

Logs
=============
2017-02-08 20:40:52.752 ERROR wsme.api [req-c3c30704-6f20-419b-a43f-7863aeb2068c None None] Server-side error: "Sort key supplied is invalid: goal_name". Detail:
Traceback (most recent call last):

  File "/usr/lib/python2.7/site-packages/wsmeext/pecan.py", line 85, in callfunction
    result = f(self, *args, **kwargs)

  File "/opt/stack/watcher/watcher/api/controllers/v1/audit_template.py", line 491, in get_all
    filters, marker, limit, sort_key, sort_dir)

  File "/opt/stack/watcher/watcher/api/controllers/v1/audit_template.py", line 452, in _get_audit_templates_collection
    sort_dir=sort_dir)

  File "/usr/lib/python2.7/site-packages/oslo_versionedobjects/base.py", line 184, in wrapper
    result = fn(cls, context, *args, **kwargs)

  File "/opt/stack/watcher/watcher/objects/audit_template.py", line 188, in list
    eager=eager)

  File "/opt/stack/watcher/watcher/db/sqlalchemy/api.py", line 573, in get_audit_template_list
    sort_key, sort_dir, query)

  File "/opt/stack/watcher/watcher/db/sqlalchemy/api.py", line 102, in _paginate_query
    marker=marker, sort_dir=sort_dir)

  File "/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/utils.py", line 192, in paginate_query
    raise exception.InvalidSortKey(current_sort_key)

InvalidSortKey: Sort key supplied is invalid: goal_name

Environment
===========
# ENV
devstack

# version
- devstack:
git log
commit bab8516a8503445af5582bc63493cb37098f57fb
Merge: 0ab0e50 10db2b8
Author: Jenkins <email address hidden>
Date: Fri Feb 3 16:24:32 2017 +0000

    Merge "Enable VNC console in tempest.conf"

- watcher:
$ git log
commit 26c7726c00ea378e6e113b2683f3707416821d27
Merge: 4b5dce5 5b2cdb5
Author: Jenkins <email address hidden>
Date: Fri Feb 3 09:33:24 2017 +0000

    Merge "Using items() instead of six.iteritems()"

- watchclient
# pip show python-watcherclient
Name: python-watcherclient
Version: 1.0.1.dev6
Summary: Python client library for Watcher API
Home-page: http://docs.openstack.org/developer/python-watcherclient
Author: OpenStack
Author-email: <email address hidden>
License: UNKNOWN
Location: /opt/stack/python-watcherclient
Requires: Babel, cliff, osc-lib, oslo.i18n, oslo.utils, pbr, PrettyTable, keystoneauth1, six, PyYAML

Extended bug fix
================
This bug is also affects some other models, like Strategy. When sorting
made with sort key that is not in model's fields, this key passed to DB
where key couldn't be found in model's table, because it belongs to Goal
or Strategy, for example. As a temporary fix, we could add simple validation
routine for preventing situations when invalid key passed to DB and do
sorting with keys like goal_name and strategy_name on API side without accessing to DB.

Eric Xie (eric-xie)
Changed in watcher:
status: New → In Progress
assignee: nobody → Eric Xie (eric-xie)
Eric Xie (eric-xie)
Changed in watcher:
assignee: Eric Xie (eric-xie) → nobody
status: In Progress → New
Changed in watcher:
status: New → Triaged
milestone: none → rocky-1
Changed in watcher:
importance: Undecided → Medium
Changed in watcher:
assignee: nobody → Egor Panfilov (erakli)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to watcher (master)

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

Changed in watcher:
status: Triaged → In Progress
Egor Panfilov (erakli)
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to watcher (master)

Reviewed: https://review.openstack.org/552534
Committed: https://git.openstack.org/cgit/openstack/watcher/commit/?id=3075723da91eebe75638dc6b5b09d0aabfed1410
Submitter: Zuul
Branch: master

commit 3075723da91eebe75638dc6b5b09d0aabfed1410
Author: Egor Panfilov <email address hidden>
Date: Tue Mar 13 17:24:50 2018 +0300

    Fix sort of *list command output

    While sorting output of list command ("audittemplate list",
    "strategy list", etc) by sort-key that is not belongs
    to specific model, this sort-key was passed to db what
    caused error (HTTP 500). We added check on such keys and now,
    if got one of them, then we make sort on API side
    instead of db side.

    We removed excess sort and changed all sorting routines
    to unified way.

    Also added sort tests on every model.

    Change-Id: I41faea1622605ee4fa8dc48cd572876d75be8383
    Closes-Bug: 1662887

Changed in watcher:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/watcher 1.9.0

This issue was fixed in the openstack/watcher 1.9.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.