'Test that since the request spec object contains an instance group
object, that upon choosing a host in the primary schedule loop,
that we update the request spec\'s instance group information'

@mock.patch('nova.scheduler.filter_scheduler.FilterScheduler._claim_resources')
@mock.patch('nova.scheduler.filter_scheduler.FilterScheduler._get_all_host_states')
@mock.patch('nova.scheduler.filter_scheduler.FilterScheduler._get_sorted_hosts')
def test_schedule_instance_group(self, mock_get_hosts, mock_get_all_states, mock_claim):

    num_instances = 2
    ig = objects.InstanceGroup(hosts=[])
    spec_obj = objects.RequestSpec(num_instances=num_instances, flavor=objects.Flavor(memory_mb=512, root_gb=512, ephemeral_gb=0, swap=0, vcpus=1), project_id=uuids.project_id, instance_group=ig)
    hs1 = mock.Mock(spec=host_manager.HostState, host='host1', uuid=uuids.cn1)
    hs2 = mock.Mock(spec=host_manager.HostState, host='host2', uuid=uuids.cn2)
    all_host_states = [hs1, hs2]
    mock_get_all_states.return_value = all_host_states
    mock_claim.return_value = True
    alloc_reqs_by_rp_uuid = {uuids.cn1: [mock.sentinel.alloc_req_cn1], uuids.cn2: [mock.sentinel.alloc_req_cn2]}
    mock_get_hosts.side_effect = ([hs2, hs1], [hs1, hs2])
    instance_uuids = [getattr(uuids, ('instance%d' % x)) for x in range(num_instances)]
    ctx = mock.Mock()
    self.driver._schedule(ctx, spec_obj, instance_uuids, alloc_reqs_by_rp_uuid, mock.sentinel.provider_summaries)
    claim_calls = [mock.call(ctx.elevated.return_value, spec_obj, uuids.instance0, [mock.sentinel.alloc_req_cn2]), mock.call(ctx.elevated.return_value, spec_obj, uuids.instance1, [mock.sentinel.alloc_req_cn1])]
    mock_claim.assert_has_calls(claim_calls)
    sorted_host_calls = [mock.call(spec_obj, all_host_states, 0), mock.call(spec_obj, [hs2, hs1], 1)]
    mock_get_hosts.assert_has_calls(sorted_host_calls)
    self.assertEqual(['host2', 'host1'], ig.hosts)
    self.assertEqual({}, ig.obj_get_changes())
