fix cinder ceph backup driver padding error

While restore an extended source, ceph backup driver will pad
0 to the unused space if restore_discard_excess_bytes is True.
The original code use total length of the unused space to fill
each chunk. Change to use chunk size to fill each chunk.

Change-Id: I9658d31a55e5024f5f6d5ccf00939edd668ea451
Signed-off-by: Liu Qing <liuqing@chinac.com>
Closes-Bug: 1595014
This commit is contained in:
Liu Qing 2016-06-21 17:14:44 +08:00
parent d669449cd2
commit ea99de3f37
2 changed files with 11 additions and 1 deletions
cinder
backup/drivers
tests/unit/backup/drivers

@ -283,7 +283,7 @@ class CephBackupDriver(driver.BackupDriver):
if self._file_is_rbd(volume):
volume.rbd_image.discard(offset, length)
else:
zeroes = '\0' * length
zeroes = '\0' * self.chunk_size
chunks = int(length / self.chunk_size)
for chunk in range(0, chunks):
LOG.debug("Writing zeroes chunk %d", chunk)

@ -667,8 +667,12 @@ class BackupCephTestCase(test.TestCase):
self.assertEqual(2, image.write.call_count)
self.assertEqual(2, image.flush.call_count)
self.assertFalse(image.discard.called)
zeroes = '\0' * self.service.chunk_size
image.write.assert_has_calls([mock.call(zeroes, 0),
mock.call(zeroes, self.chunk_size)])
image.reset_mock()
image.write.reset_mock()
# Now test with a remainder.
with mock.patch.object(self.service, '_file_is_rbd') as \
@ -681,6 +685,12 @@ class BackupCephTestCase(test.TestCase):
self.assertEqual(3, image.write.call_count)
self.assertEqual(3, image.flush.call_count)
self.assertFalse(image.discard.called)
image.write.assert_has_calls([mock.call(zeroes,
self.chunk_size * 2),
mock.call(zeroes,
self.chunk_size * 3),
mock.call('\0',
self.chunk_size * 4)])
@common_mocks
def test_delete_backup_snapshot(self):