exception when running 'watcher service list'

Bug #1674196 reported by licanwei
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
watcher
Fix Released
Medium
licanwei

Bug Description

[root@host-10-43-203-132 ~(keystone_admin)]# watcher service list
Multiple rows were found for one() (HTTP 500)

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

  File "/usr/lib/python2.7/site-packages/watcher/api/controllers/v1/service.py", line 225, in get_all
    return self._get_services_collection(marker, limit, sort_key, sort_dir)

  File "/usr/lib/python2.7/site-packages/watcher/api/controllers/v1/service.py", line 210, in _get_services_collection
    sort_key=sort_key, sort_dir=sort_dir)

  File "/usr/lib/python2.7/site-packages/watcher/api/controllers/v1/service.py", line 155, in convert_with_links
    Service.convert_with_links(g, expand) for g in services]

  File "/usr/lib/python2.7/site-packages/watcher/api/controllers/v1/service.py", line 127, in convert_with_links
    service = Service(**service.as_dict())

  File "/usr/lib/python2.7/site-packages/watcher/api/controllers/v1/service.py", line 111, in __init__
    field if field != 'status' else 'name', wtypes.Unset))

  File "/usr/lib/python2.7/site-packages/watcher/api/controllers/v1/service.py", line 60, in _set_status
    service = objects.Service.get_by_name(pecan.request.context, name)

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

  File "/usr/lib/python2.7/site-packages/watcher/objects/service.py", line 75, in get_by_name
    db_service = cls.dbapi.get_service_by_name(context, name)

  File "/usr/lib/python2.7/site-packages/watcher/db/sqlalchemy/api.py", line 1115, in get_service_by_name
    context, fieldname="name", value=service_name, eager=eager)

  File "/usr/lib/python2.7/site-packages/watcher/db/sqlalchemy/api.py", line 1105, in _get_service
    fieldname=fieldname, value=value, eager=eager)

  File "/usr/lib/python2.7/site-packages/watcher/db/sqlalchemy/api.py", line 268, in _get
    obj = query.one()

  File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 2702, in one
    "Multiple rows were found for one()")

MultipleResultsFound: Multiple rows were found for one()

Revision history for this message
licanwei (li-canwei2) wrote :

We have two controllers as HA in our OpenStack environment. There are watcher-applier and watcher-decision-engine in each controller.
So there are two same name in the services table. In this case, the objects.Service.get_by_name(context, name) will trigger exception of MultipleResultsFound.
We should use objects.Service.get(context, id) replace of objects.Service.get_by_name(context, name).

MariaDB [watcher]> select * from services;
+---------------------+---------------------+------------+---------+----+-------------------------+--------------------+---------------------+
| created_at | updated_at | deleted_at | deleted | id | name | host | last_seen_up |
+---------------------+---------------------+------------+---------+----+-------------------------+--------------------+---------------------+
| 2017-03-15 05:01:56 | 2017-03-15 06:23:05 | NULL | 0 | 1 | watcher-applier | host-10-43-203-132 | 2017-03-15 06:23:05 |
| 2017-03-15 05:01:57 | 2017-03-15 06:23:06 | NULL | 0 | 2 | watcher-decision-engine | host-10-43-203-132 | 2017-03-15 06:23:06 |
| 2017-03-15 05:01:57 | NULL | NULL | 0 | 3 | watcher-applier | controller04 | NULL |
| 2017-03-15 05:01:58 | NULL | NULL | 0 | 4 | watcher-decision-engine | controller04 | NULL |
+---------------------+---------------------+------------+---------+----+-------------------------+--------------------+---------------------+

Changed in watcher:
assignee: nobody → licanwei (li-canwei2)
importance: Undecided → Medium
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/447354

Changed in watcher:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to watcher (master)

Reviewed: https://review.openstack.org/447354
Committed: https://git.openstack.org/cgit/openstack/watcher/commit/?id=38a3cbc84a59bca4516358a788de50aca17f7cb5
Submitter: Jenkins
Branch: master

commit 38a3cbc84a59bca4516358a788de50aca17f7cb5
Author: licanwei <email address hidden>
Date: Mon Mar 20 12:17:34 2017 +0800

    exception when running 'watcher service list'

    We have two controllers as HA in our OpenStack environment.
    There are watcher-applier and watcher-decision-engine in each
    controller. So there are two same name in the services table.
    In this case, the objects.Service.get_by_name(context, name)
    will trigger exception of MultipleResultsFound.
    We should use objects.Service.get(context, id) replace of
    objects.Service.get_by_name(context, name).

    Change-Id: Ic3ce784590d6c2a648cb3b28299744deed281332
    Closes-Bug: #1674196

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

This issue was fixed in the openstack/watcher 1.1.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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