[PATCH] Fix: accelerate mockmodel for file upload

From: Royce Lv <lvroyce@linux.vnet.ibm.com> File upload fails with error 404 because of small read is time consuming, change read size and wait in test to guarentee storage volume created when query URI. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/mockmodel.py | 2 +- tests/test_rest.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index ab4357d..cbbdba3 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -534,7 +534,7 @@ class MockModel(object): size = 0 try: while True: - data = upload_file.file.read(8192) + data = upload_file.file.read(8192*32) if not data: break size += len(data) diff --git a/tests/test_rest.py b/tests/test_rest.py index 7eb6233..fa44985 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -1948,8 +1948,10 @@ class RestTests(unittest.TestCase): self.assertEquals(r.status_code, 202) task = r.json() self._wait_task(task['id']) + time.sleep(5) resp = self.request('/storagepools/default/storagevolumes/%s' % task['target_uri'].split('/')[-1]) + self.assertEquals(200, resp.status) # Create a file with 5M to upload -- 1.8.3.2

On 25-09-2014 08:12, lvroyce@linux.vnet.ibm.com wrote:
- data = upload_file.file.read(8192) + data = upload_file.file.read(8192*32) if not data: break size += len(data)
The variable "data" doesn't seem to be used anywhere else after receiving data from the upload file. So why are we even reading it? Can't we skip the reading operation completely and just store the "volume"? It's a mock environment.
diff --git a/tests/test_rest.py b/tests/test_rest.py index 7eb6233..fa44985 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -1948,8 +1948,10 @@ class RestTests(unittest.TestCase): self.assertEquals(r.status_code, 202) task = r.json() self._wait_task(task['id']) + time.sleep(5)
The function "_wait_task" has an optional parameter which selects the maximum time it will wait for the task, in seconds. Its default value is 5. If you need to wait another 5 seconds, I'd suggest using: self._wait_task(task['id'], 10) rather than adding another sleep command. But I guess this won't be necessary if we skip reading the file as I suggested above.

On 2014年09月25日 21:46, Crístian Viana wrote:
On 25-09-2014 08:12, lvroyce@linux.vnet.ibm.com wrote:
- data = upload_file.file.read(8192) + data = upload_file.file.read(8192*32) if not data: break size += len(data)
The variable "data" doesn't seem to be used anywhere else after receiving data from the upload file. So why are we even reading it? Can't we skip the reading operation completely and just store the "volume"? It's a mock environment. I think why it is added on the first occasion is to test the status update (I mean progress) of reading, if no reading, no progress we can see.
diff --git a/tests/test_rest.py b/tests/test_rest.py index 7eb6233..fa44985 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -1948,8 +1948,10 @@ class RestTests(unittest.TestCase): self.assertEquals(r.status_code, 202) task = r.json() self._wait_task(task['id']) + time.sleep(5)
The function "_wait_task" has an optional parameter which selects the maximum time it will wait for the task, in seconds. Its default value is 5. If you need to wait another 5 seconds, I'd suggest using:
self._wait_task(task['id'], 10) ACK
rather than adding another sleep command.
But I guess this won't be necessary if we skip reading the file as I suggested above.
participants (3)
-
Crístian Viana
-
lvroyce@linux.vnet.ibm.com
-
Royce Lv