Skip to content

Add Neutron quota reservations query and order GetQuotas - #13

Merged
Mohammed Naser (mnaser) merged 1 commit into
vexxhost:mainfrom
samaritanark:contrib/neutron-2b4
Dec 4, 2026
Merged

Mohammed Naser (mnaser) merged 1 commit into
vexxhost:mainfrom
samaritanark:contrib/neutron-2b4

Conversation

@legit-ninja

@legit-ninja Jeremy Lee (legit-ninja) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add GetReservationsForResources to neutron/db, and order GetQuotas results.

GetReservationsForResources follows Neutron's [get_reservations_for_resources(..., expired=False)](https://github.com/openstack/neutron/blob/master/neutron/db/quota/api.py) for every project at once. It returns one row per active reservation delta (ReservationID, ProjectID, Expiration, Resource, Amount) instead of a per-resource sum.

Motivation

Neutron's quota usage plus its active reservations is what Neutron checks new requests against. GetQuotas and GetResourceCountsByProject already expose limits and usage; this adds the reservations so consumers can see the full picture.

Behavior

  • A reservation is active when expiration >= UTC_TIMESTAMP(), the same inclusive boundary Neutron uses. The comparison runs on the database clock in UTC, because Neutron writes expirations in UTC, so caller clock skew and the session time zone do not affect the result. NULL expirations are never active.
  • resources is a positional argument and follows upstream: a nil or empty list matches nothing rather than every resource.
  • Amounts are returned as stored, including NULL and negative values; summing and handling malformed amounts is the caller's job.
  • Rows are ordered by project, resource and reservation ID.
  • NULL owners are excluded and empty-string owners are kept, matching GetQuotas and GetResourceCountsByProject, so limits, usage and reservations join on ProjectID without special cases.
  • GetQuotas now orders by project, resource and quota ID, so callers that collapse duplicate rows get a stable result.

Performance

Upstream Neutron defines no index on reservations.expiration or reservations.project_id, and the schema fixture mirrors that. Each call scans reservations and joins resourcedeltas through the index InnoDB creates for its reservation_id foreign key, the same access path Neutron's own quota engine uses. The table stays small while Neutron's expired-reservation cleanup runs.

Compatibility

The change is additive. GetResourceCountsByProject is unchanged. GetQuotas returns the same rows, now in a defined order. The reservations and resourcedeltas tables are added to the Neutron schema fixture for tests and code generation; they are not production migrations.

Tests and docs

  • Unit tests for row scanning, the empty-list case and error propagation.
  • MariaDB integration tests (TestNeutronReservationsForResources, TestNeutronQuotaOwnersAndOrdering) using expirations relative to the database clock.
  • Query semantics documented in API.md; README.md only updates the neutron/db summary row.

@mnaser Mohammed Naser (mnaser) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code itself looks great—GetReservationsForResources using UTC_TIMESTAMP() on the database clock and sqlc.slice('resources'), deterministic ORDER BY on GetQuotas, consistent empty-string owner handling across all three Neutron quota queries, and keeping README.md concise with detailed docs in API.md all fit the repo cleanly.

Just housekeeping before we run CI and merge:

  1. Update the PR title and description to match the final code: the title is currently the raw branch name (Contrib/neutron 2b4), and the description still describes commit 1 (GetActiveReservationsByProject) and claims a breaking change excluding empty project_id records from GetResourceCountsByProject—which commit 2 reverted so empty-string owners are preserved.
  2. Squash the two commits into one clean commit (keeping DCO sign-off) so commit history reflects the final API directly.

Once updated (and rebased if any of #10–#12 merge ahead of it and touch API.md/README.md), this is ready for CI and merge.

Add GetReservationsForResources, which follows Neutron's
get_reservations_for_resources(expired=False) for every project at once.
It returns one row per active reservation delta (reservation ID,
project ID, expiration, resource and amount), ordered by project,
resource and reservation ID. Amounts are returned as stored, including
NULL and negative values, rather than summed.

A reservation is active when expiration >= UTC_TIMESTAMP(), the same
inclusive boundary Neutron uses. The comparison runs on the database
clock in UTC, so caller clock skew and session time zones do not
affect the result. The resources to read are a positional argument; an
empty list matches nothing, as upstream.

NULL owners are excluded and empty-string owners are kept, matching
GetQuotas and GetResourceCountsByProject, so limits, usage and
reservations join on project ID without special cases.
GetResourceCountsByProject is unchanged. GetQuotas now orders by
project, resource and quota ID so callers that collapse duplicate rows
get a stable result.

Add the reservations and resourcedeltas tables to the Neutron schema
fixture, without indexes on expiration or project_id as upstream. Add
unit tests, MariaDB integration tests for reservations and quota owner
handling and ordering, and API.md documentation.

Co-authored-by: David Hulick <dave.hulick@gmail.com>
Signed-off-by: David Hulick <dave.hulick@gmail.com>
Signed-off-by: Jeremy Lee <jeremy.lee1664@gmail.com>

@mnaser Mohammed Naser (mnaser) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates—CI is green, approving and merging.

@mnaser
Mohammed Naser (mnaser) merged commit 581c166 into vexxhost:main Dec 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants