[Kimchi-devel] [PATCH 2/5] Fix 'disk full' issue: Fix Templates db store/delete error handling
Rodrigo Trujillo
rodrigo.trujillo at linux.vnet.ibm.com
Mon Mar 24 20:53:35 UTC 2014
If disk is full and user tries to create a new template, Kimchi is going
to fail with "server unexpected error". The same problem happens if user
tries to delete a template. This patch modifies Templates code in order
to handle errors properly.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 2 ++
src/kimchi/model/templates.py | 22 +++++++++++++++-------
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 589c8cb..231ea25 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -107,6 +107,8 @@ messages = {
"KCHTMPL0015E": _("Invalid storage pool URI %(value)s specified for template"),
"KCHTMPL0016E": _("Specify an ISO image as CDROM to create a template"),
"KCHTMPL0017E": _("All networks for the template must be specified in a list."),
+ "KCHTMPL0018E": _("Unable to create template due error: %(err)s"),
+ "KCHTMPL0019E": _("Unable to delete template due error: %(err)s"),
"KCHPOOL0001E": _("Storage pool %(name)s already exists"),
"KCHPOOL0002E": _("Storage pool %(name)s does not exist"),
diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py
index 5376b6c..ecdc907 100644
--- a/src/kimchi/model/templates.py
+++ b/src/kimchi/model/templates.py
@@ -25,6 +25,7 @@ import libvirt
from kimchi import xmlutils
from kimchi.exception import InvalidOperation, InvalidParameter
+from kimchi.exception import OperationFailed
from kimchi.kvmusertests import UserTests
from kimchi.utils import pool_name_from_uri
from kimchi.utils import probe_file_permission_as_user
@@ -71,11 +72,15 @@ class TemplatesModel(object):
raise InvalidParameter("KCHTMPL0003E", {'network': net_name,
'template': name})
- with self.objstore as session:
- if name in session.get_list('template'):
- raise InvalidOperation("KCHTMPL0001E", {'name': name})
- t = LibvirtVMTemplate(params, scan=True)
- session.store('template', name, t.info)
+ try:
+ with self.objstore as session:
+ if name in session.get_list('template'):
+ raise InvalidOperation("KCHTMPL0001E", {'name': name})
+ t = LibvirtVMTemplate(params, scan=True)
+ session.store('template', name, t.info)
+ except Exception as e:
+ raise OperationFailed('KCHTMPL0018E', {'err': e.message})
+
return name
def get_list(self):
@@ -118,8 +123,11 @@ class TemplateModel(object):
return ident
def delete(self, name):
- with self.objstore as session:
- session.delete('template', name)
+ try:
+ with self.objstore as session:
+ session.delete('template', name)
+ except Exception as e:
+ raise OperationFailed('KCHTMPL0019E', {'err': e.message})
def update(self, name, params):
old_t = self.lookup(name)
--
1.8.5.3
More information about the Kimchi-devel
mailing list