[PATCH v2][Kimchi 0/2] Do not delete storage pool with storage volumes assigned to guests

Changes: v2: Use path to determine if volume comes from storage pool Do not use "get_disk_used_by". It will be usefull if we start querying by volumes. Since, we cannot list volumes with inactivate storage pools. Ramon Medeiros (2): Do not remove storagepools linked to guests Update tests i18n.py | 1 + model/storagepools.py | 22 ++++++++++++++++++++++ tests/test_rest.py | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+) -- 2.5.5

The initial propose was to extend this task to network pools, but, they already check if guests or templates are linked before deleting. Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- i18n.py | 1 + model/storagepools.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/i18n.py b/i18n.py index e8d9c05..ea2c4ab 100644 --- a/i18n.py +++ b/i18n.py @@ -227,6 +227,7 @@ messages = { "KCHPOOL0036E": _("A volume group named '%(name)s' already exists. Please, choose another name to create the logical pool."), "KCHPOOL0037E": _("Unable to update database with deep scan information due error: %(err)s"), "KCHPOOL0038E": _("No volume group '%(name)s' found. Please, specify an existing volume group to create the logical pool from."), + "KCHPOOL0039E": _("Unable to delete pool %(name)s as it is associated with guests: %(vms)s"), "KCHVOL0001E": _("Storage volume %(name)s already exists"), "KCHVOL0002E": _("Storage volume %(name)s does not exist in storage pool %(pool)s"), diff --git a/model/storagepools.py b/model/storagepools.py index a2dbaec..31c636c 100644 --- a/model/storagepools.py +++ b/model/storagepools.py @@ -474,12 +474,34 @@ class StoragePoolModel(object): pool = self.get_storagepool(name, self.conn) if pool.isActive(): raise InvalidOperation("KCHPOOL0005E", {'name': name}) + + vms = self._get_vms_attach_to_storagepool(name) + if len(vms) > 0: + raise InvalidOperation('KCHPOOL0039E', {'name': name, + 'vms': ",".join(vms)}) try: pool.undefine() except libvirt.libvirtError as e: raise OperationFailed("KCHPOOL0011E", {'name': name, 'err': e.get_error_message()}) + def _get_vms_attach_to_storagepool(self, storagepool): + conn = self.conn.get() + + # get storage pool path + pool = self.get_storagepool(storagepool, self.conn) + path = "".join(xpath_get_text(pool.XMLDesc(), "/pool/target/path")) + + # activate and deactive quickly to get volumes + vms = [] + for dom in conn.listAllDomains(0): + xml = dom.XMLDesc(0) + files = "/domain/devices/disk[@device='disk']/source/@file" + for file in xpath_get_text(xml, files): + if file not in vms and file.startswith(path): + vms.append(dom.name()) + return vms + class IsoPoolModel(object): def __init__(self, **kargs): -- 2.5.5

Signed-off-by: Ramon Medeiros <ramonn@linux.vnet.ibm.com> --- tests/test_rest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_rest.py b/tests/test_rest.py index 80596c2..c776cfe 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -863,8 +863,29 @@ class RestTests(unittest.TestCase): resp = self.request('/plugins/kimchi/storagepools/tmp/deactivate', {}, 'POST') self.assertEquals(200, resp.status) + + # cannot delete storagepool with volumes associate to guests resp = self.request('/plugins/kimchi/storagepools/tmp', {}, 'DELETE') + self.assertEquals(400, resp.status) + + # activate pool + resp = self.request('/plugins/kimchi/storagepools/tmp/activate', + {}, 'POST') + self.assertEquals(200, resp.status) + + # delete volumes + l = '/plugins/kimchi/vms/test-vm/storages/hdd' + resp = self.request(l, {}, 'DELETE') + self.assertEquals(204, resp.status) + + # deactive and delete storage pool + resp = self.request('/plugins/kimchi/storagepools/tmp/deactivate', + {}, 'POST') + self.assertEquals(200, resp.status) + resp = self.request('/plugins/kimchi/storagepools/tmp', {}, + 'DELETE') + self.assertEquals(204, resp.status) def test_vm_iface(self): -- 2.5.5

Reviewed-by: Paulo Ricardo Paz Vital <pvital@linux.vnet.ibm.com> On Aug 24 02:58PM, Ramon Medeiros wrote:
Changes:
v2: Use path to determine if volume comes from storage pool Do not use "get_disk_used_by". It will be usefull if we start querying by volumes. Since, we cannot list volumes with inactivate storage pools.
Ramon Medeiros (2): Do not remove storagepools linked to guests Update tests
i18n.py | 1 + model/storagepools.py | 22 ++++++++++++++++++++++ tests/test_rest.py | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+)
-- 2.5.5
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
-- Paulo Ricardo Paz Vital Linux Technology Center, IBM Systems http://www.ibm.com/linux/ltc/

Hi Ramon, could you rebase on master and resend, please? Thanks, Aline Manera On 08/24/2016 02:58 PM, Ramon Medeiros wrote:
Changes:
v2: Use path to determine if volume comes from storage pool Do not use "get_disk_used_by". It will be usefull if we start querying by volumes. Since, we cannot list volumes with inactivate storage pools.
Ramon Medeiros (2): Do not remove storagepools linked to guests Update tests
i18n.py | 1 + model/storagepools.py | 22 ++++++++++++++++++++++ tests/test_rest.py | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+)

Seems to be commited: https://github.com/kimchi-project/kimchi/commit/762437046fed6ba31549bd25af33... On 09/06/2016 01:49 PM, Aline Manera wrote:
Hi Ramon,
could you rebase on master and resend, please?
Thanks, Aline Manera
On 08/24/2016 02:58 PM, Ramon Medeiros wrote:
Changes:
v2: Use path to determine if volume comes from storage pool Do not use "get_disk_used_by". It will be usefull if we start querying by volumes. Since, we cannot list volumes with inactivate storage pools.
Ramon Medeiros (2): Do not remove storagepools linked to guests Update tests
i18n.py | 1 + model/storagepools.py | 22 ++++++++++++++++++++++ tests/test_rest.py | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+)
-- Ramon Nunes Medeiros Kimchi Developer Linux Technology Center Brazil IBM Systems & Technology Group Phone : +55 19 2132 7878 ramonn@br.ibm.com

On 09/06/2016 03:20 PM, Ramon Medeiros wrote:
Seems to be commited:
https://github.com/kimchi-project/kimchi/commit/762437046fed6ba31549bd25af33...
Ops... Seems I need vacation =)
On 09/06/2016 01:49 PM, Aline Manera wrote:
Hi Ramon,
could you rebase on master and resend, please?
Thanks, Aline Manera
On 08/24/2016 02:58 PM, Ramon Medeiros wrote:
Changes:
v2: Use path to determine if volume comes from storage pool Do not use "get_disk_used_by". It will be usefull if we start querying by volumes. Since, we cannot list volumes with inactivate storage pools.
Ramon Medeiros (2): Do not remove storagepools linked to guests Update tests
i18n.py | 1 + model/storagepools.py | 22 ++++++++++++++++++++++ tests/test_rest.py | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+)
participants (3)
-
Aline Manera
-
Paulo Ricardo Paz Vital
-
Ramon Medeiros