[Kimchi-devel] [PATCH V2 1/2] Fix debug report naming problem (backend)
Rodrigo Trujillo
rodrigo.trujillo at linux.vnet.ibm.com
Mon Feb 24 14:20:49 UTC 2014
On 02/24/2014 09:59 AM, Aline Manera wrote:
> On 02/21/2014 06:10 PM, Rodrigo Trujillo wrote:
>> 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.
>>
>> Implement name generation in backend
>>
>> 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..e393324 100644
>> --- a/src/kimchi/API.json
>> +++ b/src/kimchi/API.json
>> @@ -29,6 +29,18 @@
>> }
>> },
>> "properties": {
>> + "debugreports_create": {
>> + "type": "object",
>> + "error": "KCHDEBREP0006E",
>> + "properties": {
>> + "name": {
>> + "description": "The name for the debug report
>> file.",
>> + "type": "string",
>> + "pattern": "^[A-Za-z0-9-]*$",
>> + "error": "KCHDEBREP0007E"
>> + }
>> + }
>> + },
>> "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."),
>
> The above message isn't being used.
Actually it is used in error return of json schema, but it was wrongly
written there. I fixed this
>
>> + "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..aa70a6b 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')
>
> You need to strip() the name value. Otherwise we will accept " "
> like a name
The api schema will not allow spaces in the name. But I am going to add
the strip, then we avoid problems in the case of
someone calls the function directly.
>
>> + # 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)
>>
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>
More information about the Kimchi-devel
mailing list