On 12/16/2015 12:24 PM, Aline Manera wrote:
On 15/12/2015 10:11, pvital(a)linux.vnet.ibm.com wrote:
> From: Paulo Vital <pvital(a)linux.vnet.ibm.com>
>
> Libvirt of the Fedora 23 is not able to delete the storage volume in the
> testcase test_image_based_template when testing ModelTests. This happens
> because Libvirt is not able to unlink/rmdir returning an error (-1) and
> setting errno to ENOENT, causing the error:
>
> "cannot unlink file '/var/lib/libvirt/images/base-vol.img':
Success"
>
> This patch fixes the testcase by manually remove the volume file from the
> storage pool directory if the
> wok.plugins.kimchi.model.storagevolume_delete()
> was not capable to delete the volume.
>
> Signed-off-by: Paulo Vital <pvital(a)linux.vnet.ibm.com>
> ---
> tests/test_model.py | 19 ++++++++++++++++---
> 1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/tests/test_model.py b/tests/test_model.py
> index 762f0f8..4aa19bd 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -96,6 +96,16 @@ class ModelTests(unittest.TestCase):
>
> os.unlink(self.tmp_store)
>
> + def temporary_storagevolume_delete(inst, pool, vol):
> + # Quick fix to passby the Libvirt error:
> + # "error: cannot unlink file '%(vol)': Success"
> + # in Fedora <= 23. The Libvirt fix will be present only on
> Fedora 24
> + try:
> + inst.storagevolume_delete(pool, vol)
> + except OperationFailed as e:
> + path = inst.storagevolume_lookup(pool, vol)['path']
> + os.remove(path)
> +
> def test_vm_info(self):
> inst = model.Model('test:///default', self.tmp_store)
> vms = inst.vms_get_list()
> @@ -250,19 +260,22 @@ class ModelTests(unittest.TestCase):
>
> @unittest.skipUnless(utils.running_as_root(), 'Must be run as
> root')
> def test_image_based_template(self):
> +
> inst = model.Model(objstore_loc=self.tmp_store)
>
> with RollbackContext() as rollback:
> + pool = 'default'
> vol = 'base-vol.img'
> params = {'name': vol,
> 'capacity': 1073741824, # 1 GiB
> 'allocation': 1048576, # 1 MiB
> 'format': 'qcow2'}
> - task_id = inst.storagevolumes_create('default',
> params)['id']
> - rollback.prependDefer(inst.storagevolume_delete,
> 'default', vol)
Does that mean the user will not be able to delete a volume through
Kimchi API?
DELETE /plugins/kimchi/storagepools/default/<vol>
If so, I suggest to move the manual removal to the API. So even though
libvirt fails, Kimchi will be able to remove the volume.
This happens only on Kimchi testcases. Look the ouput of my test:
[pvital(a)blah.br.ibm.com] [Thu Dec 17 19:01:13]
[~/Projects/wok+all]
$ curl -k -u test -H 'Content-type: application/json' -H 'Accept:
application/json'
'https://localhost:8001/plugins/kimchi/storagepools/default/storagevolumes'
-X POST -d '{"name": "base-vol.img", "capacity":
1073741824, "format":
"qcow2"}'
Enter host password for user 'test':
{
"status":"running",
"message":"OK",
"id":"1",
"target_uri":"/plugins/kimchi/storagepools/default/storagevolumes/base-vol.img"
}-------------------------------------------------------------------------------
[pvital(a)blah.br.ibm.com] [Thu Dec 17 19:02:33]
[~/Projects/wok+all]
$ curl -k -u test -H 'Content-type: application/json' -H 'Accept:
application/json'
'https://localhost:8001/plugins/kimchi/storagepools/default/storagevolumes/base-vol.img'
-X GET
Enter host password for user 'test':
{
"allocation":200704,
"isvalid":true,
"capacity":1073741824,
"name":"base-vol.img",
"format":"qcow2",
"path":"/var/lib/libvirt/images/base-vol.img",
"used_by":[],
"type":"file"
}-------------------------------------------------------------------------------
[pvital(a)blah.br.ibm.com] [Thu Dec 17 19:03:01]
[~/Projects/wok+all]
$ curl -k -u test -H 'Content-type: application/json' -H 'Accept:
application/json'
'https://localhost:8001/plugins/kimchi/storagepools/default/storagevolumes/base-vol.img'
-X DELETE
Enter host password for user 'test':
-------------------------------------------------------------------------------
[pvital(a)blah.br.ibm.com] [Thu Dec 17 19:03:47]
[~/Projects/wok+all]
$ curl -k -u test -H 'Content-type: application/json' -H 'Accept:
application/json'
'https://localhost:8001/plugins/kimchi/storagepools/default/storagevolumes/base-vol.img'
-X GET
Enter host password for user 'test':
{
"reason":"KCHVOL0002E: Storage volume base-vol.img does not exist in
storage pool default",
"code":"404 Not Found",
"call_stack":"Traceback (most recent call last):\n File
\"/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py\", line 670,
in respond\n response.body = self.handler()\n File
\"/usr/lib/python2.7/site-packages/cherrypy/lib/encoding.py\", line 217,
in __call__\n self.body = self.oldhandler(*args, **kwargs)\n File
\"/usr/lib/python2.7/site-packages/cherrypy/_cpdispatch.py\", line 61,
in __call__\n return self.callable(*self.args, **self.kwargs)\n File
\"/home/pvital/Projects/wok+all/src/wok/control/base.py\", line 184, in
index\n raise cherrypy.HTTPError(404, e.message)\nHTTPError: (404,
u'KCHVOL0002E: Storage volume base-vol.img does not exist in storage
pool default')\n"
}-------------------------------------------------------------------------------
[pvital(a)blah.br.ibm.com] [Thu Dec 17 19:03:57]
[~/Projects/wok+all]
$
> + task_id = inst.storagevolumes_create(pool, params)['id']
> + rollback.prependDefer(temporary_storagevolume_delete, inst,
> + pool, vol)
> inst.task_wait(task_id)
> self.assertEquals('finished',
> inst.task_lookup(task_id)['status'])
> - vol_path = inst.storagevolume_lookup('default',
vol)['path']
> + vol_path = inst.storagevolume_lookup(pool, vol)['path']
>
> # Create template based on IMG file
> tmpl_name = "img-tmpl"