functional test utf-encode-decode issues with python3

Bug #1811627 reported by Tom Barron
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-manilaclient
Fix Released
Undecided
Tom Barron

Bug Description

Functional tests for python-manilaclient include tests to list shares and share_networks by "inexact" unicode name and description. These take unicode values for 'name' and 'description' fields, and substrings of these for filter values, create the resource, and then list the resource based on the filters.

The tests use tempest.lib.client exec routine to to the manila command that creates the resource (share or share-network) with unicode name and description fields.

When run under python3, the creation fails with stack traces like the following:

manilaclient.tests.functional.test_shares_listing.SharesListReadWriteTest.test_list_shares_by_inexact_unicode_option
--------------------------------------------------------------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    b'Traceback (most recent call last):'
    b' File "/opt/stack/python-manilaclient/manilaclient/tests/functional/test_shares_listing.py", line 45, in test_list_shares_by_inexact_unicode_option'
    b' cleanup_in_class=True)'
    b' File "/opt/stack/python-manilaclient/manilaclient/tests/functional/base.py", line 259, in create_share'
    b' share = client.create_share(**data)'
    b' File "/opt/stack/python-manilaclient/manilaclient/tests/functional/client.py", line 619, in create_share'
    b' share_raw = self.manila(cmd, microversion=microversion)'
    b' File "/opt/stack/python-manilaclient/manilaclient/tests/functional/client.py", line 131, in manila'
    b" 'manila', action, flags, params, fail_ok, merge_stderr)"
    b' File "/opt/stack/python-manilaclient/.tox/functional/lib/python3.6/site-packages/tempest/lib/cli/base.py", line 421, in cmd_with_auth'
    b' self.cli_dir, prefix=self.prefix)'
    b' File "/opt/stack/python-manilaclient/.tox/functional/lib/python3.6/site-packages/tempest/lib/cli/base.py", line 69, in execute'
    b" proc = subprocess.Popen(cmd, stdout=stdout, stderr=stderr)"
    b' File "/usr/lib/python3.6/subprocess.py", line 709, in __init__'
    b' restore_signals, start_new_session)'
    b' File "/usr/lib/python3.6/subprocess.py", line 1275, in _execute_child'
    b' restore_signals, start_new_session, preexec_fn)'
    b"UnicodeEncodeError: 'ascii' codec can't encode characters in positio 0-3: ordinal not in range(128)"
    b''

