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(a)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 50f8c43..91a70ae 100644
--- a/src/kimchi/control/base.py
+++ b/src/kimchi/control/base.py
@@ -308,6 +308,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 fc4b1ff..fea0184 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -174,6 +174,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 should give a name for the debug file
report."),
+ "KCHDR0007E": _("Name should 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