dims / etcd3-gateway

This repository is now read-only. Please see https://opendev.org/openstack/etcd3gw for the new location for this code.
https://opendev.org/openstack/etcd3gw
Apache License 2.0
10 stars 20 forks source link

Values are not correctly decoded in python3 #24

Closed huntxu closed 6 years ago

huntxu commented 6 years ago

I was trying to get the lock using this module with python3, however lock.is_acquired() always returned False. After some investigation, I found the reason is that the values are not correctly decoded. utils._decode returns an instance of bytes instead of str in python3.

Run the unit tests with Python3 with etcd3 server running would reveal the issue.

$ tox -e py36
...
collected 21 items                                                                                                                                                             

etcd3gw/tests/test_client.py::TestEtcd3Gateway::test_client_default PASSED                                                                                               [  4%]
etcd3gw/tests/test_client.py::TestEtcd3Gateway::test_client_ipv4 PASSED                                                                                                  [  9%]
etcd3gw/tests/test_client.py::TestEtcd3Gateway::test_client_ipv6 PASSED                                                                                                  [ 14%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_client_lease PASSED                                                                                                [ 19%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_client_lease_with_keys FAILED                                                                                      [ 23%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_client_lock_acquire_release PASSED                                                                                 [ 28%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_client_locks FAILED                                                                                                [ 33%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_client_members PASSED                                                                                              [ 38%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_client_status PASSED                                                                                               [ 42%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_client_with_keys_and_values FAILED                                                                                 [ 47%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_create_fail FAILED                                                                                                 [ 52%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_create_success FAILED                                                                                              [ 57%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_get_and_delete_prefix FAILED                                                                                       [ 61%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_get_prefix_sort_order FAILED                                                                                       [ 66%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_get_prefix_sort_order_explicit_sort_target_key FAILED                                                              [ 71%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_get_prefix_sort_order_explicit_sort_target_rev FAILED                                                              [ 76%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_replace_fail FAILED                                                                                                [ 80%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_replace_success FAILED                                                                                             [ 85%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_sequential_watch_prefix_once PASSED                                                                                [ 90%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_watch_key FAILED                                                                                                   [ 95%]
etcd3gw/tests/test_etcd3gw.py::TestEtcd3Gateway::test_watch_prefix FAILED                                                                                                [100%]

=================================================================================== FAILURES ===================================================================================
...
_________________________________________________________________ TestEtcd3Gateway.test_client_lease_with_keys _________________________________________________________________
NOTE: Incompatible Exception Representation, displaying natively:

testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/root/src/etcd3gw/etcd3gw/tests/test_etcd3gw.py", line 222, in test_client_lease_with_keys
    self.assertIn('foo12', keys)
  File "/root/src/etcd3gw/.tox/py36/lib/python3.6/site-packages/testtools/testcase.py", line 417, in assertIn
    self.assertThat(haystack, Contains(needle), message)
  File "/root/src/etcd3gw/.tox/py36/lib/python3.6/site-packages/testtools/testcase.py", line 498, in assertThat
    raise mismatch_error
testtools.matchers._impl.MismatchError: 'foo12' not in [b'foo12', b'foo13']

______________________________________________________________________ TestEtcd3Gateway.test_client_locks ______________________________________________________________________
NOTE: Incompatible Exception Representation, displaying natively:

testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/root/src/etcd3gw/etcd3gw/tests/test_etcd3gw.py", line 354, in test_client_locks
    self.assertTrue(lock.is_acquired())
  File "/root/src/etcd3gw/.tox/py36/lib/python3.6/site-packages/unittest2/case.py", line 702, in assertTrue
    raise self.failureException(msg)
AssertionError: False is not true
...
===================================================================== 13 failed, 8 passed in 9.60 seconds ======================================================================