Merge "Stop using mox in unit/api/contrib/ tests (1/2)"
This commit is contained in:
commit
fa2ceea516
@ -45,9 +45,9 @@ class ControllerTestCase(cinder.test.TestCase):
|
|||||||
super(ControllerTestCase, self).setUp()
|
super(ControllerTestCase, self).setUp()
|
||||||
self.controller = cinder.api.contrib.availability_zones.Controller()
|
self.controller = cinder.api.contrib.availability_zones.Controller()
|
||||||
self.req = FakeRequest()
|
self.req = FakeRequest()
|
||||||
self.stubs.Set(cinder.volume.api.API,
|
self.mock_object(cinder.volume.api.API,
|
||||||
'list_availability_zones',
|
'list_availability_zones',
|
||||||
list_availability_zones)
|
list_availability_zones)
|
||||||
|
|
||||||
def test_list_hosts(self):
|
def test_list_hosts(self):
|
||||||
"""Verify that the volume hosts are returned."""
|
"""Verify that the volume hosts are returned."""
|
||||||
|
@ -574,13 +574,10 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
|
|||||||
name = 'mycg'
|
name = 'mycg'
|
||||||
description = 'consistency group 1'
|
description = 'consistency group 1'
|
||||||
fake_type = {'id': fake.CONSISTENCY_GROUP_ID, 'name': 'fake_type'}
|
fake_type = {'id': fake.CONSISTENCY_GROUP_ID, 'name': 'fake_type'}
|
||||||
self.stubs.Set(db, 'volume_types_get_by_name_or_id',
|
self.mock_object(db, 'volume_types_get_by_name_or_id',
|
||||||
mock.Mock(return_value=[fake_type]))
|
return_value=[fake_type])
|
||||||
self.stubs.Set(self.cg_api,
|
self.mock_object(self.cg_api, '_cast_create_consistencygroup')
|
||||||
'_cast_create_consistencygroup',
|
self.mock_object(self.cg_api, 'update_quota')
|
||||||
mock.Mock())
|
|
||||||
self.stubs.Set(self.cg_api, 'update_quota',
|
|
||||||
mock.Mock())
|
|
||||||
cg = self.cg_api.create(self.ctxt, name, description,
|
cg = self.cg_api.create(self.ctxt, name, description,
|
||||||
fake_type['name'])
|
fake_type['name'])
|
||||||
self.cg_api.update_quota.assert_called_once_with(
|
self.cg_api.update_quota.assert_called_once_with(
|
||||||
@ -1135,7 +1132,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
|
|||||||
@mock.patch(
|
@mock.patch(
|
||||||
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
|
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
|
||||||
def test_create_consistencygroup_from_src(self, mock_validate):
|
def test_create_consistencygroup_from_src(self, mock_validate):
|
||||||
self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
|
self.mock_object(volume_api.API, "create", stubs.stub_volume_create)
|
||||||
|
|
||||||
consistencygroup = utils.create_consistencygroup(self.ctxt)
|
consistencygroup = utils.create_consistencygroup(self.ctxt)
|
||||||
volume_id = utils.create_volume(
|
volume_id = utils.create_volume(
|
||||||
@ -1210,7 +1207,7 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
|
|||||||
source_cg.destroy()
|
source_cg.destroy()
|
||||||
|
|
||||||
def test_create_consistencygroup_from_src_both_snap_cg(self):
|
def test_create_consistencygroup_from_src_both_snap_cg(self):
|
||||||
self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
|
self.mock_object(volume_api.API, "create", stubs.stub_volume_create)
|
||||||
|
|
||||||
consistencygroup = utils.create_consistencygroup(self.ctxt)
|
consistencygroup = utils.create_consistencygroup(self.ctxt)
|
||||||
volume_id = utils.create_volume(
|
volume_id = utils.create_volume(
|
||||||
|
@ -53,8 +53,8 @@ class SchedulerHintsTestCase(test.TestCase):
|
|||||||
self.assertNotIn('scheduler_hints', kwargs['body'])
|
self.assertNotIn('scheduler_hints', kwargs['body'])
|
||||||
return self.fake_instance
|
return self.fake_instance
|
||||||
|
|
||||||
self.stubs.Set(cinder.api.v2.volumes.VolumeController, 'create',
|
self.mock_object(cinder.api.v2.volumes.VolumeController, 'create',
|
||||||
fake_create)
|
fake_create)
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank('/v2/%s/volumes' % fake.PROJECT_ID)
|
req = fakes.HTTPRequest.blank('/v2/%s/volumes' % fake.PROJECT_ID)
|
||||||
req.method = 'POST'
|
req.method = 'POST'
|
||||||
@ -74,8 +74,8 @@ class SchedulerHintsTestCase(test.TestCase):
|
|||||||
self.assertEqual({"a": "b"}, kwargs['body']['scheduler_hints'])
|
self.assertEqual({"a": "b"}, kwargs['body']['scheduler_hints'])
|
||||||
return self.fake_instance
|
return self.fake_instance
|
||||||
|
|
||||||
self.stubs.Set(cinder.api.v2.volumes.VolumeController, 'create',
|
self.mock_object(cinder.api.v2.volumes.VolumeController, 'create',
|
||||||
fake_create)
|
fake_create)
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank('/v2/%s/volumes' % fake.PROJECT_ID)
|
req = fakes.HTTPRequest.blank('/v2/%s/volumes' % fake.PROJECT_ID)
|
||||||
req.method = 'POST'
|
req.method = 'POST'
|
||||||
|
@ -25,7 +25,7 @@ from cinder.tests.unit.api.v2 import stubs
|
|||||||
from cinder.tests.unit import fake_constants as fake
|
from cinder.tests.unit import fake_constants as fake
|
||||||
|
|
||||||
|
|
||||||
def stub_snapshot_get(context, snapshot_id):
|
def fake_snapshot_get(context, snapshot_id):
|
||||||
snapshot = stubs.stub_snapshot(snapshot_id)
|
snapshot = stubs.stub_snapshot(snapshot_id)
|
||||||
|
|
||||||
if snapshot_id == fake.SNAPSHOT_ID:
|
if snapshot_id == fake.SNAPSHOT_ID:
|
||||||
@ -44,7 +44,7 @@ class SnapshotActionsTest(test.TestCase):
|
|||||||
|
|
||||||
@mock.patch('cinder.db.snapshot_update', autospec=True)
|
@mock.patch('cinder.db.snapshot_update', autospec=True)
|
||||||
@mock.patch('cinder.db.sqlalchemy.api._snapshot_get',
|
@mock.patch('cinder.db.sqlalchemy.api._snapshot_get',
|
||||||
side_effect=stub_snapshot_get)
|
side_effect=fake_snapshot_get)
|
||||||
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
|
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
|
||||||
def test_update_snapshot_status(self, metadata_get, *args):
|
def test_update_snapshot_status(self, metadata_get, *args):
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ class SnapshotActionsTest(test.TestCase):
|
|||||||
self.assertEqual(202, res.status_int)
|
self.assertEqual(202, res.status_int)
|
||||||
|
|
||||||
@mock.patch('cinder.db.sqlalchemy.api._snapshot_get',
|
@mock.patch('cinder.db.sqlalchemy.api._snapshot_get',
|
||||||
side_effect=stub_snapshot_get)
|
side_effect=fake_snapshot_get)
|
||||||
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
|
@mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
|
||||||
def test_update_snapshot_status_invalid_status(self, metadata_get, *args):
|
def test_update_snapshot_status_invalid_status(self, metadata_get, *args):
|
||||||
body = {'os-update_snapshot_status': {'status': 'in-use'}}
|
body = {'os-update_snapshot_status': {'status': 'in-use'}}
|
||||||
@ -76,7 +76,7 @@ class SnapshotActionsTest(test.TestCase):
|
|||||||
self.assertEqual(400, res.status_int)
|
self.assertEqual(400, res.status_int)
|
||||||
|
|
||||||
def test_update_snapshot_status_without_status(self):
|
def test_update_snapshot_status_without_status(self):
|
||||||
self.stubs.Set(db, 'snapshot_get', stub_snapshot_get)
|
self.mock_object(db, 'snapshot_get', fake_snapshot_get)
|
||||||
body = {'os-update_snapshot_status': {}}
|
body = {'os-update_snapshot_status': {}}
|
||||||
req = webob.Request.blank('/v2/%s/snapshots/%s/action' % (
|
req = webob.Request.blank('/v2/%s/snapshots/%s/action' % (
|
||||||
fake.PROJECT_ID, fake.SNAPSHOT_ID))
|
fake.PROJECT_ID, fake.SNAPSHOT_ID))
|
||||||
|
@ -28,26 +28,14 @@ import cinder.wsgi
|
|||||||
|
|
||||||
def return_create_volume_type_extra_specs(context, volume_type_id,
|
def return_create_volume_type_extra_specs(context, volume_type_id,
|
||||||
extra_specs):
|
extra_specs):
|
||||||
return stub_volume_type_extra_specs()
|
return fake_volume_type_extra_specs()
|
||||||
|
|
||||||
|
|
||||||
def return_volume_type_extra_specs(context, volume_type_id):
|
def return_volume_type_extra_specs(context, volume_type_id):
|
||||||
return stub_volume_type_extra_specs()
|
return fake_volume_type_extra_specs()
|
||||||
|
|
||||||
|
|
||||||
def return_empty_volume_type_extra_specs(context, volume_type_id):
|
def fake_volume_type_extra_specs():
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
def delete_volume_type_extra_specs(context, volume_type_id, key):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def delete_volume_type_extra_specs_not_found(context, volume_type_id, key):
|
|
||||||
raise exception.VolumeTypeExtraSpecsNotFound("Not Found")
|
|
||||||
|
|
||||||
|
|
||||||
def stub_volume_type_extra_specs():
|
|
||||||
specs = {"key1": "value1",
|
specs = {"key1": "value1",
|
||||||
"key2": "value2",
|
"key2": "value2",
|
||||||
"key3": "value3",
|
"key3": "value3",
|
||||||
@ -56,16 +44,12 @@ def stub_volume_type_extra_specs():
|
|||||||
return specs
|
return specs
|
||||||
|
|
||||||
|
|
||||||
def volume_type_get(context, id, inactive=False, expected_fields=None):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class VolumeTypesExtraSpecsTest(test.TestCase):
|
class VolumeTypesExtraSpecsTest(test.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(VolumeTypesExtraSpecsTest, self).setUp()
|
super(VolumeTypesExtraSpecsTest, self).setUp()
|
||||||
self.flags(host='fake')
|
self.flags(host='fake')
|
||||||
self.stubs.Set(cinder.db, 'volume_type_get', volume_type_get)
|
self.mock_object(cinder.db, 'volume_type_get')
|
||||||
self.api_path = '/v2/%s/os-volume-types/%s/extra_specs' % (
|
self.api_path = '/v2/%s/os-volume-types/%s/extra_specs' % (
|
||||||
fake.PROJECT_ID, fake.VOLUME_TYPE_ID)
|
fake.PROJECT_ID, fake.VOLUME_TYPE_ID)
|
||||||
self.controller = types_extra_specs.VolumeTypeExtraSpecsController()
|
self.controller = types_extra_specs.VolumeTypeExtraSpecsController()
|
||||||
@ -73,8 +57,8 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
|||||||
"""to reset notifier drivers left over from other api/contrib tests"""
|
"""to reset notifier drivers left over from other api/contrib tests"""
|
||||||
|
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_get',
|
self.mock_object(cinder.db, 'volume_type_extra_specs_get',
|
||||||
return_volume_type_extra_specs)
|
return_volume_type_extra_specs)
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank(self.api_path)
|
req = fakes.HTTPRequest.blank(self.api_path)
|
||||||
res_dict = self.controller.index(req, fake.VOLUME_TYPE_ID)
|
res_dict = self.controller.index(req, fake.VOLUME_TYPE_ID)
|
||||||
@ -82,8 +66,8 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
|||||||
self.assertEqual('value1', res_dict['extra_specs']['key1'])
|
self.assertEqual('value1', res_dict['extra_specs']['key1'])
|
||||||
|
|
||||||
def test_index_no_data(self):
|
def test_index_no_data(self):
|
||||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_get',
|
self.mock_object(cinder.db, 'volume_type_extra_specs_get',
|
||||||
return_empty_volume_type_extra_specs)
|
return_value={})
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank(self.api_path)
|
req = fakes.HTTPRequest.blank(self.api_path)
|
||||||
res_dict = self.controller.index(req, fake.VOLUME_TYPE_ID)
|
res_dict = self.controller.index(req, fake.VOLUME_TYPE_ID)
|
||||||
@ -91,8 +75,8 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
|||||||
self.assertEqual(0, len(res_dict['extra_specs']))
|
self.assertEqual(0, len(res_dict['extra_specs']))
|
||||||
|
|
||||||
def test_show(self):
|
def test_show(self):
|
||||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_get',
|
self.mock_object(cinder.db, 'volume_type_extra_specs_get',
|
||||||
return_volume_type_extra_specs)
|
return_volume_type_extra_specs)
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank(self.api_path + '/key5')
|
req = fakes.HTTPRequest.blank(self.api_path + '/key5')
|
||||||
res_dict = self.controller.show(req, fake.VOLUME_TYPE_ID, 'key5')
|
res_dict = self.controller.show(req, fake.VOLUME_TYPE_ID, 'key5')
|
||||||
@ -100,16 +84,15 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
|||||||
self.assertEqual('value5', res_dict['key5'])
|
self.assertEqual('value5', res_dict['key5'])
|
||||||
|
|
||||||
def test_show_spec_not_found(self):
|
def test_show_spec_not_found(self):
|
||||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_get',
|
self.mock_object(cinder.db, 'volume_type_extra_specs_get',
|
||||||
return_empty_volume_type_extra_specs)
|
return_value={})
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank(self.api_path + '/key6')
|
req = fakes.HTTPRequest.blank(self.api_path + '/key6')
|
||||||
self.assertRaises(exception.VolumeTypeExtraSpecsNotFound,
|
self.assertRaises(exception.VolumeTypeExtraSpecsNotFound,
|
||||||
self.controller.show, req, fake.VOLUME_ID, 'key6')
|
self.controller.show, req, fake.VOLUME_ID, 'key6')
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_delete',
|
self.mock_object(cinder.db, 'volume_type_extra_specs_delete')
|
||||||
delete_volume_type_extra_specs)
|
|
||||||
|
|
||||||
self.assertEqual(0, len(self.notifier.notifications))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
req = fakes.HTTPRequest.blank(self.api_path + '/key5')
|
req = fakes.HTTPRequest.blank(self.api_path + '/key5')
|
||||||
@ -117,8 +100,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
|||||||
self.assertEqual(1, len(self.notifier.notifications))
|
self.assertEqual(1, len(self.notifier.notifications))
|
||||||
|
|
||||||
def test_delete_not_found(self):
|
def test_delete_not_found(self):
|
||||||
self.stubs.Set(cinder.db, 'volume_type_extra_specs_delete',
|
self.mock_object(cinder.db, 'volume_type_extra_specs_delete',
|
||||||
delete_volume_type_extra_specs_not_found)
|
side_effect=exception.VolumeTypeExtraSpecsNotFound(
|
||||||
|
"Not Found"))
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank(self.api_path + '/key6')
|
req = fakes.HTTPRequest.blank(self.api_path + '/key6')
|
||||||
self.assertRaises(exception.VolumeTypeExtraSpecsNotFound,
|
self.assertRaises(exception.VolumeTypeExtraSpecsNotFound,
|
||||||
@ -126,9 +110,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
|||||||
|
|
||||||
@mock.patch('cinder.utils.check_string_length')
|
@mock.patch('cinder.utils.check_string_length')
|
||||||
def test_create(self, mock_check):
|
def test_create(self, mock_check):
|
||||||
self.stubs.Set(cinder.db,
|
self.mock_object(cinder.db,
|
||||||
'volume_type_extra_specs_update_or_create',
|
'volume_type_extra_specs_update_or_create',
|
||||||
return_create_volume_type_extra_specs)
|
return_create_volume_type_extra_specs)
|
||||||
body = {"extra_specs": {"key1": "value1"}}
|
body = {"extra_specs": {"key1": "value1"}}
|
||||||
|
|
||||||
self.assertEqual(0, len(self.notifier.notifications))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
@ -192,9 +176,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
|||||||
|
|
||||||
@mock.patch('cinder.utils.check_string_length')
|
@mock.patch('cinder.utils.check_string_length')
|
||||||
def test_update_item(self, mock_check):
|
def test_update_item(self, mock_check):
|
||||||
self.stubs.Set(cinder.db,
|
self.mock_object(cinder.db,
|
||||||
'volume_type_extra_specs_update_or_create',
|
'volume_type_extra_specs_update_or_create',
|
||||||
return_create_volume_type_extra_specs)
|
return_create_volume_type_extra_specs)
|
||||||
body = {"key1": "value1"}
|
body = {"key1": "value1"}
|
||||||
|
|
||||||
self.assertEqual(0, len(self.notifier.notifications))
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
@ -206,9 +190,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
|||||||
self.assertEqual('value1', res_dict['key1'])
|
self.assertEqual('value1', res_dict['key1'])
|
||||||
|
|
||||||
def test_update_item_too_many_keys(self):
|
def test_update_item_too_many_keys(self):
|
||||||
self.stubs.Set(cinder.db,
|
self.mock_object(cinder.db,
|
||||||
'volume_type_extra_specs_update_or_create',
|
'volume_type_extra_specs_update_or_create',
|
||||||
return_create_volume_type_extra_specs)
|
return_create_volume_type_extra_specs)
|
||||||
body = {"key1": "value1", "key2": "value2"}
|
body = {"key1": "value1", "key2": "value2"}
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank(self.api_path + '/key1')
|
req = fakes.HTTPRequest.blank(self.api_path + '/key1')
|
||||||
@ -216,9 +200,9 @@ class VolumeTypesExtraSpecsTest(test.TestCase):
|
|||||||
req, fake.VOLUME_ID, 'key1', body)
|
req, fake.VOLUME_ID, 'key1', body)
|
||||||
|
|
||||||
def test_update_item_body_uri_mismatch(self):
|
def test_update_item_body_uri_mismatch(self):
|
||||||
self.stubs.Set(cinder.db,
|
self.mock_object(cinder.db,
|
||||||
'volume_type_extra_specs_update_or_create',
|
'volume_type_extra_specs_update_or_create',
|
||||||
return_create_volume_type_extra_specs)
|
return_create_volume_type_extra_specs)
|
||||||
body = {"key1": "value1"}
|
body = {"key1": "value1"}
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank(self.api_path + '/bad')
|
req = fakes.HTTPRequest.blank(self.api_path + '/bad')
|
||||||
|
@ -347,8 +347,8 @@ class VolumeActionsTest(test.TestCase):
|
|||||||
def test_begin_detaching(self):
|
def test_begin_detaching(self):
|
||||||
def fake_begin_detaching(*args, **kwargs):
|
def fake_begin_detaching(*args, **kwargs):
|
||||||
return {}
|
return {}
|
||||||
self.stubs.Set(volume.api.API, 'begin_detaching',
|
self.mock_object(volume.api.API, 'begin_detaching',
|
||||||
fake_begin_detaching)
|
fake_begin_detaching)
|
||||||
|
|
||||||
body = {'os-begin_detaching': {'fake': 'fake'}}
|
body = {'os-begin_detaching': {'fake': 'fake'}}
|
||||||
req = webob.Request.blank('/v2/%s/volumes/%s/action' %
|
req = webob.Request.blank('/v2/%s/volumes/%s/action' %
|
||||||
@ -364,8 +364,8 @@ class VolumeActionsTest(test.TestCase):
|
|||||||
def test_roll_detaching(self):
|
def test_roll_detaching(self):
|
||||||
def fake_roll_detaching(*args, **kwargs):
|
def fake_roll_detaching(*args, **kwargs):
|
||||||
return {}
|
return {}
|
||||||
self.stubs.Set(volume.api.API, 'roll_detaching',
|
self.mock_object(volume.api.API, 'roll_detaching',
|
||||||
fake_roll_detaching)
|
fake_roll_detaching)
|
||||||
|
|
||||||
body = {'os-roll_detaching': {'fake': 'fake'}}
|
body = {'os-roll_detaching': {'fake': 'fake'}}
|
||||||
req = webob.Request.blank('/v2/%s/volumes/%s/action' %
|
req = webob.Request.blank('/v2/%s/volumes/%s/action' %
|
||||||
@ -381,8 +381,8 @@ class VolumeActionsTest(test.TestCase):
|
|||||||
def test_extend_volume(self):
|
def test_extend_volume(self):
|
||||||
def fake_extend_volume(*args, **kwargs):
|
def fake_extend_volume(*args, **kwargs):
|
||||||
return {}
|
return {}
|
||||||
self.stubs.Set(volume.api.API, 'extend',
|
self.mock_object(volume.api.API, 'extend',
|
||||||
fake_extend_volume)
|
fake_extend_volume)
|
||||||
|
|
||||||
body = {'os-extend': {'new_size': 5}}
|
body = {'os-extend': {'new_size': 5}}
|
||||||
req = webob.Request.blank('/v2/%s/volumes/%s/action' %
|
req = webob.Request.blank('/v2/%s/volumes/%s/action' %
|
||||||
@ -399,8 +399,8 @@ class VolumeActionsTest(test.TestCase):
|
|||||||
def fake_extend_volume(*args, **kwargs):
|
def fake_extend_volume(*args, **kwargs):
|
||||||
msg = "Volume status must be available"
|
msg = "Volume status must be available"
|
||||||
raise exception.InvalidVolume(reason=msg)
|
raise exception.InvalidVolume(reason=msg)
|
||||||
self.stubs.Set(volume.api.API, 'extend',
|
self.mock_object(volume.api.API, 'extend',
|
||||||
fake_extend_volume)
|
fake_extend_volume)
|
||||||
|
|
||||||
body = {'os-extend': {'new_size': 5}}
|
body = {'os-extend': {'new_size': 5}}
|
||||||
req = webob.Request.blank('/v2/%s/volumes/%s/action' %
|
req = webob.Request.blank('/v2/%s/volumes/%s/action' %
|
||||||
@ -415,8 +415,8 @@ class VolumeActionsTest(test.TestCase):
|
|||||||
def test_update_readonly_flag(self):
|
def test_update_readonly_flag(self):
|
||||||
def fake_update_readonly_flag(*args, **kwargs):
|
def fake_update_readonly_flag(*args, **kwargs):
|
||||||
return {}
|
return {}
|
||||||
self.stubs.Set(volume.api.API, 'update_readonly_flag',
|
self.mock_object(volume.api.API, 'update_readonly_flag',
|
||||||
fake_update_readonly_flag)
|
fake_update_readonly_flag)
|
||||||
|
|
||||||
def make_update_readonly_flag_test(self, readonly, return_code):
|
def make_update_readonly_flag_test(self, readonly, return_code):
|
||||||
body = {"os-update_readonly_flag": {"readonly": readonly}}
|
body = {"os-update_readonly_flag": {"readonly": readonly}}
|
||||||
@ -751,7 +751,7 @@ class VolumeRetypeActionsTest(test.TestCase):
|
|||||||
self._retype_volume_encryption('available', 202)
|
self._retype_volume_encryption('available', 202)
|
||||||
|
|
||||||
|
|
||||||
def stub_volume_get(self, context, volume_id):
|
def fake_volume_get(self, context, volume_id):
|
||||||
volume = stubs.stub_volume(volume_id)
|
volume = stubs.stub_volume(volume_id)
|
||||||
if volume_id == fake.VOLUME3_ID:
|
if volume_id == fake.VOLUME3_ID:
|
||||||
volume['status'] = 'in-use'
|
volume['status'] = 'in-use'
|
||||||
@ -760,7 +760,7 @@ def stub_volume_get(self, context, volume_id):
|
|||||||
return volume
|
return volume
|
||||||
|
|
||||||
|
|
||||||
def stub_upload_volume_to_image_service(self, context, volume, metadata,
|
def fake_upload_volume_to_image_service(self, context, volume, metadata,
|
||||||
force):
|
force):
|
||||||
ret = {"id": volume['id'],
|
ret = {"id": volume['id'],
|
||||||
"updated_at": datetime.datetime(1, 1, 1, 1, 1, 1),
|
"updated_at": datetime.datetime(1, 1, 1, 1, 1, 1),
|
||||||
@ -779,8 +779,6 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(VolumeImageActionsTest, self).setUp()
|
super(VolumeImageActionsTest, self).setUp()
|
||||||
self.controller = volume_actions.VolumeActionsController()
|
self.controller = volume_actions.VolumeActionsController()
|
||||||
|
|
||||||
self.stubs.Set(volume_api.API, 'get', stub_volume_get)
|
|
||||||
self.context = context.RequestContext(fake.USER_ID, fake.PROJECT_ID,
|
self.context = context.RequestContext(fake.USER_ID, fake.PROJECT_ID,
|
||||||
is_admin=False)
|
is_admin=False)
|
||||||
|
|
||||||
@ -836,11 +834,10 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
def fake_rpc_copy_volume_to_image(self, *args):
|
def fake_rpc_copy_volume_to_image(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@mock.patch.object(volume_api.API, 'get', fake_volume_get)
|
||||||
|
@mock.patch.object(volume_api.API, "copy_volume_to_image",
|
||||||
|
fake_upload_volume_to_image_service)
|
||||||
def test_copy_volume_to_image(self):
|
def test_copy_volume_to_image(self):
|
||||||
self.stubs.Set(volume_api.API,
|
|
||||||
"copy_volume_to_image",
|
|
||||||
stub_upload_volume_to_image_service)
|
|
||||||
|
|
||||||
id = fake.VOLUME_ID
|
id = fake.VOLUME_ID
|
||||||
vol = {"container_format": 'bare',
|
vol = {"container_format": 'bare',
|
||||||
"disk_format": 'raw',
|
"disk_format": 'raw',
|
||||||
@ -865,10 +862,10 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
self.assertDictMatch(expected, res_dict)
|
self.assertDictMatch(expected, res_dict)
|
||||||
|
|
||||||
def test_copy_volume_to_image_volumenotfound(self):
|
def test_copy_volume_to_image_volumenotfound(self):
|
||||||
def stub_volume_get_raise_exc(self, context, volume_id):
|
def fake_volume_get_raise_exc(self, context, volume_id):
|
||||||
raise exception.VolumeNotFound(volume_id=volume_id)
|
raise exception.VolumeNotFound(volume_id=volume_id)
|
||||||
|
|
||||||
self.stubs.Set(volume_api.API, 'get', stub_volume_get_raise_exc)
|
self.mock_object(volume_api.API, 'get', fake_volume_get_raise_exc)
|
||||||
|
|
||||||
id = fake.WILL_NOT_BE_FOUND_ID
|
id = fake.WILL_NOT_BE_FOUND_ID
|
||||||
vol = {"container_format": 'bare',
|
vol = {"container_format": 'bare',
|
||||||
@ -884,14 +881,10 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
id,
|
id,
|
||||||
body)
|
body)
|
||||||
|
|
||||||
def test_copy_volume_to_image_invalidvolume(self):
|
@mock.patch.object(volume_api.API, 'get', fake_volume_get)
|
||||||
def stub_upload_volume_to_image_service_raise(self, context, volume,
|
@mock.patch.object(volume_api.API, 'copy_volume_to_image',
|
||||||
metadata, force):
|
side_effect=exception.InvalidVolume(reason='blah'))
|
||||||
raise exception.InvalidVolume(reason='blah')
|
def test_copy_volume_to_image_invalidvolume(self, mock_copy):
|
||||||
self.stubs.Set(volume_api.API,
|
|
||||||
"copy_volume_to_image",
|
|
||||||
stub_upload_volume_to_image_service_raise)
|
|
||||||
|
|
||||||
id = fake.VOLUME2_ID
|
id = fake.VOLUME2_ID
|
||||||
vol = {"container_format": 'bare',
|
vol = {"container_format": 'bare',
|
||||||
"disk_format": 'raw',
|
"disk_format": 'raw',
|
||||||
@ -906,6 +899,7 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
id,
|
id,
|
||||||
body)
|
body)
|
||||||
|
|
||||||
|
@mock.patch.object(volume_api.API, 'get', fake_volume_get)
|
||||||
def test_copy_volume_to_image_invalid_disk_format(self):
|
def test_copy_volume_to_image_invalid_disk_format(self):
|
||||||
id = fake.IMAGE_ID
|
id = fake.IMAGE_ID
|
||||||
vol = {"container_format": 'bare',
|
vol = {"container_format": 'bare',
|
||||||
@ -921,14 +915,10 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
id,
|
id,
|
||||||
body)
|
body)
|
||||||
|
|
||||||
def test_copy_volume_to_image_valueerror(self):
|
@mock.patch.object(volume_api.API, 'get', fake_volume_get)
|
||||||
def stub_upload_volume_to_image_service_raise(self, context, volume,
|
@mock.patch.object(volume_api.API, 'copy_volume_to_image',
|
||||||
metadata, force):
|
side_effect=ValueError)
|
||||||
raise ValueError
|
def test_copy_volume_to_image_valueerror(self, mock_copy):
|
||||||
self.stubs.Set(volume_api.API,
|
|
||||||
"copy_volume_to_image",
|
|
||||||
stub_upload_volume_to_image_service_raise)
|
|
||||||
|
|
||||||
id = fake.VOLUME2_ID
|
id = fake.VOLUME2_ID
|
||||||
vol = {"container_format": 'bare',
|
vol = {"container_format": 'bare',
|
||||||
"disk_format": 'raw',
|
"disk_format": 'raw',
|
||||||
@ -943,14 +933,10 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
id,
|
id,
|
||||||
body)
|
body)
|
||||||
|
|
||||||
def test_copy_volume_to_image_remoteerror(self):
|
@mock.patch.object(volume_api.API, 'get', fake_volume_get)
|
||||||
def stub_upload_volume_to_image_service_raise(self, context, volume,
|
@mock.patch.object(volume_api.API, 'copy_volume_to_image',
|
||||||
metadata, force):
|
side_effect=messaging.RemoteError)
|
||||||
raise messaging.RemoteError
|
def test_copy_volume_to_image_remoteerror(self, mock_copy):
|
||||||
self.stubs.Set(volume_api.API,
|
|
||||||
"copy_volume_to_image",
|
|
||||||
stub_upload_volume_to_image_service_raise)
|
|
||||||
|
|
||||||
id = fake.VOLUME2_ID
|
id = fake.VOLUME2_ID
|
||||||
vol = {"container_format": 'bare',
|
vol = {"container_format": 'bare',
|
||||||
"disk_format": 'raw',
|
"disk_format": 'raw',
|
||||||
@ -991,6 +977,7 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
res = req.get_response(fakes.wsgi_app(fake_auth_context=self.context))
|
res = req.get_response(fakes.wsgi_app(fake_auth_context=self.context))
|
||||||
self.assertEqual(400, res.status_int)
|
self.assertEqual(400, res.status_int)
|
||||||
|
|
||||||
|
@mock.patch.object(volume_api.API, 'get', fake_volume_get)
|
||||||
def test_extend_volume_valueerror(self):
|
def test_extend_volume_valueerror(self):
|
||||||
id = fake.VOLUME2_ID
|
id = fake.VOLUME2_ID
|
||||||
body = {'os-extend': {'new_size': 'fake'}}
|
body = {'os-extend': {'new_size': 'fake'}}
|
||||||
@ -1019,8 +1006,6 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
|
|
||||||
def _create_volume_with_type(self, status='available',
|
def _create_volume_with_type(self, status='available',
|
||||||
display_description='displaydesc', **kwargs):
|
display_description='displaydesc', **kwargs):
|
||||||
self.stubs.UnsetAll()
|
|
||||||
|
|
||||||
admin_ctxt = context.get_admin_context()
|
admin_ctxt = context.get_admin_context()
|
||||||
vol_type = db.volume_type_create(admin_ctxt, {'name': 'vol_name'})
|
vol_type = db.volume_type_create(admin_ctxt, {'name': 'vol_name'})
|
||||||
self.addCleanup(db.volume_type_destroy, admin_ctxt, vol_type.id)
|
self.addCleanup(db.volume_type_destroy, admin_ctxt, vol_type.id)
|
||||||
@ -1071,6 +1056,7 @@ class VolumeImageActionsTest(test.TestCase):
|
|||||||
self.assertEqual('uploading', vol_db.status)
|
self.assertEqual('uploading', vol_db.status)
|
||||||
self.assertEqual('available', vol_db.previous_status)
|
self.assertEqual('available', vol_db.previous_status)
|
||||||
|
|
||||||
|
@mock.patch.object(volume_api.API, 'get', fake_volume_get)
|
||||||
def test_copy_volume_to_image_public_not_authorized(self):
|
def test_copy_volume_to_image_public_not_authorized(self):
|
||||||
"""Test unauthorized create public image from volume."""
|
"""Test unauthorized create public image from volume."""
|
||||||
id = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
|
id = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user