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 c81cabb..d73871d 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 dc807e4..664b128 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -155,9 +155,6 @@ class StorageVolumesModel(object):
name)
vol_path = vol_info['path']
- if params.get('upload', False):
- upload_volumes[vol_path] = {'lock': threading.Lock(),
'offset': 0}
-
try:
with self.objstore as session:
session.store('storagevolume', vol_path, {'ref_cnt': 0})
@@ -167,7 +164,12 @@ class StorageVolumesModel(object):
kimchi_log.warning('Unable to store storage volume id in '
'objectstore due error: %s', e.message)
- 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']
@@ -462,7 +464,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)
@@ -470,6 +472,8 @@ class StorageVolumeModel(object):
st.finish()
except Exception as e:
st and st.abort()
+ cb('', False)
+
try:
vol.delete(0)
except Exception as e:
@@ -492,17 +496,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 fea1de1..8f0e878 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