Skip to content

Percent-encode resource ids in URL paths - #152

Merged
mergify[bot] merged 3 commits into
gnocchixyz:masterfrom
fivetime:fix/encode-resource-id
Oct 26, 2026
Merged

mergify[bot] merged 3 commits into
gnocchixyz:masterfrom
fivetime:fix/encode-resource-id

Conversation

@fivetime

@fivetime fivetime commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Resource ids are free-form strings on the server side (non-UUID ids get hashed into a UUID), and real-world ids contain characters that are significant in a URL. Cinder reports storage pools as <host>@<backend>#<pool>; the client splices that id raw into the path, so everything from # on becomes a URL fragment and the server sees /v1/resource/volume_provider_pool/<host>@<backend> — a different, usually nonexistent resource → 404.

Observed with Ceilometer's gnocchi publisher on volume.provider.pool.capacity.* samples: creation works (the id travels in the batch body), but every attribute update is rejected:

PATCH /v1/resource/volume_provider_pool/ceph-aa@hdd-rep3#hdd-rep3   (client)
PATCH /v1/resource/volume_provider_pool/ceph-aa@hdd-rep3            (what the server receives) → 404

Fix

Add utils.encode_resource_id() (urllib.parse.quote(..., safe="")) and apply it wherever a resource id is spliced into a path: ResourceManager.get/history/update/delete and the MetricManager resource-scoped paths (get, create, delete, get_measures, add_measures, set_measures). UUID ids are unchanged; the server decodes percent-encoding, verified against Gnocchi 4.7:

PATCH /v1/resource/volume_provider_pool/ceph-aa%40hdd-rep3%23hdd-rep3 → 200

safe="" is there so that a / in an id is encoded as well (quote() leaves / alone by default); @ and # are encoded either way.

Tests

gnocchiclient/tests/unit/test_resource_id_encoding.py pins the encoding and the URLs produced by each affected method. Unit suite and flake8 (with the repo's ignore list) pass.

Co-authored with Claude (Anthropic); reviewed and tested by a human.

Comment thread gnocchiclient/v1/metric.py Resolved
Comment thread gnocchiclient/v1/metric.py Resolved
Comment thread gnocchiclient/utils.py Resolved
Resource ids are free-form strings server-side (anything that is not a
UUID gets hashed into one), and real-world ids contain characters that
are significant in a URL. Cinder reports storage pools as
"<host>@<backend>#<pool>"; putting that id raw into the path turns
everything from '#' on into a URL fragment, so resource show/update/
delete and metric-by-resource requests land on "<host>@<backend>" -- a
different, usually nonexistent resource -- and fail with 404.

The Ceilometer gnocchi publisher hits this on every polled
volume.provider.pool.capacity.* sample that carries resource attributes:
the initial creation works (the id travels in the batch body) but the
attribute update never does.

Add utils.encode_resource_id() (urllib.parse.quote with safe="", so
that a '/' in an id is encoded as well) and apply it wherever a
resource id is spliced into a path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fivetime
fivetime force-pushed the fix/encode-resource-id branch from 6aa06d8 to 0978ea8 Compare October 17, 2026 16:14
@Callum027

Copy link
Copy Markdown
Contributor

@fivetime, could you please rebase this branch on the latest? @tobias-urdin, could you please approve running the pipeline?

fivetime and others added 2 commits October 24, 2026 11:08
testtools is not one of this repository's test dependencies, so the
module failed to import in an environment installed from .[test].
The tests only use assertEqual and assertTrue; use unittest.TestCase
like the other unit tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fivetime

Copy link
Copy Markdown
Contributor Author

Merged the latest master into the branch. While doing it I noticed the new test imported testtools, which isn't one of this repo's test dependencies (the earlier CI run failed before reaching the tests), so it now uses unittest.TestCase like the other unit tests (e902136). Unit tests and flake8 pass locally.

@mergify mergify Bot added the queued label Oct 26, 2026
@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-26 07:13 UTC · Rule: duplicated default from automatic merge · triggered by rule automatic merge + automatic merge backports from Mergify
  • ✅ Checks passed · on draft merge queue: checking #152 on master (b2e2058) #159
  • ✅ Merged — 2026-10-26 07:18 UTC · at 0a5518d54acfff65eefa7e5a5e8bad8465c703c1 · merge

This pull request spent 4 minutes 41 seconds in the queue, including 4 minutes 2 seconds running CI.

Required conditions to merge
  • check-success=test (build)
  • check-success=test (docs-gnocchi-web)
  • check-success=test (pep8)
  • check-success=test (py310)
  • check-success=test (py311)
  • check-success=test (py312)

@mergify mergify Bot mentioned this pull request Oct 26, 2026
14 tasks done
@mergify
mergify Bot merged commit 0a5518d into gnocchixyz:master Oct 26, 2026
10 checks passed
@mergify mergify Bot removed the queued label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants