diff --git a/nova/api/openstack/placement/requestlog.py b/nova/api/openstack/placement/requestlog.py index ad071d78f..8b3639e76 100644 --- a/nova/api/openstack/placement/requestlog.py +++ b/nova/api/openstack/placement/requestlog.py @@ -36,6 +36,10 @@ class RequestLog(object): LOG.debug('Starting request: %s "%s %s"', environ['REMOTE_ADDR'], environ['REQUEST_METHOD'], self._get_uri(environ)) + # Set the accept header if it is not otherwise set. This + # ensures that error responses will be in JSON. + if not environ.get('HTTP_ACCEPT'): + environ['HTTP_ACCEPT'] = 'application/json' if LOG.isEnabledFor(logging.INFO): return self._log_app(environ, start_response) else: diff --git a/nova/tests/functional/api/openstack/placement/gabbits/bug-1674694.yaml b/nova/tests/functional/api/openstack/placement/gabbits/bug-1674694.yaml new file mode 100644 index 000000000..609f01574 --- /dev/null +++ b/nova/tests/functional/api/openstack/placement/gabbits/bug-1674694.yaml @@ -0,0 +1,38 @@ +# Test launchpad bug https://bugs.launchpad.net/nova/+bug/1674694 + +fixtures: + - APIFixture + +defaults: + request_headers: + x-auth-token: admin + +tests: + +- name: 404 with application/json + GET: /bc8d9d50-7b0d-45ef-839c-e7b5e1c4e8fd + request_headers: + accept: application/json + status: 404 + response_headers: + content-type: application/json + response_json_paths: + $.errors[0].status: 404 + +- name: 404 with no accept + GET: /bc8d9d50-7b0d-45ef-839c-e7b5e1c4e8fd + status: 404 + response_headers: + content-type: application/json + response_json_paths: + $.errors[0].status: 404 + +- name: 404 with other accept + GET: /bc8d9d50-7b0d-45ef-839c-e7b5e1c4e8fd + status: 404 + request_headers: + accept: text/html + response_headers: + content-type: /text/html/ + response_strings: + - The resource could not be found diff --git a/nova/tests/functional/api/openstack/placement/gabbits/microversion-bug-1724065.yaml b/nova/tests/functional/api/openstack/placement/gabbits/microversion-bug-1724065.yaml new file mode 100644 index 000000000..718faaf02 --- /dev/null +++ b/nova/tests/functional/api/openstack/placement/gabbits/microversion-bug-1724065.yaml @@ -0,0 +1,22 @@ +# Test launchpad bug https://bugs.launchpad.net/nova/+bug/1724065 + +fixtures: + - APIFixture + +defaults: + request_headers: + x-auth-token: user + +tests: + +# min version from start of placement time is 1.0 +# Without the fix, this results in a 500 with an 'HTTP_ACCEPT' +# KeyError. +- name: no accept header and out of range microversion + GET: /resource_providers + request_headers: + openstack-api-version: placement 0.9 + status: 406 + response_strings: + - Unacceptable version header + diff --git a/nova/tests/functional/api/openstack/placement/gabbits/traits.yaml b/nova/tests/functional/api/openstack/placement/gabbits/traits.yaml index c8e6ba9bb..6cdadf138 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/traits.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/traits.yaml @@ -13,13 +13,13 @@ tests: PUT: /traits/TRAIT_X status: 400 response_strings: - - 'The trait is invalid. A valid trait must include prefix "CUSTOM_" and use following characters: "A"-"Z", "0"-"9" and "_"' + - 'The trait is invalid. A valid trait must include prefix \"CUSTOM_\" and use following characters: \"A\"-\"Z\", \"0\"-\"9\" and \"_\"' - name: create a trait with invalid characters PUT: /traits/CUSTOM_ABC:1 status: 400 response_strings: - - 'The trait is invalid. A valid trait must include prefix "CUSTOM_" and use following characters: "A"-"Z", "0"-"9" and "_"' + - 'The trait is invalid. A valid trait must include prefix \"CUSTOM_\" and use following characters: \"A\"-\"Z\", \"0\"-\"9\" and \"_\"' - name: create a trait PUT: /traits/CUSTOM_TRAIT_1 @@ -93,7 +93,7 @@ tests: GET: /traits?name=in_abc status: 400 response_strings: - - 'Badly formatted name parameter. Expected name query string parameter in form: ?name=[in|startswith]:[name1,name2|prefix]. Got: "in_abc"' + - 'Badly formatted name parameter. Expected name query string parameter in form: ?name=[in|startswith]:[name1,name2|prefix]. Got: \"in_abc\"' - name: list traits with name=in filter GET: /traits?name=in:CUSTOM_TRAIT_1,CUSTOM_TRAIT_2 @@ -177,7 +177,7 @@ tests: GET: /traits?associated=xyz status: 400 response_strings: - - 'The query parameter "associated" only accepts "true" or "false"' + - 'The query parameter \"associated\" only accepts \"true\" or \"false\"' - name: set traits for resource provider without resource provider generation PUT: /resource_providers/$ENVIRON['RP_UUID']/traits