Commit Graph

331 Commits

Author SHA1 Message Date
Erno Kuvaja 3dde3204d5 Remove Images API v1 entry points
This change removes option to configure Images API v1
This change removes Images API v1 endpoints from the router
This change removes all v1 tests
This change removes the v1 dependant glance-cache-manage command

This change does not remove all v1 codebase. Further cleanup and
decoupling will be needed.

Change-Id: Ia086230cc8c92f7b7dfd5b001923110d5bc55d4d
2018-07-13 10:21:49 +01:00
Jenkins a97c77a210 Merge "Fix some reST field lists in docstrings" 2017-06-30 20:46:05 +00:00
Doug Hellmann 03c0a1875c do not declare code blocks as json when they do not parse
Change-Id: I697be9b9dd15801d8d8df4fdae429e2d639f250e
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2017-06-21 14:15:58 -04:00
rtmdk 705e3a962d Fix some reST field lists in docstrings
fix the ":raises:" to ":raises".

Probably the most common format for documenting arguments is reST field
lists [1]. This change updates some docstrings to comply with the field
lists syntax.

[1] http://sphinx-doc.org/domains.html#info-field-lists

Change-Id: Ic7e2f80a48057547115453432c41803eb1cc948e
2017-03-25 01:35:59 -07:00
Nolwenn Cauchois d719b3a164 Fix bug Swift ACL which disappears on Glance v1 images
Currently, when we make an update on a public image, Swift ACL disappears.
This patch allows to avoid the ACL update if there is no change to the
is_public_attribute.
If an update is made on a Glance image without changing the public attribute
or location, then the function which modifies ACLS is not called, in order
to keep ACLS.

Closes-Bug: 1584076

Change-Id: I21e9deb9105faee87500998eff47c6faa1d02914
2016-06-15 09:50:03 +02:00
Tom Cocozzello adfc7e5a3f fix docstring warnings and errors
There are many warnings and errors that occur when the docs are
generated.

Co-Author-By: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Closes-Bug: 1556818
Change-Id: Ifebeb3904f136a56bd6fe6877220b279a1f98354
2016-03-14 18:40:15 +00:00
Cyril Roelandt e9fc06ccf3 Python 3: fix glance.tests.unit
With this change, all Glance unit tests now pass on Python3!

* Replace dict.keys() with list(dict.keys()) to get a list on Python
  3. On Python 3, dict.keys() now returns a view, not a list
* Replace filter() with a list-comprehension with if, to get a list
  on Python 3.
* Don't encode HTTP headers to UTF-8 on Python 3. Python 3 already
  encodes them for us.
* On Python 3, decode the request identifier of the context to get
  a Unicode string.
* Replace jsonutils.dumps(obj) with jsonutils.dump_as_bytes() to
  create a HTTP body, since the HTTP body must be a bytes string.
* start_http_server(): use bytes for image data, not Unicode.
* Use byte strings to check HTTP body, not Unicode. Or on some unit
  tests, decode the HTTP body to get Unicode.
* Skip test on invalid unicode image property on Python 3. It's now
  supported on Python 3.
* tox.ini: remove the whitelist of tests run on Python 3, since the
  whole test suite now pass on Python 3!

Note: With the gate, the Python 3 gate became unstable: bug #1521756.
The bug was caused by eventlet and the eventlet bug has been fixed in
eventlet 0.18, released a few days ago.

Co-authored-by: Victor Stinner <vstinner@redhat.com>
Change-Id: I99e0a80df93d0304c33ce50859c92e62ccc71648
2016-01-26 19:05:03 +01:00
Jenkins 89855b13b5 Merge "Validate empty location value for v1 api" 2016-01-23 05:35:25 +00:00
Julien Danjou 4d5330088f Replace oslo_utils.timeutils
This change introduces glance.common.timeutils that provides the
timeutils previously consumed from oslo_utils.

Oslo is deprecating some timeutils functionality which of Glance
depends on. Suggested replacement (isoformat) would break glance APIs
so it's cleaner to carry this functionality in Glance rather than
re-invent the wheel.

