[Kimchi-devel] [PATCH V2 3/5] Fix 'disk full' issue: Fix storage volume error handling

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Thu Mar 27 16:08:42 UTC 2014


This patch fixes the error handling when storagevolume.py tries to
update the database with reference count information.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/kimchi/i18n.py                 |  1 +
 src/kimchi/model/storagevolumes.py | 49 ++++++++++++++++++++++++--------------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index e8b3503..35aeef9 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -163,6 +163,7 @@ messages = {
     "KCHVOL0014E": _("Storage volume allocation must be an integer number"),
     "KCHVOL0015E": _("Storage volume format not supported"),
     "KCHVOL0016E": _("Storage volume requires a volume name"),
+    "KCHVOL0017E": _("Unable to update database with storage volume information due error: %(err)s"),
 
     "KCHIFACE0001E": _("Interface %(name)s does not exist"),
 
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index 1253823..6a91c86 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -79,8 +79,14 @@ class StorageVolumesModel(object):
                                   {'name': name, 'pool': pool,
                                    'err': e.get_error_message()})
 
-        with self.objstore as session:
-            session.store('storagevolume', vol_id, {'ref_cnt': 0})
+        try:
+            with self.objstore as session:
+                session.store('storagevolume', vol_id, {'ref_cnt': 0})
+        except Exception as e:
+            # If the storage volume was created flawlessly, then lets hide this
+            # error to avoid more error in the VM creation process
+            kimchi_log.warning('Unable to store storage volume id in '
+                               'objectstore due error: %s', e.message)
 
         return name
 
@@ -117,22 +123,29 @@ class StorageVolumeModel(object):
 
     def _get_ref_cnt(self, pool, name, path):
         vol_id = '%s:%s' % (pool, name)
-        with self.objstore as session:
-            try:
-                ref_cnt = session.get('storagevolume', vol_id)['ref_cnt']
-            except NotFoundError:
-                # Fix storage volume created outside kimchi scope
-                ref_cnt = 0
-                args = {'conn': self.conn, 'objstore': self.objstore}
-                # try to find this volume in exsisted vm
-                vms = VMsModel.get_vms(self.conn)
-                for vm in vms:
-                    storages = VMStoragesModel(**args).get_list(vm)
-                    for disk in storages:
-                        d_info = VMStorageModel(**args).lookup(vm, disk)
-                        if path == d_info['path']:
-                            ref_cnt = ref_cnt + 1
-                session.store('storagevolume', vol_id, {'ref_cnt': ref_cnt})
+        try:
+            with self.objstore as session:
+                try:
+                    ref_cnt = session.get('storagevolume', vol_id)['ref_cnt']
+                except NotFoundError:
+                    # Fix storage volume created outside kimchi scope
+                    ref_cnt = 0
+                    args = {'conn': self.conn, 'objstore': self.objstore}
+                    # try to find this volume in exsisted vm
+                    vms = VMsModel.get_vms(self.conn)
+                    for vm in vms:
+                        storages = VMStoragesModel(**args).get_list(vm)
+                        for disk in storages:
+                            d_info = VMStorageModel(**args).lookup(vm, disk)
+                            if path == d_info['path']:
+                                ref_cnt = ref_cnt + 1
+                    session.store('storagevolume', vol_id,
+                                 {'ref_cnt': ref_cnt})
+        except Exception as e:
+            # This exception is going to catch errors returned by 'with',
+            # specially ones generated by 'session.store'. It is outside
+            # to avoid conflict with the __exit__ function of 'with'
+            raise OperationFailed('KCHVOL0017E',{'err': e.message})
 
         return ref_cnt
 
-- 
1.8.5.3




More information about the Kimchi-devel mailing list