Commit Graph

17 Commits (master)

Author SHA1 Message Date
Eric Harney 6b067f2b47 Import HTTPStatus instead of http_client
We don't need an HTTP client for this, we only
need status codes.  Just load that instead.

https://docs.python.org/3/library/http.html

Change-Id: Ia0a00a820fff55e25d352d2bf472054ef7074f34
3 years ago
xuanyandong a85ce6c817 Remove six of dir cinder/api/*
Replace the following items with Python 3 style code.

- six.string_types
- six.text_type
- six.moves
- six.PY3
- six.unichr

Change-Id: Ic46ec5f13a0dc1986d9c01e0d11df827d7e17bb0
3 years ago
pooja jadhav afa410bcf6 V3 jsonschema validation: Volume metadata
This patch adds jsonschema validation for below metadata API's
* POST /v3/{project_id}/volumes/{volume_id}/metadata
* PUT  /v3/{project_id}/volumes/{volume_id}/metadata
* PUT  /v3/{project_id}/volumes/{volume_id}/metadata/{key}

The reason behind applying schema for v2(update and update_all) is
that in "/cinder/tests/unit/api/v2/test_volume_metadata.py" module
from this patch, V2's unit test cases are inherited for V3 and now
we are applying schema validation for V3 because of that V2's unit
test cases responses are modified.  If we remove schema validation
from V2 then we will need to add separate unit test cases for V3.

Made changes to unit tests to pass body as keyword argument as wsgi
calls action method [1] and passes body as keyword argument.

[1] https://github.com/openstack/cinder/blob/master/cinder/api/openstack/wsgi.py#L997
Partial-Implements: bp json-schema-validation

Change-Id: I2226c8533cbd1ddd274d8dd0b2d77708463896f4
6 years ago
poojajadhav 92980e4972 Extracted HTTP response codes to constants
There are several places in the source code where HTTP response
codes are used as numeric values.

Status codes 200, 202, 204, 300, 400, 401, 403, 404, 405, 409, 413,
415, 500, 501, 503 under api/v1 and api/v2 are replaced with symbolic
constants from six.moves.http_client thus improves code readability.
More patches will be submitted to address other status codes.

Partial-Bug: #1520159
Change-Id: I7c61122a6b043d7d238bea95ef39d8fa97817df4
6 years ago
Yuriy Nesenenko 9771c2cd4e Separate create and update rules for volume metadata
This patch allows different policy rules for create and
update volume metadata.

Change-Id: I23dabd8866a9358c41eb3e048d91011a53c41cc3
Closes-Bug: #1472042
7 years ago
Gorka Eguileor c491c3ee61 Handle API NotFound exceptions at WSGI level
Throughout the API code we keep catching NotFound exceptions in their
various forms and converting them to webob.exc.HTTPNotFound exceptions,
but we can leave the WSGI fault handler convert them on its own.

This patch changes current behavior and removes the exception handling
closer to the operation so that those exceptions can be handled at the
WSGI level.

This has the following benefits:

- Reduces code complexity
- Increases code readability
- Provides consistent error responses, as messages are stored on the
  Exceptions.
- Prevents raising errors with only partial information (we have cases
  now that were removing the UUID from the message because they used a
  custom message).  For example: before returned error would be "The
  resource could not be found", and now we raise "Volume type encryption
  for type 4e9e6d23-eed0-426d-b90a-28f87a94b6fe does not exist."
  automatically.
- Reduces workload for the translation team because we remove all
  unnecessary custom messages.

Change-Id: I09f98921fdc2400cc3f6056e59001100abe06920
7 years ago
Ivan Kolodyazhny c042a05ac3 Remove XML API
Cinder XML API is not tested by Tempest about for one year.
We don't know if it works or not. It was deprecated in
Mitaka release.

Implements blueprint: remove-xml-api
APIImpact
DocImpact
UpgradeImpact

Change-Id: If98db25f1f4032725444c3959acb9aad8f869802
7 years ago
Vincent Hou 21bc0537e0 Volume status management during migration
This patch proposes a new implementation for the status and
the migration_status for volumes.

* The initial migration_status is None, meaning no migration has been
done; Migration_status 'error' means the previous migration failed.
Migration_status 'success' means the previous migration succeeded.

* If the key 'lock_volume' is set to True from the request, the volume
status should be set to 'maintenance' during migration and goes
back to its original status after migration. Otherwise, if the
key 'lock_volume' is set to False, the volume status will remain the
same as its original status. The default value for lock_volume is
False and it applies to the available volume.

* From the REST's perspectives, all the create, update and delete
actions are not allowed if the volume is in 'maintenance', because
it means the volume is out of service. If it is not in maintenance
mode, the migration can be interrupted if other requests are
issued, e.g. attach. For the termination of migration, another
patch will target to resolve it.

DocImpact
APIImpact The key 'lock_volume' has been added into the API,
telling the volume to change the status to 'maintenance' or not.
The migration_status has been added into results returned
from volume list command, if the request is from an admin.

Change-Id: Ia86421f2d6fce61dcfeb073f8e7b9c9dde517373
Partial-implements: blueprint migration-improvement
8 years ago
Dave Chen 4196e5f2d5 set/unset volume image metadata
This patch implements:
- Create, delete, update APIs for modifying volume image metadata.
- Refactoring in the volume API to accommodate both user and
  image metadata.
- All of the necessary testcases needed for the changes.

DocImpact
APIImpact
Partially implements: bp support-modify-volume-image-metadata
Change-Id: I22792ef7bd49c763d7c130aa8cac9abc3fff2d4c
8 years ago
Jenkins 2596c5ed1c Merge "Validate outermost request body element name consistently" 8 years ago
PranaliDeore cb8bce4f1b Change generic NotFound to specific exception
1. Changed exception type from NotFound to specific NotFound
   exception for better readability.
   e.g. VolumeNotFound, SnapshotNotFound etc.

2. Error messages returned to the user are not consistent across
   all apis in case of all exceptions derived from NotFound exception.
   Instead of returning custom error messages return message
   defined in exception class itself.
   NOTE: Doesn't applied to 'HostBinaryNotFound' as host information to
         the tenant should not be leaked.

3. Added explanation to HTTPNotFound wherever appropriate.
   e.g. raise webob.exc.HTTPNotFound() to
        raise webob.exc.HTTPNotFound(explanation=err.msg)

Closes-Bug: #1459958
Change-Id: Ice2c375796fac7533d82125ef97288075fa68b85
8 years ago
Abhijeet Malawade 7d203027c7 Validate outermost request body element name consistently
1. Return useful error message instead of empty error message.
ex.- Return "Missing required element '<element name>' in request body"
     instead of "Bad Request"
2. Return consistent error message in case request body element
name is not present.
3. Added 'assert_valid_body' method to raise HTTPBadRequest exception
if request body is not valid. It is not possible to modify
'is_valid_body' method itself to raise exception because V1 and v2
api's return different error code when 'is_valid_body' returns False.

APIImpact

Closes-bug: #1461402
Change-Id: I81764cd8517484fbee4beae2b30668c8b180d677
8 years ago
James Carey ac33ad9ec9 Use oslo.i18n
oslo.i18n provides the i18n function that were provided by
oslo-incubator's gettextutils module.

Change-Id: I1f361a8321fb02f03b4f3f3e2ef688fcf19514a3
9 years ago
Jay S. Bryant eafcc41e82 Explicitly import _() in Cinder code
To ensure that logs are properly translated and logged to
the Cinder log files (using the Cinder message catalogs)
we need to explicitly import _() in any python files that
use the _() function.

Closes-bug: 1306275
Related-Blueprint: i18n-enablement
Change-Id: I3cf1f1d63d5f8bd8ffd007104691f914e3fd8538
9 years ago
DennyZhang ff3f2e5735 Remove vim header
No need to set tabstop tons of times, this can be set in your vimrc
file instead.

More disucssion:
http://openstack.10931.n7.nabble.com/Remove-vim-modelines-td21780.html

Partial-Bug: #1229324
Change-Id: Ib3a31c8819ee1950d72f7da5627593623d351560
10 years ago
ling-yun 3b2842bf2d All API controllers inherit from wsgi.Controller
Most of the Cinder Public API Controllers inherit from wsgi.Controller,
but still some Cinder Public APIs controllers directly inherit from
object. So it's necessary to unify all the Cinder Public API Controllers
inherit from wsgi.Controller.
1. For code cleanup.
2. When we try to do body valid check in api's put/post method later, we
can use the helper function is_valid_body instead of using try...catch
block.

Change-Id: I88812224e0b182939cfccce63982cb8f95792891
Closes-Bug: #1257198
10 years ago
Mike Perez 4e3fa390b1 Add volume metadata to v2
This exposes volume metadata in the Cinder v2 API. This already exists
in v1 and was originally suppose to exist back with Grizzly, but appears
to have slipped.

Closes-Bug: #1227979
Change-Id: I512dad591d7d491eca54a230d3cc290d9a349e6f
10 years ago