Unicode error when getting integer/datetime trait

Bug #1324523 reported by Fernando González
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ceilometer
Fix Released
High
ZhiQiang Fan

Bug Description

When i try to get an integer or datetime trait with cli im getting a unicode error:

$ ceilometer trait-list -e compute.instance.create.start -t disk_gb
WARNING (http:173) Request returned failure status.
HTTPBadRequest (HTTP 400) ERROR Invalid input for field/attribute value. Value: '20'. Wrong type. Expected '<type 'unicode'>', got '<type 'long'>'

$ ceilometer trait-list -e compute.instance.create.end -t launched_at
WARNING (http:173) Request returned failure status.
HTTPBadRequest (HTTP 400) ERROR Invalid input for field/attribute value. Value: '2014-05-29 12:15:49.954393'. Wrong type. Expected '<type 'unicode'>', got '<type 'datetime.datetime'>'

If i get an string trait it works fine:

$ ceilometer trait-list -e compute.instance.create.end -t host
+------------+-----------+------------+
| Trait Name | Value | Data Type |
+------------+-----------+------------+
| host | redstack | string |
+------------+-----------+------------+

Debug info:

DEBUG (http:121)
HTTP/1.0 400 Bad Request
date: Thu, 29 May 2014 12:45:18 GMT
content-length: 231
content-type: application/json
server: WSGIServer/0.1 Python/2.7.6

{"error_message": {"debuginfo": null, "faultcode": "Client", "faultstring": "Invalid input for field/attribute value. Value: '2014-05-29 12:15:49.954393'. Wrong type. Expected '<type 'unicode'>', got '<type 'datetime.datetime'>'"}}

WARNING (http:173) Request returned failure status.
Traceback (most recent call last):
  File "/usr/local/bin/ceilometer", line 10, in <module>
    sys.exit(main())
  File "/opt/stack/python-ceilometerclient/ceilometerclient/shell.py", line 335, in main
    CeilometerShell().main(args)
  File "/opt/stack/python-ceilometerclient/ceilometerclient/shell.py", line 289, in main
    args.func(client, args)
  File "/opt/stack/python-ceilometerclient/ceilometerclient/v2/shell.py", line 740, in do_trait_list
    traits = cc.traits.list(args.event_type, args.trait_name)
  File "/opt/stack/python-ceilometerclient/ceilometerclient/v2/traits.py", line 29, in list
    return self._list(path)
  File "/opt/stack/python-ceilometerclient/ceilometerclient/common/base.py", line 58, in _list
    resp, body = self.api.json_request('GET', url)
  File "/opt/stack/python-ceilometerclient/ceilometerclient/common/http.py", line 191, in json_request
    resp, body_iter = self._http_request(url, method, **kwargs)
  File "/opt/stack/python-ceilometerclient/ceilometerclient/common/http.py", line 174, in _http_request
    raise exc.from_response(resp, ''.join(body_iter))
ceilometerclient.exc.HTTPBadRequest: HTTPBadRequest (HTTP 400) ERROR Invalid input for field/attribute value. Value: '2014-05-29 12:15:49.954393'. Wrong type. Expected '<type 'unicode'>', got '<type 'datetime.datetime'>'

description: updated
description: updated
ZhiQiang Fan (aji-zqfan)
Changed in ceilometer:
assignee: nobody → ZhiQiang Fan (aji-zqfan)
Eoghan Glynn (eglynn)
Changed in ceilometer:
status: New → Triaged
importance: Undecided → High
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to ceilometer (master)

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

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

Reviewed: https://review.openstack.org/97588
Committed: https://git.openstack.org/cgit/openstack/ceilometer/commit/?id=8f3f15b6d1023eadbf4b18dc7755778ebb3a4dd7
Submitter: Jenkins
Branch: master

commit 8f3f15b6d1023eadbf4b18dc7755778ebb3a4dd7
Author: ZhiQiang Fan <email address hidden>
Date: Wed Jun 4 02:10:53 2014 +0800

    Fix incorrect trait initialization

    Currently, when we try to get trait, the api service uses storage
    data to directly initialize the trait model. However, the trait class
    init method expects value field as wsme.text type, while in storage,
    it could be int, float, or datetime. So, end user will get 400 error
    in such scenarios.

    The static method _convert_storage_trait() in Event class can convert
    a storage trait data to api trait object, we can use it to fix this
    bug. Also, this method should be in Trait class instead of Event class,
    This patch does this refactor too.

    Change-Id: Ia7bf667967a31a3cc6e8d457f3b6330ffc728471
    Closes-Bug: #1324523

Changed in ceilometer:
status: In Progress → Fix Committed
Changed in ceilometer:
milestone: none → juno-2
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in ceilometer:
milestone: juno-2 → 2014.2
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.