Merge "Port backup drivers to Python 3"

This commit is contained in:
Jenkins 2016-02-09 19:34:38 +00:00 committed by Gerrit Code Review
commit 232c2efc3a
4 changed files with 21 additions and 11 deletions

View File

@ -108,7 +108,7 @@ class PosixBackupDriver(chunkeddriver.ChunkedBackupDriver):
def get_object_writer(self, container, object_name, extra_metadata=None):
path = os.path.join(self.backup_path, container, object_name)
f = open(path, 'w')
f = open(path, 'wb')
permissions = (
stat.S_IRUSR |
stat.S_IWUSR |
@ -119,7 +119,7 @@ class PosixBackupDriver(chunkeddriver.ChunkedBackupDriver):
def get_object_reader(self, container, object_name, extra_metadata=None):
path = os.path.join(self.backup_path, container, object_name)
return open(path, 'r')
return open(path, 'rb')
def delete_object(self, container, object_name):
# TODO(tbarron): clean up the container path if it is empty

View File

@ -27,6 +27,7 @@ import zlib
import mock
from os_brick.remotefs import remotefs as remotefs_brick
from oslo_config import cfg
import six
from cinder.backup.drivers import nfs
from cinder import context
@ -620,11 +621,17 @@ class BackupNFSSwiftBasedTestCase(test.TestCase):
self.assertEqual(compressor, bz2)
self.assertRaises(ValueError, service._get_compressor, 'fake')
def create_buffer(self, size):
# Set up buffer of zeroed bytes
fake_data = bytearray(size)
if six.PY2:
# On Python 2, zlib.compressor() accepts buffer, but not bytearray
fake_data = buffer(fake_data)
return fake_data
def test_prepare_output_data_effective_compression(self):
service = nfs.NFSBackupDriver(self.ctxt)
# Set up buffer of 128 zeroed bytes
fake_data = buffer(bytearray(128))
fake_data = self.create_buffer(128)
result = service._prepare_output_data(fake_data)
self.assertEqual('zlib', result[0])
@ -633,8 +640,7 @@ class BackupNFSSwiftBasedTestCase(test.TestCase):
def test_prepare_output_data_no_compresssion(self):
self.flags(backup_compression_algorithm='none')
service = nfs.NFSBackupDriver(self.ctxt)
# Set up buffer of 128 zeroed bytes
fake_data = buffer(bytearray(128))
fake_data = self.create_buffer(128)
result = service._prepare_output_data(fake_data)
@ -643,8 +649,8 @@ class BackupNFSSwiftBasedTestCase(test.TestCase):
def test_prepare_output_data_ineffective_compression(self):
service = nfs.NFSBackupDriver(self.ctxt)
# Set up buffer of 128 zeroed bytes
fake_data = buffer(bytearray(128))
fake_data = self.create_buffer(128)
# Pre-compress so that compression in the driver will be ineffective.
already_compressed_data = service.compressor.compress(fake_data)

View File

@ -159,14 +159,14 @@ class PosixBackupDriverTestCase(test.TestCase):
self.driver.get_object_writer(FAKE_CONTAINER, FAKE_OBJECT_NAME)
os.chmod.assert_called_once_with(FAKE_OBJECT_PATH, 0o660)
builtins.open.assert_called_once_with(FAKE_OBJECT_PATH, 'w')
builtins.open.assert_called_once_with(FAKE_OBJECT_PATH, 'wb')
def test_get_object_reader(self):
self.mock_object(builtins, 'open', mock.mock_open())
self.driver.get_object_reader(FAKE_CONTAINER, FAKE_OBJECT_NAME)
builtins.open.assert_called_once_with(FAKE_OBJECT_PATH, 'r')
builtins.open.assert_called_once_with(FAKE_OBJECT_PATH, 'rb')
def test_delete_object(self):
self.mock_object(os, 'remove')

View File

@ -28,6 +28,10 @@ cinder.tests.unit.api.test_extensions
cinder.tests.unit.api.test_versions
cinder.tests.unit.api.test_xmlutil
cinder.tests.unit.api.v2.test_volumes
cinder.tests.unit.backup.drivers.test_backup_glusterfs
cinder.tests.unit.backup.drivers.test_backup_nfs
cinder.tests.unit.backup.drivers.test_backup_posix
cinder.tests.unit.backup.test_rpcapi
cinder.tests.unit.image.test_cache
cinder.tests.unit.image.test_glance
cinder.tests.unit.keymgr.test_barbican