rally-openstack has python3-incompatible code in glance image upload and tempest verification code

Bug #1819274 reported by Dmitrii Shcherbakov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Rally
Fix Released
Undecided
Dmitrii Shcherbakov

Bug Description

Ran into two errors due to python3 incompatibility in rally-openstack (rev 992419828496abe48a6dedc71416ea8bebb87e77)

rally verify start --id <verifier-uuid> --pattern tempest.api.compute.images.test_images_oneserver.ImagesOneServerTestJSON.test_create_delete_image --detailed

almost immediately fails with:

1) the lack of comparison operator implementation for TempestContext:

xxxx-xx-xx xx:xx:xx.xx 7909 INFO rally.api [-] Starting verification (UUID=<uuid>) for deployment 'snap_generated' (UUID=<uuid>) by verifier 'tempestverifier' (UUID=<uuid>).
'<' not supported between instances of 'TestrContext' and 'TempestContext'

https://docs.python.org/3/whatsnew/3.0.html#ordering-comparisons
"The cmp() function should be treated as gone, and the __cmp__() special method is no longer supported. Use __lt__() for sorting, __eq__() with __hash__(), and other rich comparisons as needed. (If you really need the cmp() functionality, you could use the expression (a > b) - (a < b) as the equivalent for cmp(a, b).)"

2) when (1) is fixed, the second error is a bit more cryptic:

xxxx-xx-xx xx:xx:xx.xxx 20731 INFO rally.task.context [-] Verification ea029096-ec35-4247-a8db-8e1bdfaf6cd6 | Context tempest@default cleanup() started
xxxx-xx-xx xx:xx:xx.xxx 20731 INFO rally.task.context [-] Verification ea029096-ec35-4247-a8db-8e1bdfaf6cd6 | Context tempest@default cleanup() finished in 1.33 sec
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfb in position 3: invalid start byte

Tracing shows that this happens because rally-openstack passes a file opened in a text mode to glance client - it then tries to read binary image content as utf-8-encoded text and almost immediately hits an invalid utf-8 byte which happens to be a QCOW2 magic string:
https://paste.ubuntu.com/p/5j8ZFh39Kn/

<_io.TextIOWrapper name='/home/ubuntu/.rally/verification/verifier-eb466e06-6212-46a4-81ec-f8b5f1cda46d/for-deployment-954578f9-d831-4926-87e0-25b856f7ac89/tempest-image' mode='r' encoding='UTF-8'>

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfb in position 3: invalid start byte
> /snap/fcbtest/x1/lib/python3.6/site-packages/rally/api.py(1027)start()
-> with vcontext.ContextManager(context):

(Pdb) e
UnicodeDecodeError('utf-8', b'QFI\xfb\x00\x00\

https://git.qemu.org/?p=qemu.git;a=blob;f=docs/specs/qcow2.txt;h=80cdfd0e919dee9d77535429b098b89b4cb5a6a5;hb=HEAD#l15
    Byte 0 - 3: magic
                    QCOW magic string ("QFI\xfb")

This can be fixed by using 'rb' mode when opening an image file.

Revision history for this message
Dmitrii Shcherbakov (dmitriis) wrote :
Changed in rally:
status: New → In Progress
assignee: nobody → Dmitrii Shcherbakov (dmitriis)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to rally (master)

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

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on rally-openstack (master)

Change abandoned by Dmitrii Shcherbakov (<email address hidden>) on branch: master
Review: https://review.openstack.org/642234
Reason: Abandoning in favor of the Rally change.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to rally (master)

Reviewed: https://review.openstack.org/643717
Committed: https://git.openstack.org/cgit/openstack/rally/commit/?id=de4ea09398a3d3e8a71213c4b6905be979f47626
Submitter: Zuul
Branch: master

commit de4ea09398a3d3e8a71213c4b6905be979f47626
Author: Dmitrii Shcherbakov <email address hidden>
Date: Sat Mar 16 21:13:33 2019 +0300

    Task context: implement comparison operators

    __cmp__ is no longer used in python3

    Other operators need to be defined instead.

    https://docs.python.org/3/whatsnew/3.0.html#ordering-comparisons
    "The cmp() function should be treated as gone, and the __cmp__() special
    method is no longer supported. Use __lt__() for sorting, __eq__() with
    __hash__(), and other rich comparisons as needed. (If you really need
    the cmp() functionality, you could use the expression (a > b) - (a < b)
    as the equivalent for cmp(a, b).)"

    https://www.python.org/dev/peps/pep-0207/

    This change does it based on get_order and class meta properties.

    Downstream projects that rely on context comparison (such as
    rally-openstack) will benefit from this change.

    Change-Id: I4991acccefd4754e209feafd5e24d03c76c283f8
    Depends-On: I42db6045ae88c34d3576beb737bb7e955c5f2132
    Needed-By: I6bb31fe1d3f79a8fd4707a5576204dee69a3f307
    Partial-Bug: #1819274

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to rally-openstack (master)

Reviewed: https://review.openstack.org/642235
Committed: https://git.openstack.org/cgit/openstack/rally-openstack/commit/?id=4822b452304c53d3102e75d4d2924fb7ec1a93ae
Submitter: Zuul
Branch: master

commit 4822b452304c53d3102e75d4d2924fb7ec1a93ae
Author: Dmitrii Shcherbakov <email address hidden>
Date: Sat Mar 9 02:51:18 2019 +0300

    py3: use binary mode for opening image files

    If binary mode is not used when running with python3 glance image
    uploads fail as files are opened with encoding='UTF-8' by default.

    It results in the following confusing error message:

    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfb in position 3:
    invalid start byte

    (Pdb) e
    UnicodeDecodeError('utf-8', b'QFI\xfb\x00\x00\

    0xfb is a QCOW magic string and is invalid from UTF-8 standard
    perspective. From the QCOW2 spec:

    Byte 0 - 3: magic
                    QCOW magic string ("QFI\xfb")

    Tracing have shown that the error comes from python-glanceclient when a
    file handle passed to it is attempted to be used for sending image
    chunks.

    Change-Id: I6bb31fe1d3f79a8fd4707a5576204dee69a3f307
    Depends-On: I4991acccefd4754e209feafd5e24d03c76c283f8
    Closes-Bug: #1819274

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

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