diff --git a/cinder/tests/unit/api/contrib/test_admin_actions.py b/cinder/tests/unit/api/contrib/test_admin_actions.py index 3b323e839be..53fca751ae6 100644 --- a/cinder/tests/unit/api/contrib/test_admin_actions.py +++ b/cinder/tests/unit/api/contrib/test_admin_actions.py @@ -18,6 +18,7 @@ from oslo_config import fixture as config_fixture import oslo_messaging as messaging from oslo_serialization import jsonutils from oslo_utils import timeutils +from six.moves import http_client import webob from webob import exc @@ -172,7 +173,7 @@ class AdminActionsTest(BaseAdminTest): {'attach_status': fields.VolumeAttachStatus.ATTACHED}) - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual(fields.VolumeAttachStatus.ATTACHED, volume['attach_status']) @@ -186,7 +187,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'attach_status': 'bogus-status'}) - self.assertEqual(400, resp.status_int) + self.assertEqual(http_client.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual(fields.VolumeAttachStatus.DETACHED, volume['attach_status']) @@ -198,7 +199,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'migration_status': 'bogus-status'}) - self.assertEqual(400, resp.status_int) + self.assertEqual(http_client.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertIsNone(volume['migration_status']) @@ -209,7 +210,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'migration_status': 'migrating'}) - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('migrating', volume['migration_status']) @@ -220,7 +221,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'status': 'error'}) - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('error', volume['status']) @@ -234,7 +235,7 @@ class AdminActionsTest(BaseAdminTest): {'status': 'error'}) # request is not authorized - self.assertEqual(403, resp.status_int) + self.assertEqual(http_client.FORBIDDEN, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) # status is still 'error' self.assertEqual('error', volume['status']) @@ -255,7 +256,7 @@ class AdminActionsTest(BaseAdminTest): backup, {'status': fields.BackupStatus.ERROR}) - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) def test_backup_reset_status_as_non_admin(self): ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID) @@ -267,7 +268,7 @@ class AdminActionsTest(BaseAdminTest): backup, {'status': fields.BackupStatus.ERROR}) # request is not authorized - self.assertEqual(403, resp.status_int) + self.assertEqual(http_client.FORBIDDEN, resp.status_int) def test_backup_reset_status(self): volume = db.volume_create(self.ctx, @@ -284,7 +285,7 @@ class AdminActionsTest(BaseAdminTest): backup, {'status': fields.BackupStatus.ERROR}) - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) def test_invalid_status_for_backup(self): volume = db.volume_create(self.ctx, @@ -295,7 +296,7 @@ class AdminActionsTest(BaseAdminTest): resp = self._issue_backup_reset(self.ctx, backup, {'status': 'restoring'}) - self.assertEqual(400, resp.status_int) + self.assertEqual(http_client.BAD_REQUEST, resp.status_int) def test_backup_reset_status_with_invalid_backup(self): volume = db.volume_create(self.ctx, @@ -313,7 +314,7 @@ class AdminActionsTest(BaseAdminTest): {'status': fields.BackupStatus.ERROR}) # Should raise 404 if backup doesn't exist. - self.assertEqual(404, resp.status_int) + self.assertEqual(http_client.NOT_FOUND, resp.status_int) def test_malformed_reset_status_body(self): volume = db.volume_create(self.ctx, {'status': 'available', 'size': 1}) @@ -322,7 +323,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'x-status': 'bad'}) - self.assertEqual(400, resp.status_int) + self.assertEqual(http_client.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('available', volume['status']) @@ -332,7 +333,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'status': 'invalid'}) - self.assertEqual(400, resp.status_int) + self.assertEqual(http_client.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('available', volume['status']) @@ -345,7 +346,7 @@ class AdminActionsTest(BaseAdminTest): req.body = jsonutils.dump_as_bytes(body) req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) - self.assertEqual(404, resp.status_int) + self.assertEqual(http_client.NOT_FOUND, resp.status_int) self.assertRaises(exception.NotFound, db.volume_get, self.ctx, fake.WILL_NOT_BE_FOUND_ID) @@ -381,7 +382,7 @@ class AdminActionsTest(BaseAdminTest): {'status': 'available', 'attach_status': fields.VolumeAttachStatus.DETACHED}) # request is accepted - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) # volume is detached volume = db.volume_get(self.ctx, volume['id']) @@ -406,7 +407,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'status': 'available', 'attach_status': fields.VolumeAttachStatus.ERROR_DETACHING}) - self.assertEqual(400, resp.status_int) + self.assertEqual(http_client.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('available', volume['status']) self.assertEqual(fields.VolumeAttachStatus.DETACHED, @@ -437,7 +438,7 @@ class AdminActionsTest(BaseAdminTest): {'status': fields.SnapshotStatus.ERROR}) - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) snapshot = objects.Snapshot.get_by_id(self.ctx, snapshot['id']) self.assertEqual(fields.SnapshotStatus.ERROR, snapshot.status) @@ -454,7 +455,7 @@ class AdminActionsTest(BaseAdminTest): resp = self._issue_snapshot_reset(self.ctx, snapshot, {'status': 'attaching'}) - self.assertEqual(400, resp.status_int) + self.assertEqual(http_client.BAD_REQUEST, resp.status_int) self.assertEqual(fields.SnapshotStatus.AVAILABLE, snapshot.status) def test_force_delete(self): @@ -469,7 +470,7 @@ class AdminActionsTest(BaseAdminTest): req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) # request is accepted - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) # volume is deleted self.assertRaises(exception.NotFound, objects.Volume.get_by_id, self.ctx, volume.id) @@ -496,7 +497,7 @@ class AdminActionsTest(BaseAdminTest): # attach admin context to request req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) def _migrate_volume_prep(self): # create volume's current host and the destination host @@ -551,7 +552,7 @@ class AdminActionsTest(BaseAdminTest): @ddt.data('3.0', '3.15', '3.16') def test_migrate_volume_success_3(self, version): - expected_status = 202 + expected_status = http_client.ACCEPTED host = 'test2' volume = self._migrate_volume_prep() volume = self._migrate_volume_3_exec(self.ctx, volume, host, @@ -559,7 +560,7 @@ class AdminActionsTest(BaseAdminTest): self.assertEqual('starting', volume['migration_status']) def test_migrate_volume_success_cluster(self): - expected_status = 202 + expected_status = http_client.ACCEPTED # We cannot provide host and cluster, so send host to None host = None cluster = 'cluster' @@ -596,7 +597,7 @@ class AdminActionsTest(BaseAdminTest): return volume def test_migrate_volume_success(self): - expected_status = 202 + expected_status = http_client.ACCEPTED host = 'test2' volume = self._migrate_volume_prep() volume = self._migrate_volume_exec(self.ctx, volume, host, @@ -604,7 +605,7 @@ class AdminActionsTest(BaseAdminTest): self.assertEqual('starting', volume['migration_status']) def test_migrate_volume_fail_replication(self): - expected_status = 400 + expected_status = http_client.BAD_REQUEST host = 'test2' volume = self._migrate_volume_prep() # current status is available @@ -616,14 +617,14 @@ class AdminActionsTest(BaseAdminTest): expected_status) def test_migrate_volume_as_non_admin(self): - expected_status = 403 + expected_status = http_client.FORBIDDEN host = 'test2' ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID) volume = self._migrate_volume_prep() self._migrate_volume_exec(ctx, volume, host, expected_status) def test_migrate_volume_without_host_parameter(self): - expected_status = 400 + expected_status = http_client.BAD_REQUEST host = 'test3' volume = self._migrate_volume_prep() # build request to migrate without host @@ -640,19 +641,19 @@ class AdminActionsTest(BaseAdminTest): self.assertEqual(expected_status, resp.status_int) def test_migrate_volume_host_no_exist(self): - expected_status = 400 + expected_status = http_client.BAD_REQUEST host = 'test3' volume = self._migrate_volume_prep() self._migrate_volume_exec(self.ctx, volume, host, expected_status) def test_migrate_volume_same_host(self): - expected_status = 400 + expected_status = http_client.BAD_REQUEST host = 'test' volume = self._migrate_volume_prep() self._migrate_volume_exec(self.ctx, volume, host, expected_status) def test_migrate_volume_migrating(self): - expected_status = 400 + expected_status = http_client.BAD_REQUEST host = 'test2' volume = self._migrate_volume_prep() volume.migration_status = 'migrating' @@ -660,7 +661,7 @@ class AdminActionsTest(BaseAdminTest): self._migrate_volume_exec(self.ctx, volume, host, expected_status) def test_migrate_volume_with_snap(self): - expected_status = 400 + expected_status = http_client.BAD_REQUEST host = 'test2' volume = self._migrate_volume_prep() snap = objects.Snapshot(self.ctx, volume_id=volume['id']) @@ -669,7 +670,7 @@ class AdminActionsTest(BaseAdminTest): self._migrate_volume_exec(self.ctx, volume, host, expected_status) def test_migrate_volume_bad_force_host_copy(self): - expected_status = 400 + expected_status = http_client.BAD_REQUEST host = 'test2' volume = self._migrate_volume_prep() self._migrate_volume_exec(self.ctx, volume, host, expected_status, @@ -700,7 +701,7 @@ class AdminActionsTest(BaseAdminTest): def test_migrate_volume_comp_as_non_admin(self): volume = db.volume_create(self.ctx, {'id': fake.VOLUME_ID}) new_volume = db.volume_create(self.ctx, {'id': fake.VOLUME2_ID}) - expected_status = 403 + expected_status = http_client.FORBIDDEN expected_id = None ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID) self._migrate_volume_comp_exec(ctx, volume, new_volume, False, @@ -710,7 +711,7 @@ class AdminActionsTest(BaseAdminTest): volume1 = self._create_volume(self.ctx, {'migration_status': 'foo'}) volume2 = self._create_volume(self.ctx, {'migration_status': None}) - expected_status = 400 + expected_status = http_client.BAD_REQUEST expected_id = None self._migrate_volume_comp_exec(self.ctx, volume1, volume2, False, expected_status, expected_id) @@ -722,7 +723,7 @@ class AdminActionsTest(BaseAdminTest): {'migration_status': 'migrating'}) volume2 = self._create_volume(self.ctx, {'migration_status': 'target:foo'}) - expected_status = 400 + expected_status = http_client.BAD_REQUEST expected_id = None self._migrate_volume_comp_exec(self.ctx, volume1, volume2, False, expected_status, expected_id) @@ -730,7 +731,7 @@ class AdminActionsTest(BaseAdminTest): def test_migrate_volume_comp_no_action(self): volume = db.volume_create(self.ctx, {'id': fake.VOLUME_ID}) new_volume = db.volume_create(self.ctx, {'id': fake.VOLUME2_ID}) - expected_status = 400 + expected_status = http_client.BAD_REQUEST expected_id = None ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID) self._migrate_volume_comp_exec(ctx, volume, new_volume, False, @@ -747,7 +748,7 @@ class AdminActionsTest(BaseAdminTest): 'attach_status': fields.VolumeAttachStatus. DETACHED}) - expected_status = 200 + expected_status = http_client.OK expected_id = new_volume.id self._migrate_volume_comp_exec(self.ctx, volume, new_volume, False, expected_status, expected_id) @@ -783,7 +784,7 @@ class AdminActionsTest(BaseAdminTest): req.environ['cinder.context'] = self.ctx res = req.get_response(app()) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual( 'deleting', test_backups.BackupsAPITestCase._get_backup_attrib(id, 'status')) @@ -820,7 +821,7 @@ class AdminActionsTest(BaseAdminTest): req.body = jsonutils.dump_as_bytes({'os-force_delete': {}}) req.environ['cinder.context'] = self.ctx res = req.get_response(app()) - self.assertEqual(405, res.status_int) + self.assertEqual(http_client.METHOD_NOT_ALLOWED, res.status_int) class AdminActionsAttachDetachTest(BaseAdminTest): @@ -872,7 +873,7 @@ class AdminActionsAttachDetachTest(BaseAdminTest): # make request resp = req.get_response(app()) # request is accepted - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) volume.refresh() self.assertRaises(exception.VolumeAttachmentNotFound, db.volume_attachment_get, @@ -924,7 +925,7 @@ class AdminActionsAttachDetachTest(BaseAdminTest): # make request resp = req.get_response(app()) # request is accepted - self.assertEqual(202, resp.status_int) + self.assertEqual(http_client.ACCEPTED, resp.status_int) volume.refresh() self.assertRaises(exception.VolumeAttachmentNotFound, db.volume_attachment_get, @@ -975,7 +976,7 @@ class AdminActionsAttachDetachTest(BaseAdminTest): req.environ['cinder.context'] = self.ctx # make request resp = req.get_response(app()) - self.assertEqual(400, resp.status_int) + self.assertEqual(http_client.BAD_REQUEST, resp.status_int) # test for KeyError when missing connector volume_remote_error = ( diff --git a/cinder/tests/unit/api/contrib/test_backups.py b/cinder/tests/unit/api/contrib/test_backups.py index e4a02d82b60..5012f27f62d 100644 --- a/cinder/tests/unit/api/contrib/test_backups.py +++ b/cinder/tests/unit/api/contrib/test_backups.py @@ -21,6 +21,7 @@ import ddt import mock from oslo_serialization import jsonutils from oslo_utils import timeutils +from six.moves import http_client import webob from cinder.api.contrib import backups @@ -122,7 +123,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('az1', res_dict['backup']['availability_zone']) self.assertEqual('volumebackups', res_dict['backup']['container']) self.assertEqual('this is a test backup', @@ -153,8 +154,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('Backup %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message']) @@ -171,7 +173,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(3, len(res_dict['backups'][0])) self.assertEqual(backup_id3, res_dict['backups'][0]['id']) self.assertEqual('test_backup', res_dict['backups'][0]['name']) @@ -198,7 +200,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(2, len(res_dict['backups'])) self.assertEqual(3, len(res_dict['backups'][0])) self.assertEqual(backup_id3, res_dict['backups'][0]['id']) @@ -218,7 +220,7 @@ class BackupsAPITestCase(test.TestCase): req.headers['Content-Type'] = 'application/json' res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_list_backups_with_marker(self): backup_id1 = self._create_backup() @@ -232,7 +234,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(2, len(res_dict['backups'])) self.assertEqual(3, len(res_dict['backups'][0])) self.assertEqual(backup_id2, res_dict['backups'][0]['id']) @@ -259,7 +261,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(1, len(res_dict['backups'])) self.assertEqual(3, len(res_dict['backups'][0])) self.assertEqual(backup_id2, res_dict['backups'][0]['id']) @@ -282,7 +284,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0])) self.assertEqual('az1', res_dict['backups'][0]['availability_zone']) self.assertEqual('volumebackups', @@ -349,7 +351,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) self.assertEqual(1, len(res_dict['backups'])) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(backup_id1, res_dict['backups'][0]['id']) req = webob.Request.blank('/v2/%s/backups/detail?status=available' % @@ -362,7 +364,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) self.assertEqual(1, len(res_dict['backups'])) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(backup_id2, res_dict['backups'][0]['id']) req = webob.Request.blank('/v2/%s/backups/detail?volume_id=%s' % ( @@ -375,7 +377,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) self.assertEqual(1, len(res_dict['backups'])) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(backup_id3, res_dict['backups'][0]['id']) db.backup_destroy(context.get_admin_context(), backup_id3) @@ -395,7 +397,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(2, len(res_dict['backups'])) self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0])) self.assertEqual(backup_id3, res_dict['backups'][0]['id']) @@ -420,7 +422,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(2, len(res_dict['backups'])) self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0])) self.assertEqual(backup_id2, res_dict['backups'][0]['id']) @@ -445,7 +447,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(1, len(res_dict['backups'])) self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0])) self.assertEqual(backup_id2, res_dict['backups'][0]['id']) @@ -462,7 +464,7 @@ class BackupsAPITestCase(test.TestCase): req.headers['Content-Type'] = 'application/json' res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) @mock.patch('cinder.db.service_get_all') @mock.patch( @@ -491,7 +493,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) _mock_service_get_all.assert_called_once_with(mock.ANY, disabled=False, @@ -526,8 +528,9 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) db.volume_destroy(context.get_admin_context(), volume_id) @@ -559,7 +562,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) _mock_service_get_all.assert_called_once_with(mock.ANY, disabled=False, @@ -595,7 +598,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) _mock_service_get_all.assert_called_once_with(mock.ANY, disabled=False, @@ -638,7 +641,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIsNotNone(res_dict['badRequest']['message']) def test_create_backup_with_invalid_snapshot(self): @@ -667,8 +670,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) def test_create_backup_with_non_existent_snapshot(self): @@ -692,8 +696,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertIsNotNone(res_dict['itemNotFound']['message']) def test_create_backup_with_invalid_container(self): @@ -752,7 +757,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) _mock_service_get_all.assert_called_once_with(mock.ANY, disabled=False, @@ -790,7 +795,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid backup: The parent backup must be ' 'available for incremental backup.', res_dict['badRequest']['message']) @@ -809,8 +815,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual("Missing required element 'backup' in request body.", res_dict['badRequest']['message']) @@ -830,8 +837,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Incorrect request body format', res_dict['badRequest']['message']) @@ -851,8 +859,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('Volume %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message']) @@ -876,8 +885,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) @mock.patch('cinder.db.service_get_all') def test_create_backup_WithOUT_enabled_backup_service( @@ -903,8 +913,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(500, res.status_int) - self.assertEqual(500, res_dict['computeFault']['code']) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, res.status_int) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, + res_dict['computeFault']['code']) self.assertEqual('Service cinder-backup could not be found.', res_dict['computeFault']['message']) @@ -937,7 +948,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid backup: No backups available to do ' 'an incremental backup.', res_dict['badRequest']['message']) @@ -1067,7 +1079,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(fields.BackupStatus.DELETING, self._get_backup_attrib(backup_id, 'status')) @@ -1089,7 +1101,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(fields.BackupStatus.DELETING, self._get_backup_attrib(delta_id, 'status')) @@ -1110,7 +1122,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(fields.BackupStatus.DELETING, self._get_backup_attrib(backup_id, 'status')) @@ -1125,8 +1137,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('Backup %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message']) @@ -1141,8 +1154,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Backup status must be ' 'available or error', res_dict['badRequest']['message']) @@ -1169,8 +1183,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Incremental backups ' 'exist for this backup.', res_dict['badRequest']['message']) @@ -1192,7 +1207,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) db.backup_destroy(context.get_admin_context(), backup_id) @@ -1217,7 +1232,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(backup_id, res_dict['restore']['backup_id']) self.assertEqual(volume_id, res_dict['restore']['volume_id']) self.assertEqual(volume_name, res_dict['restore']['volume_name']) @@ -1236,8 +1251,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual("Missing required element 'restore' in request body.", res_dict['badRequest']['message']) @@ -1259,8 +1275,9 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual("Missing required element 'restore' in request body.", res_dict['badRequest']['message']) @@ -1292,7 +1309,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(backup_id, res_dict['restore']['backup_id']) @mock.patch('cinder.db.service_get_all') @@ -1333,7 +1350,7 @@ class BackupsAPITestCase(test.TestCase): body['restore']['name'], description) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(backup_id, res_dict['restore']['backup_id']) @mock.patch('cinder.backup.api.API._get_available_backup_service_host') @@ -1355,7 +1372,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(backup_id, res_dict['restore']['backup_id']) self.assertEqual(volume_id, res_dict['restore']['volume_id']) restored_vol = db.volume_get(self.context, @@ -1385,8 +1402,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid input received: Invalid input', res_dict['badRequest']['message']) @@ -1406,8 +1424,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid volume: Volume to be restored to must ' 'be available', res_dict['badRequest']['message']) @@ -1430,8 +1449,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Backup status must be available', res_dict['badRequest']['message']) @@ -1452,8 +1472,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('Backup %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message']) @@ -1473,8 +1494,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('Volume %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message']) @@ -1506,8 +1528,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(413, res.status_int) - self.assertEqual(413, res_dict['overLimit']['code']) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + res_dict['overLimit']['code']) self.assertEqual('Requested volume or snapshot exceeds allowed ' 'gigabytes quota. Requested 2G, quota is 3G and ' '2G has been consumed.', @@ -1535,8 +1558,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(413, res.status_int) - self.assertEqual(413, res_dict['overLimit']['code']) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) + self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + res_dict['overLimit']['code']) self.assertEqual("Maximum number of volumes allowed (1) exceeded for" " quota 'volumes'.", res_dict['overLimit']['message']) @@ -1558,8 +1582,9 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid volume: volume size %d is too ' 'small to restore backup of size %d.' % (volume_size, backup_size), @@ -1589,7 +1614,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(backup_id, res_dict['restore']['backup_id']) self.assertEqual(volume_id, res_dict['restore']['volume_id']) self.assertEqual(volume_name, res_dict['restore']['volume_name']) @@ -1619,7 +1644,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(backup_id, res_dict['restore']['backup_id']) self.assertEqual(volume_id, res_dict['restore']['volume_id']) self.assertEqual(volume_name, res_dict['restore']['volume_name']) @@ -1642,7 +1667,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) # request is not authorized - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) @mock.patch('cinder.backup.api.API._get_available_backup_service_host') @mock.patch('cinder.backup.rpcapi.BackupAPI.export_record') @@ -1667,7 +1692,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) # verify that request is successful - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(backup_service, res_dict['backup-record']['backup_service']) self.assertEqual(backup_url, @@ -1686,8 +1711,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('Backup %s could not be found.' % backup_id, res_dict['itemNotFound']['message']) @@ -1703,8 +1729,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Backup status must be available ' 'and not restoring.', res_dict['badRequest']['message']) @@ -1730,8 +1757,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid backup: %s' % msg, res_dict['badRequest']['message']) db.backup_destroy(context.get_admin_context(), backup_id) @@ -1750,7 +1778,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) # request is not authorized - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) @mock.patch('cinder.backup.api.API._list_backup_hosts') @mock.patch('cinder.backup.rpcapi.BackupAPI.import_record') @@ -1780,7 +1808,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) # verify that request is successful - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) self.assertIn('id', res_dict['backup']) self.assertEqual(fake.BACKUP_ID, res_dict['backup']['id']) @@ -1825,7 +1853,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) # verify that request is successful - self.assertEqual(201, res.status_int) + self.assertEqual(http_client.CREATED, res.status_int) self.assertIn('id', res_dict['backup']) self.assertEqual(fake.BACKUP_ID, res_dict['backup']['id']) @@ -1857,8 +1885,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(500, res.status_int) - self.assertEqual(500, res_dict['computeFault']['code']) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, res.status_int) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, + res_dict['computeFault']['code']) self.assertEqual('Service %s could not be found.' % backup_service, res_dict['computeFault']['message']) @@ -1880,8 +1909,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual("Invalid input received: Can't parse backup record.", res_dict['badRequest']['message']) @@ -1905,8 +1935,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Backup already exists in database.', res_dict['badRequest']['message']) @@ -1937,8 +1968,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(500, res.status_int) - self.assertEqual(500, res_dict['computeFault']['code']) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, res.status_int) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, + res_dict['computeFault']['code']) self.assertEqual('Service %s could not be found.' % backup_service, res_dict['computeFault']['message']) @@ -1959,8 +1991,9 @@ class BackupsAPITestCase(test.TestCase): req.headers['content-type'] = 'application/json' res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Incorrect request body format.', res_dict['badRequest']['message']) @@ -1974,8 +2007,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Incorrect request body format.', res_dict['badRequest']['message']) @@ -1989,8 +2023,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Incorrect request body format.', res_dict['badRequest']['message']) @@ -2007,8 +2042,9 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) # verify that request is successful - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual("Missing required element 'backup-record' in " "request body.", res_dict['badRequest']['message']) @@ -2051,7 +2087,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertTrue(res_dict['backup']['is_incremental']) self.assertTrue(res_dict['backup']['has_dependent_backups']) self.assertIsNone(res_dict['backup']['snapshot_id']) @@ -2064,7 +2100,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertFalse(res_dict['backup']['is_incremental']) self.assertTrue(res_dict['backup']['has_dependent_backups']) self.assertIsNone(res_dict['backup']['snapshot_id']) @@ -2077,7 +2113,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertTrue(res_dict['backup']['is_incremental']) self.assertFalse(res_dict['backup']['has_dependent_backups']) self.assertEqual(snapshot_id, res_dict['backup']['snapshot_id']) diff --git a/cinder/tests/unit/api/contrib/test_cgsnapshots.py b/cinder/tests/unit/api/contrib/test_cgsnapshots.py index 68c106d54e1..bcc84f6a01b 100644 --- a/cinder/tests/unit/api/contrib/test_cgsnapshots.py +++ b/cinder/tests/unit/api/contrib/test_cgsnapshots.py @@ -19,6 +19,7 @@ Tests for cgsnapshot code. import mock from oslo_serialization import jsonutils +from six.moves import http_client import webob from cinder.consistencygroup import api as consistencygroupAPI @@ -61,7 +62,7 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('this is a test cgsnapshot', res_dict['cgsnapshot']['description']) @@ -83,8 +84,9 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('GroupSnapshot %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message']) @@ -108,7 +110,7 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(cgsnapshot1.id, res_dict['cgsnapshots'][0]['id']) self.assertEqual('test_cgsnapshot', @@ -150,7 +152,7 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('this is a test cgsnapshot', res_dict['cgsnapshots'][0]['description']) self.assertEqual('test_cgsnapshot', @@ -205,7 +207,7 @@ class CgsnapshotsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertIn('id', res_dict['cgsnapshot']) self.assertTrue(mock_validate.called) @@ -236,8 +238,9 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual( "Invalid volume: The snapshot cannot be created when the volume " "is in error status.", @@ -258,8 +261,9 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual("Missing required element 'cgsnapshot' in " "request body.", res_dict['badRequest']['message']) @@ -284,8 +288,9 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual('Invalid CgSnapshot: invalid cgsnapshot', res_dict['badRequest']['message']) consistencygroup.destroy() @@ -311,8 +316,9 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('CgSnapshot invalid_id could not be found.', res_dict['itemNotFound']['message']) consistencygroup.destroy() @@ -333,8 +339,9 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) expected = ("Invalid ConsistencyGroup: Source CG cannot be empty or " "in 'creating' or 'updating' state. No cgsnapshot will be " "created.") @@ -363,7 +370,7 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) cgsnapshot = objects.CGSnapshot.get_by_id(self.context, cgsnapshot.id) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual('deleting', cgsnapshot.status) cgsnapshot.destroy() @@ -390,7 +397,7 @@ class CgsnapshotsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app()) cgsnapshot = objects.CGSnapshot.get_by_id(self.context, cgsnapshot.id) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertEqual('available', cgsnapshot.status) cgsnapshot.destroy() @@ -408,8 +415,9 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('GroupSnapshot %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message']) @@ -431,8 +439,9 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) expected = ('Invalid CgSnapshot: CgSnapshot status must be available ' 'or error, and no CG can be currently using it as source ' 'for its creation.') diff --git a/cinder/tests/unit/api/contrib/test_consistencygroups.py b/cinder/tests/unit/api/contrib/test_consistencygroups.py index e444367e662..7e3b687a6bd 100644 --- a/cinder/tests/unit/api/contrib/test_consistencygroups.py +++ b/cinder/tests/unit/api/contrib/test_consistencygroups.py @@ -20,6 +20,7 @@ Tests for consistency group code. import ddt import mock from oslo_serialization import jsonutils +from six.moves import http_client import webob import cinder.consistencygroup @@ -114,7 +115,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('az1', res_dict['consistencygroup']['availability_zone']) self.assertEqual('this is a test consistency group', @@ -137,8 +138,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('Group %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message']) @@ -153,7 +155,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('az1', res_dict['consistencygroup']['availability_zone']) self.assertEqual('this is a test consistency group', @@ -182,7 +184,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(consistencygroup3.id, res_dict['consistencygroups'][0]['id']) self.assertEqual('test_consistencygroup', @@ -215,7 +217,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(1, len(res_dict['consistencygroups'])) self.assertEqual(consistencygroup3.id, res_dict['consistencygroups'][0]['id']) @@ -244,7 +246,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(2, len(res_dict['consistencygroups'])) self.assertEqual(consistencygroup2.id, res_dict['consistencygroups'][0]['id']) @@ -266,7 +268,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): req.headers['Content-Type'] = 'application/json' res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) @ddt.data(False, True) def test_list_consistencygroups_with_limit_and_offset(self, is_detail): @@ -284,7 +286,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(2, len(res_dict['consistencygroups'])) self.assertEqual(consistencygroup2.id, res_dict['consistencygroups'][0]['id']) @@ -315,7 +317,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(1, len(res_dict['consistencygroups'])) self.assertEqual(consistencygroup3.id, res_dict['consistencygroups'][0]['id']) @@ -373,7 +375,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup3.id] expect_result.sort() - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(3, len(res_dict['consistencygroups'])) self.assertEqual(expect_result[0], res_dict['consistencygroups'][0]['id']) @@ -400,7 +402,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual('az1', res_dict['consistencygroups'][0]['availability_zone']) self.assertEqual('this is a test consistency group', @@ -466,7 +468,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertIn('id', res_dict['consistencygroup']) self.assertTrue(mock_validate.called) @@ -490,8 +492,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual("Missing required element 'consistencygroup' in " "request body.", res_dict['badRequest']['message']) @@ -508,7 +511,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) consistencygroup.destroy() @@ -528,7 +531,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertEqual('available', consistencygroup.status) consistencygroup.destroy() @@ -551,7 +554,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) consistencygroup.destroy() @@ -570,7 +573,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual(fields.ConsistencyGroupStatus.DELETING, consistencygroup.status) @@ -586,8 +589,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertEqual('Group %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, res_dict['itemNotFound']['message']) @@ -611,7 +615,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) def test_delete_consistencygroup_no_host(self): @@ -626,7 +630,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) cg = objects.ConsistencyGroup.get_by_id( context.get_admin_context(read_deleted='yes'), @@ -672,7 +676,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_delete_consistencygroup_with_invalid_force_value_in_body(self): consistencygroup = self._create_consistencygroup( @@ -686,7 +690,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_delete_consistencygroup_with_empty_force_value_in_body(self): consistencygroup = self._create_consistencygroup( @@ -700,7 +704,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def _assert_deleting_result_400(self, cg_id, force=False): req = webob.Request.blank('/v2/%s/consistencygroups/%s/delete' % @@ -710,7 +714,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): body = {"consistencygroup": {"force": force}} req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app()) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) if force: reason = _('Consistency group must not have attached volumes, ' @@ -725,7 +729,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): % {'id': cg_id, 'reason': reason}) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertEqual(msg, res_dict['badRequest']['message']) def test_delete_consistencygroup_with_volumes(self): @@ -772,7 +777,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) consistencygroup.destroy() @@ -808,7 +813,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) consistencygroup.destroy() @@ -825,8 +830,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) msg = (_('volume_types must be provided to create ' 'consistency group %s.') % name) self.assertEqual(msg, res_dict['badRequest']['message']) @@ -896,7 +902,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertTrue(mock_validate.called) self.assertEqual(fields.ConsistencyGroupStatus.UPDATING, consistencygroup.status) @@ -941,7 +947,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertEqual(fields.ConsistencyGroupStatus.AVAILABLE, consistencygroup.status) @@ -986,7 +992,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.ConsistencyGroup.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertEqual(fields.ConsistencyGroupStatus.AVAILABLE, consistencygroup.status) @@ -1010,8 +1016,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) msg = (_("Invalid volume: Cannot add volume fake-volume-uuid " "to consistency group %(group_id)s because volume cannot " "be found.") % @@ -1037,8 +1044,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) msg = (_("Invalid volume: Cannot remove volume fake-volume-uuid " "from consistency group %(group_id)s because it is not " "in the group.") % @@ -1064,8 +1072,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) consistencygroup.destroy() @@ -1092,8 +1101,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) msg = (_("Invalid volume: Cannot add volume %(volume_id)s " "to consistency group %(group_id)s because volume is in an " "invalid state: %(status)s. Valid states are: ('available', " @@ -1127,8 +1137,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) msg = (_("Invalid volume: Cannot add volume %(volume_id)s " "to consistency group %(group_id)s because volume type " "%(volume_type)s is not supported by the group.") % @@ -1160,8 +1171,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) consistencygroup.destroy() @@ -1183,8 +1195,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) msg = (_("Invalid ConsistencyGroup: Cannot update consistency group " "%s, status must be available, and it cannot be the source " "for an ongoing CG or CG Snapshot creation.") @@ -1225,7 +1238,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertIn('id', res_dict['consistencygroup']) self.assertEqual(test_cg_name, res_dict['consistencygroup']['name']) self.assertTrue(mock_validate.called) @@ -1262,7 +1275,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) self.assertIn('id', res_dict['consistencygroup']) self.assertEqual(test_cg_name, res_dict['consistencygroup']['name']) @@ -1304,8 +1317,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) snapshot.destroy() @@ -1327,8 +1341,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) # Missing 'consistencygroup-from-src' in the body. self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1346,8 +1361,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) def test_create_consistencygroup_from_src_no_host(self): @@ -1377,8 +1393,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) msg = _('Invalid ConsistencyGroup: No host to create consistency ' 'group') self.assertIn(msg, res_dict['badRequest']['message']) @@ -1411,8 +1428,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) db.volume_destroy(self.ctxt.elevated(), volume_id) @@ -1436,8 +1454,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) source_cg.destroy() @@ -1466,8 +1485,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertIsNotNone(res_dict['itemNotFound']['message']) db.volume_destroy(self.ctxt.elevated(), volume_id) @@ -1492,8 +1512,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(404, res.status_int) - self.assertEqual(404, res_dict['itemNotFound']['code']) + self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(http_client.NOT_FOUND, + res_dict['itemNotFound']['code']) self.assertIsNotNone(res_dict['itemNotFound']['message']) @mock.patch('cinder.quota.QuotaEngine.limit_check') @@ -1528,8 +1549,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) msg = _("Create volume failed.") self.assertEqual(msg, res_dict['badRequest']['message']) @@ -1563,8 +1585,9 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) - self.assertEqual(400, res_dict['badRequest']['code']) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, + res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) db.volume_destroy(self.ctxt.elevated(), volume_id) @@ -1596,7 +1619,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn('message', res_dict['badRequest']) cg = objects.ConsistencyGroupList.get_all(self.ctxt) @@ -1642,7 +1665,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertIn('message', res_dict['badRequest']) self.assertTrue(mock_validate.called) diff --git a/cinder/tests/unit/api/contrib/test_extended_snapshot_attributes.py b/cinder/tests/unit/api/contrib/test_extended_snapshot_attributes.py index 910b4a744f6..33b52776eaa 100644 --- a/cinder/tests/unit/api/contrib/test_extended_snapshot_attributes.py +++ b/cinder/tests/unit/api/contrib/test_extended_snapshot_attributes.py @@ -16,6 +16,7 @@ import mock from oslo_serialization import jsonutils +from six.moves import http_client import webob from cinder import context @@ -97,7 +98,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase): url = '/v2/%s/snapshots/%s' % (fake.PROJECT_ID, UUID1) res = self._make_request(url) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertSnapshotAttributes(self._get_snapshot(res.body), project_id=fake.PROJECT_ID, progress='0%') @@ -106,7 +107,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase): url = '/v2/%s/snapshots/detail' % fake.PROJECT_ID res = self._make_request(url) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) for snapshot in self._get_snapshots(res.body): self.assertSnapshotAttributes(snapshot, project_id=fake.PROJECT_ID, diff --git a/cinder/tests/unit/api/contrib/test_qos_specs_manage.py b/cinder/tests/unit/api/contrib/test_qos_specs_manage.py index b417b6d7fb8..0a51f1ff9a2 100644 --- a/cinder/tests/unit/api/contrib/test_qos_specs_manage.py +++ b/cinder/tests/unit/api/contrib/test_qos_specs_manage.py @@ -16,6 +16,7 @@ import ddt import mock +from six.moves import http_client import webob from cinder.api.contrib import qos_specs_manage @@ -590,7 +591,7 @@ class QoSSpecManageApiTest(test.TestCase): (fake.PROJECT_ID, fake.QOS_SPEC_ID, fake.VOLUME_TYPE_ID)) res = self.controller.associate(req, fake.QOS_SPEC_ID) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) @mock.patch('cinder.volume.qos_specs.get_qos_specs', side_effect=return_qos_specs_get_qos_specs) @@ -643,7 +644,7 @@ class QoSSpecManageApiTest(test.TestCase): '/v2/%s/qos-specs/%s/disassociate?vol_type_id=%s' % ( fake.PROJECT_ID, fake.QOS_SPEC_ID, fake.VOLUME_TYPE_ID)) res = self.controller.disassociate(req, fake.QOS_SPEC_ID) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) @mock.patch('cinder.volume.qos_specs.get_qos_specs', side_effect=return_qos_specs_get_qos_specs) @@ -698,7 +699,7 @@ class QoSSpecManageApiTest(test.TestCase): '/v2/%s/qos-specs/%s/disassociate_all' % ( fake.PROJECT_ID, fake.QOS_SPEC_ID)) res = self.controller.disassociate_all(req, fake.QOS_SPEC_ID) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) @mock.patch('cinder.volume.qos_specs.get_qos_specs', side_effect=return_qos_specs_get_qos_specs) diff --git a/cinder/tests/unit/api/contrib/test_scheduler_hints.py b/cinder/tests/unit/api/contrib/test_scheduler_hints.py index 00b240f3165..e74929046b3 100644 --- a/cinder/tests/unit/api/contrib/test_scheduler_hints.py +++ b/cinder/tests/unit/api/contrib/test_scheduler_hints.py @@ -16,6 +16,7 @@ import datetime from oslo_serialization import jsonutils +from six.moves import http_client import cinder from cinder.api.openstack import wsgi @@ -49,7 +50,7 @@ class SchedulerHintsTestCase(test.TestCase): def test_create_server_without_hints(self): - @wsgi.response(202) + @wsgi.response(http_client.ACCEPTED) def fake_create(*args, **kwargs): self.assertNotIn('scheduler_hints', kwargs['body']) return self.fake_instance @@ -65,11 +66,11 @@ class SchedulerHintsTestCase(test.TestCase): 'volume_id': fake.VOLUME_ID, } req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_create_server_with_hints(self): - @wsgi.response(202) + @wsgi.response(http_client.ACCEPTED) def fake_create(*args, **kwargs): self.assertIn('scheduler_hints', kwargs['body']) self.assertEqual({"a": "b"}, kwargs['body']['scheduler_hints']) @@ -88,7 +89,7 @@ class SchedulerHintsTestCase(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_create_server_bad_hints(self): req = fakes.HTTPRequest.blank('/v2/%s/volumes' % fake.PROJECT_ID) @@ -102,4 +103,4 @@ class SchedulerHintsTestCase(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) diff --git a/cinder/tests/unit/api/contrib/test_services.py b/cinder/tests/unit/api/contrib/test_services.py index 97ffecf2d55..ed8384c763d 100644 --- a/cinder/tests/unit/api/contrib/test_services.py +++ b/cinder/tests/unit/api/contrib/test_services.py @@ -19,6 +19,7 @@ import datetime import ddt from iso8601 import iso8601 import mock +from six.moves import http_client import webob.exc from cinder.api.contrib import services @@ -793,7 +794,7 @@ class ServicesTest(test.TestCase): mock.sentinel.host, None, mock.sentinel.backend_id) - self.assertEqual(202, res.status_code) + self.assertEqual(http_client.ACCEPTED, res.status_code) @ddt.data(('failover_host', {'host': mock.sentinel.host, 'backend_id': mock.sentinel.backend_id}), diff --git a/cinder/tests/unit/api/contrib/test_snapshot_actions.py b/cinder/tests/unit/api/contrib/test_snapshot_actions.py index 8a6b6276b7c..800c4a753f5 100644 --- a/cinder/tests/unit/api/contrib/test_snapshot_actions.py +++ b/cinder/tests/unit/api/contrib/test_snapshot_actions.py @@ -14,6 +14,7 @@ import mock from oslo_serialization import jsonutils +from six.moves import http_client import webob from cinder import context @@ -58,7 +59,7 @@ class SnapshotActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) @mock.patch('cinder.db.sqlalchemy.api._snapshot_get', side_effect=fake_snapshot_get) @@ -73,7 +74,7 @@ class SnapshotActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_update_snapshot_status_without_status(self): self.mock_object(db, 'snapshot_get', fake_snapshot_get) @@ -86,4 +87,4 @@ class SnapshotActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) diff --git a/cinder/tests/unit/api/contrib/test_snapshot_manage.py b/cinder/tests/unit/api/contrib/test_snapshot_manage.py index b9c9e0a5232..152db592606 100644 --- a/cinder/tests/unit/api/contrib/test_snapshot_manage.py +++ b/cinder/tests/unit/api/contrib/test_snapshot_manage.py @@ -17,6 +17,7 @@ import mock from oslo_config import cfg import oslo_messaging as messaging from oslo_serialization import jsonutils +from six.moves import http_client from six.moves.urllib.parse import urlencode import webob @@ -122,7 +123,7 @@ class SnapshotManageTest(test.TestCase): binary='cinder-volume') body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(202, res.status_int, res) + self.assertEqual(http_client.ACCEPTED, res.status_int, res) # Check the db.service_get was called with correct arguments. mock_db.assert_called_once_with( @@ -156,7 +157,7 @@ class SnapshotManageTest(test.TestCase): disabled=True) body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(400, res.status_int, res) + self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) mock_create_snapshot.assert_not_called() @@ -174,7 +175,7 @@ class SnapshotManageTest(test.TestCase): mock_db.return_value = fake_service.fake_service_obj(self._admin_ctxt) body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(400, res.status_int, res) + self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) mock_create_snapshot.assert_not_called() @@ -185,26 +186,26 @@ class SnapshotManageTest(test.TestCase): """Test correct failure when volume_id is not specified.""" body = {'snapshot': {'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_manage_snapshot_missing_ref(self): """Test correct failure when the ref is not specified.""" body = {'snapshot': {'volume_id': fake.VOLUME_ID}} res = self._get_resp_post(body) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_manage_snapshot_error_body(self): """Test correct failure when body is invaild.""" body = {'error_snapshot': {'volume_id': fake.VOLUME_ID}} res = self._get_resp_post(body) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_manage_snapshot_error_volume_id(self): """Test correct failure when volume can't be found.""" body = {'snapshot': {'volume_id': 'error_volume_id', 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(404, res.status_int) + self.assertEqual(http_client.NOT_FOUND, res.status_int) def _get_resp_get(self, host, detailed, paging, admin=True): """Helper to execute a GET os-snapshot-manage API call.""" @@ -230,10 +231,10 @@ class SnapshotManageTest(test.TestCase): wraps=api_get_manageable_snapshots) def test_get_manageable_snapshots_non_admin(self, mock_api_manageable): res = self._get_resp_get('fakehost', False, False, admin=False) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) self.assertEqual(False, mock_api_manageable.called) res = self._get_resp_get('fakehost', True, False, admin=False) - self.assertEqual(403, res.status_int) + self.assertEqual(http_client.FORBIDDEN, res.status_int) self.assertEqual(False, mock_api_manageable.called) @mock.patch('cinder.volume.api.API.get_manageable_snapshots', @@ -249,7 +250,7 @@ class SnapshotManageTest(test.TestCase): {'reference': {'source-name': 'mysnap'}, 'size': 5, 'safe_to_manage': True, 'source_reference': {'source-name': 'myvol'}}]} - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(jsonutils.loads(res.body), exp) mock_api_manageable.assert_called_once_with( self._admin_ctxt, 'fakehost', None, limit=CONF.osapi_max_limit, @@ -262,7 +263,7 @@ class SnapshotManageTest(test.TestCase): def test_get_manageable_snapshots_non_existent_marker( self, mock_api_manageable): res = self._get_resp_get('fakehost', detailed=False, paging=True) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertTrue(mock_api_manageable.called) @mock.patch('cinder.volume.api.API.get_manageable_snapshots', @@ -281,7 +282,7 @@ class SnapshotManageTest(test.TestCase): 'cinder_id': None, 'safe_to_manage': True, 'reason_not_safe': None, 'extra_info': 'qos_setting:low', 'source_reference': {'source-name': 'myvol'}}]} - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) self.assertEqual(jsonutils.loads(res.body), exp) mock_api_manageable.assert_called_once_with( self._admin_ctxt, 'fakehost', None, limit=10, marker='1234', @@ -293,7 +294,7 @@ class SnapshotManageTest(test.TestCase): def test_get_manageable_snapshots_non_existent_marker_detailed( self, mock_api_manageable): res = self._get_resp_get('fakehost', detailed=True, paging=True) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) self.assertTrue(mock_api_manageable.called) @mock.patch('cinder.objects.service.Service.is_up', return_value=True) @@ -302,7 +303,7 @@ class SnapshotManageTest(test.TestCase): mock_db.return_value = fake_service.fake_service_obj(self._admin_ctxt, disabled=True) res = self._get_resp_get('host_ok', False, True) - self.assertEqual(400, res.status_int, res) + self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) mock_is_up.assert_not_called() @@ -313,7 +314,7 @@ class SnapshotManageTest(test.TestCase): def test_get_manageable_snapshots_is_down(self, mock_db, mock_is_up): mock_db.return_value = fake_service.fake_service_obj(self._admin_ctxt) res = self._get_resp_get('host_ok', False, True) - self.assertEqual(400, res.status_int, res) + self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) self.assertTrue(mock_is_up.called) diff --git a/cinder/tests/unit/api/contrib/test_snapshot_unmanage.py b/cinder/tests/unit/api/contrib/test_snapshot_unmanage.py index 630fa3b0ab9..24e79b2a0c7 100644 --- a/cinder/tests/unit/api/contrib/test_snapshot_unmanage.py +++ b/cinder/tests/unit/api/contrib/test_snapshot_unmanage.py @@ -14,6 +14,7 @@ import mock from oslo_serialization import jsonutils +from six.moves import http_client import webob from cinder import context @@ -98,9 +99,9 @@ class SnapshotUnmanageTest(test.TestCase): self.assertEqual(3, len(mock_rpcapi.call_args[0])) self.assertEqual(0, len(mock_rpcapi.call_args[1])) - self.assertEqual(202, res.status_int, res) + self.assertEqual(http_client.ACCEPTED, res.status_int, res) def test_unmanage_snapshot_bad_snapshot_id(self): """Return 404 if the volume does not exist.""" res = self._get_resp(bad_snp_id) - self.assertEqual(404, res.status_int, res) + self.assertEqual(http_client.NOT_FOUND, res.status_int, res) diff --git a/cinder/tests/unit/api/contrib/test_volume_actions.py b/cinder/tests/unit/api/contrib/test_volume_actions.py index ae328c3bb59..80d7cf7f833 100644 --- a/cinder/tests/unit/api/contrib/test_volume_actions.py +++ b/cinder/tests/unit/api/contrib/test_volume_actions.py @@ -20,6 +20,7 @@ import mock from oslo_config import cfg import oslo_messaging as messaging from oslo_serialization import jsonutils +from six.moves import http_client import webob from cinder.api.contrib import volume_actions @@ -94,7 +95,7 @@ class VolumeActionsTest(test.TestCase): req.body = jsonutils.dump_as_bytes({_action: None}) req.content_type = 'application/json' res = req.get_response(app) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_initialize_connection(self): with mock.patch.object(volume_api.API, @@ -109,7 +110,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(200, res.status_int) + self.assertEqual(http_client.OK, res.status_int) def test_initialize_connection_without_connector(self): with mock.patch.object(volume_api.API, @@ -124,7 +125,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) @mock.patch('cinder.volume.rpcapi.VolumeAPI.initialize_connection') def test_initialize_connection_without_initiator(self, @@ -139,7 +140,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_initialize_connection_exception(self): with mock.patch.object(volume_api.API, @@ -155,7 +156,8 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(500, res.status_int) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, + res.status_int) def test_terminate_connection(self): with mock.patch.object(volume_api.API, @@ -170,7 +172,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_terminate_connection_without_connector(self): with mock.patch.object(volume_api.API, @@ -185,7 +187,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_terminate_connection_with_exception(self): with mock.patch.object(volume_api.API, @@ -201,7 +203,8 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(500, res.status_int) + self.assertEqual(http_client.INTERNAL_SERVER_ERROR, + res.status_int) def test_attach_to_instance(self): body = {'os-attach': {'instance_uuid': fake.INSTANCE_ID, @@ -215,7 +218,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) body = {'os-attach': {'instance_uuid': fake.INSTANCE_ID, 'host_name': 'fake_host', @@ -227,7 +230,7 @@ class VolumeActionsTest(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_attach_to_host(self): # using 'read-write' mode attach volume by default @@ -241,7 +244,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_volume_attach_to_instance_raises_remote_error(self): volume_remote_error = \ @@ -290,7 +293,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_volume_detach_raises_remote_error(self): volume_remote_error = \ @@ -335,7 +338,7 @@ class VolumeActionsTest(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) # Invalid request to attach volume with an invalid mode body = {'os-attach': {'instance_uuid': 'fake', @@ -348,7 +351,7 @@ class VolumeActionsTest(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) body = {'os-attach': {'host_name': 'fake_host', 'mountpoint': '/dev/vdc', 'mode': 'ww'}} @@ -359,7 +362,7 @@ class VolumeActionsTest(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_attach_to_instance_no_mountpoint(self): # The mountpoint parameter is required. If not provided the @@ -391,7 +394,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_roll_detaching(self): def fake_roll_detaching(*args, **kwargs): @@ -408,7 +411,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_extend_volume(self): def fake_extend_volume(*args, **kwargs): @@ -425,7 +428,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(202, res.status_int) + self.assertEqual(http_client.ACCEPTED, res.status_int) def test_extend_volume_invalid_status(self): def fake_extend_volume(*args, **kwargs): @@ -442,10 +445,13 @@ class VolumeActionsTest(test.TestCase): req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app(fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) - @ddt.data((True, 202), (False, 202), ('1', 202), ('0', 202), ('true', 202), - ('false', 202), ('tt', 400), (11, 400), (None, 400)) + @ddt.data((True, http_client.ACCEPTED), (False, http_client.ACCEPTED), + ('1', http_client.ACCEPTED), ('0', http_client.ACCEPTED), + ('true', http_client.ACCEPTED), ('false', http_client.ACCEPTED), + ('tt', http_client.BAD_REQUEST), (11, http_client.BAD_REQUEST), + (None, http_client.BAD_REQUEST)) @ddt.unpack def test_update_readonly_flag(self, readonly, return_code): def fake_update_readonly_flag(*args, **kwargs): @@ -465,8 +471,11 @@ class VolumeActionsTest(test.TestCase): fake_auth_context=self.context)) self.assertEqual(return_code, res.status_int) - @ddt.data((True, 200), (False, 200), ('1', 200), ('0', 200), ('true', 200), - ('false', 200), ('tt', 400), (11, 400), (None, 400)) + @ddt.data((True, http_client.OK), (False, http_client.OK), + ('1', http_client.OK), ('0', http_client.OK), + ('true', http_client.OK), ('false', http_client.OK), + ('tt', http_client.BAD_REQUEST), (11, http_client.BAD_REQUEST), + (None, http_client.BAD_REQUEST)) @ddt.unpack def test_set_bootable(self, bootable, return_code): body = {"os-set_bootable": {"bootable": bootable}} @@ -525,7 +534,7 @@ class VolumeRetypeActionsTest(test.TestCase): req.headers['content-type'] = 'application/json' req.body = jsonutils.dump_as_bytes({'os-retype': None}) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_retype_volume_bad_policy(self): # Request with invalid migration policy should fail @@ -539,7 +548,7 @@ class VolumeRetypeActionsTest(test.TestCase): retype_body = {'new_type': 'foo', 'migration_policy': 'invalid'} req.body = jsonutils.dump_as_bytes({'os-retype': retype_body}) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_retype_volume_bad_status(self): # Should fail if volume does not have proper status @@ -552,7 +561,8 @@ class VolumeRetypeActionsTest(test.TestCase): volume_type_id=vol_type_old.id, testcase_instance=self) - self._retype_volume_exec(400, vol_type_new.id, vol.id) + self._retype_volume_exec(http_client.BAD_REQUEST, vol_type_new.id, + vol.id) def test_retype_type_no_exist(self): # Should fail if new type does not exist @@ -562,7 +572,8 @@ class VolumeRetypeActionsTest(test.TestCase): status='available', volume_type_id=vol_type_old.id, testcase_instance=self) - self._retype_volume_exec(404, 'fake_vol_type', vol.id) + self._retype_volume_exec(http_client.NOT_FOUND, 'fake_vol_type', + vol.id) def test_retype_same_type(self): # Should fail if new type and old type are the same @@ -572,7 +583,8 @@ class VolumeRetypeActionsTest(test.TestCase): status='available', volume_type_id=vol_type_old.id, testcase_instance=self) - self._retype_volume_exec(400, vol_type_old.id, vol.id) + self._retype_volume_exec(http_client.BAD_REQUEST, vol_type_old.id, + vol.id) def test_retype_over_quota(self): # Should fail if going over quota for new type @@ -587,28 +599,33 @@ class VolumeRetypeActionsTest(test.TestCase): usages={'gigabytes': {'reserved': 5, 'in_use': 15}}) self.retype_mocks['reserve'].side_effect = exc - self._retype_volume_exec(413, vol_type_new.id, vol.id) + self._retype_volume_exec(http_client.REQUEST_ENTITY_TOO_LARGE, + vol_type_new.id, vol.id) - @ddt.data(('in-use', 'front-end', 400), - ('in-use', 'back-end', 202), - ('available', 'front-end', 202), - ('available', 'back-end', 202), - ('in-use', 'front-end', 202, True), - ('in-use', 'back-end', 202, True), - ('available', 'front-end', 202, True), - ('available', 'back-end', 202, True), - ('in-use', 'front-end', 400, False, False), - ('in-use', 'back-end', 202, False, False), - ('in-use', '', 202, True, False), - ('available', 'front-end', 202, False, False), - ('available', 'back-end', 202, False, False), - ('available', '', 202, True, False), - ('in-use', 'front-end', 400, False, False, False), - ('in-use', '', 202, True, False, False), - ('in-use', 'back-end', 202, False, False, False), - ('available', 'front-end', 202, False, False, False), - ('in-use', '', 202, True, False, False), - ('in-use', 'back-end', 202, False, False, False)) + @ddt.data(('in-use', 'front-end', http_client.BAD_REQUEST), + ('in-use', 'back-end', http_client.ACCEPTED), + ('available', 'front-end', http_client.ACCEPTED), + ('available', 'back-end', http_client.ACCEPTED), + ('in-use', 'front-end', http_client.ACCEPTED, True), + ('in-use', 'back-end', http_client.ACCEPTED, True), + ('available', 'front-end', http_client.ACCEPTED, True), + ('available', 'back-end', http_client.ACCEPTED, True), + ('in-use', 'front-end', http_client.BAD_REQUEST, False, False), + ('in-use', 'back-end', http_client.ACCEPTED, False, False), + ('in-use', '', http_client.ACCEPTED, True, False), + ('available', 'front-end', http_client.ACCEPTED, False, False), + ('available', 'back-end', http_client.ACCEPTED, False, False), + ('available', '', http_client.ACCEPTED, True, False), + ('in-use', 'front-end', http_client.BAD_REQUEST, False, + False, False), + ('in-use', '', http_client.ACCEPTED, True, False, False), + ('in-use', 'back-end', http_client.ACCEPTED, False, + False, False), + ('available', 'front-end', http_client.ACCEPTED, False, + False, False), + ('in-use', '', http_client.ACCEPTED, True, False, False), + ('in-use', 'back-end', http_client.ACCEPTED, False, + False, False)) @ddt.unpack def test_retype_volume_qos(self, vol_status, consumer_pass, expected_status, same_qos=False, has_qos=True, @@ -691,11 +708,11 @@ class VolumeRetypeActionsTest(test.TestCase): self._retype_volume_exec(expected_status, vol_type_new, vol.id) - @ddt.data(('available', 202, False, False, False), - ('available', 202, False, False), - ('available', 202, True, False, False), - ('available', 202, True, False), - ('available', 202)) + @ddt.data(('available', http_client.ACCEPTED, False, False, False), + ('available', http_client.ACCEPTED, False, False), + ('available', http_client.ACCEPTED, True, False, False), + ('available', http_client.ACCEPTED, True, False), + ('available', http_client.ACCEPTED)) @ddt.unpack def test_retype_volume_encryption(self, vol_status, expected_status, has_type=True, @@ -932,7 +949,7 @@ class VolumeImageActionsTest(test.TestCase): req.headers['Content-Type'] = 'application/json' req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) def test_volume_upload_image_without_type(self): id = fake.VOLUME2_ID @@ -947,7 +964,7 @@ class VolumeImageActionsTest(test.TestCase): req.headers['Content-Type'] = 'application/json' req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.context)) - self.assertEqual(400, res.status_int) + self.assertEqual(http_client.BAD_REQUEST, res.status_int) @mock.patch.object(volume_api.API, 'get', fake_volume_get) def test_extend_volume_valueerror(self): diff --git a/cinder/tests/unit/api/contrib/test_volume_encryption_metadata.py b/cinder/tests/unit/api/contrib/test_volume_encryption_metadata.py index 060d401bf54..c18769bf1d3 100644 --- a/cinder/tests/unit/api/contrib/test_volume_encryption_metadata.py +++ b/cinder/tests/unit/api/contrib/test_volume_encryption_metadata.py @@ -14,6 +14,7 @@ # under the License. from oslo_serialization import jsonutils +from six.moves import http_client import webob from cinder.api.contrib import volume_encryption_metadata @@ -81,7 +82,7 @@ class VolumeEncryptionMetadataTest(test.TestCase): req = webob.Request.blank('/v2/%s/volumes/%s/encryption' % ( fake.PROJECT_ID, self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(200, res.status_code) + self.assertEqual(http_client.OK, res.status_code) res_dict = jsonutils.loads(res.body) expected = { @@ -97,10 +98,10 @@ class VolumeEncryptionMetadataTest(test.TestCase): req = webob.Request.blank('/v2/%s/volumes/%s/encryption' % ( fake.WILL_NOT_BE_FOUND_ID, self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(400, res.status_code) + self.assertEqual(http_client.BAD_REQUEST, res.status_code) res_dict = jsonutils.loads(res.body) - expected = {'badRequest': {'code': 400, + expected = {'badRequest': {'code': http_client.BAD_REQUEST, 'message': 'Malformed request url'}} self.assertEqual(expected, res_dict) @@ -109,10 +110,10 @@ class VolumeEncryptionMetadataTest(test.TestCase): req = webob.Request.blank('/v2/%s/volumes/%s/encryption' % ( fake.PROJECT_ID, bad_volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(404, res.status_code) + self.assertEqual(http_client.NOT_FOUND, res.status_code) res_dict = jsonutils.loads(res.body) - expected = {'itemNotFound': {'code': 404, + expected = {'itemNotFound': {'code': http_client.NOT_FOUND, 'message': 'Volume %s could not be found.' % bad_volume_id}} self.assertEqual(expected, res_dict) @@ -122,7 +123,7 @@ class VolumeEncryptionMetadataTest(test.TestCase): 'encryption_key_id' % ( fake.PROJECT_ID, self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(200, res.status_code) + self.assertEqual(http_client.OK, res.status_code) self.assertEqual(fake.ENCRYPTION_KEY_ID, res.body.decode()) @@ -131,7 +132,7 @@ class VolumeEncryptionMetadataTest(test.TestCase): 'control_location' % ( fake.PROJECT_ID, self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(200, res.status_code) + self.assertEqual(http_client.OK, res.status_code) self.assertEqual(b'front-end', res.body) @@ -140,7 +141,7 @@ class VolumeEncryptionMetadataTest(test.TestCase): 'provider' % ( fake.PROJECT_ID, self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(200, res.status_code) + self.assertEqual(http_client.OK, res.status_code) self.assertEqual(b'nova.volume.encryptors.base.VolumeEncryptor', res.body) @@ -151,10 +152,10 @@ class VolumeEncryptionMetadataTest(test.TestCase): (fake.WILL_NOT_BE_FOUND_ID, self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(400, res.status_code) + self.assertEqual(http_client.BAD_REQUEST, res.status_code) res_dict = jsonutils.loads(res.body) - expected = {'badRequest': {'code': 400, + expected = {'badRequest': {'code': http_client.BAD_REQUEST, 'message': 'Malformed request url'}} self.assertEqual(expected, res_dict) @@ -164,10 +165,10 @@ class VolumeEncryptionMetadataTest(test.TestCase): 'encryption_key_id' % ( fake.PROJECT_ID, bad_volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(404, res.status_code) + self.assertEqual(http_client.NOT_FOUND, res.status_code) res_dict = jsonutils.loads(res.body) - expected = {'itemNotFound': {'code': 404, + expected = {'itemNotFound': {'code': http_client.NOT_FOUND, 'message': 'Volume %s could not be found.' % bad_volume_id}} self.assertEqual(expected, res_dict) @@ -180,7 +181,7 @@ class VolumeEncryptionMetadataTest(test.TestCase): 'encryption_key_id' % ( fake.PROJECT_ID, self.volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=ctxt)) - self.assertEqual(200, res.status_code) + self.assertEqual(http_client.OK, res.status_code) self.assertEqual(fake.ENCRYPTION_KEY_ID, res.body.decode()) @@ -195,7 +196,7 @@ class VolumeEncryptionMetadataTest(test.TestCase): 'encryption_key_id' % ( fake.PROJECT_ID, volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(200, res.status_code) + self.assertEqual(http_client.OK, res.status_code) self.assertEqual(0, len(res.body)) def test_index_volume_not_encrypted_type(self): @@ -209,7 +210,7 @@ class VolumeEncryptionMetadataTest(test.TestCase): fake.PROJECT_ID, volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(200, res.status_code) + self.assertEqual(http_client.OK, res.status_code) res_dict = jsonutils.loads(res.body) expected = {