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:
parent
ea9748fa4b
commit
e4ddb090ae
@ -34,10 +34,17 @@ class Copy(object):
|
|||||||
self.current_copy = None
|
self.current_copy = None
|
||||||
self.ignore_list = ignore_list
|
self.ignore_list = ignore_list
|
||||||
self.cancelled = False
|
self.cancelled = False
|
||||||
|
self.initialized = False
|
||||||
|
self.completed = False
|
||||||
|
|
||||||
def get_progress(self):
|
def get_progress(self):
|
||||||
|
|
||||||
if self.current_copy is not None:
|
# 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:
|
try:
|
||||||
size, err = utils.execute("stat", "-c", "%s",
|
size, err = utils.execute("stat", "-c", "%s",
|
||||||
@ -47,14 +54,18 @@ class Copy(object):
|
|||||||
except utils.processutils.ProcessExecutionError:
|
except utils.processutils.ProcessExecutionError:
|
||||||
size = 0
|
size = 0
|
||||||
|
|
||||||
total_progress = 0
|
|
||||||
if self.total_size > 0:
|
|
||||||
total_progress = self.current_size * 100 / self.total_size
|
|
||||||
current_file_progress = 0
|
current_file_progress = 0
|
||||||
if self.current_copy['size'] > 0:
|
if self.current_copy['size'] > 0:
|
||||||
current_file_progress = size * 100 / self.current_copy['size']
|
current_file_progress = size * 100 / self.current_copy['size']
|
||||||
current_file_path = self.current_copy['file_path']
|
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 = {
|
progress = {
|
||||||
'total_progress': total_progress,
|
'total_progress': total_progress,
|
||||||
'current_file_path': current_file_path,
|
'current_file_path': current_file_path,
|
||||||
@ -62,8 +73,6 @@ class Copy(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
return progress
|
return progress
|
||||||
else:
|
|
||||||
return {'total_progress': 100}
|
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
|
|
||||||
@ -72,8 +81,10 @@ class Copy(object):
|
|||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
self.get_total_size(self.src)
|
self.get_total_size(self.src)
|
||||||
|
self.initialized = True
|
||||||
self.copy_data(self.src)
|
self.copy_data(self.src)
|
||||||
self.copy_stats(self.src)
|
self.copy_stats(self.src)
|
||||||
|
self.completed = True
|
||||||
|
|
||||||
LOG.info(six.text_type(self.get_progress()))
|
LOG.info(six.text_type(self.get_progress()))
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ class CopyClassTestCase(test.TestCase):
|
|||||||
mock.Mock(return_value=("100", "")))
|
mock.Mock(return_value=("100", "")))
|
||||||
|
|
||||||
# run
|
# run
|
||||||
|
self._copy.initialized = True
|
||||||
out = self._copy.get_progress()
|
out = self._copy.get_progress()
|
||||||
|
|
||||||
# asserts
|
# asserts
|
||||||
@ -53,11 +54,34 @@ class CopyClassTestCase(test.TestCase):
|
|||||||
utils.execute.assert_called_once_with("stat", "-c", "%s", "/fake/path",
|
utils.execute.assert_called_once_with("stat", "-c", "%s", "/fake/path",
|
||||||
run_as_root=True)
|
run_as_root=True)
|
||||||
|
|
||||||
def test_get_progress_current_copy_none(self):
|
def test_get_progress_not_initialized(self):
|
||||||
self._copy.current_copy = None
|
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}
|
expected = {'total_progress': 100}
|
||||||
|
|
||||||
# run
|
# 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()
|
out = self._copy.get_progress()
|
||||||
|
|
||||||
# asserts
|
# asserts
|
||||||
@ -74,6 +98,7 @@ class CopyClassTestCase(test.TestCase):
|
|||||||
mock.Mock(side_effect=utils.processutils.ProcessExecutionError()))
|
mock.Mock(side_effect=utils.processutils.ProcessExecutionError()))
|
||||||
|
|
||||||
# run
|
# run
|
||||||
|
self._copy.initialized = True
|
||||||
out = self._copy.get_progress()
|
out = self._copy.get_progress()
|
||||||
|
|
||||||
# asserts
|
# asserts
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- Fixed share migration error using Data Service when there are
|
||||||
|
only empty files.
|
Loading…
Reference in New Issue
Block a user