x-image-meta-size in POST /images not optional, contrary to documentation

Bug #696375 reported by Ewan Mellor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Critical
Jay Pipes

Bug Description

When performing this request against glance-api:

POST /images HTTP/1.0
x-image-meta-name: test
x-image-meta-type: raw
x-image-meta-location: file:///foo

I get an exception in glance-registry:

  File "/usr/lib/python2.6/site-packages/glance/registry/server.py", line 113, in create
    image_data = db.image_create(context, image_data)
  File "/usr/lib/python2.6/site-packages/glance/registry/db/api.py", line 41, in image_create
    return IMPL.image_create(context, values)
  File "/usr/lib/python2.6/site-packages/glance/registry/db/sqlalchemy/api.py", line 55, in image_create
    return _image_update(_context, values, None)
  File "/usr/lib/python2.6/site-packages/glance/registry/db/sqlalchemy/api.py", line 132, in _image_update
    values['size'] = int(values['size'])
KeyError: 'size'

As far as I can see, no attempt has been made to validate the request in glance.registry.server.create, with a dictionary passed straight to the DB layer. This then is attempting to read the size value, and failing.

I'm not sure how to fix this, because I don't know what the API definition is intended to be, other than the fact that x-image-meta-size is defined as optional in the Glance API. The options I see are:

1. Define glance-api be the one to correctly determine the image size if it's missing, and therefore glance-registry may require that the size field is present in the request (and should validate it as such before passing it to the DB layer).
2. Define glance-registry's API such that size is optional, and set the field to None or -1 or something like that, when saving the record in the database.
3 Make x-image-meta-size compulsory.

Related branches

Revision history for this message
Jay Pipes (jaypipes) wrote :

Hi Ewan,

The intent was to make the field optional. It's a bug that the layer *above* the db API is not determining the image size when not present.

Cheers,
jay

Changed in glance:
status: New → Confirmed
importance: Undecided → Critical
Revision history for this message
Jay Pipes (jaypipes) wrote :

FYI, I'm (technically) on holiday until the 6th, so I can't promise to get to all the bugs by then... doing my best between activity requests from family ;)

Revision history for this message
Ewan Mellor (ewanmellor) wrote : RE: [Bug 696375] Re: x-image-meta-size in POST /images not optional, contrary to documentation

You're not the only one who's "technically" on holiday ;-)

> -----Original Message-----
> From: <email address hidden> [mailto:<email address hidden>] On Behalf Of
> Jay Pipes
> Sent: 02 January 2011 13:44
> To: Ewan Mellor
> Subject: [Bug 696375] Re: x-image-meta-size in POST /images not
> optional, contrary to documentation
>
> FYI, I'm (technically) on holiday until the 6th, so I can't promise to
> get to all the bugs by then... doing my best between activity requests
> from family ;)
>
> --
> You received this bug notification because you are a direct subscriber
> of the bug.
> https://bugs.launchpad.net/bugs/696375
>
> Title:
> x-image-meta-size in POST /images not optional, contrary to
> documentation
>
> Status in OpenStack Image Registry and Delivery Service (Glance):
> Confirmed
>
> Bug description:
> When performing this request against glance-api:
>
> POST /images HTTP/1.0
> x-image-meta-name: test
> x-image-meta-type: raw
> x-image-meta-location: file:///foo
>
> I get an exception in glance-registry:
>
> File "/usr/lib/python2.6/site-packages/glance/registry/server.py",
> line 113, in create
> image_data = db.image_create(context, image_data)
> File "/usr/lib/python2.6/site-packages/glance/registry/db/api.py",
> line 41, in image_create
> return IMPL.image_create(context, values)
> File "/usr/lib/python2.6/site-
> packages/glance/registry/db/sqlalchemy/api.py", line 55, in
> image_create
> return _image_update(_context, values, None)
> File "/usr/lib/python2.6/site-
> packages/glance/registry/db/sqlalchemy/api.py", line 132, in
> _image_update
> values['size'] = int(values['size'])
> KeyError: 'size'
>
> As far as I can see, no attempt has been made to validate the request
> in glance.registry.server.create, with a dictionary passed straight to
> the DB layer. This then is attempting to read the size value, and
> failing.
>
> I'm not sure how to fix this, because I don't know what the API
> definition is intended to be, other than the fact that x-image-meta-
> size is defined as optional in the Glance API. The options I see are:
>
> 1. Define glance-api be the one to correctly determine the image size
> if it's missing, and therefore glance-registry may require that the
> size field is present in the request (and should validate it as such
> before passing it to the DB layer).
> 2. Define glance-registry's API such that size is optional, and set the
> field to None or -1 or something like that, when saving the record in
> the database.
> 3 Make x-image-meta-size compulsory.
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/glance/+bug/696375/+subscribe

Jay Pipes (jaypipes)
Changed in glance:
assignee: nobody → Jay Pipes (jaypipes)
status: Confirmed → In Progress
Jay Pipes (jaypipes)
Changed in glance:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in glance:
milestone: none → 0.1.7
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.