[Kimchi-devel] [PATCH v4 1/4] Add Name Existence Check for Debug Report when Create

Hongliang Wang hlwang at linux.vnet.ibm.com
Tue Jun 17 08:37:37 UTC 2014


Prevent user to overwrite an existing debug report with same name.

Signed-off-by: Hongliang Wang <hlwang at linux.vnet.ibm.com>
---
 src/kimchi/i18n.py               | 1 +
 src/kimchi/model/debugreports.py | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 452ede2..90ecc17 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -207,6 +207,7 @@ messages = {
     "KCHDR0005E": _("Unable to generate debug report %(name)s. Details: %(err)s"),
     "KCHDR0006E": _("You should give a name for the debug file report."),
     "KCHDR0007E": _("Name should be a string. Only letters, digits and hyphen ('-') are allowed."),
+    "KCHDR0008E": _("The debug report with specified name \"%(name)s\" already exists. Please use another one."),
 
     "KCHSR0001E": _("Storage server %(server)s was not used by Kimchi"),
 
diff --git a/src/kimchi/model/debugreports.py b/src/kimchi/model/debugreports.py
index cd31b31..18c2187 100644
--- a/src/kimchi/model/debugreports.py
+++ b/src/kimchi/model/debugreports.py
@@ -26,7 +26,7 @@ import subprocess
 import time
 
 from kimchi import config
-from kimchi.exception import KimchiException, NotFoundError, OperationFailed
+from kimchi.exception import KimchiException, NotFoundError, OperationFailed, InvalidParameter
 from kimchi.model.tasks import TaskModel
 from kimchi.utils import add_task, kimchi_log
 from kimchi.utils import run_command
@@ -42,6 +42,9 @@ class DebugReportsModel(object):
         # Generate a name with time and millisec precision, if necessary
         if ident is None or ident == "":
             ident = 'report-' + str(int(time.time() * 1000))
+        else:
+            if ident in self.get_list():
+                raise InvalidParameter("KCHDR0008E", {"name": ident})
         taskid = self._gen_debugreport_file(ident)
         return self.task.lookup(taskid)
 
-- 
1.8.1.4




More information about the Kimchi-devel mailing list