sample-create fails with "TypeError: string indices must be integers, not str"

Bug #1367867 reported by Chris Dent
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-ceilometerclient
Fix Released
Undecided
Chris Dent

Bug Description

When using the client, from the command line and as a library, sample-create (or samples.create) fails with "TypeError: string indices must be integers, not str" when calling the equivalent of:

    ceilometer sample-create -r 'house' -m cpu_util --meter-type gauge --meter-unit '%' --sample-volume 8

In ceilometer-api the results in the traceback pasted below.

It appears that wsme is expecting the data in the body of the post to be a list of dicts whereas what is sent is just a dict. It's not clear if the problem is in bad packaging in the client or bad expectations on the server.

Note that this was found while exploring ceilometer bugs in rally: https://bugs.launchpad.net/rally/+bug/1354683

2014-09-10 19:04:21.668 1646 ERROR wsme.api [-] Server-side error: "string indices must be integers, not str". Detail:
Traceback (most recent call last):

  File "/usr/lib/python2.7/site-packages/wsmeext/pecan.py", line 78, in callfunction
    pecan.request.body, pecan.request.content_type

  File "/usr/lib/python2.7/site-packages/wsme/rest/args.py", line 284, in get_args
    from_body = args_from_body(funcdef, body, mimetype)

  File "/usr/lib/python2.7/site-packages/wsme/rest/args.py", line 230, in args_from_body
    body, datatypes, bodyarg=funcdef.body_type is not None

  File "/usr/lib/python2.7/site-packages/wsme/rest/json.py", line 225, in parse
    kw = {argname: fromjson(datatypes[argname], jdata)}

  File "/usr/lib/python2.7/site-packages/simplegeneric.py", line 63, in dispatch
    return f(*args, **kw)

  File "/usr/lib/python2.7/site-packages/wsme/rest/json.py", line 159, in array_fromjson
    return [fromjson(datatype.item_type, item) for item in value]

  File "/usr/lib/python2.7/site-packages/simplegeneric.py", line 63, in dispatch
    return f(*args, **kw)

  File "/usr/lib/python2.7/site-packages/wsme/rest/json.py", line 140, in fromjson
    val_fromjson = fromjson(attrdef.datatype, value[attrdef.name])

TypeError: string indices must be integers, not str

192.168.1.11 - - [10/Sep/2014 19:04:21] "POST /v2/meters/cpu_util HTTP/1.1" 500 120

Revision history for this message
Chris Dent (cdent) wrote :

From IRC (below) we learn that it used to work so something must have changed in the client or server in the interim:

8:09pm] boris-42: cdent so you have issues with these 2 benchmarks?
[8:09pm] boris-42: cdent actually when we added them they worked
[8:10pm] cdent: can you pinpoint a time when they broke?
[8:10pm] boris-42: cdent nope
[8:10pm] boris-42: cdent I can point just when we added them
[8:10pm] cdent: as that will probably help us fix the problem in the client or server
[8:10pm] boris-42: cdent heh
[8:10pm] cdent: presumably some window of time though: they worked at time X, and then somebody reported they were broken at time Y
[8:11pm] boris-42: cdent I'll try to do my best
[8:11pm] cdent: thanks
[8:12pm] boris-42: cdent so we saw that they don't work ~ 1 Aug
[8:12pm] boris-42: cdent maybe few days before
[8:13pm] cdent: and they were created and working around when?
[8:13pm] boris-42: cdent looking...
[8:15pm] boris-42: cdent so lemme check
[8:15pm] boris-42: cdent end of May
[8:15pm] cdent: excellent, thank you, I suspect that will be quite helpful

Revision history for this message
Chris Dent (cdent) wrote :

8:19pm] boris-42: cdent Jun 20 everythign works
[8:19pm] boris-42: so between Jun 20 - 1 Aug

Revision history for this message
Boris Pavlovic (boris-42) wrote :

More preciese:

It started failing on 7 Aug. If I calculated properly between 11 a.m and 1 p.m (but I will check till 5 p.m.) in UTC

Chris Dent (cdent)
Changed in python-ceilometerclient:
assignee: nobody → Chris Dent (chdent)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-ceilometerclient (master)

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

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

Reviewed: https://review.openstack.org/120567
Committed: https://git.openstack.org/cgit/openstack/python-ceilometerclient/commit/?id=c5d7f96914c1ef0dbd490fbe7899c7633d16d070
Submitter: Jenkins
Branch: master

commit c5d7f96914c1ef0dbd490fbe7899c7633d16d070
Author: Chris Dent <email address hidden>
Date: Wed Sep 10 20:58:55 2014 +0100

    Fix sample-create in v2 api calls

    A dict embedded in a list is the expected input. In
    47934c777c50897b649793e0960eebdaad322c45 the list was lost, this
    puts it back.

    Note that the _exact_ date of this failure was identified by
    existing Rally jobs which started failing in early August. That made
    searching the commit logs straightforward.

    Change-Id: I37e794de7a23b8ce8e67a086732af5a19f182409
    Closes-Bug: #1367867

Changed in python-ceilometerclient:
status: In Progress → Fix Committed
Changed in python-ceilometerclient:
milestone: none → 1.3.0
status: Fix Committed → Fix Released
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.