Fix fallback share migration with empty files

Fallback share migration fails with empty files. This patch fixes it
by performing additional checks to address this specific scenario.

Change-Id: I36d59740b4e52005e6025e5df5989bf55d6bade4
Closes-bug: #1613713
This commit is contained in:
Rodrigo Barbieri 2016-08-16 10:49:35 -03:00
parent ea9748fa4b
commit e4ddb090ae
3 changed files with 68 additions and 28 deletions

View File

@ -34,37 +34,46 @@ class Copy(object):
self.current_copy = None
self.ignore_list = ignore_list
self.cancelled = False
self.initialized = False
self.completed = False
def get_progress(self):
if self.current_copy is not None:
try:
size, err = utils.execute("stat", "-c", "%s",
self.current_copy['file_path'],
run_as_root=True)
size = int(size)
except utils.processutils.ProcessExecutionError:
size = 0
total_progress = 0
if self.total_size > 0:
total_progress = self.current_size * 100 / self.total_size
current_file_progress = 0
if self.current_copy['size'] > 0:
current_file_progress = size * 100 / self.current_copy['size']
current_file_path = self.current_copy['file_path']
progress = {
'total_progress': total_progress,
'current_file_path': current_file_path,
'current_file_progress': current_file_progress
}
return progress
else:
# Empty share or empty contents
if self.completed and self.total_size == 0:
return {'total_progress': 100}
if not self.initialized or self.current_copy is None:
return {'total_progress': 0}
try:
size, err = utils.execute("stat", "-c", "%s",
self.current_copy['file_path'],
run_as_root=True)
size = int(size)
except utils.processutils.ProcessExecutionError:
size = 0
current_file_progress = 0
if self.current_copy['size'] > 0:
current_file_progress = size * 100 / self.current_copy['size']
current_file_path = self.current_copy['file_path']
total_progress = 0
if self.total_size > 0:
if current_file_progress == 100:
size = 0
total_progress = int((self.current_size + size) *
100 / self.total_size)
progress = {
'total_progress': total_progress,
'current_file_path': current_file_path,
'current_file_progress': current_file_progress
}
return progress
def cancel(self):
self.cancelled = True
@ -72,8 +81,10 @@ class Copy(object):
def run(self):
self.get_total_size(self.src)
self.initialized = True
self.copy_data(self.src)
self.copy_stats(self.src)
self.completed = True
LOG.info(six.text_type(self.get_progress()))

View File

@ -45,6 +45,7 @@ class CopyClassTestCase(test.TestCase):
mock.Mock(return_value=("100", "")))
# run
self._copy.initialized = True
out = self._copy.get_progress()
# asserts
@ -53,11 +54,34 @@ class CopyClassTestCase(test.TestCase):
utils.execute.assert_called_once_with("stat", "-c", "%s", "/fake/path",
run_as_root=True)
def test_get_progress_current_copy_none(self):
self._copy.current_copy = None
def test_get_progress_not_initialized(self):
expected = {'total_progress': 0}
# run
self._copy.initialized = False
out = self._copy.get_progress()
# asserts
self.assertEqual(expected, out)
def test_get_progress_completed_empty(self):
expected = {'total_progress': 100}
# run
self._copy.initialized = True
self._copy.completed = True
self._copy.total_size = 0
out = self._copy.get_progress()
# asserts
self.assertEqual(expected, out)
def test_get_progress_current_copy_none(self):
self._copy.current_copy = None
expected = {'total_progress': 0}
# run
self._copy.initialized = True
out = self._copy.get_progress()
# asserts
@ -74,6 +98,7 @@ class CopyClassTestCase(test.TestCase):
mock.Mock(side_effect=utils.processutils.ProcessExecutionError()))
# run
self._copy.initialized = True
out = self._copy.get_progress()
# asserts

View File

@ -0,0 +1,4 @@
---
fixes:
- Fixed share migration error using Data Service when there are
only empty files.