kytos / maintenance

Kytos Maintenance Window NApp
0 stars 12 forks source link

Error when creating a maintenance without description: KeyError: 'description' #28

Closed italovalcy closed 3 years ago

italovalcy commented 3 years ago

Even though the description is not mandatory according to the API documentation, if you create a MW without providing it, Kytos will return error 500.

Steps to reproduce:

  1. Create a MW without description:
    curl -X POST -H 'Content-type: application/json'  http://localhost:8181/api/kytos/maintenance -d '{"start": "2021-03-11T16:00:19+0000", "end": "2021-03-11T16:01:19+0000", "items": ["00:00:00:00:00:00:02"]}'

Expected behavior: the MW should be created and ID returned.

Actual behavior: error 500 - Internal Server Error:

{"code":500,"description":"The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.","name":"Internal Server Error"}

From the Kytos log:

Mar 11 16:00:57 18d7d38a4769 kytos.core.controller:ERROR app:1892:  Exception on /api/kytos/maintenance [POST]
Mar 11 16:00:57 18d7d38a4769 Traceback (most recent call last):
Mar 11 16:00:57 18d7d38a4769 File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2447, in wsgi_app
Mar 11 16:00:57 18d7d38a4769 response = self.full_dispatch_request()
Mar 11 16:00:57 18d7d38a4769 File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1952, in full_dispatch_request
Mar 11 16:00:57 18d7d38a4769 rv = self.handle_user_exception(e)
Mar 11 16:00:57 18d7d38a4769 File "/usr/local/lib/python3.6/dist-packages/flask_cors/extension.py", line 161, in wrapped_function
Mar 11 16:00:57 18d7d38a4769 return cors_after_request(app.make_response(f(*args, **kwargs)))
Mar 11 16:00:57 18d7d38a4769 File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1821, in handle_user_exception
Mar 11 16:00:57 18d7d38a4769 reraise(exc_type, exc_value, tb)
Mar 11 16:00:57 18d7d38a4769 File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 39, in reraise
Mar 11 16:00:57 18d7d38a4769 raise value
Mar 11 16:00:57 18d7d38a4769 File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1950, in full_dispatch_request
Mar 11 16:00:57 18d7d38a4769 rv = self.dispatch_request()
Mar 11 16:00:57 18d7d38a4769 File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1936, in dispatch_request
Mar 11 16:00:57 18d7d38a4769 return self.view_functions[rule.endpoint](**req.view_args)
Mar 11 16:00:57 18d7d38a4769 File "//var/lib/kytos/napps/kytos/maintenance/main.py", line 71, in create_mw
Mar 11 16:00:57 18d7d38a4769 maintenance = MW.from_dict(data, self.controller)
Mar 11 16:00:57 18d7d38a4769 File "//var/lib/kytos/napps/../napps/kytos/maintenance/models.py", line 89, in from_dict
Mar 11 16:00:57 18d7d38a4769 description = mw_dict['description'] or None
Mar 11 16:00:57 18d7d38a4769 KeyError: 'description'

Workaround: provide the any description:

$ curl -X POST -H 'Content-type: application/json'  http://localhost:8181/api/kytos/maintenance -d '{"start": "2021-03-11T17:00:19+0000", "end": "2021-03-11T17:30:19+0000", "items": ["00:00:00:00:00:00:02"], "description": "xpto foobar"}'
{"mw_id":"9dd41f73353049ce8a1661543f5d6dd6"}