Adding project id check

Add volume to group only when group's project and volumes's
project are same.

Change-Id: I493067344405a5b4a26a2330f7ea662398e8fd0a
Closes-Bug: 1712588
This commit is contained in:
Abhishek Sharma 2017-09-05 11:20:43 -05:00
parent 9495ef6aa6
commit 055433efdc
2 changed files with 22 additions and 0 deletions

View File

@ -720,6 +720,13 @@ class API(base.Base):
'orig_group': orig_group})
raise exception.InvalidVolume(reason=msg)
if add_vol_ref:
if add_vol_ref.project_id != group.project_id:
msg = (_("Cannot add volume %(volume_id)s to group "
"%(group_id)s as they belong to different "
"projects.") %
{'volume_id': add_vol_ref['id'],
'group_id': group.id})
raise exception.InvalidVolume(reason=msg)
add_vol_type_id = add_vol_ref.get('volume_type_id', None)
if not add_vol_type_id:
msg = (_("Cannot add volume %(volume_id)s to group "

View File

@ -232,6 +232,21 @@ class GroupAPITestCase(test.TestCase):
availability_zone='nova')
mock_policy.assert_called_with(self.ctxt, 'create')
@mock.patch('cinder.objects.Group')
@mock.patch('cinder.db.volume_get')
def test__validate_add_volumes(self, mock_volume_get, mock_group):
grp = utils.create_group(self.ctxt, group_type_id=fake.GROUP_TYPE_ID,
volume_type_ids=[fake.VOLUME_TYPE_ID],
availability_zone='nova', host=None,
name="name", description="description",
status=fields.GroupStatus.CREATING)
mock_group.return_value = grp
fake_volume_obj = fake_volume.fake_volume_obj(self.ctxt)
mock_volume_get.return_value = fake_volume_obj
self.assertRaises(exception.InvalidVolume,
self.group_api._validate_add_volumes, self.ctxt,
[], ['123456789'], grp)
@mock.patch('cinder.volume.rpcapi.VolumeAPI.update_group')
@mock.patch('cinder.db.volume_get_all_by_generic_group')
@mock.patch('cinder.group.api.API._cast_create_group')