Add members in InstanceGroup object members field
In InstanceGroup object, add_members method doesn't add members into object members field, which causes objects.Quotas.count(server_group_members) won't increase, and instance group quota check invalid. This makes an issue that user could spawn with one call more instances in server group than was allowed in quota_server_group_members is it was below instances quota settting. Co-authored-by: yuntongjin <yuntong.jin@intel.com> Change-Id: Icdd8aef688776f00fef6ede6e1bed01af29f9917 Closes-bug: #1538169
This commit is contained in:
parent
5a02e6ce8c
commit
43826e458e
@ -988,9 +988,12 @@ class API(base.Base):
|
||||
"group")
|
||||
raise exception.QuotaError(msg)
|
||||
|
||||
objects.InstanceGroup.add_members(context,
|
||||
instance_group.uuid,
|
||||
[instance.uuid])
|
||||
members = objects.InstanceGroup.add_members(
|
||||
context, instance_group.uuid, [instance.uuid])
|
||||
# list of members added to servers group in this iteration
|
||||
# is needed to check quota of server group during add next
|
||||
# instance
|
||||
instance_group.members.extend(members)
|
||||
|
||||
# send a state update notification for the initial create to
|
||||
# show it going from non-existent to BUILDING
|
||||
|
@ -7869,7 +7869,8 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
|
||||
self.assertEqual(ref[0]['hostname'], hostname)
|
||||
|
||||
def test_instance_create_adds_to_instance_group(self):
|
||||
@mock.patch('nova.compute.api.API._get_requested_instance_group')
|
||||
def test_instance_create_adds_to_instance_group(self, get_group_mock):
|
||||
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
|
||||
self.fake_show)
|
||||
|
||||
@ -7878,11 +7879,13 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
group.project_id = self.context.project_id
|
||||
group.user_id = self.context.user_id
|
||||
group.create()
|
||||
get_group_mock.return_value = group
|
||||
|
||||
inst_type = flavors.get_default_flavor()
|
||||
(refs, resv_id) = self.compute_api.create(
|
||||
self.context, inst_type, self.fake_image['id'],
|
||||
scheduler_hints={'group': group.uuid})
|
||||
self.assertEqual(len(refs), len(group.members))
|
||||
|
||||
group = objects.InstanceGroup.get_by_uuid(self.context, group.uuid)
|
||||
self.assertIn(refs[0]['uuid'], group.members)
|
||||
|
Loading…
Reference in New Issue
Block a user