Within tempest/lib/cli subprocess.Popen(encoding='utf-8) is used and there is apparently an attempt to encode the "action" string (which includes the high codepoint unicode values) to ascii bytestrings.

I tried supplying a "encoding='utf-8'" argument to subprocess.Popen() to no effect.

We can byte-encode the "action" string as utf-8 and avoid the UnicodeEncodeError but then the wrong command is passed to the manila command to create the share or share network. They get created, but with unintended name and description values. To make a byte-encoded transport over the pipe work correctly the receiving end would have to know that it's getting bytes and decode back to UTF-8 strings before running the manila command.

Tom Barron (tpb)
description: updated
Changed in python-manilaclient:
assignee: nobody → Goutham Pacha Ravi (gouthamr)
status: New → In Progress
Changed in python-manilaclient:
assignee: Goutham Pacha Ravi (gouthamr) → Tom Barron (tpb)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-manilaclient (master)

Reviewed: https://review.openstack.org/630462
Committed: https://git.openstack.org/cgit/openstack/python-manilaclient/commit/?id=b955ac9064b15d00e8966dda745814c146c8af01
Submitter: Zuul
Branch: master

commit b955ac9064b15d00e8966dda745814c146c8af01
Author: Goutham Pacha Ravi <email address hidden>
Date: Wed Jan 16 16:31:21 2019 -0800

    [Python3] Fix python3 bugs in code

    - The BaseException class no longer has a "message"
      attribute in python 3 [1]. On the contrary, the
      string representation of an Exception object will
      print all the exception args in all supported
      python versions, so use that instead.
    - Functional tests were run with a specific locale,
      remove those annotations so we can handle unicode
      encoding and decoding in python3 envs.
    - Cleanup errors were not being handled correctly,
      cleanup the code so we don't have spurious failures.
    - In python3, dict.keys() gives you a view for lazy
      loading, so convert occurrences to lists as expected
      in our functional tests.
    - Start capturing STDOUT and STDERR in tox envs to
      enable troubleshooting.

    Co-Authored-By: Goutham Pacha Ravi <email address hidden>
    Closes-Bug: #1811627
    Closes-Bug: #1811516
    Change-Id: Idaa2fb9b60451b3fbd298e19574195f2d663c6f4
    [1] https://www.python.org/dev/peps/pep-0352/#transition-plan

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

This issue was fixed in the openstack/python-manilaclient 1.26.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-manilaclient (stable/rocky)

Fix proposed to branch: stable/rocky
Review: https://review.opendev.org/757651

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-manilaclient (stable/rocky)

Reviewed: https://review.opendev.org/757651
Committed: https://git.openstack.org/cgit/openstack/python-manilaclient/commit/?id=c0ce858da632355404906b6b05ee8de232a1b6fa
Submitter: Zuul
Branch: stable/rocky

commit c0ce858da632355404906b6b05ee8de232a1b6fa
Author: Goutham Pacha Ravi <email address hidden>
Date: Wed Jan 16 16:31:21 2019 -0800

    [Python3] Fix python3 bugs in code

    - The BaseException class no longer has a "message"
      attribute in python 3 [1]. On the contrary, the
      string representation of an Exception object will
      print all the exception args in all supported
      python versions, so use that instead.
    - Functional tests were run with a specific locale,
      remove those annotations so we can handle unicode
      encoding and decoding in python3 envs.
    - Cleanup errors were not being handled correctly,
      cleanup the code so we don't have spurious failures.
    - In python3, dict.keys() gives you a view for lazy
      loading, so convert occurrences to lists as expected
      in our functional tests.
    - Start capturing STDOUT and STDERR in tox envs to
      enable troubleshooting.

    Co-Authored-By: Goutham Pacha Ravi <email address hidden>
    Closes-Bug: #1811627
    Closes-Bug: #1811516
    Change-Id: Idaa2fb9b60451b3fbd298e19574195f2d663c6f4
    [1] https://www.python.org/dev/peps/pep-0352/#transition-plan
    (cherry picked from commit b955ac9064b15d00e8966dda745814c146c8af01)
    Signed-off-by: Goutham Pacha Ravi <email address hidden>

tags: added: in-stable-rocky
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-manilaclient (stable/queens)

Fix proposed to branch: stable/queens
Review: https://review.opendev.org/757957

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-manilaclient (stable/queens)

Reviewed: https://review.opendev.org/757957
Committed: https://git.openstack.org/cgit/openstack/python-manilaclient/commit/?id=454eee65ef827cd3305a37b7bb3674d8408d0879
Submitter: Zuul
Branch: stable/queens

commit 454eee65ef827cd3305a37b7bb3674d8408d0879
Author: Goutham Pacha Ravi <email address hidden>
Date: Wed Jan 16 16:31:21 2019 -0800

    [Python3] Fix python3 bugs in code

    - The BaseException class no longer has a "message"
      attribute in python 3 [1]. On the contrary, the
      string representation of an Exception object will
      print all the exception args in all supported
      python versions, so use that instead.
    - Functional tests were run with a specific locale,
      remove those annotations so we can handle unicode
      encoding and decoding in python3 envs.
    - Cleanup errors were not being handled correctly,
      cleanup the code so we don't have spurious failures.
    - In python3, dict.keys() gives you a view for lazy
      loading, so convert occurrences to lists as expected
      in our functional tests.
    - Start capturing STDOUT and STDERR in tox envs to
      enable troubleshooting.

    Co-Authored-By: Goutham Pacha Ravi <email address hidden>
    Closes-Bug: #1811627
    Closes-Bug: #1811516
    Change-Id: Idaa2fb9b60451b3fbd298e19574195f2d663c6f4
    [1] https://www.python.org/dev/peps/pep-0352/#transition-plan
    (cherry picked from commit b955ac9064b15d00e8966dda745814c146c8af01)
    Signed-off-by: Goutham Pacha Ravi <email address hidden>
    (cherry picked from commit c0ce858da632355404906b6b05ee8de232a1b6fa)

tags: added: in-stable-queens
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-manilaclient queens-eol

This issue was fixed in the openstack/python-manilaclient queens-eol release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-manilaclient rocky-eol

This issue was fixed in the openstack/python-manilaclient rocky-eol 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.