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, 201, and 202 under api/contrib 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: I944ab762a268886715b37bed1704e4fd56dae4fb
This commit is contained in:
poojajadhav 2017-01-04 14:45:16 +05:30 committed by Pooja Jadhav
parent 349bda1774
commit da90ffda5d
18 changed files with 68 additions and 50 deletions

View File

@ -14,6 +14,7 @@
from oslo_log import log as logging
import oslo_messaging as messaging
from six.moves import http_client
import webob
from webob import exc
@ -123,7 +124,7 @@ class AdminController(wsgi.Controller):
notifier.info(context, self.collection + '.reset_status.end',
notifier_info)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-force_delete')
def _force_delete(self, req, id, body):
@ -133,7 +134,7 @@ class AdminController(wsgi.Controller):
# Not found exception will be handled at the wsgi level
resource = self._get(context, id)
self._delete(context, resource, force=True)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class VolumeAdminController(AdminController):
@ -232,7 +233,7 @@ class VolumeAdminController(AdminController):
# be exposed to the user and in such cases it should raise
# 500 error.
raise
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-migrate_volume')
def _migrate_volume(self, req, id, body):
@ -248,7 +249,7 @@ class VolumeAdminController(AdminController):
lock_volume = utils.get_bool_param('lock_volume', params)
self.volume_api.migrate_volume(context, volume, host, cluster_name,
force_host_copy, lock_volume)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-migrate_volume_completion')
def _migrate_volume_completion(self, req, id, body):
@ -325,7 +326,7 @@ class BackupAdminController(AdminController):
# Not found exception will be handled at the wsgi level
self.backup_api.reset_status(context=context, backup_id=id,
status=update['status'])
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Admin_actions(extensions.ExtensionDescriptor):

View File

@ -18,6 +18,7 @@
"""The backups api."""
from oslo_log import log as logging
from six.moves import http_client
import webob
from webob import exc
@ -67,7 +68,7 @@ class BackupsController(wsgi.Controller):
except exception.InvalidBackup as error:
raise exc.HTTPBadRequest(explanation=error.msg)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
def index(self, req):
"""Returns a summary list of backups."""
@ -116,7 +117,7 @@ class BackupsController(wsgi.Controller):
# - whether requested volume_id exists so we can return some errors
# immediately
# - maybe also do validation of swift container name
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
def create(self, req, body):
"""Create a new backup."""
LOG.debug('Creating new backup %s', body)
@ -160,7 +161,7 @@ class BackupsController(wsgi.Controller):
retval = self._view_builder.summary(req, dict(new_backup))
return retval
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
def restore(self, req, id, body):
"""Restore an existing backup to a volume."""
LOG.debug('Restoring backup %(backup_id)s (%(body)s)',
@ -199,7 +200,7 @@ class BackupsController(wsgi.Controller):
req, dict(new_restore))
return retval
@wsgi.response(200)
@wsgi.response(http_client.OK)
def export_record(self, req, id):
"""Export a backup."""
LOG.debug('export record called for member %s.', id)
@ -216,7 +217,7 @@ class BackupsController(wsgi.Controller):
LOG.debug('export record output: %s.', retval)
return retval
@wsgi.response(201)
@wsgi.response(http_client.CREATED)
def import_record(self, req, body):
"""Import a backup."""
LOG.debug('Importing record from %s.', body)

View File

@ -17,6 +17,7 @@
from oslo_log import log as logging
import six
from six.moves import http_client
import webob
from webob import exc
@ -84,7 +85,7 @@ class CgsnapshotsController(wsgi.Controller):
msg = _("Failed cgsnapshot")
raise exc.HTTPBadRequest(explanation=msg)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
def index(self, req):
"""Returns a summary list of cgsnapshots."""
@ -144,7 +145,7 @@ class CgsnapshotsController(wsgi.Controller):
return cgsnapshots
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
def create(self, req, body):
"""Create a new cgsnapshot."""
LOG.debug('Creating new cgsnapshot %s', body)

View File

