Fix Python 3 issues in the swift backup driver

* On Python 3, encode/decode JSON to/from UTF-8
* Use byte strings for volume content
* Replace dict.keys()[0] and dict.value()[0] with list(dict.items())[0].
  Get the key and the value at once to ensure that they are consistent.
  On Python 3, items() returns an iterator: create a list to use the [0]
  operator.
* SwiftBackupDriver: use a bytearray instead of a string because
  bytes += bytes is inefficient on Python 3, whereas str += str is
  optimized on Python 2. Replace also StringIO with BytesIO.
* BytesIO has no more len attribute on Python 3: get the length of the
  content instead.
* Replace buffer(bytearray(128)) with b'\0' * 128 to create a string of
  128 zeroed bytes
* Replace "rw" file mode with "w+" ("rw" raises an exception
  on Python 3).
* tox.ini: add the following tests to Python 3.4

  - cinder.tests.unit.test_backup_swift
  - cinder.tests.unit.test_backup_tsm

Blueprint cinder-python3
Change-Id: I62d7ef8041847f31b5d06a92fa2edb65c6780497
This commit is contained in:
Victor Stinner
2015-06-23 13:37:42 +02:00
parent c967b44110
commit 72b7a18583
6 changed files with 28 additions and 14 deletions

View File

@@ -33,6 +33,8 @@ commands =
cinder.tests.unit.test_backup \
cinder.tests.unit.test_backup_ceph \
cinder.tests.unit.test_backup_driver_base \
cinder.tests.unit.test_backup_swift \
cinder.tests.unit.test_backup_tsm \
cinder.tests.unit.test_block_device \
cinder.tests.unit.test_cloudbyte \
cinder.tests.unit.test_conf \