def stub_out_instance_quota(stubs, allowed, quota, resource='instances'):

    def fake_reserve(context, **deltas):
        requested = deltas.pop(resource, 0)
        if (requested > allowed):
            quotas = dict(instances=1, cores=1, ram=1)
            quotas[resource] = quota
            usages = dict(instances=dict(in_use=0, reserved=0), cores=dict(in_use=0, reserved=0), ram=dict(in_use=0, reserved=0))
            usages[resource]['in_use'] = ((quotas[resource] * 0.9) - allowed)
            usages[resource]['reserved'] = (quotas[resource] * 0.1)
            raise exc.OverQuota(overs=[resource], quotas=quotas, usages=usages)
    stubs.Set(QUOTAS, 'reserve', fake_reserve)
def stub_out_instance_quota(stubs, allowed, quota, resource='instances'):

    def fake_reserve(context, **deltas):
        requested = deltas.pop(resource, 0)
        if (requested > allowed):
            quotas = dict(instances=1, cores=1, ram=1)
            quotas[resource] = quota
            usages = dict(instances=dict(in_use=0, reserved=0), cores=dict(in_use=0, reserved=0), ram=dict(in_use=0, reserved=0))
            usages[resource]['in_use'] = ((quotas[resource] * 0.9) - allowed)
            usages[resource]['reserved'] = (quotas[resource] * 0.1)
            raise exc.OverQuota(overs=[resource], quotas=quotas, usages=usages)
    stubs.Set(QUOTAS, 'reserve', fake_reserve)