Co-Authored-By: Erno Kuvaja <jokke@usr.fi>
Co-Authored-By: Sabari Kumar Murugesan <smurugesan@vmware.com>

Change-Id: I91e1cc9a273249fd88749cecf21200f3f5e2bab1
2015-12-10 10:53:46 +00:00
Jenkins 2682dfe200 Merge "Import i18n functions directly" 2015-12-10 03:42:30 +00:00
kairat_kushaev c27c25f779 Import i18n functions directly
Import i18n functions from module directly and do not use
global module variables like _ = i18n._. It makes code shorter
and cleaner. It also to detect cases when these functions are not
used in module.

Change-Id: Iaa593ac1f2dd15cbcad049bef6ba68f1cfa610da
2015-12-07 18:20:43 +03:00
kairat_kushaev c2cbdd84e7 Validate empty location value for v1 api
When empty string is passed as location value the glance
raises internal server error.
The patch checks that location value is present in image meta
and generates BadRequest if it is empty.

Change-Id: I8f3640276368292ced508d5f4c918c147b9d1f19
Closes-Bug: #1498460
2015-12-07 14:31:45 +03:00
Jenkins 625269f114 Merge "Change the format of some inconsistent docstring" 2015-12-07 10:45:00 +00:00
Jenkins f8e31deaa4 Merge "Format log messages correctly" 2015-12-06 05:33:53 +00:00
leo.young bcbfa598e8 Change the format of some inconsistent docstring
Replace all the ":return:" with ":returns:"
Replace all the ":returns " wtih ":returns:"
Replace all the ":returns :" with ":returns:"

Add the changes for ":raise" also, change ":raise" to ":raise:"

Change-Id: I5d0def4665d0cd69b73c3c3826ad8f208e1e970e
2015-12-01 10:50:49 -05:00
Victor Stinner 89211b6ca6 Port _validate_time() to Python 3
The change Ib342ef6640efbc3d76c4bafc622ccfdfa3d16ade added a new
_validate_time() function for API v1. On Python 2, the function
relies on the datetime module to get a ValueError for datetime with
year older than 1900. On Python 3, the datetime module accepts years
before 1900 and so we have to test manually.

Change-Id: Id1dbf98ecf23e401f696a575dfea80fac2e297ed
2015-11-30 16:48:03 +01:00
Jenkins 467f240968 Merge "V1: Fix bad dates returning 500" 2015-11-26 19:10:36 +00:00
NiallBunting 4c486d470d V1: Fix bad dates returning 500
Currently if you send a bad date format such as 'foo', as one of the
settable dates ie. `created_at`, `updated_at` and `deleted_at` it will
cause the server to return a 500.

This change means that the server will respond with a 400 and a helpful
message.

Change-Id: Ib342ef6640efbc3d76c4bafc622ccfdfa3d16ade
Closes-Bug: 1483649
2015-11-25 11:27:10 +00:00
kairat_kushaev e2c8b23129 Format log messages correctly
Postpone formatting of log messages until check that debug is
turned on. It allows not to format and prepare formatted log
messages if debug mode is turned off.

Change-Id: Ic26a2940948fe9891e4898689e2ea9fc7f0d4350
2015-11-23 11:58:43 +03:00
NiallBunting fbe964a0f2 Disallow user modifing ACTIVE_IMMUTABLE of deactivated images
Currently the user can change the ACTIVE_IMMUTABLE properties whilst
the image is 'deactivated'. This should not be the case once an image
has become 'active'.

APIImpact
Change-Id: I744fbce90893008ef49568c3cba47bf0e26dec9d
Closes-Bug: 1517060
Closes-Bug: 1517963
2015-11-19 16:27:36 +00:00
Jenkins 88aa447f99 Merge "Fixed registry invalid token exception handling" 2015-10-18 11:06:02 +00:00
Martin Tsvetanov 5734d7c16f Fixed registry invalid token exception handling
When the registry has an error validating the token that the api
has sent it a 500 is returned rather than 401. This fix catches the
NotAuthenticated exception and throws an HTTPUnauthorized instead.

