When creating a new storage volume for upload we should keep the task
tracking to allow updating the UI properly.
That way the task will be only finished on upload error or when it is
finished.
Signed-off-by: Aline Manera <alinefm(a)linux.vnet.ibm.com>
---
src/kimchi/mockmodel.py | 3 ++-
src/kimchi/model/storagevolumes.py | 20 ++++++++++++++------
tests/test_model_storagevolume.py | 2 +-
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 19dfd1e..aaf1af2 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -308,7 +308,7 @@ class MockModel(Model):
return self._model_storagevolume_lookup(pool, vol)
- def _mock_storagevolume_doUpload(self, vol, offset, data, data_size):
+ def _mock_storagevolume_doUpload(self, cb, vol, offset, data, data_size):
vol_path = vol.path()
# MockModel does not create the storage volume as a file
@@ -325,6 +325,7 @@ class MockModel(Model):
fd.write(data)
except Exception, e:
os.remove(vol_path)
+ cb('', False)
raise OperationFailed("KCHVOL0029E", {"err": e.message})
def _mock_partitions_get_list(self):
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index 9165946..f8b3263 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -155,12 +155,14 @@ class StorageVolumesModel(object):
name)
vol_path = vol_info['path']
- if params.get('upload', False):
- upload_volumes[vol_path] = {'lock': threading.Lock(),
'offset': 0}
-
set_disk_used_by(self.objstore, vol_info['path'], [])
- cb('', True)
+ if params.get('upload', False):
+ upload_volumes[vol_path] = {'lock': threading.Lock(),
+ 'offset': 0, 'cb': cb}
+ cb('ready for upload')
+ else:
+ cb('OK', True)
def _create_volume_with_url(self, cb, params):
pool_name = params['pool']
@@ -459,7 +461,7 @@ class StorageVolumeModel(object):
cb('OK', True)
- def doUpload(self, vol, offset, data, data_size):
+ def doUpload(self, cb, vol, offset, data, data_size):
try:
st = self.conn.get().newStream(0)
vol.upload(st, offset, data_size)
@@ -467,6 +469,8 @@ class StorageVolumeModel(object):
st.finish()
except Exception as e:
st and st.abort()
+ cb('', False)
+
try:
vol.delete(0)
except Exception as e:
@@ -489,17 +493,21 @@ class StorageVolumeModel(object):
if vol_data is None:
raise OperationFailed("KCHVOL0027E", {"vol": vol_path})
+ cb = vol_data['cb']
lock = vol_data['lock']
with lock:
offset = vol_data['offset']
if (offset + chunk_size) > vol_capacity:
raise OperationFailed("KCHVOL0028E")
- self.doUpload(vol, offset, chunk_data, chunk_size)
+ cb('%s/%s' % (offset, vol_capacity))
+ self.doUpload(cb, vol, offset, chunk_data, chunk_size)
+ cb('%s/%s' % (offset + chunk_size, vol_capacity))
vol_data['offset'] += chunk_size
if vol_data['offset'] == vol_capacity:
del upload_volumes[vol_path]
+ cb('OK', True)
class IsoVolumesModel(object):
diff --git a/tests/test_model_storagevolume.py b/tests/test_model_storagevolume.py
index b6aaffb..5e76d3d 100644
--- a/tests/test_model_storagevolume.py
+++ b/tests/test_model_storagevolume.py
@@ -168,7 +168,7 @@ def _do_volume_test(self, model, host, ssl_port, pool_name):
task_id = json.loads(resp.read())['id']
wait_task(_task_lookup, task_id)
status = json.loads(self.request('/tasks/%s' % task_id).read())
- self.assertEquals('finished', status['status'])
+ self.assertEquals('ready for upload', status['message'])
# Upload volume content
url = 'https://%s:%s' % (host, ssl_port) + uri + '/' +
filename
--
2.1.0