commit 113026765fafc2c56f5911aaaec3ff5fff6e2db1 Author: xuanyandong Date: Thu Oct 8 10:17:50 2020 +0800 Remove six of dir cinder/tests/unit/api/* Replace the following items with Python 3 style code. - six.moves - six.PY3 - six.PY2 - six.text_type - six.string_types - six.unichr - six.viewkeys Change-Id: I7f701dd1e5f8cb220b08191101589858f8232178 Implements: blueprint six-removal diff --git a/cinder/tests/unit/api/contrib/test_admin_actions.py b/cinder/tests/unit/api/contrib/test_admin_actions.py index c2bf9f8..ef46274 100644 --- a/cinder/tests/unit/api/contrib/test_admin_actions.py +++ b/cinder/tests/unit/api/contrib/test_admin_actions.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock import ddt @@ -19,7 +20,6 @@ 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 cinder.api.contrib import admin_actions @@ -204,7 +204,7 @@ class AdminActionsTest(BaseAdminTest): {'attach_status': fields.VolumeAttachStatus.ATTACHED}) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual(fields.VolumeAttachStatus.ATTACHED, volume['attach_status']) @@ -219,7 +219,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'attach_status': 'bogus-status'}) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual(fields.VolumeAttachStatus.DETACHED, volume['attach_status']) @@ -233,7 +233,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'migration_status': 'bogus-status'}) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertIsNone(volume['migration_status']) @@ -246,7 +246,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'migration_status': 'migrating'}) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('migrating', volume['migration_status']) @@ -259,7 +259,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'status': 'error'}) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('error', volume['status']) @@ -275,7 +275,7 @@ class AdminActionsTest(BaseAdminTest): {'status': 'error'}) # request is not authorized - self.assertEqual(http_client.FORBIDDEN, resp.status_int) + self.assertEqual(HTTPStatus.FORBIDDEN, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) # status is still 'error' self.assertEqual('error', volume['status']) @@ -298,7 +298,7 @@ class AdminActionsTest(BaseAdminTest): backup, {'status': fields.BackupStatus.ERROR}) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) def test_backup_reset_status_as_non_admin(self): ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID) @@ -307,7 +307,7 @@ class AdminActionsTest(BaseAdminTest): backup, {'status': fields.BackupStatus.ERROR}) # request is not authorized - self.assertEqual(http_client.FORBIDDEN, resp.status_int) + self.assertEqual(HTTPStatus.FORBIDDEN, resp.status_int) def test_backup_reset_status(self): volume = db.volume_create(self.ctx, @@ -325,7 +325,7 @@ class AdminActionsTest(BaseAdminTest): backup, {'status': fields.BackupStatus.ERROR}) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) @ddt.data({'status': None}, {'status': 'restoring'}) def test_invalid_status_for_backup(self, status): @@ -337,7 +337,7 @@ class AdminActionsTest(BaseAdminTest): 'volume_id': volume['id']}) resp = self._issue_backup_reset(self.ctx, backup, status) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) def test_backup_reset_status_with_invalid_backup(self): volume = db.volume_create(self.ctx, @@ -356,7 +356,7 @@ class AdminActionsTest(BaseAdminTest): {'status': fields.BackupStatus.ERROR}) # Should raise 404 if backup doesn't exist. - self.assertEqual(http_client.NOT_FOUND, resp.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, resp.status_int) @ddt.data({'os-reset_status': {}}) def test_backup_reset_status_with_invalid_body(self, body): @@ -377,7 +377,7 @@ class AdminActionsTest(BaseAdminTest): req.body = jsonutils.dump_as_bytes(body) req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) def test_malformed_reset_status_body(self): volume = db.volume_create(self.ctx, {'status': 'available', 'size': 1, @@ -388,7 +388,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'x-status': 'bad'}) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('available', volume['status']) @@ -400,7 +400,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'status': 'invalid'}) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('available', volume['status']) @@ -413,7 +413,7 @@ class AdminActionsTest(BaseAdminTest): req.body = jsonutils.dump_as_bytes(body) req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) - self.assertEqual(http_client.NOT_FOUND, resp.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, resp.status_int) self.assertRaises(exception.NotFound, db.volume_get, self.ctx, fake.WILL_NOT_BE_FOUND_ID) @@ -449,7 +449,7 @@ class AdminActionsTest(BaseAdminTest): {'status': 'available', 'attach_status': fields.VolumeAttachStatus.DETACHED}) # request is accepted - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) # volume is detached volume = db.volume_get(self.ctx, volume['id']) @@ -475,7 +475,7 @@ class AdminActionsTest(BaseAdminTest): volume, {'status': 'available', 'attach_status': fields.VolumeAttachStatus.ERROR_DETACHING}) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) volume = db.volume_get(self.ctx, volume['id']) self.assertEqual('available', volume['status']) self.assertEqual(fields.VolumeAttachStatus.DETACHED, @@ -507,7 +507,7 @@ class AdminActionsTest(BaseAdminTest): {'status': fields.SnapshotStatus.ERROR}) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) snapshot = objects.Snapshot.get_by_id(self.ctx, snapshot['id']) self.assertEqual(fields.SnapshotStatus.ERROR, snapshot.status) @@ -525,7 +525,7 @@ class AdminActionsTest(BaseAdminTest): resp = self._issue_snapshot_reset(self.ctx, snapshot, updated_status) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) self.assertEqual(fields.SnapshotStatus.AVAILABLE, snapshot.status) @ddt.data({'os-reset_status': {}}) @@ -548,7 +548,7 @@ class AdminActionsTest(BaseAdminTest): req.body = jsonutils.dump_as_bytes(body) req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) def test_force_delete(self): # current status is creating @@ -562,7 +562,7 @@ class AdminActionsTest(BaseAdminTest): req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) # request is accepted - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) # volume is deleted self.assertRaises(exception.NotFound, objects.Volume.get_by_id, self.ctx, volume.id) @@ -589,7 +589,7 @@ class AdminActionsTest(BaseAdminTest): # attach admin context to request req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) def _migrate_volume_prep(self): # create volume's current host and the destination host @@ -644,7 +644,7 @@ class AdminActionsTest(BaseAdminTest): mv.get_prior_version(mv.VOLUME_MIGRATE_CLUSTER), mv.VOLUME_MIGRATE_CLUSTER) def test_migrate_volume_success_3(self, version): - expected_status = http_client.ACCEPTED + expected_status = HTTPStatus.ACCEPTED host = 'test2' volume = self._migrate_volume_prep() volume = self._migrate_volume_3_exec(self.ctx, volume, host, @@ -652,7 +652,7 @@ class AdminActionsTest(BaseAdminTest): self.assertEqual('starting', volume['migration_status']) def test_migrate_volume_success_cluster(self): - expected_status = http_client.ACCEPTED + expected_status = HTTPStatus.ACCEPTED # We cannot provide host and cluster, so send host to None host = None cluster = 'cluster' @@ -668,7 +668,7 @@ class AdminActionsTest(BaseAdminTest): host = 'test2' cluster = 'cluster' volume = self._migrate_volume_prep() - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST self._migrate_volume_3_exec(self.ctx, volume, host, expected_status, version=mv.VOLUME_MIGRATE_CLUSTER, cluster=cluster) @@ -692,7 +692,7 @@ class AdminActionsTest(BaseAdminTest): return volume def test_migrate_volume_success(self): - expected_status = http_client.ACCEPTED + expected_status = HTTPStatus.ACCEPTED host = 'test2' volume = self._migrate_volume_prep() volume = self._migrate_volume_exec(self.ctx, volume, host, @@ -700,7 +700,7 @@ class AdminActionsTest(BaseAdminTest): self.assertEqual('starting', volume['migration_status']) def test_migrate_volume_fail_replication(self): - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST host = 'test2' volume = self._migrate_volume_prep() # current status is available @@ -712,7 +712,7 @@ class AdminActionsTest(BaseAdminTest): expected_status) def test_migrate_volume_replication_not_caple_success(self): - expected_status = http_client.ACCEPTED + expected_status = HTTPStatus.ACCEPTED host = 'test2' volume = self._migrate_volume_prep() # current status is available @@ -725,7 +725,7 @@ class AdminActionsTest(BaseAdminTest): @mock.patch("cinder.volume.api.API.get") def test_migrate_volume_as_non_admin(self, fake_get): - expected_status = http_client.FORBIDDEN + expected_status = HTTPStatus.FORBIDDEN host = 'test2' ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID) volume = self._migrate_volume_prep() @@ -733,7 +733,7 @@ class AdminActionsTest(BaseAdminTest): self._migrate_volume_exec(ctx, volume, host, expected_status) def test_migrate_volume_without_host_parameter(self): - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST host = 'test3' volume = self._migrate_volume_prep() # build request to migrate without host @@ -750,19 +750,19 @@ class AdminActionsTest(BaseAdminTest): self.assertEqual(expected_status, resp.status_int) def test_migrate_volume_host_no_exist(self): - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.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 = http_client.BAD_REQUEST + expected_status = HTTPStatus.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 = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST host = 'test2' volume = self._migrate_volume_prep() volume.migration_status = 'migrating' @@ -770,7 +770,7 @@ class AdminActionsTest(BaseAdminTest): self._migrate_volume_exec(self.ctx, volume, host, expected_status) def test_migrate_volume_with_snap(self): - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST host = 'test2' volume = self._migrate_volume_prep() snap = objects.Snapshot(self.ctx, volume_id=volume['id']) @@ -780,7 +780,7 @@ class AdminActionsTest(BaseAdminTest): @ddt.data('force_host_copy', None, ' true ', 0) def test_migrate_volume_bad_force_host_copy(self, force_host_copy): - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST host = 'test2' volume = self._migrate_volume_prep() self._migrate_volume_exec(self.ctx, volume, host, expected_status, @@ -788,7 +788,7 @@ class AdminActionsTest(BaseAdminTest): @ddt.data('lock_volume', None, ' true ', 0) def test_migrate_volume_bad_lock_volume(self, lock_volume): - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST host = 'test2' volume = self._migrate_volume_prep() self._migrate_volume_exec(self.ctx, volume, host, expected_status, @@ -796,7 +796,7 @@ class AdminActionsTest(BaseAdminTest): @ddt.data('true', False, '1', '0') def test_migrate_volume_valid_lock_volume(self, lock_volume): - expected_status = http_client.ACCEPTED + expected_status = HTTPStatus.ACCEPTED host = 'test2' volume = self._migrate_volume_prep() self._migrate_volume_exec(self.ctx, volume, host, expected_status, @@ -832,7 +832,7 @@ class AdminActionsTest(BaseAdminTest): new_volume = db.volume_create(self.ctx, {'id': fake.VOLUME2_ID, 'volume_type_id': fake.VOLUME_TYPE_ID}) - expected_status = http_client.FORBIDDEN + expected_status = HTTPStatus.FORBIDDEN expected_id = None fake_get.return_value = volume ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID) @@ -843,7 +843,7 @@ class AdminActionsTest(BaseAdminTest): volume1 = self._create_volume(self.ctx, {'migration_status': 'foo'}) volume2 = self._create_volume(self.ctx, {'migration_status': None}) - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST expected_id = None self._migrate_volume_comp_exec(self.ctx, volume1, volume2, False, expected_status, expected_id) @@ -855,7 +855,7 @@ class AdminActionsTest(BaseAdminTest): {'migration_status': 'migrating'}) volume2 = self._create_volume(self.ctx, {'migration_status': 'target:foo'}) - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST expected_id = None self._migrate_volume_comp_exec(self.ctx, volume1, volume2, False, expected_status, expected_id) @@ -867,7 +867,7 @@ class AdminActionsTest(BaseAdminTest): new_volume = db.volume_create(self.ctx, {'id': fake.VOLUME2_ID, 'volume_type_id': fake.VOLUME_TYPE_ID}) - expected_status = http_client.BAD_REQUEST + expected_status = HTTPStatus.BAD_REQUEST expected_id = None ctx = context.RequestContext(fake.USER_ID, fake.PROJECT_ID) self._migrate_volume_comp_exec(ctx, volume, new_volume, False, @@ -884,7 +884,7 @@ class AdminActionsTest(BaseAdminTest): 'attach_status': fields.VolumeAttachStatus. DETACHED}) - expected_status = http_client.OK + expected_status = HTTPStatus.OK expected_id = new_volume.id self._migrate_volume_comp_exec(self.ctx, volume, new_volume, False, expected_status, expected_id) @@ -902,7 +902,7 @@ class AdminActionsTest(BaseAdminTest): req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) res_dict = jsonutils.loads(resp.body) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) @mock.patch('cinder.backup.rpcapi.BackupAPI.delete_backup', mock.Mock()) @@ -929,7 +929,7 @@ class AdminActionsTest(BaseAdminTest): res = req.get_response(app()) backup.refresh() - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual('deleting', backup.status) backup.destroy() @@ -964,7 +964,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(http_client.METHOD_NOT_ALLOWED, res.status_int) + self.assertEqual(HTTPStatus.METHOD_NOT_ALLOWED, res.status_int) class AdminActionsAttachDetachTest(BaseAdminTest): @@ -1016,7 +1016,7 @@ class AdminActionsAttachDetachTest(BaseAdminTest): # make request resp = req.get_response(app()) # request is accepted - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) volume.refresh() self.assertRaises(exception.VolumeAttachmentNotFound, db.volume_attachment_get, @@ -1068,7 +1068,7 @@ class AdminActionsAttachDetachTest(BaseAdminTest): # make request resp = req.get_response(app()) # request is accepted - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) volume.refresh() self.assertRaises(exception.VolumeAttachmentNotFound, db.volume_attachment_get, @@ -1119,7 +1119,7 @@ class AdminActionsAttachDetachTest(BaseAdminTest): req.environ['cinder.context'] = self.ctx # make request resp = req.get_response(app()) - self.assertEqual(http_client.BAD_REQUEST, resp.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, resp.status_int) # test for VolumeBackendAPIException volume_remote_error = ( @@ -1224,7 +1224,7 @@ class AdminActionsAttachDetachTest(BaseAdminTest): req.environ['cinder.context'] = self.ctx # make request resp = req.get_response(app()) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) def test_attach_in_used_volume_by_instance(self): """Test that attaching to an in-use volume fails.""" diff --git a/cinder/tests/unit/api/contrib/test_backups.py b/cinder/tests/unit/api/contrib/test_backups.py index 560d3c2..6a260bd 100644 --- a/cinder/tests/unit/api/contrib/test_backups.py +++ b/cinder/tests/unit/api/contrib/test_backups.py @@ -15,13 +15,12 @@ """Tests for Backup code.""" +from http import HTTPStatus from unittest import mock import ddt from oslo_serialization import jsonutils from oslo_utils import timeutils -import six -from six.moves import http_client import webob from cinder.api.contrib import backups @@ -90,7 +89,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(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.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', @@ -139,8 +138,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Backup %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -158,7 +157,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(3, len(res_dict['backups'][0])) self.assertEqual(backup3.id, res_dict['backups'][0]['id']) self.assertEqual('test_backup', res_dict['backups'][0]['name']) @@ -185,7 +184,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(2, len(res_dict['backups'])) self.assertEqual(3, len(res_dict['backups'][0])) self.assertEqual(backup3.id, res_dict['backups'][0]['id']) @@ -205,7 +204,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_list_backups_with_marker(self): backup1 = utils.create_backup(self.context) @@ -219,7 +218,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(2, len(res_dict['backups'])) self.assertEqual(3, len(res_dict['backups'][0])) self.assertEqual(backup2.id, res_dict['backups'][0]['id']) @@ -246,7 +245,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(1, len(res_dict['backups'])) self.assertEqual(3, len(res_dict['backups'][0])) self.assertEqual(backup2.id, res_dict['backups'][0]['id']) @@ -273,7 +272,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0])) self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][1])) self.assertEqual(2, len(res_dict['backups'])) @@ -311,7 +310,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.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', @@ -406,7 +405,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) self.assertEqual(1, len(res_dict['backups'])) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(backup1.id, res_dict['backups'][0]['id']) req = webob.Request.blank('/v2/%s/backups/detail?status=available' % @@ -419,7 +418,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) self.assertEqual(1, len(res_dict['backups'])) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(backup2.id, res_dict['backups'][0]['id']) req = webob.Request.blank('/v2/%s/backups/detail?volume_id=%s' % ( @@ -432,7 +431,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) self.assertEqual(1, len(res_dict['backups'])) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(backup3.id, res_dict['backups'][0]['id']) backup3.destroy() @@ -452,7 +451,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(2, len(res_dict['backups'])) self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0])) self.assertEqual(backup3.id, res_dict['backups'][0]['id']) @@ -477,7 +476,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(2, len(res_dict['backups'])) self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0])) self.assertEqual(backup2.id, res_dict['backups'][0]['id']) @@ -502,7 +501,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(1, len(res_dict['backups'])) self.assertEqual(NUM_ELEMENTS_IN_BACKUP, len(res_dict['backups'][0])) self.assertEqual(backup2.id, res_dict['backups'][0]['id']) @@ -519,7 +518,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_create_backup_json(self): volume = utils.create_volume(self.context, size=5) @@ -540,7 +539,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) volume.destroy() @@ -678,8 +677,8 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -708,7 +707,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) backup.destroy() @@ -732,7 +731,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) volume.destroy() @@ -759,7 +758,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) self.assertIsNotNone(res_dict['badRequest']['message']) snapshot.destroy() @@ -786,8 +785,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -811,8 +810,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertIsNotNone(res_dict['itemNotFound']['message']) @@ -877,7 +876,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) backup.destroy() @@ -914,7 +913,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid backup: The parent backup must be ' 'available for incremental backup.', @@ -934,8 +933,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual("None is not of type 'object'", res_dict['badRequest']['message']) @@ -956,8 +955,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIn("'volume_id' is a required property", res_dict['badRequest']['message']) @@ -978,8 +977,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Volume %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -1000,7 +999,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) self.assertIn("'not a uuid' is not a 'uuid'", res_dict['badRequest']['message']) @@ -1022,8 +1021,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) @mock.patch('cinder.db.service_get_all') @@ -1049,7 +1048,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual('available', volume.status) @mock.patch('cinder.db.service_get_all') @@ -1078,7 +1077,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid backup: No backups available to do ' 'an incremental backup.', @@ -1105,7 +1104,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) volume.destroy() @@ -1135,7 +1134,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['backup']) volume.destroy() @@ -1274,7 +1273,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) backup.refresh() - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(fields.BackupStatus.DELETING, backup.status) @@ -1302,7 +1301,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) delta.refresh() - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(fields.BackupStatus.DELETING, delta.status) @@ -1327,7 +1326,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) backup.refresh() - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(fields.BackupStatus.DELETING, backup.status) @@ -1342,8 +1341,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Backup %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -1359,8 +1358,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Backup status must be ' 'available or error', @@ -1390,8 +1389,8 @@ 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(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Incremental backups ' 'exist for this backup.', @@ -1416,7 +1415,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) - self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) backup.destroy() @@ -1439,7 +1438,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(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) @mock.patch('cinder.backup.api.API._get_available_backup_service_host') def test_restore_backup_volume_id_specified_json( @@ -1463,7 +1462,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.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']) @@ -1483,8 +1482,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual("None is not of type 'object'", res_dict['badRequest']['message']) @@ -1508,8 +1507,8 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIn("Additional properties are not allowed ", @@ -1547,7 +1546,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(backup.id, res_dict['restore']['backup_id']) @mock.patch('cinder.db.service_get_all') @@ -1590,7 +1589,7 @@ class BackupsAPITestCase(test.TestCase): body['restore']['name'], description) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(backup.id, res_dict['restore']['backup_id']) @mock.patch('cinder.backup.api.API._get_available_backup_service_host') @@ -1612,7 +1611,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.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, @@ -1640,7 +1639,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(backup.id, res_dict['restore']['backup_id']) @mock.patch('cinder.backup.api.API.restore') @@ -1666,8 +1665,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid input received: Invalid input', res_dict['badRequest']['message']) @@ -1688,8 +1687,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid volume: Volume to be restored to must ' 'be available', @@ -1714,8 +1713,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Backup status must be available', res_dict['badRequest']['message']) @@ -1737,8 +1736,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Backup %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -1760,8 +1759,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Volume %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -1795,8 +1794,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) - self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + self.assertEqual(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, res.status_int) + self.assertEqual(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, res_dict['overLimit']['code']) self.assertEqual('Requested volume or snapshot exceeds allowed ' 'gigabytes quota. Requested 2G, quota is 3G and ' @@ -1826,8 +1825,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, res.status_int) - self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, + self.assertEqual(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, res.status_int) + self.assertEqual(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, res_dict['overLimit']['code']) self.assertEqual("Maximum number of volumes allowed (1) exceeded for" " quota 'volumes'.", res_dict['overLimit']['message']) @@ -1851,8 +1850,8 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid volume: volume size %d is too ' 'small to restore backup of size %d.' @@ -1883,7 +1882,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.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']) @@ -1914,7 +1913,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.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']) @@ -1938,7 +1937,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) # request is not authorized - self.assertEqual(http_client.FORBIDDEN, res.status_int) + self.assertEqual(HTTPStatus.FORBIDDEN, res.status_int) @mock.patch('cinder.backup.api.API._get_available_backup_service_host') @mock.patch('cinder.backup.rpcapi.BackupAPI.export_record') @@ -1964,7 +1963,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(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(backup_service, res_dict['backup-record']['backup_service']) self.assertEqual(backup_url, @@ -1983,8 +1982,8 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Backup %s could not be found.' % backup_id, res_dict['itemNotFound']['message']) @@ -2002,8 +2001,8 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Backup status must be available ' 'and not restoring.', @@ -2031,8 +2030,8 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid backup: %s' % msg, res_dict['badRequest']['message']) @@ -2052,7 +2051,7 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_context)) # request is not authorized - self.assertEqual(http_client.FORBIDDEN, res.status_int) + self.assertEqual(HTTPStatus.FORBIDDEN, res.status_int) @mock.patch.object(quota.QUOTAS, 'commit') @mock.patch.object(quota.QUOTAS, 'rollback') @@ -2090,7 +2089,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) # verify that request is successful - self.assertEqual(http_client.CREATED, res.status_int) + self.assertEqual(HTTPStatus.CREATED, res.status_int) self.assertIn('id', res_dict['backup']) self.assertEqual(fake.BACKUP_ID, res_dict['backup']['id']) @@ -2147,7 +2146,7 @@ class BackupsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) # verify that request is successful - self.assertEqual(http_client.CREATED, res.status_int) + self.assertEqual(HTTPStatus.CREATED, res.status_int) self.assertIn('id', res_dict['backup']) self.assertEqual(fake.BACKUP_ID, res_dict['backup']['id']) @@ -2181,8 +2180,8 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.SERVICE_UNAVAILABLE, res.status_int) - self.assertEqual(http_client.SERVICE_UNAVAILABLE, + self.assertEqual(HTTPStatus.SERVICE_UNAVAILABLE, res.status_int) + self.assertEqual(HTTPStatus.SERVICE_UNAVAILABLE, res_dict['serviceUnavailable']['code']) self.assertEqual('Service %s could not be found.' % backup_service, @@ -2205,8 +2204,8 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual("Invalid input received: Can't parse backup record.", res_dict['badRequest']['message']) @@ -2237,8 +2236,8 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid backup: Backup already exists in database.', res_dict['badRequest']['message']) @@ -2277,8 +2276,8 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.SERVICE_UNAVAILABLE, res.status_int) - self.assertEqual(http_client.SERVICE_UNAVAILABLE, + self.assertEqual(HTTPStatus.SERVICE_UNAVAILABLE, res.status_int) + self.assertEqual(HTTPStatus.SERVICE_UNAVAILABLE, res_dict['serviceUnavailable']['code']) self.assertEqual('Service %s could not be found.' % backup_service, res_dict['serviceUnavailable']['message']) @@ -2300,21 +2299,14 @@ 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(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) - if six.PY3: - self.assertEqual( - "Invalid input for field/attribute backup-record. " - "Value: {'backup_url': 'fake'}. 'backup_service' " - "is a required property", - res_dict['badRequest']['message']) - else: - self.assertEqual( - "Invalid input for field/attribute backup-record. " - "Value: {u'backup_url': u'fake'}. 'backup_service' " - "is a required property", - res_dict['badRequest']['message']) + self.assertEqual( + "Invalid input for field/attribute backup-record. " + "Value: {'backup_url': 'fake'}. 'backup_service' " + "is a required property", + res_dict['badRequest']['message']) # test with no backup_url req = webob.Request.blank('/v2/%s/backups/import_record' % @@ -2326,21 +2318,14 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) - if six.PY3: - self.assertEqual( - "Invalid input for field/attribute backup-record. " - "Value: {'backup_service': 'fake'}. 'backup_url' " - "is a required property", - res_dict['badRequest']['message']) - else: - self.assertEqual( - "Invalid input for field/attribute backup-record. " - "Value: {u'backup_service': u'fake'}. 'backup_url' " - "is a required property", - res_dict['badRequest']['message']) + self.assertEqual( + "Invalid input for field/attribute backup-record. " + "Value: {'backup_service': 'fake'}. 'backup_url' " + "is a required property", + res_dict['badRequest']['message']) # test with no backup_url and backup_url req = webob.Request.blank('/v2/%s/backups/import_record' % @@ -2352,8 +2337,8 @@ class BackupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app(fake_auth_context=ctx)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual( "Invalid input for field/attribute backup-record. " @@ -2373,8 +2358,8 @@ 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(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual("None is not of type 'object'", res_dict['badRequest']['message']) @@ -2417,7 +2402,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.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']) @@ -2430,7 +2415,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.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']) @@ -2443,7 +2428,7 @@ class BackupsAPITestCase(test.TestCase): fake_auth_context=self.user_context)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.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 11049dd..8f23038 100644 --- a/cinder/tests/unit/api/contrib/test_cgsnapshots.py +++ b/cinder/tests/unit/api/contrib/test_cgsnapshots.py @@ -15,10 +15,10 @@ """Tests for cgsnapshot code.""" +from http import HTTPStatus from unittest import mock from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder import context @@ -73,7 +73,7 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual('this is a test group snapshot', res_dict['cgsnapshot']['description']) @@ -95,8 +95,8 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('GroupSnapshot %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -130,7 +130,7 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(cgsnapshot3.id, res_dict['cgsnapshots'][0]['id']) self.assertEqual('test_group_snapshot', @@ -180,7 +180,7 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual('this is a test group snapshot', res_dict['cgsnapshots'][0]['description']) self.assertEqual('test_group_snapshot', @@ -241,7 +241,7 @@ class CgsnapshotsAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['cgsnapshot']) self.assertTrue(mock_validate.called) @@ -278,8 +278,8 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual( "Invalid volume: The snapshot cannot be created when the volume " @@ -302,8 +302,8 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual("Missing required element 'cgsnapshot' in " "request body.", @@ -335,8 +335,8 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid GroupSnapshot: invalid group_snapshot', res_dict['badRequest']['message']) @@ -371,8 +371,8 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('GroupSnapshot invalid_id could not be found.', res_dict['itemNotFound']['message']) @@ -401,8 +401,8 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -436,7 +436,7 @@ class CgsnapshotsAPITestCase(test.TestCase): cgsnapshot = objects.GroupSnapshot.get_by_id(self.context, cgsnapshot.id) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual('deleting', cgsnapshot.status) cgsnapshot.destroy() @@ -471,7 +471,7 @@ class CgsnapshotsAPITestCase(test.TestCase): cgsnapshot = objects.GroupSnapshot.get_by_id(self.context, cgsnapshot.id) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) self.assertEqual('available', cgsnapshot.status) cgsnapshot.destroy() @@ -488,8 +488,8 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('GroupSnapshot %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -519,8 +519,8 @@ class CgsnapshotsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) diff --git a/cinder/tests/unit/api/contrib/test_consistencygroups.py b/cinder/tests/unit/api/contrib/test_consistencygroups.py index b1af4d3..760ee11 100644 --- a/cinder/tests/unit/api/contrib/test_consistencygroups.py +++ b/cinder/tests/unit/api/contrib/test_consistencygroups.py @@ -15,11 +15,11 @@ """Tests for consistency group code.""" +from http import HTTPStatus from unittest import mock import ddt from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder import context @@ -100,7 +100,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup.destroy() - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual('az1', res_dict['consistencygroup']['availability_zone']) self.assertEqual('this is a test consistency group', @@ -121,8 +121,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Group %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -138,7 +138,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual('az1', res_dict['consistencygroup']['availability_zone']) self.assertEqual('this is a test consistency group', @@ -167,7 +167,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(consistencygroup3.id, res_dict['consistencygroups'][0]['id']) self.assertEqual('test_consistencygroup', @@ -200,7 +200,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(1, len(res_dict['consistencygroups'])) self.assertEqual(consistencygroup3.id, res_dict['consistencygroups'][0]['id']) @@ -229,7 +229,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(2, len(res_dict['consistencygroups'])) self.assertEqual(consistencygroup2.id, res_dict['consistencygroups'][0]['id']) @@ -251,7 +251,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) @ddt.data(False, True) def test_list_consistencygroups_with_limit_and_offset(self, is_detail): @@ -269,7 +269,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(2, len(res_dict['consistencygroups'])) self.assertEqual(consistencygroup2.id, res_dict['consistencygroups'][0]['id']) @@ -300,7 +300,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(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(1, len(res_dict['consistencygroups'])) self.assertEqual(consistencygroup3.id, res_dict['consistencygroups'][0]['id']) @@ -352,7 +352,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup3.id] expect_result.sort() - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(3, len(res_dict['consistencygroups'])) self.assertEqual(expect_result[0], res_dict['consistencygroups'][0]['id']) @@ -392,7 +392,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup2.destroy() consistencygroup3.destroy() - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual('az1', res_dict['consistencygroups'][0]['availability_zone']) self.assertEqual('this is a test consistency group', @@ -451,7 +451,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['consistencygroup']) self.assertTrue(mock_validate.called) @@ -471,8 +471,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual("Missing required element 'consistencygroup' in " "request body.", @@ -490,7 +490,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) consistencygroup.destroy() @@ -512,7 +512,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) consistencygroup.destroy() @@ -531,7 +531,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(fields.ConsistencyGroupStatus.DELETING, consistencygroup.status) @@ -547,8 +547,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Group %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -573,7 +573,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) def test_delete_consistencygroup_no_host(self): @@ -588,7 +588,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(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) cg = objects.Group.get_by_id( context.get_admin_context(read_deleted='yes'), @@ -643,7 +643,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_delete_consistencygroup_with_invalid_force_value_in_body(self): consistencygroup = self._create_consistencygroup( @@ -657,7 +657,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_delete_consistencygroup_with_empty_force_value_in_body(self): consistencygroup = self._create_consistencygroup( @@ -671,7 +671,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def _assert_deleting_result_400(self, cg_id, force=False): req = webob.Request.blank('/v2/%s/consistencygroups/%s/delete' % @@ -681,10 +681,10 @@ class ConsistencyGroupsAPITestCase(test.TestCase): body = {"consistencygroup": {"force": force}} req.body = jsonutils.dump_as_bytes(body) res = req.get_response(fakes.wsgi_app()) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -740,7 +740,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) consistencygroup.destroy() @@ -761,7 +761,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual('deleting', consistencygroup.status) consistencygroup.destroy() @@ -778,8 +778,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -860,7 +860,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertTrue(mock_validate.called) self.assertEqual(fields.ConsistencyGroupStatus.UPDATING, consistencygroup.status) @@ -905,7 +905,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) self.assertEqual(fields.ConsistencyGroupStatus.AVAILABLE, consistencygroup.status) @@ -950,7 +950,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) self.assertEqual(fields.ConsistencyGroupStatus.AVAILABLE, consistencygroup.status) @@ -974,8 +974,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -998,8 +998,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1022,8 +1022,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) consistencygroup.destroy() @@ -1051,8 +1051,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1080,8 +1080,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1108,8 +1108,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1139,8 +1139,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1184,7 +1184,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['consistencygroup']) self.assertEqual(test_cg_name, res_dict['consistencygroup']['name']) self.assertTrue(mock_validate.called) @@ -1226,7 +1226,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['consistencygroup']) self.assertEqual(test_cg_name, res_dict['consistencygroup']['name']) @@ -1272,8 +1272,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1296,8 +1296,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) # Missing 'consistencygroup-from-src' in the body. self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1316,8 +1316,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1351,8 +1351,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) msg = _('Invalid Group: No valid host to create group') self.assertIn(msg, res_dict['badRequest']['message']) @@ -1390,8 +1390,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1421,8 +1421,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) @@ -1454,8 +1454,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertIsNotNone(res_dict['itemNotFound']['message']) @@ -1481,8 +1481,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertIsNotNone(res_dict['itemNotFound']['message']) @@ -1522,8 +1522,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) msg = _("Create volume failed.") self.assertEqual(msg, res_dict['badRequest']['message']) @@ -1563,8 +1563,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertIsNotNone(res_dict['badRequest']['message']) 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 5f00eb9..f7e7311 100644 --- a/cinder/tests/unit/api/contrib/test_extended_snapshot_attributes.py +++ b/cinder/tests/unit/api/contrib/test_extended_snapshot_attributes.py @@ -13,10 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder import context @@ -101,7 +101,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase): url = '/v2/%s/snapshots/%s' % (fake.PROJECT_ID, UUID1) res = self._make_request(url) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertSnapshotAttributes(self._get_snapshot(res.body), project_id=fake.PROJECT_ID, progress='0%') @@ -115,7 +115,7 @@ class ExtendedSnapshotAttributesTest(test.TestCase): res = self._make_request(url) mock_authorize.return_value = False - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.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 49a5001..83fe2b5 100644 --- a/cinder/tests/unit/api/contrib/test_qos_specs_manage.py +++ b/cinder/tests/unit/api/contrib/test_qos_specs_manage.py @@ -14,10 +14,10 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock import ddt -from six.moves import http_client import webob from cinder.api.contrib import qos_specs_manage @@ -627,7 +627,7 @@ class QoSSpecManageApiTest(test.TestCase): use_admin_context=True) res = self.controller.associate(req, fake.QOS_SPEC_ID) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) @mock.patch('cinder.volume.qos_specs.get_qos_specs', side_effect=return_qos_specs_get_qos_specs) @@ -684,7 +684,7 @@ class QoSSpecManageApiTest(test.TestCase): fake.PROJECT_ID, fake.QOS_SPEC_ID, fake.VOLUME_TYPE_ID), use_admin_context=True) res = self.controller.disassociate(req, fake.QOS_SPEC_ID) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) @mock.patch('cinder.volume.qos_specs.get_qos_specs', side_effect=return_qos_specs_get_qos_specs) @@ -741,7 +741,7 @@ class QoSSpecManageApiTest(test.TestCase): '/v2/%s/qos-specs/%s/disassociate_all' % ( fake.PROJECT_ID, fake.QOS_SPEC_ID), use_admin_context=True) res = self.controller.disassociate_all(req, fake.QOS_SPEC_ID) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.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 16435f7..b0be6a8 100644 --- a/cinder/tests/unit/api/contrib/test_scheduler_hints.py +++ b/cinder/tests/unit/api/contrib/test_scheduler_hints.py @@ -14,10 +14,10 @@ # under the License. import datetime +from http import HTTPStatus import ddt from oslo_serialization import jsonutils -from six.moves import http_client import cinder from cinder.api.openstack import wsgi @@ -58,7 +58,7 @@ class SchedulerHintsTestCase(test.TestCase): def test_create_server_without_hints(self): - @wsgi.response(http_client.ACCEPTED) + @wsgi.response(HTTPStatus.ACCEPTED) def fake_create(*args, **kwargs): self.assertNotIn('scheduler_hints', kwargs['body']) return self.fake_instance @@ -74,11 +74,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(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_create_server_with_hints(self): - @wsgi.response(http_client.ACCEPTED) + @wsgi.response(HTTPStatus.ACCEPTED) def fake_create(*args, **kwargs): self.assertIn('scheduler_hints', kwargs['body']) self.assertEqual({"a": "b"}, kwargs['body']['scheduler_hints']) @@ -97,7 +97,7 @@ class SchedulerHintsTestCase(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_create_server_bad_hints(self): req = fakes.HTTPRequest.blank('/v2/%s/volumes' % fake.PROJECT_ID) @@ -111,7 +111,7 @@ class SchedulerHintsTestCase(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) @ddt.data({'local_to_instance': UUID}, {'local_to_instance': None}, @@ -131,7 +131,7 @@ class SchedulerHintsTestCase(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) @ddt.data({'local_to_instance': 'local_to_instance'}, {'different_host': 'different_host'}, @@ -152,4 +152,4 @@ class SchedulerHintsTestCase(test.TestCase): req.body = jsonutils.dump_as_bytes(body) res = req.get_response(self.app) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.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 6b19b7d..7b91a5c 100644 --- a/cinder/tests/unit/api/contrib/test_services.py +++ b/cinder/tests/unit/api/contrib/test_services.py @@ -14,12 +14,12 @@ # under the License. import datetime +from http import HTTPStatus from unittest import mock import ddt import iso8601 from oslo_config import cfg -from six.moves import http_client from cinder.api.contrib import services from cinder.api import extensions @@ -734,7 +734,7 @@ class ServicesTest(test.TestCase): 'fake_host', None, 'fake_backend') - self.assertEqual(http_client.ACCEPTED, res.status_code) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_code) @ddt.data(('failover_host', {'host': 'fake_host', 'backend_id': 'fake_backend'}), diff --git a/cinder/tests/unit/api/contrib/test_snapshot_actions.py b/cinder/tests/unit/api/contrib/test_snapshot_actions.py index b770978..e2d0428 100644 --- a/cinder/tests/unit/api/contrib/test_snapshot_actions.py +++ b/cinder/tests/unit/api/contrib/test_snapshot_actions.py @@ -12,11 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock import ddt from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder.api.contrib import snapshot_actions @@ -66,7 +66,7 @@ class SnapshotActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) @mock.patch('cinder.db.sqlalchemy.api._snapshot_get', side_effect=fake_snapshot_get) @@ -81,7 +81,7 @@ class SnapshotActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_update_snapshot_status_without_status(self): self.mock_object(db, 'snapshot_get', fake_snapshot_get) @@ -94,7 +94,7 @@ class SnapshotActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) @mock.patch('cinder.db.snapshot_update', autospec=True) @mock.patch('cinder.db.sqlalchemy.api._snapshot_get', @@ -112,7 +112,7 @@ class SnapshotActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) @ddt.data(({'os-update_snapshot_status': {'status': fields.SnapshotStatus.AVAILABLE, diff --git a/cinder/tests/unit/api/contrib/test_snapshot_manage.py b/cinder/tests/unit/api/contrib/test_snapshot_manage.py index 75a59e6..a270e95 100644 --- a/cinder/tests/unit/api/contrib/test_snapshot_manage.py +++ b/cinder/tests/unit/api/contrib/test_snapshot_manage.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock +from urllib.parse import urlencode 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 from cinder.common import constants @@ -130,7 +130,7 @@ class SnapshotManageTest(test.TestCase): 'ref': {'fake_key': 'fake_ref'}}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int, res) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int, res) # Check the db.service_get was called with correct arguments. mock_db.assert_called_once_with( @@ -166,7 +166,7 @@ class SnapshotManageTest(test.TestCase): 'metadata': None}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) args = mock_create_snapshot.call_args[0] # 5th argument of args is metadata. self.assertIsNone(args[5]) @@ -187,7 +187,7 @@ class SnapshotManageTest(test.TestCase): 'ref': "string"}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int, res) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int, res) # Check the volume_rpcapi.manage_existing_snapshot was called with # correct arguments. @@ -209,7 +209,7 @@ class SnapshotManageTest(test.TestCase): body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': { 'fake_key': 'fake_ref'}}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) mock_create_snapshot.assert_not_called() @@ -228,7 +228,7 @@ class SnapshotManageTest(test.TestCase): body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': {'fake_key': 'fake_ref'}}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) mock_create_snapshot.assert_not_called() @@ -239,25 +239,25 @@ 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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_manage_snapshot_error_volume_id(self): """Test correct failure when volume id is invalid format.""" body = {'snapshot': {'volume_id': 'error_volume_id', 'ref': {}}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) self.assertIn("'error_volume_id' is not a 'uuid'", jsonutils.loads(res.body)['badRequest']['message']) @@ -285,10 +285,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(http_client.FORBIDDEN, res.status_int) + self.assertEqual(HTTPStatus.FORBIDDEN, res.status_int) self.assertEqual(False, mock_api_manageable.called) res = self._get_resp_get('fakehost', True, False, admin=False) - self.assertEqual(http_client.FORBIDDEN, res.status_int) + self.assertEqual(HTTPStatus.FORBIDDEN, res.status_int) self.assertEqual(False, mock_api_manageable.called) @mock.patch('cinder.volume.api.API.get_manageable_snapshots', @@ -304,7 +304,7 @@ class SnapshotManageTest(test.TestCase): {'reference': {'source-name': 'mysnap'}, 'size': 5, 'safe_to_manage': True, 'source_reference': {'source-name': 'myvol'}}]} - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.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, @@ -317,7 +317,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) self.assertTrue(mock_api_manageable.called) @mock.patch('cinder.volume.api.API.get_manageable_snapshots', @@ -336,7 +336,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(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.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', @@ -348,7 +348,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) self.assertTrue(mock_api_manageable.called) @mock.patch('cinder.objects.service.Service.is_up', return_value=True) @@ -357,7 +357,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(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) mock_is_up.assert_not_called() @@ -368,7 +368,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(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) self.assertTrue(mock_is_up.called) @@ -388,5 +388,5 @@ class SnapshotManageTest(test.TestCase): 'description': None}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int, res) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int, res) self.assertIn('snapshot', jsonutils.loads(res.body)) diff --git a/cinder/tests/unit/api/contrib/test_snapshot_unmanage.py b/cinder/tests/unit/api/contrib/test_snapshot_unmanage.py index c564454..55ac209 100644 --- a/cinder/tests/unit/api/contrib/test_snapshot_unmanage.py +++ b/cinder/tests/unit/api/contrib/test_snapshot_unmanage.py @@ -12,10 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder import context @@ -100,9 +100,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(http_client.ACCEPTED, res.status_int, res) + self.assertEqual(HTTPStatus.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(http_client.NOT_FOUND, res.status_int, res) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int, res) diff --git a/cinder/tests/unit/api/contrib/test_types_manage.py b/cinder/tests/unit/api/contrib/test_types_manage.py index 4b3b5ef..e9fe619 100644 --- a/cinder/tests/unit/api/contrib/test_types_manage.py +++ b/cinder/tests/unit/api/contrib/test_types_manage.py @@ -17,7 +17,6 @@ from unittest import mock import ddt from oslo_utils import strutils -import six import webob from cinder.api.contrib import types_manage @@ -43,24 +42,24 @@ def fake_volume_type(id): "key4": "value4", "key5": "value5"} return dict(id=id, - name='vol_type_%s' % six.text_type(id), - description='vol_type_desc_%s' % six.text_type(id), + name='vol_type_%s' % id, + description='vol_type_desc_%s' % id, extra_specs=specs) def fake_volume_type_updated(id, is_public=True): return dict(id=id, - name='vol_type_%s_%s' % (six.text_type(id), six.text_type(id)), + name='vol_type_%s_%s' % (id, id), is_public=is_public, description='vol_type_desc_%s_%s' % ( - six.text_type(id), six.text_type(id))) + id, id)) def fake_volume_type_updated_desc_only(id): return dict(id=id, - name='vol_type_%s' % six.text_type(id), + name='vol_type_%s' % id, description='vol_type_desc_%s_%s' % ( - six.text_type(id), six.text_type(id))) + id, id)) def return_volume_types_get_volume_type(context, id): @@ -99,14 +98,14 @@ def return_volume_types_create_duplicate_type(context, def fake_volume_type_updated_name_only(id): return dict(id=id, - name='vol_type_%s_%s' % (six.text_type(id), six.text_type(id)), - description='vol_type_desc_%s' % six.text_type(id)) + name='vol_type_%s_%s' % (id, id), + description='vol_type_desc_%s' % id) def fake_volume_type_updated_name_after_delete(id): return dict(id=id, - name='vol_type_%s' % six.text_type(id), - description='vol_type_desc_%s' % six.text_type(id)) + name='vol_type_%s' % id, + description='vol_type_desc_%s' % id) def return_volume_types_get_volume_type_updated(id, is_public=True): diff --git a/cinder/tests/unit/api/contrib/test_volume_actions.py b/cinder/tests/unit/api/contrib/test_volume_actions.py index 45e5811..bdff30d 100644 --- a/cinder/tests/unit/api/contrib/test_volume_actions.py +++ b/cinder/tests/unit/api/contrib/test_volume_actions.py @@ -13,13 +13,13 @@ # under the License. import datetime +from http import HTTPStatus from unittest import mock import ddt 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 @@ -95,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(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_initialize_connection(self): with mock.patch.object(volume_api.API, @@ -111,7 +111,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) def test_initialize_connection_without_connector(self): with mock.patch.object(volume_api.API, @@ -126,7 +126,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) @mock.patch('cinder.volume.rpcapi.VolumeAPI.initialize_connection') def test_initialize_connection_without_initiator(self, @@ -141,7 +141,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_initialize_connection_exception(self): with mock.patch.object(volume_api.API, @@ -158,7 +158,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.INTERNAL_SERVER_ERROR, + self.assertEqual(HTTPStatus.INTERNAL_SERVER_ERROR, res.status_int) def test_terminate_connection(self): @@ -174,7 +174,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_terminate_connection_without_connector(self): with mock.patch.object(volume_api.API, @@ -189,7 +189,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_terminate_connection_with_exception(self): with mock.patch.object(volume_api.API, @@ -205,7 +205,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.INTERNAL_SERVER_ERROR, + self.assertEqual(HTTPStatus.INTERNAL_SERVER_ERROR, res.status_int) def test_attach_to_instance(self): @@ -220,7 +220,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) body = {'os-attach': {'instance_uuid': fake.INSTANCE_ID, 'host_name': 'fake_host', @@ -232,7 +232,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(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_attach_to_host(self): # using 'read-write' mode attach volume by default @@ -246,7 +246,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_volume_attach_to_instance_raises_remote_error(self): volume_remote_error = \ @@ -295,7 +295,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_detach_null_attachment_id(self): body = {'os-detach': {'attachment_id': None}} @@ -307,7 +307,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_volume_detach_raises_remote_error(self): volume_remote_error = \ @@ -352,7 +352,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) # Invalid request to attach volume with an invalid mode body = {'os-attach': {'instance_uuid': 'fake', @@ -365,7 +365,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) body = {'os-attach': {'host_name': 'fake_host', 'mountpoint': '/dev/vdc', 'mode': 'ww'}} @@ -376,7 +376,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_attach_to_instance_no_mountpoint(self): # The mountpoint parameter is required. If not provided the @@ -408,7 +408,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_roll_detaching(self): def fake_roll_detaching(*args, **kwargs): @@ -425,7 +425,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_extend_volume(self): def fake_extend_volume(*args, **kwargs): @@ -442,7 +442,7 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.context)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_extend_volume_invalid_status(self): def fake_extend_volume(*args, **kwargs): @@ -459,13 +459,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) - @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.data((True, HTTPStatus.ACCEPTED), (False, HTTPStatus.ACCEPTED), + ('1', HTTPStatus.ACCEPTED), ('0', HTTPStatus.ACCEPTED), + ('true', HTTPStatus.ACCEPTED), ('false', HTTPStatus.ACCEPTED), + ('tt', HTTPStatus.BAD_REQUEST), (11, HTTPStatus.BAD_REQUEST), + (None, HTTPStatus.BAD_REQUEST)) @ddt.unpack def test_update_readonly_flag(self, readonly, return_code): def fake_update_readonly_flag(*args, **kwargs): @@ -485,11 +485,11 @@ class VolumeActionsTest(test.TestCase): fake_auth_context=self.context)) self.assertEqual(return_code, res.status_int) - @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.data((True, HTTPStatus.OK), (False, HTTPStatus.OK), + ('1', HTTPStatus.OK), ('0', HTTPStatus.OK), + ('true', HTTPStatus.OK), ('false', HTTPStatus.OK), + ('tt', HTTPStatus.BAD_REQUEST), (11, HTTPStatus.BAD_REQUEST), + (None, HTTPStatus.BAD_REQUEST)) @ddt.unpack def test_set_bootable(self, bootable, return_code): body = {"os-set_bootable": {"bootable": bootable}} @@ -548,7 +548,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_retype_volume_bad_policy(self): # Request with invalid migration policy should fail @@ -562,7 +562,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_retype_volume_bad_status(self): # Should fail if volume does not have proper status @@ -575,7 +575,7 @@ class VolumeRetypeActionsTest(test.TestCase): volume_type_id=vol_type_old.id, testcase_instance=self) - self._retype_volume_exec(http_client.BAD_REQUEST, vol_type_new.id, + self._retype_volume_exec(HTTPStatus.BAD_REQUEST, vol_type_new.id, vol.id) def test_retype_type_no_exist(self): @@ -586,7 +586,7 @@ class VolumeRetypeActionsTest(test.TestCase): status='available', volume_type_id=vol_type_old.id, testcase_instance=self) - self._retype_volume_exec(http_client.NOT_FOUND, 'fake_vol_type', + self._retype_volume_exec(HTTPStatus.NOT_FOUND, 'fake_vol_type', vol.id) def test_retype_same_type(self): @@ -597,7 +597,7 @@ class VolumeRetypeActionsTest(test.TestCase): status='available', volume_type_id=vol_type_old.id, testcase_instance=self) - self._retype_volume_exec(http_client.BAD_REQUEST, vol_type_old.id, + self._retype_volume_exec(HTTPStatus.BAD_REQUEST, vol_type_old.id, vol.id) def test_retype_over_quota(self): @@ -613,32 +613,32 @@ class VolumeRetypeActionsTest(test.TestCase): usages={'gigabytes': {'reserved': 5, 'in_use': 15}}) self.retype_mocks['reserve'].side_effect = exc - self._retype_volume_exec(http_client.REQUEST_ENTITY_TOO_LARGE, + self._retype_volume_exec(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, vol_type_new.id, vol.id) - @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, + @ddt.data(('in-use', 'front-end', HTTPStatus.BAD_REQUEST), + ('in-use', 'back-end', HTTPStatus.ACCEPTED), + ('available', 'front-end', HTTPStatus.ACCEPTED), + ('available', 'back-end', HTTPStatus.ACCEPTED), + ('in-use', 'front-end', HTTPStatus.ACCEPTED, True), + ('in-use', 'back-end', HTTPStatus.ACCEPTED, True), + ('available', 'front-end', HTTPStatus.ACCEPTED, True), + ('available', 'back-end', HTTPStatus.ACCEPTED, True), + ('in-use', 'front-end', HTTPStatus.BAD_REQUEST, False, False), + ('in-use', 'back-end', HTTPStatus.ACCEPTED, False, False), + ('in-use', '', HTTPStatus.ACCEPTED, True, False), + ('available', 'front-end', HTTPStatus.ACCEPTED, False, False), + ('available', 'back-end', HTTPStatus.ACCEPTED, False, False), + ('available', '', HTTPStatus.ACCEPTED, True, False), + ('in-use', 'front-end', HTTPStatus.BAD_REQUEST, False, False, False), - ('in-use', '', http_client.ACCEPTED, True, False, False), - ('in-use', 'back-end', http_client.ACCEPTED, False, + ('in-use', '', HTTPStatus.ACCEPTED, True, False, False), + ('in-use', 'back-end', HTTPStatus.ACCEPTED, False, False, False), - ('available', 'front-end', http_client.ACCEPTED, False, + ('available', 'front-end', HTTPStatus.ACCEPTED, False, False, False), - ('in-use', '', http_client.ACCEPTED, True, False, False), - ('in-use', 'back-end', http_client.ACCEPTED, False, + ('in-use', '', HTTPStatus.ACCEPTED, True, False, False), + ('in-use', 'back-end', HTTPStatus.ACCEPTED, False, False, False)) @ddt.unpack def test_retype_volume_qos(self, vol_status, consumer_pass, @@ -722,11 +722,11 @@ class VolumeRetypeActionsTest(test.TestCase): self._retype_volume_exec(expected_status, vol_type_new, vol.id) - @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.data(('available', HTTPStatus.ACCEPTED, False, False, False), + ('available', HTTPStatus.ACCEPTED, False, False), + ('available', HTTPStatus.ACCEPTED, True, False, False), + ('available', HTTPStatus.ACCEPTED, True, False), + ('available', HTTPStatus.ACCEPTED)) @ddt.unpack def test_retype_volume_encryption(self, vol_status, expected_status, has_type=True, @@ -1096,7 +1096,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_volume_upload_image_without_type(self): id = fake.VOLUME2_ID @@ -1111,7 +1111,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(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.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 65fb816..4a36446 100644 --- a/cinder/tests/unit/api/contrib/test_volume_encryption_metadata.py +++ b/cinder/tests/unit/api/contrib/test_volume_encryption_metadata.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus + from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder.api.contrib import volume_encryption_metadata @@ -83,7 +84,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(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) res_dict = jsonutils.loads(res.body) expected = { @@ -99,10 +100,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(http_client.BAD_REQUEST, res.status_code) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_code) res_dict = jsonutils.loads(res.body) - expected = {'badRequest': {'code': http_client.BAD_REQUEST, + expected = {'badRequest': {'code': HTTPStatus.BAD_REQUEST, 'message': 'Malformed request url'}} self.assertEqual(expected, res_dict) @@ -111,10 +112,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(http_client.NOT_FOUND, res.status_code) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_code) res_dict = jsonutils.loads(res.body) - expected = {'itemNotFound': {'code': http_client.NOT_FOUND, + expected = {'itemNotFound': {'code': HTTPStatus.NOT_FOUND, 'message': 'Volume %s could not be found.' % bad_volume_id}} self.assertEqual(expected, res_dict) @@ -124,7 +125,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(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) self.assertEqual(fake.ENCRYPTION_KEY_ID, res.body.decode()) @@ -133,7 +134,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(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) self.assertEqual(b'front-end', res.body) @@ -142,7 +143,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(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) self.assertEqual(b'nova.volume.encryptors.base.VolumeEncryptor', res.body) @@ -153,10 +154,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(http_client.BAD_REQUEST, res.status_code) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_code) res_dict = jsonutils.loads(res.body) - expected = {'badRequest': {'code': http_client.BAD_REQUEST, + expected = {'badRequest': {'code': HTTPStatus.BAD_REQUEST, 'message': 'Malformed request url'}} self.assertEqual(expected, res_dict) @@ -166,10 +167,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(http_client.NOT_FOUND, res.status_code) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_code) res_dict = jsonutils.loads(res.body) - expected = {'itemNotFound': {'code': http_client.NOT_FOUND, + expected = {'itemNotFound': {'code': HTTPStatus.NOT_FOUND, 'message': 'Volume %s could not be found.' % bad_volume_id}} self.assertEqual(expected, res_dict) @@ -182,7 +183,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(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) self.assertEqual(fake.ENCRYPTION_KEY_ID, res.body.decode()) @@ -197,7 +198,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(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) self.assertEqual(0, len(res.body)) def test_index_volume_not_encrypted_type(self): @@ -211,7 +212,7 @@ class VolumeEncryptionMetadataTest(test.TestCase): fake.PROJECT_ID, volume_id)) res = req.get_response(fakes.wsgi_app(fake_auth_context=self.ctxt)) - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) res_dict = jsonutils.loads(res.body) expected = { diff --git a/cinder/tests/unit/api/contrib/test_volume_image_metadata.py b/cinder/tests/unit/api/contrib/test_volume_image_metadata.py index 3ee9560..fc0d7e1 100644 --- a/cinder/tests/unit/api/contrib/test_volume_image_metadata.py +++ b/cinder/tests/unit/api/contrib/test_volume_image_metadata.py @@ -12,13 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock import uuid from oslo_policy import policy as oslo_policy from oslo_serialization import jsonutils from oslo_utils import timeutils -from six.moves import http_client import webob from cinder.api.contrib import volume_image_metadata @@ -165,14 +165,14 @@ class VolumeImageMetadataTest(test.TestCase): self._create_volume_and_glance_metadata() res = self._make_request('/v2/%s/volumes/%s' % ( fake.PROJECT_ID, self.UUID)) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(fake_image_metadata, self._get_image_metadata(res.body)) def test_list_detail_volumes(self): self._create_volume_and_glance_metadata() res = self._make_request('/v2/%s/volumes/detail' % fake.PROJECT_ID) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(fake_image_metadata, self._get_image_metadata_list(res.body)[0]) @@ -186,7 +186,7 @@ class VolumeImageMetadataTest(test.TestCase): fake_volume_get_all_empty) res = self._make_request('/v2/%s/volumes/detail' % fake.PROJECT_ID) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertFalse(fake_dont_call_this.called) def test_list_detail_volumes_with_limit(self): @@ -201,7 +201,7 @@ class VolumeImageMetadataTest(test.TestCase): 'key2', 'value2') res = self._make_request('/v2/%s/volumes/detail?limit=1' % fake.PROJECT_ID) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual({'key1': 'value1', 'key2': 'value2'}, self._get_image_metadata_list(res.body)[0]) @@ -222,7 +222,7 @@ class VolumeImageMetadataTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(fake_image_metadata, jsonutils.loads(res.body)["metadata"]) @@ -278,7 +278,7 @@ class VolumeImageMetadataTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(fake_image_metadata, jsonutils.loads(res.body)["metadata"]) @@ -364,7 +364,7 @@ class VolumeImageMetadataTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) @mock.patch('cinder.objects.Volume.get_by_id') def test_delete_image_metadata_policy_not_authorized(self, fake_get): @@ -444,6 +444,6 @@ class VolumeImageMetadataTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(fake_image_metadata, jsonutils.loads(res.body)["metadata"]) diff --git a/cinder/tests/unit/api/contrib/test_volume_manage.py b/cinder/tests/unit/api/contrib/test_volume_manage.py index 47de0c5..b57d385 100644 --- a/cinder/tests/unit/api/contrib/test_volume_manage.py +++ b/cinder/tests/unit/api/contrib/test_volume_manage.py @@ -13,14 +13,14 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock +from urllib.parse import urlencode import ddt 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 from cinder.api.contrib import volume_manage @@ -220,7 +220,7 @@ class VolumeManageTest(test.TestCase): 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) # Check that the manage API was called with the correct arguments. self.assertEqual(1, mock_api_manage.call_count) @@ -238,7 +238,7 @@ class VolumeManageTest(test.TestCase): 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def _get_resp_create(self, body, version=mv.BASE_VERSION): url = '/v3/%s/os-volume-manage' % fake.PROJECT_ID @@ -278,7 +278,7 @@ class VolumeManageTest(test.TestCase): """Test correct failure when host is not specified.""" body = {'volume': {'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) @mock.patch('cinder.objects.Service.get_by_args') def test_manage_volume_service_not_found_on_host(self, mock_service): @@ -289,13 +289,13 @@ class VolumeManageTest(test.TestCase): service_id='cinder-volume', host='host_ok') res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_manage_volume_missing_ref(self): """Test correct failure when the ref is not specified.""" body = {'volume': {'host': 'host_ok'}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_manage_volume_with_invalid_bootable(self): """Test correct failure when invalid bool value is specified.""" @@ -303,7 +303,7 @@ class VolumeManageTest(test.TestCase): 'ref': 'fake_ref', 'bootable': 'InvalidBool'}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) @mock.patch('cinder.objects.service.Service.is_up', return_value=True, new_callable=mock.PropertyMock) @@ -311,7 +311,7 @@ class VolumeManageTest(test.TestCase): """Test manage volume failure due to disabled service.""" body = {'volume': {'host': 'host_disabled', 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) mock_is_up.assert_not_called() @@ -322,7 +322,7 @@ class VolumeManageTest(test.TestCase): """Test manage volume failure due to down service.""" body = {'volume': {'host': 'host_ok', 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) self.assertTrue(mock_is_up.called) @@ -339,7 +339,7 @@ class VolumeManageTest(test.TestCase): 'volume_type': fake.VOLUME_TYPE_ID, 'bootable': True}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) @mock.patch('cinder.volume.api.API.manage_existing', api_manage) def test_manage_volume_volume_type_by_name(self): @@ -352,7 +352,7 @@ class VolumeManageTest(test.TestCase): 'ref': 'fake_ref', 'volume_type': 'good_fakevt'}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) def test_manage_volume_bad_volume_type_by_uuid(self): """Test failure on nonexistent volume type specified by ID.""" @@ -360,7 +360,7 @@ class VolumeManageTest(test.TestCase): 'ref': 'fake_ref', 'volume_type': fake.WILL_NOT_BE_FOUND_ID}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_manage_volume_bad_volume_type_by_name(self): """Test failure on nonexistent volume type specified by name.""" @@ -368,7 +368,7 @@ class VolumeManageTest(test.TestCase): 'ref': 'fake_ref', 'volume_type': 'bad_fakevt'}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def _get_resp_get(self, host, detailed, paging, admin=True): """Helper to execute a GET os-volume-manage API call.""" @@ -394,10 +394,10 @@ class VolumeManageTest(test.TestCase): wraps=api_get_manageable_volumes) def test_get_manageable_volumes_non_admin(self, mock_api_manageable): res = self._get_resp_get('fakehost', False, False, admin=False) - self.assertEqual(http_client.FORBIDDEN, res.status_int) + self.assertEqual(HTTPStatus.FORBIDDEN, res.status_int) mock_api_manageable.assert_not_called() res = self._get_resp_get('fakehost', True, False, admin=False) - self.assertEqual(http_client.FORBIDDEN, res.status_int) + self.assertEqual(HTTPStatus.FORBIDDEN, res.status_int) mock_api_manageable.assert_not_called() @mock.patch('cinder.volume.api.API.get_manageable_volumes', @@ -411,7 +411,7 @@ class VolumeManageTest(test.TestCase): 'size': 4, 'safe_to_manage': False}, {'reference': {'source-name': 'myvol'}, 'size': 5, 'safe_to_manage': True}]} - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(exp, jsonutils.loads(res.body)) mock_api_manageable.assert_called_once_with( self._admin_ctxt, 'fakehost', None, limit=10, marker='1234', @@ -438,7 +438,7 @@ class VolumeManageTest(test.TestCase): {'reference': {'source-name': 'myvol'}, 'cinder_id': None, 'size': 5, 'reason_not_safe': None, 'safe_to_manage': True, 'extra_info': 'qos_setting:low'}]} - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(exp, jsonutils.loads(res.body)) mock_api_manageable.assert_called_once_with( self._admin_ctxt, 'fakehost', None, limit=CONF.osapi_max_limit, @@ -464,13 +464,13 @@ class VolumeManageTest(test.TestCase): 'ref': 'fake_ref', "metadata": value}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) @mock.patch('cinder.objects.service.Service.is_up', return_value=True, new_callable=mock.PropertyMock) def test_get_manageable_volumes_disabled(self, mock_is_up): res = self._get_resp_get('host_disabled', False, True) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) mock_is_up.assert_not_called() @@ -479,7 +479,7 @@ class VolumeManageTest(test.TestCase): new_callable=mock.PropertyMock) def test_get_manageable_volumes_is_down(self, mock_is_up): res = self._get_resp_get('host_ok', False, True) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) self.assertEqual(exception.ServiceUnavailable.message, res.json['badRequest']['message']) self.assertTrue(mock_is_up.called) @@ -490,7 +490,7 @@ class VolumeManageTest(test.TestCase): body = {'volume': {'host': 'host_ok', 'ref': 'fake_ref'}} res = self._get_resp_post_v3(body, mv.ETAGS) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(1, mock_api_manage.call_count) self.assertEqual('creating', jsonutils.loads(res.body)['volume']['status']) @@ -502,7 +502,7 @@ class VolumeManageTest(test.TestCase): body = {'volume': {'host': 'host_ok', 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(1, mock_api_manage.call_count) self.assertEqual('creating', jsonutils.loads(res.body)['volume']['status']) @@ -510,4 +510,4 @@ class VolumeManageTest(test.TestCase): @ddt.data({'volume': {}}, None) def test_manage_volume_with_invalid_body(self, body): res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) diff --git a/cinder/tests/unit/api/contrib/test_volume_transfer.py b/cinder/tests/unit/api/contrib/test_volume_transfer.py index af30dc2..7192018 100644 --- a/cinder/tests/unit/api/contrib/test_volume_transfer.py +++ b/cinder/tests/unit/api/contrib/test_volume_transfer.py @@ -15,10 +15,10 @@ """Tests for volume transfer code.""" +from http import HTTPStatus from unittest import mock from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder.api.contrib import volume_transfer @@ -82,7 +82,7 @@ class VolumeTransferAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual('test_transfer', res_dict['transfer']['name']) self.assertEqual(transfer['id'], res_dict['transfer']['id']) self.assertEqual(volume_id, res_dict['transfer']['volume_id']) @@ -99,8 +99,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Transfer %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -120,7 +120,7 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(4, len(res_dict['transfers'][0])) self.assertEqual(transfer1['id'], res_dict['transfers'][0]['id']) self.assertEqual('test_transfer', res_dict['transfers'][0]['name']) @@ -147,7 +147,7 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(5, len(res_dict['transfers'][0])) self.assertEqual('test_transfer', res_dict['transfers'][0]['name']) @@ -202,7 +202,7 @@ class VolumeTransferAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['transfer']) self.assertIn('auth_key', res_dict['transfer']) self.assertIn('created_at', res_dict['transfer']) @@ -222,8 +222,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) def test_create_transfer_with_body_KeyError(self): @@ -237,8 +237,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) def test_create_transfer_with_invalid_volume_id_value(self): @@ -254,8 +254,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) def test_create_transfer_with_InvalidVolume(self): @@ -271,8 +271,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual('Invalid volume: status must be available', res_dict['badRequest']['message']) @@ -294,7 +294,7 @@ class VolumeTransferAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(body['transfer']['name'].strip(), res_dict['transfer']['name']) db.volume_destroy(context.get_admin_context(), volume_id) @@ -309,7 +309,7 @@ class VolumeTransferAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) # verify transfer has been deleted req = webob.Request.blank('/v2/%s/os-volume-transfer/%s' % ( @@ -320,8 +320,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Transfer %s could not be found.' % transfer['id'], res_dict['itemNotFound']['message']) @@ -339,8 +339,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Transfer %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -363,7 +363,7 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(transfer['id'], res_dict['transfer']['id']) self.assertEqual(volume_id, res_dict['transfer']['volume_id']) # cleanup @@ -383,8 +383,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) db.transfer_destroy(context.get_admin_context(), transfer['id']) @@ -406,8 +406,8 @@ class VolumeTransferAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) db.transfer_destroy(context.get_admin_context(), transfer['id']) @@ -427,8 +427,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) self.assertEqual(res_dict['badRequest']['message'], 'Invalid auth key: Attempt to transfer %s with ' @@ -451,8 +451,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Transfer %s could not be found.' % fake.WILL_NOT_BE_FOUND_ID, @@ -547,9 +547,9 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) db.transfer_destroy(context.get_admin_context(), transfer['id']) db.volume_destroy(context.get_admin_context(), volume_id) diff --git a/cinder/tests/unit/api/contrib/test_volume_type_access.py b/cinder/tests/unit/api/contrib/test_volume_type_access.py index a5f1420..28f5f32 100644 --- a/cinder/tests/unit/api/contrib/test_volume_type_access.py +++ b/cinder/tests/unit/api/contrib/test_volume_type_access.py @@ -12,9 +12,9 @@ # under the License. import datetime +from http import HTTPStatus from unittest import mock -from six.moves import http_client import webob from cinder.api.contrib import volume_type_access as type_access @@ -300,7 +300,7 @@ class VolumeTypeAccessTest(test.TestCase): use_admin_context=True) result = self.type_action_controller._addProjectAccess( req, fake.VOLUME_TYPE4_ID, body=body) - self.assertEqual(http_client.ACCEPTED, result.status_code) + self.assertEqual(HTTPStatus.ACCEPTED, result.status_code) def test_add_project_access_with_no_admin_user(self): req = fakes.HTTPRequest.blank('/v2/%s/types/%s/action' % ( diff --git a/cinder/tests/unit/api/contrib/test_volume_type_encryption.py b/cinder/tests/unit/api/contrib/test_volume_type_encryption.py index c41309f..8a7f35e 100644 --- a/cinder/tests/unit/api/contrib/test_volume_type_encryption.py +++ b/cinder/tests/unit/api/contrib/test_volume_type_encryption.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus + from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder import context @@ -85,7 +86,7 @@ class VolumeTypeEncryptionTest(test.TestCase): self._create_type_and_encryption(volume_type) res = self._get_response(volume_type) - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) res_dict = jsonutils.loads(res.body) expected = fake_volume_type_encryption() @@ -96,12 +97,12 @@ class VolumeTypeEncryptionTest(test.TestCase): def test_index_invalid_type(self): volume_type = self._default_volume_type res = self._get_response(volume_type) - self.assertEqual(http_client.NOT_FOUND, res.status_code) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_code) res_dict = jsonutils.loads(res.body) expected = { 'itemNotFound': { - 'code': http_client.NOT_FOUND, + 'code': HTTPStatus.NOT_FOUND, 'message': ('Volume type %s could not be found.' % volume_type['id']) } @@ -115,7 +116,7 @@ class VolumeTypeEncryptionTest(test.TestCase): url='/v2/%s/types/%s/encryption/key_size') res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) self.assertEqual(256, res_dict['key_size']) db.volume_type_destroy(context.get_admin_context(), volume_type['id']) @@ -128,7 +129,7 @@ class VolumeTypeEncryptionTest(test.TestCase): url='/v2/%s/types/%s/encryption/provider') res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) self.assertEqual('fake_provider', res_dict['provider']) db.volume_type_destroy(context.get_admin_context(), volume_type['id']) @@ -140,10 +141,10 @@ class VolumeTypeEncryptionTest(test.TestCase): url='/v2/%s/types/%s/encryption/fake') res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_code) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_code) expected = { 'itemNotFound': { - 'code': http_client.NOT_FOUND, + 'code': HTTPStatus.NOT_FOUND, 'message': ('Volume type encryption for type %s does not ' 'exist.' % volume_type['id']) } @@ -164,7 +165,7 @@ class VolumeTypeEncryptionTest(test.TestCase): self.assertEqual(0, len(self.notifier.notifications)) res = self._get_response(volume_type) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) # Confirm that volume type has no encryption information # before create. self.assertEqual(b'{}', res.body) @@ -207,11 +208,11 @@ class VolumeTypeEncryptionTest(test.TestCase): res_dict = jsonutils.loads(res.body) self.assertEqual(0, len(self.notifier.notifications)) - self.assertEqual(http_client.NOT_FOUND, res.status_code) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_code) expected = { 'itemNotFound': { - 'code': http_client.NOT_FOUND, + 'code': HTTPStatus.NOT_FOUND, 'message': ('Volume type %s could not be found.' % volume_type['id']) } @@ -232,7 +233,7 @@ class VolumeTypeEncryptionTest(test.TestCase): expected = { 'badRequest': { - 'code': http_client.BAD_REQUEST, + 'code': HTTPStatus.BAD_REQUEST, 'message': ('Volume type encryption for type ' '%s already exists.' % fake.VOLUME_TYPE_ID) } @@ -268,7 +269,7 @@ class VolumeTypeEncryptionTest(test.TestCase): expected = { 'badRequest': { - 'code': http_client.BAD_REQUEST, + 'code': HTTPStatus.BAD_REQUEST, 'message': ('Cannot create encryption specs. ' 'Volume type in use.') } @@ -287,7 +288,7 @@ class VolumeTypeEncryptionTest(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) db.volume_type_destroy(context.get_admin_context(), volume_type['id']) @@ -346,7 +347,7 @@ class VolumeTypeEncryptionTest(test.TestCase): # Test that before create, there's nothing with a get res = self._get_response(volume_type) - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) res_dict = jsonutils.loads(res.body) self.assertEqual({}, res_dict) @@ -364,7 +365,7 @@ class VolumeTypeEncryptionTest(test.TestCase): res = self._get_response(volume_type, req_method='GET', req_headers='application/json', url='/v2/%s/types/%s/encryption') - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) res_dict = jsonutils.loads(res.body) self.assertEqual(volume_type['id'], res_dict['volume_type_id']) @@ -372,12 +373,12 @@ class VolumeTypeEncryptionTest(test.TestCase): res = self._get_response(volume_type, req_method='DELETE', req_headers='application/json', url='/v2/%s/types/%s/encryption/provider') - self.assertEqual(http_client.ACCEPTED, res.status_code) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_code) self.assertEqual(0, len(res.body)) res = self._get_response(volume_type, req_method='GET', req_headers='application/json', url='/v2/%s/types/%s/encryption') - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) res_dict = jsonutils.loads(res.body) self.assertEqual({}, res_dict) @@ -401,7 +402,7 @@ class VolumeTypeEncryptionTest(test.TestCase): res = self._get_response(volume_type, req_method='GET', req_headers='application/json', url='/v2/%s/types/%s/encryption') - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) res_dict = jsonutils.loads(res.body) self.assertEqual(volume_type['id'], res_dict['volume_type_id']) @@ -428,11 +429,11 @@ class VolumeTypeEncryptionTest(test.TestCase): res = self._get_response(volume_type, req_method='DELETE', req_headers='application/json', url='/v2/%s/types/%s/encryption/provider') - self.assertEqual(http_client.BAD_REQUEST, res.status_code) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_code) res_dict = jsonutils.loads(res.body) expected = { 'badRequest': { - 'code': http_client.BAD_REQUEST, + 'code': HTTPStatus.BAD_REQUEST, 'message': 'Cannot delete encryption specs. ' 'Volume type in use.' } @@ -447,12 +448,12 @@ class VolumeTypeEncryptionTest(test.TestCase): res = self._get_response(volume_type, req_method='DELETE', req_headers='application/json', url='/v2/%s/types/%s/encryption/provider') - self.assertEqual(http_client.ACCEPTED, res.status_code) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_code) self.assertEqual(0, len(res.body)) res = self._get_response(volume_type, req_method='GET', req_headers='application/json', url='/v2/%s/types/%s/encryption') - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) res_dict = jsonutils.loads(res.body) self.assertEqual({}, res_dict) @@ -468,12 +469,12 @@ class VolumeTypeEncryptionTest(test.TestCase): res = self._get_response(volume_type, req_method='DELETE', req_headers='application/json', url='/v2/%s/types/%s/encryption/provider') - self.assertEqual(http_client.NOT_FOUND, res.status_code) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_code) expected = { "itemNotFound": { "message": "Volume type encryption for type " "%s does not exist." % fake.VOLUME_TYPE_ID, - "code": http_client.NOT_FOUND + "code": HTTPStatus.NOT_FOUND } } self.assertEqual(expected, jsonutils.loads(res.body)) @@ -529,7 +530,7 @@ class VolumeTypeEncryptionTest(test.TestCase): res_dict = jsonutils.loads(res.body) # Confirm Failure - self.assertEqual(http_client.BAD_REQUEST, + self.assertEqual(HTTPStatus.BAD_REQUEST, res_dict['badRequest']['code']) db.volume_type_destroy(context.get_admin_context(), volume_type['id']) @@ -572,7 +573,7 @@ class VolumeTypeEncryptionTest(test.TestCase): # Get the Encryption res = self._get_response(volume_type) - self.assertEqual(http_client.OK, res.status_code) + self.assertEqual(HTTPStatus.OK, res.status_code) res_dict = jsonutils.loads(res.body) self.assertEqual(volume_type['id'], res_dict['volume_type_id']) @@ -585,11 +586,11 @@ class VolumeTypeEncryptionTest(test.TestCase): req_headers='application/json', url='/v2/%s/types/%s/encryption/' + fake.ENCRYPTION_KEY_ID) - self.assertEqual(http_client.BAD_REQUEST, res.status_code) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_code) res_dict = jsonutils.loads(res.body) expected = { 'badRequest': { - 'code': http_client.BAD_REQUEST, + 'code': HTTPStatus.BAD_REQUEST, 'message': 'Cannot update encryption specs. ' 'Volume type in use.' } diff --git a/cinder/tests/unit/api/contrib/test_volume_unmanage.py b/cinder/tests/unit/api/contrib/test_volume_unmanage.py index e6b52b1..33efc78 100644 --- a/cinder/tests/unit/api/contrib/test_volume_unmanage.py +++ b/cinder/tests/unit/api/contrib/test_volume_unmanage.py @@ -12,10 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder import context @@ -67,7 +67,7 @@ class VolumeUnmanageTest(test.TestCase): """Return success for valid and unattached volume.""" vol = utils.create_volume(self.ctxt) res = self._get_resp(vol.id) - self.assertEqual(http_client.ACCEPTED, res.status_int, res) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int, res) mock_rpcapi.assert_called_once_with(self.ctxt, mock.ANY, True, False) vol = objects.volume.Volume.get_by_id(self.ctxt, vol.id) @@ -77,7 +77,7 @@ class VolumeUnmanageTest(test.TestCase): def test_unmanage_volume_bad_volume_id(self): """Return 404 if the volume does not exist.""" res = self._get_resp(fake.WILL_NOT_BE_FOUND_ID) - self.assertEqual(http_client.NOT_FOUND, res.status_int, res) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int, res) def test_unmanage_volume_attached(self): """Return 400 if the volume exists but is attached.""" @@ -85,7 +85,7 @@ class VolumeUnmanageTest(test.TestCase): self.ctxt, status='in-use', attach_status=fields.VolumeAttachStatus.ATTACHED) res = self._get_resp(vol.id) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) db.volume_destroy(self.ctxt, vol.id) def test_unmanage_volume_with_snapshots(self): @@ -93,7 +93,7 @@ class VolumeUnmanageTest(test.TestCase): vol = utils.create_volume(self.ctxt) snap = utils.create_snapshot(self.ctxt, vol.id) res = self._get_resp(vol.id) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) db.volume_destroy(self.ctxt, vol.id) db.snapshot_destroy(self.ctxt, snap.id) @@ -102,5 +102,5 @@ class VolumeUnmanageTest(test.TestCase): self.ctxt, encryption_key_id='7a98391f-6619-46af-bd00-5862a3f7f1bd') res = self._get_resp(vol.id) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) db.volume_destroy(self.ctxt, vol.id) diff --git a/cinder/tests/unit/api/middleware/test_auth.py b/cinder/tests/unit/api/middleware/test_auth.py index ec8a606..53cdd93 100644 --- a/cinder/tests/unit/api/middleware/test_auth.py +++ b/cinder/tests/unit/api/middleware/test_auth.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus + from oslo_middleware import request_id -from six.moves import http_client import webob import cinder.api.middleware.auth @@ -39,32 +40,32 @@ class TestCinderKeystoneContextMiddleware(test.TestCase): def test_no_user_or_user_id(self): response = self.request.get_response(self.middleware) - self.assertEqual(http_client.UNAUTHORIZED, response.status_int) + self.assertEqual(HTTPStatus.UNAUTHORIZED, response.status_int) def test_user_only(self): self.request.headers['X_USER'] = 'testuser' response = self.request.get_response(self.middleware) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) self.assertEqual('testuser', self.context.user_id) def test_user_id_only(self): self.request.headers['X_USER_ID'] = 'testuserid' response = self.request.get_response(self.middleware) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) self.assertEqual('testuserid', self.context.user_id) def test_user_id_trumps_user(self): self.request.headers['X_USER_ID'] = 'testuserid' self.request.headers['X_USER'] = 'testuser' response = self.request.get_response(self.middleware) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) self.assertEqual('testuserid', self.context.user_id) def test_tenant_id_name(self): self.request.headers['X_USER_ID'] = 'testuserid' self.request.headers['X_TENANT_NAME'] = 'testtenantname' response = self.request.get_response(self.middleware) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) self.assertEqual('testtenantid', self.context.project_id) self.assertEqual('testtenantname', self.context.project_name) diff --git a/cinder/tests/unit/api/middleware/test_faults.py b/cinder/tests/unit/api/middleware/test_faults.py index f5eb64e..527d139 100644 --- a/cinder/tests/unit/api/middleware/test_faults.py +++ b/cinder/tests/unit/api/middleware/test_faults.py @@ -12,9 +12,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + +from http import HTTPStatus + from oslo_i18n import fixture as i18n_fixture from oslo_serialization import jsonutils -from six.moves import http_client import webob.dec from cinder.api.middleware import fault @@ -43,7 +45,7 @@ class TestFaults(test.TestCase): expected = { "badRequest": { "message": "scram", - "code": http_client.BAD_REQUEST, + "code": HTTPStatus.BAD_REQUEST, }, } actual = jsonutils.loads(response.body) @@ -67,7 +69,7 @@ class TestFaults(test.TestCase): expected = { "overLimit": { "message": "sorry", - "code": http_client.REQUEST_ENTITY_TOO_LARGE, + "code": HTTPStatus.REQUEST_ENTITY_TOO_LARGE, "retryAfter": "4", }, } @@ -79,7 +81,7 @@ class TestFaults(test.TestCase): def test_fault_has_status_int(self): """Ensure the status_int is set correctly on faults.""" fault = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='what?')) - self.assertEqual(http_client.BAD_REQUEST, fault.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, fault.status_int) class ExceptionTest(test.TestCase): diff --git a/cinder/tests/unit/api/openstack/test_api_version_request.py b/cinder/tests/unit/api/openstack/test_api_version_request.py index d5b1deb..d1194c4 100644 --- a/cinder/tests/unit/api/openstack/test_api_version_request.py +++ b/cinder/tests/unit/api/openstack/test_api_version_request.py @@ -15,7 +15,6 @@ # under the License. import ddt -import six from cinder.api.openstack import api_version_request from cinder import exception @@ -144,7 +143,7 @@ class APIVersionRequestTests(test.TestCase): def test_str(self, major, minor): request_input = '%s.%s' % (major, minor) request = api_version_request.APIVersionRequest(request_input) - request_string = six.text_type(request) + request_string = str(request) self.assertEqual('API Version Request ' 'Major: %s, Minor: %s' % (major, minor), diff --git a/cinder/tests/unit/api/openstack/test_versioned_method.py b/cinder/tests/unit/api/openstack/test_versioned_method.py index 3ef76f8..2cd3ada 100644 --- a/cinder/tests/unit/api/openstack/test_versioned_method.py +++ b/cinder/tests/unit/api/openstack/test_versioned_method.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - from cinder.api.openstack import versioned_method from cinder.tests.unit import test @@ -24,7 +22,7 @@ class VersionedMethodTestCase(test.TestCase): def test_str(self): args = ('fake_name', 'fake_min', 'fake_max') method = versioned_method.VersionedMethod(*(args + (False, None))) - method_string = six.text_type(method) + method_string = str(method) self.assertEqual('Version Method %s: min: %s, max: %s' % args, method_string) diff --git a/cinder/tests/unit/api/openstack/test_wsgi.py b/cinder/tests/unit/api/openstack/test_wsgi.py index 2f2e94c..c436ac4 100644 --- a/cinder/tests/unit/api/openstack/test_wsgi.py +++ b/cinder/tests/unit/api/openstack/test_wsgi.py @@ -10,12 +10,12 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus import inspect from unittest import mock import ddt from oslo_utils import encodeutils -from six.moves import http_client import webob from cinder.api.openstack import wsgi @@ -234,7 +234,7 @@ class ResourceTest(test.TestCase): app = fakes.TestRouter(Controller()) response = req.get_response(app) self.assertEqual(b'off', response.body) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) def test_resource_not_authorized(self): class Controller(object): @@ -244,7 +244,7 @@ class ResourceTest(test.TestCase): req = webob.Request.blank('/tests') app = fakes.TestRouter(Controller()) response = req.get_response(app) - self.assertEqual(http_client.FORBIDDEN, response.status_int) + self.assertEqual(HTTPStatus.FORBIDDEN, response.status_int) def test_dispatch(self): class Controller(object): @@ -777,21 +777,21 @@ class ResourceTest(test.TestCase): class ResponseObjectTest(test.TestCase): def test_default_code(self): robj = wsgi.ResponseObject({}) - self.assertEqual(http_client.OK, robj.code) + self.assertEqual(HTTPStatus.OK, robj.code) def test_modified_code(self): robj = wsgi.ResponseObject({}) - robj._default_code = http_client.ACCEPTED - self.assertEqual(http_client.ACCEPTED, robj.code) + robj._default_code = HTTPStatus.ACCEPTED + self.assertEqual(HTTPStatus.ACCEPTED, robj.code) def test_override_default_code(self): - robj = wsgi.ResponseObject({}, code=http_client.NOT_FOUND) - self.assertEqual(http_client.NOT_FOUND, robj.code) + robj = wsgi.ResponseObject({}, code=HTTPStatus.NOT_FOUND) + self.assertEqual(HTTPStatus.NOT_FOUND, robj.code) def test_override_modified_code(self): - robj = wsgi.ResponseObject({}, code=http_client.NOT_FOUND) - robj._default_code = http_client.ACCEPTED - self.assertEqual(http_client.NOT_FOUND, robj.code) + robj = wsgi.ResponseObject({}, code=HTTPStatus.NOT_FOUND) + robj._default_code = HTTPStatus.ACCEPTED + self.assertEqual(HTTPStatus.NOT_FOUND, robj.code) def test_set_header(self): robj = wsgi.ResponseObject({}) diff --git a/cinder/tests/unit/api/test_api_validation.py b/cinder/tests/unit/api/test_api_validation.py index 2751006..2d41b1a 100644 --- a/cinder/tests/unit/api/test_api_validation.py +++ b/cinder/tests/unit/api/test_api_validation.py @@ -13,12 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from http import client as http import re import sys import fixtures -import six -from six.moves import http_client as http from cinder.api.openstack import api_version_request as api_version from cinder.api import validation @@ -38,7 +37,7 @@ class ValidationRegex(test.TestCase): def _get_all_chars(): for i in range(0x7F): - yield six.unichr(i) + yield chr(i) self.useFixture(fixtures.MonkeyPatch( 'cinder.api.validation.parameter_types._get_all_chars', diff --git a/cinder/tests/unit/api/test_versions.py b/cinder/tests/unit/api/test_versions.py index 4481de0..7af1c2e 100644 --- a/cinder/tests/unit/api/test_versions.py +++ b/cinder/tests/unit/api/test_versions.py @@ -12,14 +12,13 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus import ddt from oslo_config import cfg from oslo_config import fixture as config_fixture from oslo_serialization import jsonutils from oslo_utils import encodeutils -import six -from six.moves import http_client import webob from cinder.api.openstack import api_version_request @@ -67,7 +66,7 @@ class VersionsControllerTestCase(test.TestCase): req = self.build_request(base_url='http://localhost') response = req.get_response(versions.Versions()) - self.assertEqual(http_client.MULTIPLE_CHOICES, response.status_int) + self.assertEqual(HTTPStatus.MULTIPLE_CHOICES, response.status_int) body = jsonutils.loads(response.body) version_list = body['versions'] @@ -103,7 +102,7 @@ class VersionsControllerTestCase(test.TestCase): req = self.build_request(base_url='http://localhost/v2') response = req.get_response(router.APIRouter()) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) @ddt.data('2.0', '3.0') def test_versions(self, version): @@ -115,7 +114,7 @@ class VersionsControllerTestCase(test.TestCase): req.headers = {VERSION_HEADER_NAME: VOLUME_SERVICE + version} response = req.get_response(router.APIRouter()) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) body = jsonutils.loads(response.body) version_list = body['versions'] @@ -137,7 +136,7 @@ class VersionsControllerTestCase(test.TestCase): response = req.get_response(router.APIRouter()) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) self.check_response(response, api_version_request._MAX_API_VERSION) def test_versions_version_invalid(self): @@ -146,7 +145,7 @@ class VersionsControllerTestCase(test.TestCase): for app in self.wsgi_apps: response = req.get_response(app) - self.assertEqual(http_client.BAD_REQUEST, response.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, response.status_int) @ddt.data('2.0', '3.0') def test_versions_response_fault(self, version): @@ -157,7 +156,7 @@ class VersionsControllerTestCase(test.TestCase): app = wsgi.Fault(webob.exc.HTTPBadRequest(explanation='what?')) response = req.get_response(app) - self.assertEqual(http_client.BAD_REQUEST, response.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, response.status_int) if version == '3.0': self.check_response(response, '3.0') else: @@ -169,8 +168,6 @@ class VersionsControllerTestCase(test.TestCase): return "%s.%s" % (version._ver_major, version._ver_minor) def assert_method_equal(expected, observed): - if six.PY2: - expected = expected.im_func self.assertEqual(expected, observed) class ControllerParent(wsgi.Controller): @@ -243,32 +240,32 @@ class VersionsControllerTestCase(test.TestCase): self.assertEqual('None.None', _get_str_version(new_method.end_version)) @ddt.data( - ('2.0', 'index', http_client.NOT_ACCEPTABLE, 'ControllerParent'), - ('2.0', 'show', http_client.NOT_ACCEPTABLE, 'ControllerParent'), - ('3.0', 'index', http_client.NOT_FOUND, 'ControllerParent'), - ('3.0', 'show', http_client.NOT_FOUND, 'ControllerParent'), + ('2.0', 'index', HTTPStatus.NOT_ACCEPTABLE, 'ControllerParent'), + ('2.0', 'show', HTTPStatus.NOT_ACCEPTABLE, 'ControllerParent'), + ('3.0', 'index', HTTPStatus.NOT_FOUND, 'ControllerParent'), + ('3.0', 'show', HTTPStatus.NOT_FOUND, 'ControllerParent'), ('3.1', 'index', 'parent', 'ControllerParent'), - ('3.1', 'show', http_client.NOT_FOUND, 'ControllerParent'), + ('3.1', 'show', HTTPStatus.NOT_FOUND, 'ControllerParent'), ('3.2', 'index', 'parent', 'ControllerParent'), - ('3.2', 'show', http_client.NOT_FOUND, 'ControllerParent'), + ('3.2', 'show', HTTPStatus.NOT_FOUND, 'ControllerParent'), - ('2.0', 'index', http_client.NOT_ACCEPTABLE, 'Controller'), - ('2.0', 'show', http_client.NOT_ACCEPTABLE, 'Controller'), - ('3.0', 'index', http_client.NOT_FOUND, 'Controller'), - ('3.0', 'show', http_client.NOT_FOUND, 'Controller'), + ('2.0', 'index', HTTPStatus.NOT_ACCEPTABLE, 'Controller'), + ('2.0', 'show', HTTPStatus.NOT_ACCEPTABLE, 'Controller'), + ('3.0', 'index', HTTPStatus.NOT_FOUND, 'Controller'), + ('3.0', 'show', HTTPStatus.NOT_FOUND, 'Controller'), ('3.1', 'index', 'single', 'Controller'), - ('3.1', 'show', http_client.NOT_FOUND, 'Controller'), + ('3.1', 'show', HTTPStatus.NOT_FOUND, 'Controller'), ('3.2', 'index', 'single', 'Controller'), - ('3.2', 'show', http_client.NOT_FOUND, 'Controller'), + ('3.2', 'show', HTTPStatus.NOT_FOUND, 'Controller'), - ('2.0', 'index', http_client.NOT_ACCEPTABLE, 'ControllerChild'), - ('2.0', 'show', http_client.NOT_ACCEPTABLE, 'ControllerChild'), - ('3.0', 'index', http_client.NOT_FOUND, 'ControllerChild'), - ('3.0', 'show', http_client.NOT_FOUND, 'ControllerChild'), + ('2.0', 'index', HTTPStatus.NOT_ACCEPTABLE, 'ControllerChild'), + ('2.0', 'show', HTTPStatus.NOT_ACCEPTABLE, 'ControllerChild'), + ('3.0', 'index', HTTPStatus.NOT_FOUND, 'ControllerChild'), + ('3.0', 'show', HTTPStatus.NOT_FOUND, 'ControllerChild'), ('3.1', 'index', 'parent', 'ControllerChild'), - ('3.1', 'show', http_client.NOT_FOUND, 'ControllerChild'), + ('3.1', 'show', HTTPStatus.NOT_FOUND, 'ControllerChild'), ('3.2', 'index', 'child 3.2', 'ControllerChild'), - ('3.2', 'show', http_client.NOT_FOUND, 'ControllerChild'), + ('3.2', 'show', HTTPStatus.NOT_FOUND, 'ControllerChild'), ('3.3', 'index', 'child 3.3', 'ControllerChild'), ('3.3', 'show', 'show', 'ControllerChild'), ('3.4', 'index', 'child 3.4', 'ControllerChild')) @@ -315,8 +312,8 @@ class VersionsControllerTestCase(test.TestCase): response = req.get_response(app) resp = encodeutils.safe_decode(response.body, incoming='utf-8') - if isinstance(expected, six.string_types): - self.assertEqual(http_client.OK, response.status_int) + if isinstance(expected, str): + self.assertEqual(HTTPStatus.OK, response.status_int) self.assertEqual(expected, resp) else: self.assertEqual(expected, response.status_int) @@ -338,14 +335,14 @@ class VersionsControllerTestCase(test.TestCase): response = req.get_response(app) - self.assertEqual(http_client.NOT_FOUND, response.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, response.status_int) def test_versions_version_not_acceptable(self): req = self.build_request(header_version='4.0') response = req.get_response(router.APIRouter()) - self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_int) + self.assertEqual(HTTPStatus.NOT_ACCEPTABLE, response.status_int) @ddt.data(['volume 3.0, compute 2.22', True], ['volume 3.0, compute 2.22, identity 2.3', True], @@ -364,7 +361,7 @@ class VersionsControllerTestCase(test.TestCase): elif not should_pass: return - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) body = jsonutils.loads(response.body) version_list = body['versions'] @@ -377,7 +374,7 @@ class VersionsControllerTestCase(test.TestCase): self.assertEqual(api_version_request._MIN_API_VERSION, version_list[0].get('min_version')) - @ddt.data(['3.5', http_client.OK], ['3.55', http_client.NOT_FOUND]) + @ddt.data(['3.5', HTTPStatus.OK], ['3.55', HTTPStatus.NOT_FOUND]) @ddt.unpack def test_req_version_matches(self, version, HTTP_ret): version_request = api_version_request.APIVersionRequest(version) @@ -397,9 +394,9 @@ class VersionsControllerTestCase(test.TestCase): response = req.get_response(app) resp = encodeutils.safe_decode(response.body, incoming='utf-8') - if HTTP_ret == http_client.OK: + if HTTP_ret == HTTPStatus.OK: self.assertEqual('off', resp) - elif HTTP_ret == http_client.NOT_FOUND: + elif HTTP_ret == HTTPStatus.NOT_FOUND: self.assertNotEqual('off', resp) self.assertEqual(HTTP_ret, response.status_int) @@ -427,7 +424,7 @@ class VersionsControllerTestCase(test.TestCase): resp = encodeutils.safe_decode(response.body, incoming='utf-8') self.assertEqual(ret_val, resp) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) @ddt.data(['3.5', 'older'], ['3.37', 'newer']) @ddt.unpack @@ -453,7 +450,7 @@ class VersionsControllerTestCase(test.TestCase): resp = encodeutils.safe_decode(response.body, incoming='utf-8') self.assertEqual(ret_val, resp) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) def test_req_version_matches_with_None_None(self): version_request = api_version_request.APIVersionRequest('3.39') @@ -476,4 +473,4 @@ class VersionsControllerTestCase(test.TestCase): resp = encodeutils.safe_decode(response.body, incoming='utf-8') self.assertEqual("Pass", resp) - self.assertEqual(http_client.OK, response.status_int) + self.assertEqual(HTTPStatus.OK, response.status_int) diff --git a/cinder/tests/unit/api/v2/test_limits.py b/cinder/tests/unit/api/v2/test_limits.py index 62b7768..0ee8c87 100644 --- a/cinder/tests/unit/api/v2/test_limits.py +++ b/cinder/tests/unit/api/v2/test_limits.py @@ -17,10 +17,10 @@ Tests dealing with HTTP rate-limiting. """ +from http import client as http_client +import io + from oslo_serialization import jsonutils -import six -from six.moves import http_client -from six.moves import range import webob from cinder.api.v2 import limits @@ -348,7 +348,7 @@ class ParseLimitsTest(BaseLimitTestSuite): '(POST, /bar*, /bar.*, 5, second);' '(Say, /derp*, /derp.*, 1, day)') except ValueError as e: - self.assertFalse(six.text_type(e)) + self.assertFalse(str(e)) # Make sure the number of returned limits are correct self.assertEqual(4, len(test_limits)) @@ -624,9 +624,9 @@ class FakeHttplibSocket(object): def __init__(self, response_string): """Initialize new `FakeHttplibSocket`.""" - if isinstance(response_string, six.text_type): + if isinstance(response_string, str): response_string = response_string.encode('utf-8') - self._buffer = six.BytesIO(response_string) + self._buffer = io.BytesIO(response_string) def makefile(self, mode, *args): """Returns the socket's internal buffer.""" diff --git a/cinder/tests/unit/api/v2/test_snapshot_metadata.py b/cinder/tests/unit/api/v2/test_snapshot_metadata.py index 73575e6..13ed0d0 100644 --- a/cinder/tests/unit/api/v2/test_snapshot_metadata.py +++ b/cinder/tests/unit/api/v2/test_snapshot_metadata.py @@ -13,12 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock import uuid import ddt from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder.api import extensions @@ -243,7 +243,7 @@ class SnapshotMetaDataTest(test.TestCase): req.method = 'DELETE' res = self.controller.delete(req, self.req_id, 'key2') - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) def test_delete_nonexistent_snapshot(self): self.mock_object(cinder.db, 'snapshot_get', diff --git a/cinder/tests/unit/api/v2/test_snapshots.py b/cinder/tests/unit/api/v2/test_snapshots.py index f0541ac..b53ee91 100644 --- a/cinder/tests/unit/api/v2/test_snapshots.py +++ b/cinder/tests/unit/api/v2/test_snapshots.py @@ -14,13 +14,13 @@ # under the License. import datetime +from http import HTTPStatus from unittest import mock +from urllib import parse as urllib import ddt from oslo_config import cfg import pytz -from six.moves import http_client -from six.moves.urllib import parse as urllib import webob from cinder.api import common @@ -411,7 +411,7 @@ class SnapshotApiTest(test.TestCase): snapshot_id = UUID req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % snapshot_id) resp = self.controller.delete(req, snapshot_id) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) def test_snapshot_delete_invalid_id(self): self.mock_object(volume.api.API, "delete_snapshot", diff --git a/cinder/tests/unit/api/v2/test_types.py b/cinder/tests/unit/api/v2/test_types.py index 6049235..9b6fa30 100644 --- a/cinder/tests/unit/api/v2/test_types.py +++ b/cinder/tests/unit/api/v2/test_types.py @@ -16,7 +16,6 @@ from unittest import mock from oslo_utils import timeutils -import six import webob from cinder.api.v2 import types @@ -40,8 +39,8 @@ def fake_volume_type(id): } return dict( id=id, - name='vol_type_%s' % six.text_type(id), - description='vol_type_desc_%s' % six.text_type(id), + name='vol_type_%s' % id, + description='vol_type_desc_%s' % id, extra_specs=specs, ) diff --git a/cinder/tests/unit/api/v2/test_volume_metadata.py b/cinder/tests/unit/api/v2/test_volume_metadata.py index c552135..798e6c4 100644 --- a/cinder/tests/unit/api/v2/test_volume_metadata.py +++ b/cinder/tests/unit/api/v2/test_volume_metadata.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock from oslo_config import cfg from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder.api import extensions @@ -203,7 +203,7 @@ class VolumeMetaDataTest(test.TestCase): 'get') as get_volume: get_volume.return_value = fake_volume res = self.controller.delete(req, self.req_id, 'key2') - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) get_volume.assert_called_once_with(fake_context, self.req_id) @mock.patch.object(db, 'volume_metadata_delete') diff --git a/cinder/tests/unit/api/v2/test_volumes.py b/cinder/tests/unit/api/v2/test_volumes.py index 8086851..a59d7cf 100644 --- a/cinder/tests/unit/api/v2/test_volumes.py +++ b/cinder/tests/unit/api/v2/test_volumes.py @@ -15,17 +15,15 @@ import datetime +from http import HTTPStatus import json from unittest import mock +import urllib import ddt import fixtures import iso8601 from oslo_config import cfg -import six -from six.moves import http_client -from six.moves import range -from six.moves import urllib import webob from cinder.api import common @@ -1446,7 +1444,7 @@ class VolumeApiTest(test.TestCase): def test_volume_delete(self): req = fakes.HTTPRequest.blank('/v2/volumes/%s' % fake.VOLUME_ID) resp = self.controller.delete(req, fake.VOLUME_ID) - self.assertEqual(http_client.ACCEPTED, resp.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, resp.status_int) def test_volume_delete_attached(self): def fake_volume_attached(self, context, volume, @@ -1460,7 +1458,7 @@ class VolumeApiTest(test.TestCase): self.controller.delete, req, 1) expect_msg = "Volume 1 is still attached, detach volume first." - self.assertEqual(expect_msg, six.text_type(exp)) + self.assertEqual(expect_msg, str(exp)) def test_volume_delete_no_volume(self): self.mock_object(volume_api.API, "get", diff --git a/cinder/tests/unit/api/v3/test_consistencygroups.py b/cinder/tests/unit/api/v3/test_consistencygroups.py index ee03acf..383eb00 100644 --- a/cinder/tests/unit/api/v3/test_consistencygroups.py +++ b/cinder/tests/unit/api/v3/test_consistencygroups.py @@ -11,8 +11,9 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus + import ddt -from six.moves import http_client import webob from cinder.api import microversions as mv @@ -86,7 +87,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase): body) consistencygroup = objects.Group.get_by_id( self.ctxt, consistencygroup.id) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) self.assertEqual("", consistencygroup.name) self.assertEqual("", consistencygroup.description) consistencygroup.destroy() diff --git a/cinder/tests/unit/api/v3/test_group_snapshots.py b/cinder/tests/unit/api/v3/test_group_snapshots.py index acafb27..b1b50d8 100644 --- a/cinder/tests/unit/api/v3/test_group_snapshots.py +++ b/cinder/tests/unit/api/v3/test_group_snapshots.py @@ -15,11 +15,11 @@ """Tests for group_snapshot code.""" +from http import HTTPStatus from unittest import mock import ddt from oslo_policy import policy as oslo_policy -from six.moves import http_client import webob from cinder.api import microversions as mv @@ -502,7 +502,7 @@ class GroupSnapshotsAPITestCase(test.TestCase): group_snapshot = objects.GroupSnapshot.get_by_id(self.context, group_snapshot.id) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) self.assertEqual(fields.GroupSnapshotStatus.DELETING, group_snapshot.status) @@ -627,7 +627,7 @@ class GroupSnapshotsAPITestCase(test.TestCase): g_snapshot = objects.GroupSnapshot.get_by_id(self.context, group_snapshot.id) - self.assertEqual(http_client.ACCEPTED, response.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, response.status_int) self.assertEqual(fields.GroupSnapshotStatus.AVAILABLE, g_snapshot.status) group_snapshot.destroy() diff --git a/cinder/tests/unit/api/v3/test_group_types.py b/cinder/tests/unit/api/v3/test_group_types.py index 4c7382d..1041aaf 100644 --- a/cinder/tests/unit/api/v3/test_group_types.py +++ b/cinder/tests/unit/api/v3/test_group_types.py @@ -19,7 +19,6 @@ import uuid import ddt from oslo_utils import strutils from oslo_utils import timeutils -import six import webob from cinder.api import microversions as mv @@ -46,8 +45,8 @@ def stub_group_type(id): } return dict( id=id, - name='group_type_%s' % six.text_type(id), - description='group_type_desc_%s' % six.text_type(id), + name='group_type_%s' % id, + description='group_type_desc_%s' % id, group_specs=specs, ) @@ -345,7 +344,7 @@ class GroupTypesApiTest(test.TestCase): def test_update_group_type_with_valid_is_public_in_string( self, is_public, mock_show, mock_cache_resource, mock_update, mock_get): - type_id = six.text_type(uuid.uuid4()) + type_id = str(uuid.uuid4()) req = fakes.HTTPRequest.blank( '/v3/%s/types/%s' % (fake.PROJECT_ID, type_id), version=mv.GROUP_TYPE) @@ -398,7 +397,7 @@ class GroupTypesApiTest(test.TestCase): self.mock_object(group_types, 'get_group_type', return_group_types_get_group_type) - type_id = six.text_type(uuid.uuid4()) + type_id = str(uuid.uuid4()) req = fakes.HTTPRequest.blank('/v3/%s/group_types/' % fake.PROJECT_ID + type_id, version=mv.GROUP_TYPE) diff --git a/cinder/tests/unit/api/v3/test_groups.py b/cinder/tests/unit/api/v3/test_groups.py index 5ba12b6..3ffb1bc 100644 --- a/cinder/tests/unit/api/v3/test_groups.py +++ b/cinder/tests/unit/api/v3/test_groups.py @@ -15,10 +15,10 @@ """Tests for group code.""" +from http import HTTPStatus from unittest import mock import ddt -from six.moves import http_client import webob from cinder.api import microversions as mv @@ -527,7 +527,7 @@ class GroupsAPITestCase(test.TestCase): group = objects.Group.get_by_id( self.ctxt, self.group1.id) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) self.assertEqual(fields.GroupStatus.DELETING, group.status) def test_delete_group_available_no_delete_volumes(self): @@ -542,7 +542,7 @@ class GroupsAPITestCase(test.TestCase): group = objects.Group.get_by_id( self.ctxt, self.group1.id) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) self.assertEqual(fields.GroupStatus.DELETING, group.status) @@ -577,7 +577,7 @@ class GroupsAPITestCase(test.TestCase): group = objects.Group.get_by_id( self.ctxt, self.group1.id) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) self.assertEqual(fields.GroupStatus.DELETING, group.status) def test_delete_group_no_host(self): @@ -592,7 +592,7 @@ class GroupsAPITestCase(test.TestCase): res_dict = self.controller.delete_group( req, self.group1.id, body=body) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) group = objects.Group.get_by_id( context.get_admin_context(read_deleted='yes'), self.group1.id) @@ -646,7 +646,7 @@ class GroupsAPITestCase(test.TestCase): ex = self.assertRaises(exception.GroupLimitExceeded, self.controller.create, req, body=body) - self.assertEqual(http_client.REQUEST_ENTITY_TOO_LARGE, ex.code) + self.assertEqual(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, ex.code) def test_delete_group_with_invalid_body(self): self.group1.status = fields.GroupStatus.AVAILABLE @@ -701,7 +701,7 @@ class GroupsAPITestCase(test.TestCase): group = objects.Group.get_by_id( self.ctxt, self.group1.id) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) self.assertEqual(fields.GroupStatus.DELETING, group.status) def test_delete_group_delete_volumes(self): @@ -717,7 +717,7 @@ class GroupsAPITestCase(test.TestCase): group = objects.Group.get_by_id( self.ctxt, self.group1.id) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) self.assertEqual(fields.GroupStatus.DELETING, group.status) vol.destroy() @@ -768,7 +768,7 @@ class GroupsAPITestCase(test.TestCase): group = objects.Group.get_by_id( self.ctxt, self.group1.id) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) self.assertEqual(fields.GroupStatus.DELETING, group.status) vol.destroy() @@ -867,7 +867,7 @@ class GroupsAPITestCase(test.TestCase): group = objects.Group.get_by_id( self.ctxt, self.group1.id) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) self.assertEqual(fields.GroupStatus.UPDATING, group.status) @@ -890,7 +890,7 @@ class GroupsAPITestCase(test.TestCase): res_dict = self.controller.update( req, self.group1.id, body=body) - self.assertEqual(http_client.ACCEPTED, res_dict.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res_dict.status_int) group = objects.Group.get_by_id(self.ctxt, self.group1.id) self.assertEqual("new name", group.name) @@ -1081,7 +1081,7 @@ class GroupsAPITestCase(test.TestCase): self.group2.id, body=body) group = objects.Group.get_by_id(self.ctxt, self.group2.id) - self.assertEqual(http_client.ACCEPTED, response.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, response.status_int) self.assertEqual(fields.GroupStatus.AVAILABLE, group.status) @ddt.data(True, False) diff --git a/cinder/tests/unit/api/v3/test_messages.py b/cinder/tests/unit/api/v3/test_messages.py index 64fcdb6..a4de9cd 100644 --- a/cinder/tests/unit/api/v3/test_messages.py +++ b/cinder/tests/unit/api/v3/test_messages.py @@ -10,10 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock import ddt -from six.moves import http_client from cinder.api import extensions from cinder.api import microversions as mv @@ -108,7 +108,7 @@ class MessageApiTest(test.TestCase): resp = self.controller.delete(req, fakes.FAKE_UUID) - self.assertEqual(http_client.NO_CONTENT, resp.status_int) + self.assertEqual(HTTPStatus.NO_CONTENT, resp.status_int) self.assertTrue(message_api.API.delete.called) def test_delete_not_found(self): diff --git a/cinder/tests/unit/api/v3/test_resource_filters.py b/cinder/tests/unit/api/v3/test_resource_filters.py index a677df3..7f8afed 100644 --- a/cinder/tests/unit/api/v3/test_resource_filters.py +++ b/cinder/tests/unit/api/v3/test_resource_filters.py @@ -15,7 +15,6 @@ from unittest import mock import ddt -import six from cinder.api import microversions as mv from cinder.api.v3 import resource_filters as v3_filters @@ -55,9 +54,5 @@ class ResourceFiltersAPITestCase(test.TestCase): with mock.patch('cinder.api.common._FILTERS_COLLECTION', filters): result = self.controller.index(req) - six.assertCountEqual(self, - list(six.viewkeys(result)), - ['resource_filters']) - six.assertCountEqual(self, - expected_filters, - result['resource_filters']) + self.assertCountEqual(list(result), ['resource_filters']) + self.assertCountEqual(expected_filters, result['resource_filters']) diff --git a/cinder/tests/unit/api/v3/test_snapshot_manage.py b/cinder/tests/unit/api/v3/test_snapshot_manage.py index 78f581d..81e8754 100644 --- a/cinder/tests/unit/api/v3/test_snapshot_manage.py +++ b/cinder/tests/unit/api/v3/test_snapshot_manage.py @@ -12,13 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock +from urllib.parse import urlencode import ddt from oslo_config import cfg from oslo_serialization import jsonutils -from six.moves import http_client -from six.moves.urllib.parse import urlencode import webob from cinder.api import microversions as mv @@ -85,13 +85,13 @@ class SnapshotManageTest(test.TestCase): body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': {'fake_ref': "fake_val"}}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int, res) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int, res) def test_manage_snapshot_previous_version(self): body = {'snapshot': {'volume_id': fake.VOLUME_ID, 'ref': 'fake_ref'}} res = self._get_resp_post( body, version=mv.get_prior_version(mv.MANAGE_EXISTING_LIST)) - self.assertEqual(http_client.NOT_FOUND, res.status_int, res) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int, res) def _get_resp_get(self, host, detailed, paging, version=mv.MANAGE_EXISTING_LIST, **kwargs): @@ -124,13 +124,13 @@ class SnapshotManageTest(test.TestCase): than copying all the tests. """ res = self._get_resp_get('fakehost', False, False) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) def test_get_manageable_snapshots_previous_version(self): res = self._get_resp_get( 'fakehost', False, False, version=mv.get_prior_version(mv.MANAGE_EXISTING_LIST)) - self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) @mock.patch('cinder.volume.api.API.get_manageable_snapshots', wraps=test_contrib.api_get_manageable_snapshots) @@ -142,13 +142,13 @@ class SnapshotManageTest(test.TestCase): than copying all the tests. """ res = self._get_resp_get('fakehost', True, True) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) def test_get_manageable_snapshots_detail_previous_version(self): res = self._get_resp_get( 'fakehost', True, True, version=mv.get_prior_version(mv.MANAGE_EXISTING_LIST)) - self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) @ddt.data((True, True, 'detail_list'), (True, False, 'summary_list'), (False, True, 'detail_list'), (False, False, 'summary_list')) @@ -182,7 +182,7 @@ class SnapshotManageTest(test.TestCase): res = self._get_resp_get(host, is_detail, False, version=version, **kwargs) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) get_cctxt_mock.assert_called_once_with(service.service_topic_queue, version=('3.10', '3.0')) get_cctxt_mock.return_value.call.assert_called_once_with( @@ -197,10 +197,10 @@ class SnapshotManageTest(test.TestCase): @ddt.data(mv.MANAGE_EXISTING_LIST, mv.MANAGE_EXISTING_CLUSTER) def test_get_manageable_missing_host(self, version): res = self._get_resp_get(None, True, False, version=version) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_get_manageable_both_host_cluster(self): res = self._get_resp_get('host', True, False, version=mv.MANAGE_EXISTING_CLUSTER, cluster='cluster') - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) diff --git a/cinder/tests/unit/api/v3/test_volume_manage.py b/cinder/tests/unit/api/v3/test_volume_manage.py index aad0e78..cc8a385 100644 --- a/cinder/tests/unit/api/v3/test_volume_manage.py +++ b/cinder/tests/unit/api/v3/test_volume_manage.py @@ -12,13 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock +from urllib.parse import urlencode import ddt from oslo_config import cfg from oslo_serialization import jsonutils -from six.moves import http_client -from six.moves.urllib.parse import urlencode import webob from cinder.api import microversions as mv @@ -84,12 +84,12 @@ class VolumeManageTest(test.TestCase): """ body = {'volume': {'host': 'host_ok', 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_int, res) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int, res) def test_manage_volume_previous_version(self): body = {'volume': {'host': 'host_ok', 'ref': 'fake_ref'}} res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_int, res) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int, res) def _get_resp_get(self, host, detailed, paging, version=mv.MANAGE_EXISTING_LIST, **kwargs): @@ -123,13 +123,13 @@ class VolumeManageTest(test.TestCase): than copying all the tests. """ res = self._get_resp_get('fakehost', False, True) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) def test_get_manageable_volumes_previous_version(self): res = self._get_resp_get( 'fakehost', False, True, version=mv.get_prior_version(mv.MANAGE_EXISTING_LIST)) - self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) @mock.patch('cinder.volume.api.API.get_manageable_volumes', wraps=test_contrib.api_get_manageable_volumes) @@ -141,13 +141,13 @@ class VolumeManageTest(test.TestCase): than copying all the tests. """ res = self._get_resp_get('fakehost', True, False) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) def test_get_manageable_volumes_detail_previous_version(self): res = self._get_resp_get( 'fakehost', True, False, version=mv.get_prior_version(mv.MANAGE_EXISTING_LIST)) - self.assertEqual(http_client.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) @ddt.data((True, True, 'detail_list'), (True, False, 'summary_list'), (False, True, 'detail_list'), (False, False, 'summary_list')) @@ -180,7 +180,7 @@ class VolumeManageTest(test.TestCase): res = self._get_resp_get(host, is_detail, False, version=version, **kwargs) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) get_cctxt_mock.assert_called_once_with(service.service_topic_queue, version=('3.10', '3.0')) get_cctxt_mock.return_value.call.assert_called_once_with( @@ -196,10 +196,10 @@ class VolumeManageTest(test.TestCase): @ddt.data(mv.MANAGE_EXISTING_LIST, mv.MANAGE_EXISTING_CLUSTER) def test_get_manageable_missing_host(self, version): res = self._get_resp_get(None, True, False, version=version) - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) def test_get_manageable_both_host_cluster(self): res = self._get_resp_get('host', True, False, version=mv.MANAGE_EXISTING_CLUSTER, cluster='cluster') - self.assertEqual(http_client.BAD_REQUEST, res.status_int) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_int) diff --git a/cinder/tests/unit/api/v3/test_volume_transfer.py b/cinder/tests/unit/api/v3/test_volume_transfer.py index 0998273..d12d77b 100644 --- a/cinder/tests/unit/api/v3/test_volume_transfer.py +++ b/cinder/tests/unit/api/v3/test_volume_transfer.py @@ -15,11 +15,11 @@ """Tests for volume transfer code.""" +from http import HTTPStatus from unittest import mock import ddt from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder.api.contrib import volume_transfer @@ -107,7 +107,7 @@ class VolumeTransferAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual('test_transfer', res_dict['transfer']['name']) self.assertEqual(transfer['id'], res_dict['transfer']['id']) self.assertEqual(volume_id, res_dict['transfer']['volume_id']) @@ -127,7 +127,7 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(self.SUMMARY_LEN, len(res_dict['transfers'][0])) self.assertEqual(transfer1['id'], res_dict['transfers'][0]['id']) self.assertEqual('test_transfer', res_dict['transfers'][0]['name']) @@ -200,7 +200,7 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(self.DETAIL_LEN, len(res_dict['transfers'][0])) self.assertEqual('test_transfer', res_dict['transfers'][0]['name']) @@ -231,7 +231,7 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.OK, res.status_int) + self.assertEqual(HTTPStatus.OK, res.status_int) self.assertEqual(self.DETAIL_LEN, len(res_dict['transfers'][0])) self.assertEqual('test_transfer', res_dict['transfers'][0]['name']) @@ -262,7 +262,7 @@ class VolumeTransferAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['transfer']) self.assertIn('auth_key', res_dict['transfer']) self.assertIn('created_at', res_dict['transfer']) @@ -287,7 +287,7 @@ class VolumeTransferAPITestCase(test.TestCase): res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['transfer']) self.assertIn('auth_key', res_dict['transfer']) self.assertIn('created_at', res_dict['transfer']) @@ -308,7 +308,7 @@ class VolumeTransferAPITestCase(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.user_ctxt)) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) # verify transfer has been deleted req = webob.Request.blank('/v3/%s/volume-transfers/%s' % ( @@ -319,8 +319,8 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.NOT_FOUND, res.status_int) - self.assertEqual(http_client.NOT_FOUND, + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_int) + self.assertEqual(HTTPStatus.NOT_FOUND, res_dict['itemNotFound']['code']) self.assertEqual('Transfer %s could not be found.' % transfer['id'], res_dict['itemNotFound']['message']) @@ -346,7 +346,7 @@ class VolumeTransferAPITestCase(test.TestCase): fake_auth_context=self.user_ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertEqual(transfer['id'], res_dict['transfer']['id']) self.assertEqual(volume_id, res_dict['transfer']['volume_id']) # cleanup diff --git a/cinder/tests/unit/api/v3/test_volumes.py b/cinder/tests/unit/api/v3/test_volumes.py index dffccdd..06b936a 100644 --- a/cinder/tests/unit/api/v3/test_volumes.py +++ b/cinder/tests/unit/api/v3/test_volumes.py @@ -12,6 +12,7 @@ # under the License. import datetime +from http import HTTPStatus import json from unittest import mock @@ -21,7 +22,6 @@ import iso8601 from oslo_serialization import jsonutils from oslo_utils import strutils from oslo_utils import timeutils -from six.moves import http_client import webob from cinder.api import api_utils @@ -748,7 +748,7 @@ class VolumeApiTest(test.TestCase): res = req.get_response(fakes.wsgi_app( fake_auth_context=self.ctxt)) res_dict = jsonutils.loads(res.body) - self.assertEqual(http_client.ACCEPTED, res.status_int) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_int) self.assertIn('id', res_dict['volume']) @ddt.data('fake_host', '', 1234, ' ') diff --git a/cinder/tests/unit/api/v3/test_workers.py b/cinder/tests/unit/api/v3/test_workers.py index b1f5fa2..dcd343a 100644 --- a/cinder/tests/unit/api/v3/test_workers.py +++ b/cinder/tests/unit/api/v3/test_workers.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from http import HTTPStatus from unittest import mock import ddt from oslo_serialization import jsonutils -from six.moves import http_client import webob from cinder.api import microversions as mv @@ -78,7 +78,7 @@ class WorkersTestCase(test.TestCase): @mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.work_cleanup') def test_cleanup_old_api_version(self, rpc_mock): res = self._get_resp_post({}, mv.get_prior_version(mv.WORKERS_CLEANUP)) - self.assertEqual(http_client.NOT_FOUND, res.status_code) + self.assertEqual(HTTPStatus.NOT_FOUND, res.status_code) rpc_mock.assert_not_called() @mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.work_cleanup') @@ -89,7 +89,7 @@ class WorkersTestCase(test.TestCase): read_deleted='no', overwrite=False) res = self._get_resp_post({}, ctxt=ctxt) - self.assertEqual(http_client.FORBIDDEN, res.status_code) + self.assertEqual(HTTPStatus.FORBIDDEN, res.status_code) rpc_mock.assert_not_called() @ddt.data({'binary': 'nova-scheduler'}, @@ -100,7 +100,7 @@ class WorkersTestCase(test.TestCase): @mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.work_cleanup') def test_cleanup_wrong_param(self, body, rpc_mock): res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_code) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_code) expected = 'Invalid input' self.assertIn(expected, res.json['badRequest']['message']) rpc_mock.assert_not_called() @@ -109,7 +109,7 @@ class WorkersTestCase(test.TestCase): @mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.work_cleanup') def test_cleanup_with_additional_properties(self, body, rpc_mock): res = self._get_resp_post(body) - self.assertEqual(http_client.BAD_REQUEST, res.status_code) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_code) expected = 'Additional properties are not allowed' self.assertIn(expected, res.json['badRequest']['message']) rpc_mock.assert_not_called() @@ -137,7 +137,7 @@ class WorkersTestCase(test.TestCase): return_value=SERVICES) def test_cleanup_params(self, body, rpc_mock): res = self._get_resp_post(body) - self.assertEqual(http_client.ACCEPTED, res.status_code) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_code) rpc_mock.assert_called_once_with(self.context, mock.ANY) cleanup_request = rpc_mock.call_args[0][1] for key, value in body.items(): @@ -153,7 +153,7 @@ class WorkersTestCase(test.TestCase): return_value=SERVICES) def test_cleanup_missing_location_ok(self, rpc_mock, worker_mock): res = self._get_resp_post({'resource_id': fake.VOLUME_ID}) - self.assertEqual(http_client.ACCEPTED, res.status_code) + self.assertEqual(HTTPStatus.ACCEPTED, res.status_code) rpc_mock.assert_called_once_with(self.context, mock.ANY) cleanup_request = rpc_mock.call_args[0][1] self.assertEqual(fake.VOLUME_ID, cleanup_request.resource_id) @@ -164,7 +164,7 @@ class WorkersTestCase(test.TestCase): @mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.work_cleanup') def test_cleanup_missing_location_fail_none(self, rpc_mock): res = self._get_resp_post({'resource_id': fake.VOLUME_ID}) - self.assertEqual(http_client.BAD_REQUEST, res.status_code) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_code) self.assertIn('Invalid input', res.json['badRequest']['message']) rpc_mock.assert_not_called() @@ -172,6 +172,6 @@ class WorkersTestCase(test.TestCase): return_value=[1, 2]) def test_cleanup_missing_location_fail_multiple(self, rpc_mock): res = self._get_resp_post({'resource_id': fake.VOLUME_ID}) - self.assertEqual(http_client.BAD_REQUEST, res.status_code) + self.assertEqual(HTTPStatus.BAD_REQUEST, res.status_code) self.assertIn('Invalid input', res.json['badRequest']['message']) rpc_mock.assert_not_called()