Change-Id: I405cd98346e2df06c02e37bfdf903a54a29f7b19
Closes-bug:1504184
2015-10-16 10:42:14 +00:00
Jenkins 7ba2346795 Merge "Change string generation mechanism for info logging" 2015-10-09 18:24:13 +00:00
itisha 3f79417ce7 An explicit check for the presence of a property
A more explicit way of checking if the immutable image metadata is
present or not.

Closes-Bug: #1499038
Change-Id: I72d372b8c2894cd3f8f0a3eebeae68886d4e0d65
2015-10-01 19:57:51 +00:00
kairat_kushaev 37fa0fca83 Change string generation mechanism for info logging
As stated in Openstack logging and i18n guidelines it is
recommended that formatted string for log messages should be
generated by logger (not by logger client/user). In this case
we can skip formatted message generation if log level configured
not to show info messages.
Also some non-used initialization of logger has been deleted
from the code.

Change-Id: I25660395417ea288aee6a70609a5336e6f74c291
2015-09-30 02:20:37 +03:00
Stuart McLaren 34f9f03713 Prevent image status being directly modified via v1
Users shouldn't be able to change an image's status directly via the
v1 API.

Some existing consumers of Glance set the x-image-meta-status header in
requests to the Glance API, eg:

https://github.com/openstack/nova/blob/master/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance#L184

We should try to prevent users setting 'status' via v1, but without breaking
existing benign API calls such as these.

I've adopted the following approach (which has some prior art in 'protected properties').

If a PUT request is received which contains an x-image-meta-status header:

* The user provided status is ignored if it matches the current image
  status (this prevents benign calls such as the nova one above from
  breaking). The usual code (eg 200) will be returned.

* If the user provided status doesn't match the current image status (ie
  there is a real attempt to change the value) 403 will be returned. This
  will break any calls which currently intentionally change the status.

APIImpact

Closes-bug: 1482371

Change-Id: I44fadf32abb57c962b67467091c3f51c1ccc25e6
2015-09-22 16:07:02 +02:00
ankitagrawal 16ab5d7c17 Use dictionary literal for dictionary creation
Dictionary creation could be rewritten as a dictionary literal.
for example:

filters = {}
filter['namespace'] = namespace

could be rewritten as

filters = {'namespace': namespace}

Closes-Bug: 1482586
Change-Id: I860483e958296da248a579a6032c14370843d9e4
2015-08-07 06:00:35 -07:00
Mike Fedosin 3fc57a4e0a Glance to handle exceptions from glance_store
After the split glance_store raises its own exceptions, that
have the same names as in glance. Several times those exceptions
aren't caught in glance and it leads to incorrect behaviour.
This code fixed it.

Change-Id: I8600e0813ecbc599b5411e1fc0d0c9b470f68f6b
Closes-Bug: #1469817
2015-07-27 14:43:35 +03:00
Victor Stinner 1c186e23fd Use oslo_utils.encodeutils.exception_to_unicode()
* Replace glance.common.utils.exception_to_str() with
  oslo_utils.encodeutils.exception_to_unicode().
* Remove exception_to_str() from glance.common.utils
* Add "from oslo_utils import encodeutils" and remove "from
  glance.common import utils" (when utils is no more used)
* glance/api/v2/images.py: replace utils.exception_to_str() with
  six.text_type() to cast the oslo_i18n message to Unicode

Glance exception_to_str() function was not compatible with Python 3,
whereas exception_to_unicode() is compatible with Python 3, it's in Oslo
common libraries and it's well tested.

This patch was first generated by a tool (modified version of sixer),
and then fixed to respect the PEP8 (especially the constraint of 80
columns).

