1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 16:36:06 +00:00

fix(api): a volume's size is GiB to create and bytes to read, each documented

One serializer created volumes and read them: size was GiB in a request
and bytes in an answer, the same field in the schema. A client that sent
back a size it read asked for a volume 2**30 times as large. A new
volume is CreateVolumeSerializer (size in GiB); a volume read is
VolumeSerializer (allocation and size in bytes), and the schema says so,
as for the pools' size and free space.
This commit is contained in:
catborise 2026-11-07 00:19:55 +03:00
parent 0610c23a34
commit 470cc9860e
3 changed files with 30 additions and 10 deletions

View file

@ -36,6 +36,16 @@ class APISchemaTestCase(TestCase):
self.assertEqual(getattr(client, method)("/api/v1/nothere/").status_code, 404)
self.assertEqual(client.get("/api/schema/").status_code, 200)
def test_a_volume_s_size_is_gib_to_create_and_bytes_to_read(self):
# one serializer had both: a size read back and sent again asked 2**30 times as much
schema = SchemaGenerator().get_schema(request=None, public=True)
create = schema["paths"]["/api/v1/computes/{compute_pk}/storages/{storage_pk}/volumes/"]["post"]
self.assertEqual(create["requestBody"]["content"]["application/json"]["schema"]["$ref"],
"#/components/schemas/CreateVolume")
components = schema["components"]["schemas"]
self.assertEqual(components["CreateVolume"]["properties"]["size"]["description"], "Capacity in GiB")
self.assertEqual(components["Volume"]["properties"]["size"]["description"], "Capacity in bytes")
def test_a_refusal_s_body_is_documented_with_its_409(self):
schema = SchemaGenerator().get_schema(request=None, public=True)
poweron = schema["paths"]["/api/v1/computes/{compute_pk}/instances/{id}/poweron/"]["post"]