@ -17,6 +17,7 @@
from oslo_log import log as logging
from oslo_utils import strutils
from six.moves import http_client
import webob
from webob import exc
@ -91,7 +92,7 @@ class ConsistencyGroupsController(wsgi.Controller):
except exception.InvalidConsistencyGroup as error:
raise exc.HTTPBadRequest(explanation=error.msg)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
def index(self, req):
"""Returns a summary list of consistency groups."""
@ -154,7 +155,7 @@ class ConsistencyGroupsController(wsgi.Controller):
groups['consistencygroups'])
return consistencygroups
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
def create(self, req, body):
"""Create a new consistency group."""
LOG.debug('Creating new consistency group %s', body)
@ -198,7 +199,7 @@ class ConsistencyGroupsController(wsgi.Controller):
retval = self._view_builder.summary(req, new_consistencygroup)
return retval
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
def create_from_src(self, req, body):
"""Create a new consistency group from a source.
@ -335,7 +336,7 @@ class ConsistencyGroupsController(wsgi.Controller):
remove_volumes)
self._update(context, id, name, description, add_volumes,
remove_volumes)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Consistencygroups(extensions.ExtensionDescriptor):

View File

@ -17,6 +17,7 @@
from oslo_log import log as logging
import six
from six.moves import http_client
import webob
from cinder.api import common
@ -191,7 +192,7 @@ class QoSSpecsController(wsgi.Controller):
msg = _('Qos specs still in use.')
raise webob.exc.HTTPBadRequest(explanation=msg)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
def delete_keys(self, req, id, body):
"""Deletes specified keys in qos specs."""
@ -219,7 +220,7 @@ class QoSSpecsController(wsgi.Controller):
# Not found exception will be handled at the wsgi level
raise
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
def associations(self, req, id):
"""List all associations of given qos specs."""
@ -298,7 +299,7 @@ class QoSSpecsController(wsgi.Controller):
raise webob.exc.HTTPInternalServerError(
explanation=six.text_type(err))
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
def disassociate(self, req, id):
"""Disassociate a qos specs from a volume type."""
@ -338,7 +339,7 @@ class QoSSpecsController(wsgi.Controller):
raise webob.exc.HTTPInternalServerError(
explanation=six.text_type(err))
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
def disassociate_all(self, req, id):
"""Disassociate a qos specs from all volume types."""
@ -368,7 +369,7 @@ class QoSSpecsController(wsgi.Controller):
raise webob.exc.HTTPInternalServerError(
explanation=six.text_type(err))
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Qos_specs_manage(extensions.ExtensionDescriptor):

View File

@ -18,6 +18,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import versionutils
from oslo_utils import timeutils
from six.moves import http_client
import webob.exc
from cinder.api import common
@ -127,7 +128,7 @@ class ServiceController(wsgi.Controller):
cluster_name, host = common.get_cluster_host(req, body, version)
self.volume_api.failover(context, host, cluster_name,
body.get('backend_id'))
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
def update(self, req, id, body):
"""Enable/Disable scheduling for a service.

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_log import log as logging
from six.moves import http_client
import webob
from cinder.api import extensions
@ -98,7 +99,7 @@ class SnapshotActionsController(wsgi.Controller):
current_snapshot.update(update_dict)
current_snapshot.save()
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Snapshot_actions(extensions.ExtensionDescriptor):

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_log import log as logging
from six.moves import http_client
from webob import exc
from cinder.api.contrib import resource_common_manage
@ -40,7 +41,7 @@ class SnapshotManageController(wsgi.Controller):
self.volume_api = cinder_volume.API()
self._list_manageable_view = list_manageable_view.ViewBuilder()
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
def create(self, req, body):
"""Instruct Cinder to manage a storage snapshot object.

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_log import log as logging
from six.moves import http_client
import webob
from webob import exc
@ -31,7 +32,7 @@ class SnapshotUnmanageController(wsgi.Controller):
super(SnapshotUnmanageController, self).__init__(*args, **kwargs)
self.volume_api = volume.API()
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
@wsgi.action('os-unmanage')
def unmanage(self, req, id, body):
"""Stop managing a snapshot.
@ -57,7 +58,7 @@ class SnapshotUnmanageController(wsgi.Controller):
# Not found exception will be handled at the wsgi level
except exception.InvalidSnapshot as ex:
raise exc.HTTPBadRequest(explanation=ex.msg)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Snapshot_unmanage(extensions.ExtensionDescriptor):

View File

@ -15,6 +15,7 @@
"""The volume types extra specs extension"""
from six.moves import http_client
import webob
from cinder.api import common
@ -123,7 +124,7 @@ class VolumeTypeExtraSpecsController(wsgi.Controller):
notifier.info(context,
'volume_type_extra_specs.delete',
notifier_info)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
def _check_key_names(self, keys):
if not common.validate_key_names(keys):

View File

@ -16,6 +16,7 @@
"""The volume types manage extension."""
import six
from six.moves import http_client
import webob
from oslo_utils import strutils
@ -187,7 +188,7 @@ class VolumeTypesManageController(wsgi.Controller):
# Not found exception will be handled at the wsgi level
raise
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Types_manage(extensions.ExtensionDescriptor):

View File

@ -18,6 +18,7 @@ import oslo_messaging as messaging
from oslo_utils import encodeutils
from oslo_utils import strutils
import six
from six.moves import http_client
import webob
from cinder.api import extensions
@ -87,7 +88,7 @@ class VolumeActionsController(wsgi.Controller):
# to the user and in such cases it should raise 500 error.
raise
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-detach')
def _detach(self, req, id, body):
@ -113,7 +114,7 @@ class VolumeActionsController(wsgi.Controller):
# to the user and in such cases it should raise 500 error.
raise
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-reserve')
def _reserve(self, req, id, body):
@ -123,7 +124,7 @@ class VolumeActionsController(wsgi.Controller):
volume = self.volume_api.get(context, id)
self.volume_api.reserve_volume(context, volume)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-unreserve')
def _unreserve(self, req, id, body):
@ -133,7 +134,7 @@ class VolumeActionsController(wsgi.Controller):
volume = self.volume_api.get(context, id)
self.volume_api.unreserve_volume(context, volume)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-begin_detaching')
def _begin_detaching(self, req, id, body):
@ -143,7 +144,7 @@ class VolumeActionsController(wsgi.Controller):
volume = self.volume_api.get(context, id)
self.volume_api.begin_detaching(context, volume)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-roll_detaching')
def _roll_detaching(self, req, id, body):
@ -153,7 +154,7 @@ class VolumeActionsController(wsgi.Controller):
volume = self.volume_api.get(context, id)
self.volume_api.roll_detaching(context, volume)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-initialize_connection')
def _initialize_connection(self, req, id, body):
@ -195,9 +196,9 @@ class VolumeActionsController(wsgi.Controller):
except exception.VolumeBackendAPIException:
msg = _("Unable to terminate volume connection from backend.")
raise webob.exc.HTTPInternalServerError(explanation=msg)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
@wsgi.action('os-volume_upload_image')
def _volume_upload_image(self, req, id, body):
"""Uploads the specified volume to image service."""
@ -288,7 +289,7 @@ class VolumeActionsController(wsgi.Controller):
except exception.InvalidVolume as error:
raise webob.exc.HTTPBadRequest(explanation=error.msg)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-update_readonly_flag')
def _volume_readonly_update(self, req, id, body):
@ -312,7 +313,7 @@ class VolumeActionsController(wsgi.Controller):
raise webob.exc.HTTPBadRequest(explanation=msg)
self.volume_api.update_readonly_flag(context, volume, readonly_flag)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-retype')
def _retype(self, req, id, body):
@ -327,7 +328,7 @@ class VolumeActionsController(wsgi.Controller):
policy = body['os-retype'].get('migration_policy')
self.volume_api.retype(context, volume, new_type, policy)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('os-set_bootable')
def _set_bootable(self, req, id, body):
@ -353,7 +354,7 @@ class VolumeActionsController(wsgi.Controller):
update_dict = {'bootable': bootable}
self.volume_api.update(context, volume, update_dict)
return webob.Response(status_int=200)
return webob.Response(status_int=http_client.OK)
class Volume_actions(extensions.ExtensionDescriptor):

View File

@ -13,6 +13,7 @@
# under the License.
"""The Volume Image Metadata API extension."""
from six.moves import http_client
import webob
from oslo_log import log as logging
@ -147,7 +148,7 @@ class VolumeImageMetadataController(wsgi.Controller):
msg = _("The key cannot be None.")
raise webob.exc.HTTPBadRequest(explanation=msg)
return webob.Response(status_int=200)
return webob.Response(status_int=http_client.OK)
class Volume_image_metadata(extensions.ExtensionDescriptor):

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_log import log as logging
from six.moves import http_client
from cinder.api import common
from cinder.api.contrib import resource_common_manage
@ -42,7 +43,7 @@ class VolumeManageController(wsgi.Controller):
self.volume_api = cinder_volume.API()
self._list_manageable_view = list_manageable_view.ViewBuilder()
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
def create(self, req, body):
"""Instruct Cinder to manage a storage object.

View File

@ -14,6 +14,7 @@
# under the License.
from oslo_log import log as logging
from six.moves import http_client
import webob
from webob import exc
@ -72,7 +73,7 @@ class VolumeTransferController(wsgi.Controller):
return transfers
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
def create(self, req, body):
"""Create a new volume transfer."""
LOG.debug('Creating new volume transfer %s', body)
@ -107,7 +108,7 @@ class VolumeTransferController(wsgi.Controller):
dict(new_transfer))
return transfer
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
def accept(self, req, id, body):
"""Accept a new volume transfer."""
transfer_id = id
@ -147,7 +148,7 @@ class VolumeTransferController(wsgi.Controller):
# Not found exception will be handled at the wsgi level
self.transfer_api.delete(context, transfer_id=id)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Volume_transfer(extensions.ExtensionDescriptor):

View File

@ -15,6 +15,7 @@
from oslo_utils import uuidutils
import six
from six.moves import http_client
import webob
from cinder.api import extensions
@ -118,7 +119,7 @@ class VolumeTypeActionController(wsgi.Controller):
# Not found exception will be handled at the wsgi level
except exception.VolumeTypeAccessExists as err:
raise webob.exc.HTTPConflict(explanation=six.text_type(err))
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
@wsgi.action('removeProjectAccess')
def _removeProjectAccess(self, req, id, body):
@ -129,7 +130,7 @@ class VolumeTypeActionController(wsgi.Controller):
# Not found exception will be handled at the wsgi level
volume_types.remove_volume_type_access(context, id, project)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Volume_type_access(extensions.ExtensionDescriptor):

View File

@ -15,6 +15,7 @@
"""The volume types encryption extension."""
from six.moves import http_client
import webob
from cinder.api import extensions
@ -167,7 +168,7 @@ class VolumeTypeEncryptionController(wsgi.Controller):
# Not found exception will be handled at the wsgi level
db.volume_type_encryption_delete(context, type_id)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Volume_type_encryption(extensions.ExtensionDescriptor):

View File

@ -13,6 +13,7 @@
# under the License.
from oslo_log import log as logging
from six.moves import http_client
import webob
from cinder.api import extensions
@ -29,7 +30,7 @@ class VolumeUnmanageController(wsgi.Controller):
super(VolumeUnmanageController, self).__init__(*args, **kwargs)
self.volume_api = volume.API()
@wsgi.response(202)
@wsgi.response(http_client.ACCEPTED)
@wsgi.action('os-unmanage')
def unmanage(self, req, id, body):
"""Stop managing a volume.
@ -54,7 +55,7 @@ class VolumeUnmanageController(wsgi.Controller):
# Not found exception will be handled at the wsgi level
vol = self.volume_api.get(context, id)
self.volume_api.delete(context, vol, unmanage_only=True)
return webob.Response(status_int=202)
return webob.Response(status_int=http_client.ACCEPTED)
class Volume_unmanage(extensions.ExtensionDescriptor):