[PATCH V2] [Kimchi 0/2] Run wok tests without administration permissions

- Updated test case instead of deleting it. Lucio Correia (2): Fix tests to run without proxy Fix storage volume test to run without nginx tests/test_model_storagevolume.py | 15 ++++++++++----- tests/test_rest.py | 16 ++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) -- 2.7.4

Connect directly to cherrypy, without using nginx. Use json instead of dictionary, since Cherrypy does not understand a dict as JSON data. Since tests are now ran without nginx proxy, those need to be fixed. Signed-off-by: Lucio Correia <luciojhc@linux.vnet.ibm.com> --- tests/test_model_storagevolume.py | 4 ++-- tests/test_rest.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test_model_storagevolume.py b/tests/test_model_storagevolume.py index a1f1db9..638751a 100644 --- a/tests/test_model_storagevolume.py +++ b/tests/test_model_storagevolume.py @@ -28,7 +28,7 @@ import unittest from functools import partial from tests.utils import fake_auth_header, HOST -from tests.utils import patch_auth, PROXY_PORT, request +from tests.utils import patch_auth, PORT, request from tests.utils import rollback_wrapper, run_server, wait_task from wok.config import paths @@ -171,7 +171,7 @@ def _do_volume_test(self, model, pool_name): self.assertEquals('ready for upload', status['message']) # Upload volume content - url = 'https://%s:%s' % (HOST, PROXY_PORT) + uri + '/' + filename + url = 'http://%s:%s' % (HOST, PORT) + uri + '/' + filename # Create a file with 5M to upload # Max body size is set to 4M so the upload will fail with 413 diff --git a/tests/test_rest.py b/tests/test_rest.py index 4c7ab5b..852e4bd 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -909,17 +909,17 @@ class RestTests(unittest.TestCase): ) self.assertEquals(3, len(devs)) resp = self.request('/plugins/kimchi/storagepools/tmp/deactivate', - {}, 'POST') + '{}', 'POST') self.assertEquals(200, resp.status) # cannot delete storagepool with volumes associate to guests - resp = self.request('/plugins/kimchi/storagepools/tmp', {}, + resp = self.request('/plugins/kimchi/storagepools/tmp', '{}', 'DELETE') self.assertEquals(400, resp.status) # activate pool resp = self.request('/plugins/kimchi/storagepools/tmp/activate', - {}, 'POST') + '{}', 'POST') self.assertEquals(200, resp.status) # delete volumes @@ -927,14 +927,14 @@ class RestTests(unittest.TestCase): l = '/plugins/kimchi/vms/test-vm/storages/hdd' else: l = '/plugins/kimchi/vms/test-vm/storages/vdb' - resp = self.request(l, {}, 'DELETE') + resp = self.request(l, '{}', 'DELETE') self.assertEquals(204, resp.status) # deactive and delete storage pool resp = self.request('/plugins/kimchi/storagepools/tmp/deactivate', - {}, 'POST') + '{}', 'POST') self.assertEquals(200, resp.status) - resp = self.request('/plugins/kimchi/storagepools/tmp', {}, + resp = self.request('/plugins/kimchi/storagepools/tmp', '{}', 'DELETE') self.assertEquals(204, resp.status) @@ -1151,7 +1151,7 @@ class RestTests(unittest.TestCase): self.assertEquals(202, resp.status) task = json.loads(resp.read()) wait_task(self._task_lookup, task['id']) - resp = self.request('/plugins/kimchi/vms/test-vm', {}, 'GET') + resp = self.request('/plugins/kimchi/vms/test-vm', '{}', 'GET') vm_info = json.loads(resp.read()) # Test template not changed after vm customise its pool @@ -1246,7 +1246,7 @@ class RestTests(unittest.TestCase): task = json.loads(self.request('/plugins/kimchi/vms', req, 'POST').read()) wait_task(self._task_lookup, task['id']) - resp = self.request('/plugins/kimchi/vms/test-vm-%i' % i, {}, + resp = self.request('/plugins/kimchi/vms/test-vm-%i' % i, '{}', 'GET') self.assertEquals(resp.status, 200) count = len(json.loads(self.request('/plugins/kimchi/vms').read())) -- 2.7.4

Now that test requests are made directly to cherrypy, which aborts connection in case of an HTTP 413 error, the test case needs to be changed to expect for that exception instead. Signed-off-by: Lucio Correia <luciojhc@linux.vnet.ibm.com> --- tests/test_model_storagevolume.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_model_storagevolume.py b/tests/test_model_storagevolume.py index 638751a..36be961 100644 --- a/tests/test_model_storagevolume.py +++ b/tests/test_model_storagevolume.py @@ -26,6 +26,7 @@ import requests import tempfile import unittest from functools import partial +from requests.exceptions import ConnectionError from tests.utils import fake_auth_header, HOST from tests.utils import patch_auth, PORT, request @@ -174,7 +175,10 @@ def _do_volume_test(self, model, pool_name): url = 'http://%s:%s' % (HOST, PORT) + uri + '/' + filename # Create a file with 5M to upload - # Max body size is set to 4M so the upload will fail with 413 + # Max body size is set to 4M so the upload should fail with 413. + # Since nginx is not being used for testing anymore, and cherrypy + # aborts connection instead of returning a 413 like nginx does, + # test case expects for exception raised by cherrypy. newfile = '/tmp/5m-file' with open(newfile, 'wb') as fd: fd.seek(5*1024*1024-1) @@ -187,11 +191,12 @@ def _do_volume_test(self, model, pool_name): tmp_fd.write(data) with open(newfile + '.tmp', 'rb') as tmp_fd: - r = requests.put(url, data={'chunk_size': len(data)}, + error_msg = "Connection aborted" + with self.assertRaisesRegexp(ConnectionError, error_msg): + requests.put(url, data={'chunk_size': len(data)}, files={'chunk': tmp_fd}, verify=False, headers=fake_auth_header()) - self.assertEquals(r.status_code, 413) # Do upload index = 0 -- 2.7.4
participants (2)
-
Aline Manera
-
Lucio Correia