Change-Id: I86008c8adc0c5664f96573c1015cc15e2d06e3e2
2015-07-17 18:31:03 +02:00
Jenkins e68b6c1a86 Merge "Change generic NotFound to ImageNotFound exception" 2015-06-25 05:20:12 +00:00
Jenkins a432b1f0f6 Merge "Fix DbError when image params are out of range" 2015-06-12 03:34:52 +00:00
Inessa Vasilevskaya 1badf69b01 Fix DbError when image params are out of range
Image params such as checksum, min_ram and min_disk are validated.
Checksum is expected to be not longer than 32 characters,
min_ram/min_disk can't exceed pow(2, 31) - 1.
A method for mysql_int validation has been moved to glance.common.utils.

Change-Id: I78554ef1ba65fc11da3de56467d6d70bb7991787
Closes-Bug: #1454730
Closes-Bug: #1460060
2015-06-11 19:27:17 +03:00
Auktavian Garrett 8a7086b9bf Change generic NotFound to ImageNotFound exception
When an image can not be found an ImageNotFound exception
will be raised instead of a generic NotFound
exception.  Does not apply to Image Metadata,
Image Members, Image Tags, Image Tasks

Closes-Bug #1247633

Change-Id: I84c754e51fb40ef1f9744bf85dbaa716b55cbb95
2015-05-30 08:18:33 -07:00
Mike Fedosin ac9f373cd0 Fix delayed activation without disk and containers formats
If we want to perform a delayed activation of an image without
providing disk format or container format, Glance tries to
upload a file and fails with 400 error.

This code handles this situation by checking that no sources
were provided, and returns information about the image before
starting the upload.

Change-Id: Id6f81df9bb43697b0d694528b010bb3c7c9bedb3
Closes-Bug: #1268680
2015-05-08 16:10:42 +03:00
Jin Long Wang 7896c00635 Add logging when policies forbid an action
There is currently no logging in images.py of glance API v1 or v2
and other files of glance API when policies forbid an action.This
patch adds logging in these situations.

Co-Authored-By: Ian Cordasco <ian.cordasco@rackspace.com>
Co-Authored-By: Kamil Rykowski <kamil.rykowski@intel.com>

Closes-Bug: #1270229
Change-Id: I32afbfc98a3de6370b0396f39c2cf481f6fc47a9
2015-04-15 17:59:37 +02:00
Stuart McLaren d88b4b6d56 Catch UnknownScheme exception
There are a couple of places where an UnknownScheme
exception could be raises but was not being caught.

Change-Id: I25af9a762c49a1bbea661c3858ffb46cff891ee2
Closes-bug: #1379308
2015-04-09 13:44:31 +00:00
Jenkins d63523a269 Merge "Raise exception if store location URL not found" 2015-03-16 18:32:29 +00:00
Eddie Sheffield b000c85b7f Add ability to deactivate an image
This patch provides the ability to 'deactivate' an image by
providing two new API calls and a new image status 'deactivated'.
Attempting to download a deactivated image will result in a
403 'Forbidden' return code. Also, image locations won't be visible
for deactivated images unless the user is admin.
All other image operations should remain unaffected.

The two new API calls are:
    - POST /images/{image_id}/actions/deactivate
    - POST /images/{image_id}/actions/reactivate

DocImpact
UpgradeImpact

Change-Id: I32b7cc7ce8404457a87c8c05041aa2a30152b930
Implements: bp deactivate-image
2015-03-13 14:21:11 -04:00
Rajesh Tailor cfa55973d9 Raise exception if store location URL not found
Glance doesn't catch NotFound exception when --location parameter
is used with non-exist http store URL.

If the URL returns HTTP 404, glance is just ignoring it and returns
image-size as zero.

While getting the image-size caught NotFound exception as well
if location parameter is specified.

Depends-On: Ieb3dcb79ed9ba4368d0b3ca69b30095c1fd800b9
Change-Id: I9ffad7666c6e64c007c9938684903aed44e60151
Closes-Bug: 1316137
2015-03-13 02:45:34 -07:00
Louis Taylor 0acff569e0 Move to graduated oslo.log module
This removes the log module from the oslo incubator directory.

