Refactor argument parsing, validation, error reporting in REST API
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
craton |
Fix Released
|
High
|
Jim Baker |
Bug Description
Various fixes for Craton API we need to do:
* Better input validation, such as checking bad IP addresses before
insertion corrupts subsequent database usage
* Reporting of errors, especially CRUD errors such as duplicate
resources that violate uniqueness indexes
* Usage consistency - /v1/netdevices?
* Support for queries like so /v1/hosts?
this requires relaxing the current input validation
(We may want to split into separate bugs, but it is possible this can be reasonably done in a single refactoring change that's not so big - they are all related.)
Let's look at input validation. For example we will attempt to create
a new NetDevice with the ip_address = 'bad-ip':
curl http://
The inventory entry is successfully created, as reported:
{"parent_id": null, "name": "cabinet_
Subsequent queries of any network devices
curl http://
will then result in messages like so:
{
"message": "Unknown Error",
"status": 500
}
The underlying error is reported in the API server logs:
172.17.0.1 - - [13/Sep/2016 14:19:44] "GET /v1/netdevices?
2016-09-13 14:20:21.458 188 INFO craton.
2016-09-13 14:20:21.466 188 ERROR craton.
Note that any filtering query on netdevices will fail with the same
error. Likely this is the correct error here - we should not
necessarily report details on database corruption.
After manually cleaning up the database, we can try another
interaction where we insert a duplicate. Run the following command
twice:
curl http://
The second attempt results in
{
"message": "Unknown Error",
"status": 500
}
with the log
172.17.0.1 - - [13/Sep/2016 15:21:19] "POST /v1/netdevices HTTP/1.1" 200 964
2016-09-13 15:21:20.543 188 ERROR craton.
It should be instead something like 409: Duplicate entry, with the API server supporting bubbling up integrity errors like this as appropriate user friendly exceptions.
Changed in craton: | |
importance: | Undecided → High |
assignee: | nobody → Jim Baker (jimbaker) |
milestone: | none → newton-rc |
Changed in craton: | |
status: | New → Fix Committed |
Changed in craton: | |
status: | Fix Committed → Fix Released |
Reviewed: https:/ /review. openstack. org/378977 /git.openstack. org/cgit/ openstack/ craton/ commit/ ?id=33349891a7e 28ff9d9f58a5e5e 654e653ed293a9
Committed: https:/
Submitter: Jenkins
Branch: master
commit 33349891a7e28ff 9d9f58a5e5e654e 653ed293a9
Author: Jim Baker <email address hidden>
Date: Tue Oct 4 08:45:17 2016 -0600
Refactor REST API support to remove boilerplate
This change removes the following boilerplate:
* Most filter setup, along with output to a JSON response, is now api.v1. base.filtered_ context decorator.
captured in the new craton.
* Provides standard exception to HTTP status code mapping using the api.v1. base.http_ codes decorator.
new craton.
There are additional opportunities for boilerplate removal, especially
in scenarios where we have multiple ways of looking up a specific cell
or region; but this boilerplate is not addressed in this fix.
This change does not implement related opportunities for cleanup, such
as import reordering or doc strings. These should be in separate
changes, per discussion on Gerrit.
In addition, this change now returns 204 upon DELETE in the API; and
adds version info to requirements.txt for Flask to conform to Jenkins
gate check.
Change-Id: I7da8e9620c2fb0 7ebd3953cc6d76d 47c08651fe7
Partial-Bug: 1623095
Closes-Bug: 1628050