[Kimchi-devel] [PATCH V3 1/2] Fix debug report naming problem (backend)

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Mon Feb 24 14:20:35 UTC 2014


The tool sosreport only accepts letters, digits and hyphen in the name
of the report, non alphanumeric characteres are removed from the file
name and then Kimchi is not able to find the file.

This patch fixes the problem in the backend, adding json schema
verification.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/kimchi/API.json              | 12 ++++++++++++
 src/kimchi/control/base.py       |  1 +
 src/kimchi/i18n.py               |  2 ++
 src/kimchi/model/debugreports.py |  5 ++++-
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/API.json b/src/kimchi/API.json
index 1189c01..f595bbf 100644
--- a/src/kimchi/API.json
+++ b/src/kimchi/API.json
@@ -29,6 +29,18 @@
         }
     },
     "properties": {
+        "debugreports_create": {
+            "type": "object",
+            "error": "KCHDR0006E",
+            "properties": {
+                "name": {
+                    "description": "The name for the debug report file.",
+                    "type": "string",
+                    "pattern": "^[A-Za-z0-9-]*$",
+                    "error": "KCHDR0007E"
+                }
+            }
+        },
         "storagepools_create": {
             "type": "object",
             "error": "KCHPOOL0026E",
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
index 048dd34..2cfcfd7 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -307,6 +307,7 @@ class AsyncCollection(Collection):
                                                  get_class_name(self)})
             raise cherrypy.HTTPError(405, e.message)
 
+        validate_params(params, self, 'create')
         args = self.model_args + [params]
         task = create(*args)
         cherrypy.response.status = 202
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index dfc1b2b..7ca4060 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -173,6 +173,8 @@ messages = {
     "KCHDR0003E": _("Unable to create debug report %(name)s. Details: %(err)s."),
     "KCHDR0004E": _("Can not find any generated debug report matching name %(name)s"),
     "KCHDR0005E": _("Unable to generate debug report %(name)s. Details: %(err)s"),
+    "KCHDR0006E": _("You must give a name for the debug file report."),
+    "KCHDR0007E": _("Name must be a string. Only letters, digits and hyphen ('-') are allowed."),
 
     "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 7dbd69f..7573a5b 100644
--- a/src/kimchi/model/debugreports.py
+++ b/src/kimchi/model/debugreports.py
@@ -41,7 +41,10 @@ class DebugReportsModel(object):
         self.task = TaskModel(**kargs)
 
     def create(self, params):
-        ident = params['name']
+        ident = params.get('name').strip()
+        # Generate a name with time and millisec precision, if necessary
+        if ident is None or ident == "":
+            ident = 'report-' + str(int(time.time()*1000))
         taskid = self._gen_debugreport_file(ident)
         return self.task.lookup(taskid)
 
-- 
1.8.5.3




More information about the Kimchi-devel mailing list