Change-Id: Ib017cc2777e27c58b376c3138c9fba614783cc34
2015-03-12 11:48:24 +00:00
Jenkins 7c339ac58e Merge "Zero downtime configuration reload" 2015-03-11 21:28:42 +00:00
Zhi Yan Liu efc333ffbd Add capabilities to storage driver
This patch is work for glance, and the main change on glance_store side
is change Iedf0d4f829e46ca64c3f4fc6a7dfee54d9b0605b .

This change works with glance_store v0.1.11 at least.

Implements: blueprint store-capabilities
Depends-On: I5055b837e94fdee7e01cc94f8bdb89bada34f77b

Change-Id: Ibbc85b6bc2ea98c564d316db2874d7df5aac32a6
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
2015-03-10 13:30:06 +08:00
Jenkins d271a8844c Merge "Typos fixed in the comments" 2015-03-10 01:02:47 +00:00
abhishekkekane ea2252b4fd Zero downtime configuration reload
Add the ability to dynamically change configuration settings of a running
glance server with no impact to service.

A running glance server consists of a parent/master process and one or
more child/worker processes.

On receipt of a SIGHUP signal the master process will:

* reload the configuration
* send a SIGHUP to the original workers
* start (a potentially different number of) new workers with the new
  configuration
* its listening socket will *not* be closed

On receipt of a SIGHUP signal each original worker process will:

* close the listening socket so as not to accept new requests
* complete any in-flight requests
* complete async requests (V1 create with copy-from option and V2 task api)
* exit

This approach is based on nginx's behaviour and avoids some of the
disadvantages of the current oslo Launcher reload:

* Race conditions: Launcher does not shutdown eventlet cleanly, existing
  requests can fail.
* If all workers are busy (likely if #workers is small) there can be a
  lengthy delay when new requests are not processed.
* Long lived pre-SIGHUP idle client connections can stall request
  processing indefinitely.
* Not all parameters can be changed, eg number of workers.
* The wsgi pipeline cannot be changed, eg to enable caching.

Change-Id: I73875c654410f207e3efdb2932147cf26d75b3f1
Partially implements: bp sighup-conf-reload
2015-03-09 05:12:25 -07:00
Jenkins b6eb01a18f Merge "Glance returns HTTP 500 for image download" 2015-02-25 23:07:05 +00:00
ankitagrawal 6982284218 Glance returns HTTP 500 for image download
HTTPInternalServerError 500 response is returned to the user while
image server is down during downloading the image. When glance tries
to download the image from the remote location (image server) which
is down, Connection refused ECONNREFUSED error is raised on the
glance server.

Raised RemoteServiceUnavailable exception from glance_store and handle
it in v1 and v2 api's to return 503 HTTPServiceUnavailable response
to user.

Note: Please refer below link to check glance_store related changes
which addresses this issue partially.
I065b9a3e8e674ea74ff8563aad99d7d022417caa

Closes-Bug: #1379798
Change-Id: I45099153e75d53b028e249fad8a4d944d38adf65
2015-02-25 05:48:30 +00:00
Danny Al-Gaaf e7634c5766 unify some messages
Add missing chars (':', ' ', '=', '.', "is") to some messages
to reduce translation effort by unifying them.

Change-Id: Iab5ee81169dbcee2ca514b696369d2ac53086164
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
2015-02-10 13:36:13 +01:00
hzrandd bfd212354e Typos fixed in the comments
Change-Id: I94f896ae8c4f2017f0bfda5dbb6bc913cba12498
Related-Change-Id  I9ffad7666c6e64c007c9938684903aed44e60151
2015-02-10 18:14:21 +08:00
Louis Taylor d759a6fd1a Move from oslo.config to oslo_config
oslo_config was moved out of the oslo namespace in oslo.config>=1.6.0.

Related-to: blueprint drop-namespace-packages

Change-Id: I30ecbf8f9de77496fcb643c7ad9738d79ad359f0
2015-01-12 14:34:22 +00:00
Louis Taylor 41d45dfb1c Move from oslo.utils to oslo_utils
oslo_utils has been moved out of the oslo namespace.

bp drop-namespace-packages

Change-Id: Ie818e72b31efd2a6ab182444967bdfaca9366f4a
2015-01-09 20:01:42 +00:00