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(a)linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 2 ++
src/kimchi/model/templates.py | 27 ++++++++++++++++++++-------
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index d45f607..b3c3313 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -107,6 +107,8 @@ messages = {
"KCHTMPL0017E": _("All networks for the template must be specified in
a list."),
"KCHTMPL0018E": _("Must specify a volume to a template, when storage
pool is iscsi or scsi"),
"KCHTMPL0019E": _("The volume: %(volume)s in not in storage pool
%(pool)s"),
+ "KCHTMPL0020E": _("Unable to create template due error:
%(err)s"),
+ "KCHTMPL0021E": _("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 0e5c2b2..60f4de5 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 NotFoundError, OperationFailed
from kimchi.kvmusertests import UserTests
from kimchi.utils import pool_name_from_uri
from kimchi.utils import probe_file_permission_as_user
@@ -73,12 +74,19 @@ class TemplatesModel(object):
except Exception:
raise InvalidParameter("KCHTMPL0003E", {'network':
net_name,
'template': name})
+ # Creates the template class with necessary information
+ # Checkings will be done while creating this class, so any exception
+ # will be raised here
+ t = LibvirtVMTemplate(params, scan=True)
+
+ try:
+ with self.objstore as session:
+ if name in session.get_list('template'):
+ raise InvalidOperation("KCHTMPL0001E", {'name':
name})
+ session.store('template', name, t.info)
+ except Exception as e:
+ raise OperationFailed('KCHTMPL0020E', {'err': e.message})
- 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)
return name
def get_list(self):
@@ -143,8 +151,13 @@ 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 NotFoundError:
+ raise
+ except Exception as e:
+ raise OperationFailed('KCHTMPL0021E', {'err': e.message})
def update(self, name, params):
old_t = self.lookup(name)
--
1.8.5.3