Commit Graph

69 Commits

Author SHA1 Message Date
Takashi Natsume 0c594dfcf2 Fix misuse of assertTrue
Replace assertTrue with assertIsInstance or assertEqual.

Change-Id: Ied3d6ba3941745a6bebda50780d16be2908a619c
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2023-02-12 08:00:35 +00:00
Takashi Kajinami 6738d0b156 Swift: Honor *_domain_name parameters
The *_domain_id parmaeters should not have any default. Otherwise
keystoneauth ignores the *_domain_name parameters and it requires
only *_domain_id parameters are used.

Closes-Bug: #1620999
Change-Id: I1f8c9184761313f9fc5fda2f257e52233e0196d1
2022-08-18 11:20:52 +09:00
liyou01 5ff06df97f Remove Python 2 support
Python 2 has been deprecated for almost two years, and has not been
guaranteed to work with glance_store for a while. This patch removes all
traces of six, unicode strings and Python 2 tweaks.

Co-Authored-By: Cyril Roelandt <cyril@redhat.com>
Change-Id: Ifa78924d7ecf4f2d9a54c677888ab2926530c487
2022-05-25 04:42:06 +02:00
Zuul 4598766890 Merge "Raise correct exception from "Quota full"" 2021-08-16 17:08:25 +00:00
Erno Kuvaja 6a241a20c9 Raise correct exception from "Quota full"
Swift driver reraises the client exception causing glance-api
to return 500. Lets raise g_s StoreFull correctly instead.

Change-Id: I5be151afe242a75142e74d488c4787a35929e189
Closes-bug: #1926404
2021-08-16 12:20:08 +01:00
Alexandre Arents 16924dbe51 swift: Take into account swift_store_endpoint
In SingleTenant authv3 context, connection manager does not evaluate
swift_store_endpoint and always takes endpoint from catalog.

The change ensures CONF.glance_store.swift_store_endpoint
will take over catalog value also in that case.

Closes-Bug: #1885651
Change-Id: Ib18ff19cd539e0117909f849672036b8c9e5f049
2021-03-01 16:10:37 +00:00
Ade Lee a34419aecd Replace md5 with oslo version
md5 is not an approved algorithm in FIPS mode, and trying to
instantiate a hashlib.md5() will fail when the system is running in
FIPS mode.

md5 is allowed when in a non-security context.  There is a plan to
add a keyword parameter (usedforsecurity) to hashlib.md5() to annotate
whether or not the instance is being used in a security context.

In the case where it is not, the instantiation of md5 will be allowed.
See https://bugs.python.org/issue9216 for more details.

Some downstream python versions already support this parameter.  To
support these versions, a new encapsulation of md5() has been added to
oslo_utils.  See https://review.opendev.org/#/c/750031/

This patch is to replace the instances of hashlib.md5() with this new
encapsulation, adding an annotation indicating whether the usage is
a security context or not.

It looks like the uses of the md5 are primarily for checksums and
generation of etags.

With this patch, all the unit and functional tests appear to pass
on a FIPS enabled system.

Change-Id: I0603ba217d6dc19f5c9f73c60c7b365efd28d30b
Depends-On: https://review.opendev.org/#/c/760160
2020-11-11 13:40:46 -05:00
whoami-rajat 403ab32a05 Update user/project referencing from context
The old context references (user, tenant) errors out during functional
testing on glance side[1][2] with the following error:

2020-09-07 07:29:34,125 ERROR [glance.async_.taskflow_executor] Failed to
execute task 6ee97c27-b87b-42f9-86af-151ef9a7ecd4: Property 'tenant' has
moved to 'project_id' in version '2.6' and will be removed in version '3.0'

(similar error for user/user_id)

This patch updates the same.

[1] https://review.opendev.org/#/c/750144/
[2] https://storage.gra.cloud.ovh.net/v1/AUTH_dcaab5e32b234d56b626f72581e3644c/zuul_opendev_logs_fdc/750144/2/check/openstack-tox-functional-py36/fdc43f4/testr_results.html

Closes-Bug: #1894735

Change-Id: I279e442d7d00a6ebca0679cbf46a295fa07b6306
2020-09-07 16:00:35 +00:00
Sean McGinnis 814b7f23e2
Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: I3e92b23ab2a335b378f156c0456fb1d52706ed12
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
2020-04-18 11:52:47 -05:00
Andreas Jaeger 279ea4766e Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found.

Remove hacking and friends from lower-constraints, they are not needed
for installation.

Change-Id: I99b8b24f714858f6b289e5e7b5976e519bb81c11
2020-04-02 15:26:13 +02:00
Zuul 934759d721 Merge "Re-use swift_store_cacert for Keystone session" 2020-03-26 05:11:47 +00:00
Elancheran T.S eedf0460b6 Fix for BufferedReader sets is_zero_size true for a chunk
When the image is size larger than chunk size, swift store
uploads 0 bytes for swift_buffered_upload enabled.

Closes-Bug: #1863691

Change-Id: I272d380d8fc093e946ecd6bd5ba99b5bbe2409b2
2020-03-04 22:34:57 -08:00
Pavlo Shchelokovskyy ee2a3d3032 Re-use swift_store_cacert for Keystone session
pass configured cacert for Swift to the keystoneauth's Session
as well so that the swift endpoint can be resolved from the catalog
when a custom CA bundle is used.

Change-Id: I439f6b5af34c685f72c9b4933c7eb0c77cc92e14
Closes-Bug: #1820817
2020-01-14 07:25:29 +00:00
Alfredo Moralejo ed356fc6b4 Do not include ETag when puting manifest in chunked uploads
While testing glance with Ceph Rados Gateway using latest Ceph release
(Nautilus), i've found that glance fails to upload the manifest using
dynamic large objects mode because of the value used in ETag request.

This issue has been reported to Ceph as it seems related to some recent
change in radosgw code [1].

However, checking at the upload workflow used by glance and comparing
to Swift documentation [2], I wonder if adding the etag is actually
providing any value. In the Swift the ETag header is used to validate
integrity when uploading chunks, not the manifest while glance is doing
exactly the oposite, not sending the etag in the chunks (I guess to
avoid checksuming big images, which makes sense to me) and sending it
when puting the manifest.

This patch is removing the etag header when sending the PUT request for
the manifest in chunked uploads.

[1] https://tracker.ceph.com/issues/39160
[2] https://docs.openstack.org/swift/latest/api/large_objects.html#dynamic-large-objects

Closes-bug: #1824533
Change-Id: I0b563dfcdc30026669fb089c82db8c3df7edc808
2019-04-17 12:38:22 +02:00
Tim Burke d3029fe4b4 Return bytes even when get()ing a zero-byte image from swift
Drive-by: treat an unspecified slice start as 0 instead of
raising TypeErrors.

Change-Id: I5ae556771a3aa4af062772a0fa2c730a2e447972
2019-03-06 16:21:31 -08:00
Zuul 7cdda1be12 Merge "Remove moxstubout usage" 2019-01-24 05:23:15 +00:00
Chuck Short aefad17de8 Remove moxstubout usage
As of version 3.5.0 moxstub will be deprecated, so remove it where it has
been used.

Change-Id: I2622c457871815311241d2eea562d7a3c70b0795
Signed-off-by: Chuck Short <chucks@redhat.com>
2018-10-29 10:22:05 -04:00
Cyril Roelandt 6ce857397d Fix defaults for ConfigParser
As of 3.7, the configparser module will not allow defaults values to be None.
This patch replaces such values with "default".

Change-Id: Id5a414412cd66d479fb8f8784cba5deddc628dfd
Closes-Bug: #1785641
2018-09-04 18:47:31 +02:00
Scott McClymont ba9808cebb Multihash Implementation for Glance
Adds the ability to compute a "multihash" (see the Glance spec
for what this is exactly).  To maintain backward compatability,
a new store_add_to_backend_with_multihash function is added.
Backward compatability for each store's add() method is achieved
by a back_compat_add wrapper.

Co-Authored-by: Scott McClymont <scott.mcclymont@verizonwireless.com>
Co-Authored-by: Brian Rosmaita <rosmaita.fossdev@gmail.com>

Change-Id: I063d0900b7dc7e0d94dfb685971eb9b17ed67c7b
Partially-implements: blueprint multihash
2018-07-18 09:27:54 -04:00
Zuul fd2a80a08f Merge "Disable verification for Keystone session in Swift" 2018-06-19 04:06:15 +00:00
Jenkins 6a0c147c5d Merge "Buffered reader: Upload recovery for swift store" 2017-09-19 22:34:38 +00:00
Jenkins 051e2353b0 Merge "Replace six.iteritems() with .items()" 2017-07-14 07:24:45 +00:00
Szymon Datko 2c65bf7f1a Fixed tests due to updated oslo.config
Change-Id: Ib7923543862275629d86a0fa76baa88722493bad
Closes-Bug: #1691132
2017-05-26 21:27:05 -04:00
Brian D. Elliott 2e0024c85c Buffered reader: Upload recovery for swift store
During segmented (chunked) uploads of large files to Swift, if a
single segment fails to upload, Glance will abort the entire
upload, which could have been in progress for many hours.
However, if seek() and tell() methods are provided on the input
file stream, swiftclient will attempt to reset the filestream
back to the beginning of the segment and retry.
This patch adds glance_store._drivers.swift.buffered.BufferedReader to
provide this reset capability.  It works by buffering the segment/chunk
to disk in case an upload error occurs and a reset is required.  This
could potentially use much larger disk space, so a CONF setting,
CONF.glance_store.swift_store_reader_class is required to
enable the new reader.  (The default is to use the existing
glance_store._drivers.swift.store.ChunkReader.)
This patch does not address the automatic revert to ChunkReader if
we run out of space for buffering.

Co-Authored-By: Brian Elliott <bdelliott@gmail.com>
Co-Authored-By: Hemanth Makkapati <hemanth.makkapati@rackspace.com>
Co-Authored-By: Dharini Chandrasekar <dharini.chandrasekar@intel.com>

DocImpact
Partially Implements: blueprint buffered-reader-for-swift-driver
Change-Id: I7d7337cee930fd2fb451fa5c7093c5fa9f985dcb
2017-03-15 21:05:33 +00:00
gengchc2 edc19a290b Replace six.iteritems() with .items()
1.As mentioned in [1], we should avoid using
six.iteritems to achieve iterators. We can
use dict.items instead, as it will return
iterators in PY3 as well. And dict.items/keys
will more readable. 2.In py2, the performance
about list should be negligible, see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: I225da4f95187387007df11c91047497a2a93e862
2017-03-10 01:47:26 +00:00
Vincent Untz 54b7ccbb9b Disable verification for Keystone session in Swift
The swift backend did not make use of the insecure option in
the config when creating a Keystone session, enable or disable
verification based on it.

Co-Authored-By: Steve Kowalik <steven@wedontsleep.org>
Change-Id: Ic783afde7ae8af522480996fdf91ed54e02e72d2
Closes-Bug: #1606268
2016-12-20 16:07:45 +11:00
Jenkins 6982b3c2e5 Merge "Raise exc when using multi-tenant and swift+config" 2016-12-19 19:58:29 +00:00
Dharini Chandrasekar e79162423f Raise exc when using multi-tenant and swift+config
When Swift multi-tenant store is used along with the
scheme ``swift+config`` (the scheme that identifies the
need to use the swift config), a reference to use swift
objects from the swift config file set using the option
``swift_store_config_file`` is made resulting in the
storage url for an accessible object being created from
a swift auth_address. So is the case when the scheme is
``swift``. This behavior is suitable for single-tenant
swift store and not multi-tenant store.

The solution is to ensure that if deploying multi-tenant swift
store, prohibit setting of swift_store_config_file.
This patch does this by ensuring that multi-tenant and
swift_store_config_file are not configured to work together.

TODO: When somebody changes to multi-tenant from single-tenant store,
and they were using the swift config for single-tenant, the operator will
not be able to access those images any longer. Logic to ensure that
multi-tenant uses the swift conf file if there is a need to  access
an image that was created using single-tenant and swift+config could be
introduced.

UpgradeImpact
DocImpact

Closes-Bug: 1625075

Change-Id: I8b5c31541d3c501ad7c2520b463f881599f4a28e
Co-Authored-By: Hemanth Makkapati <hemanth.makkapati@rackspace.com>
Co-Authored-By: Dharini Chandrasekar <dharini.chandrasekar@intel.com>
2016-12-16 19:48:09 +00:00
Jenkins 32bdeddfb1 Merge "Use storage_url in DB for multi-tenant swift store" 2016-12-14 16:35:26 +00:00
Dharini Chandrasekar 2b4f75a628 Use storage_url in DB for multi-tenant swift store
When using swift multi-tenant store, using a user's service
catalog to obtain the storage url for an object does not work
if the image was not created by the same user. This is because
the user's context, if used to establish a connection, would only
be looking at a location url formed with the wrong owner information
resulting in an object GET failure (404).

This patch solves this issue by a 'revert in principle' to the old code
logic where the storage_url for an image when using multi-tenant store
was fetched from the database via 'location.swift_url'. The change
that had introduced the fetch of storage_url from user's context is [1].

[1] I7bc23dfc11900b55f45fe98144d14f883c381c9f

Co-Authored-By: Hemanth Makkapati <hemanth.makkapati@rackspace.com>
Co-Authored-By: Dharini Chandrasekar <dharini.chandrasekar@intel.com>

Partial-Bug: #1625075

Change-Id: I8c22a0ab566cf1ec99cbee78ea43ef28abcd8dc0
2016-12-13 18:17:34 +00:00
Jenkins 2689a350c3 Merge "Clean imports in code" 2016-11-18 08:33:17 +00:00
Jamie Lennox 4d7703b934 Convert to keystoneauth
A direct conversion of keystoneclient usage to the newer supported
keystoneauth library. The libraries are largely compatible and there
should be no issues swapping between them.

This doesn't fix any problems of the way auth is used, it just changes
out the library.

Change-Id: Ibe212e17150a3c750e9c2536a4c869d87e9d4e13
2016-11-02 09:53:07 +11:00
Jamie Lennox ab0254750a Refactor get_manager_for_store in an OO manner
get_manager_for_store is a weird function that switches based on the
class type of the first parameter. This is an odd throw back to pre
object orientated days where the object defines what it wants. Refactor
it to put the class on the object.

Change-Id: I0bca2607267aef3bda720cdfbbbe0e5a8093a20d
2016-10-14 17:39:35 +11:00
Cao Xuan Hoang affcff2e85 Clean imports in code
This patch set modifies lines which are importing objects
instead of modules. As per openstack import guide lines, user should
import modules in a file not objects.

http://docs.openstack.org/developer/hacking/#imports

Change-Id: I7525672d64a3bc5df2dc6bdbf19da5b1d6c9dc1e
2016-09-07 16:16:16 +07:00
yuyafei fd1e846a60 Fix argument order for assertEqual to (expected, observed)
assertEqual expects that the arguments provided to it should be
(expected, observed). If a particluar order is kept as a convention,
then it helps to provide a cleaner message to the developer if Unit
Tests fail. The following patch fixes this issue.

TrivialFix

Change-Id: I07b78383ef38731140143c91ae3a902bea55eebb
Closes-Bug: #1259292
2016-06-15 13:28:51 +08:00
Jenkins bc074d4718 Merge "Setup defaults for swift driver authentication" 2016-04-07 18:44:07 +00:00
Tim Burke 9addf29b52 Fix swiftclient mocks
In particular, stop mocking out some internal details like
swiftclient.client.Connection._retry

Change-Id: If118b9656ae1e87139c0d48dcc97c1daee948a85
Related-Change: I62cc037493af87373a75e37e2d9f33b8aedf9889
Related-Bug: 1556059
2016-04-04 15:13:14 -07:00
kairat_kushaev 1ae475c88e Setup defaults for swift driver authentication
Previously we passed all user configurations to swift.
Swift uses keystoneclient when authenticating and some
parameters were defaulting by swiftclient. Swiftclient
did not use sessions and auth plugins. When we implemented
re-authentication we started to use sessions and auth plugins
but it turned out that some parameters are not defaulting here:
namely, project_domain_name and project_domain_id.
glance_store is also not defaulting them (we need to introduce
configurations params for that in glance_store) so as a result
we have error from keystone service.
The patch introduces default domains (as keystoneclient
without sessions does). The long term fix (introduce
configuration parameters) will be proposed later.

Change-Id: I90665dabaab13a9c9d5f00770496f8ccfccba024
Closes-Bug: #1561947
2016-03-25 17:59:45 +03:00
Tom Cocozzello 851508c2bf Mock swiftclient's functions in tests
swiftclient changed their code so if the chuck size is greater than
zero it will return a generator otherwise it will return the response.
Which would be the object you are looking for.  This causes our tests
to fail since they are always expecting the response instead of a
generator.

Closes-bug: 1556059

Co-Authored-by: avarner <avarner@us.ibm.com>
Change-Id: I62cc037493af87373a75e37e2d9f33b8aedf9889
2016-03-11 12:10:44 +00:00
kairat_kushaev fb77cb73c5 swift: Do not search storage_url for ks v2
Previously, we introduced a re-auth approach for swift store.
In case of single-tenant store we stated that it works with
Keystone v3 only when re-authenticating but we also need to make
the same restriction when receiving swift endpoint from keystone
becase it breaks some installations where auth_url contains
trailing slash.

So now if auth_version is not v3 then we don't search endpoint url
from Keystone in this case and simply return None. It is safe
because we don't do any re-authentication for v1 or v2 and use
old methods for that version.

Change-Id: Id8dab9ed74eef56ffa4937bf29f96888b673ad64
Closes-Bug: #1552132
2016-03-02 12:06:03 +03:00
Jenkins 6c4ae678f5 Merge "Implement re-authentication for swift driver" 2016-03-01 09:35:09 +00:00
Jenkins 14eac13184 Merge "Implement swift store connection manager" 2016-02-29 16:51:16 +00:00
kairat_kushaev 1b782cee85 Implement re-authentication for swift driver
Enable re-authentication when downloading or uploading images.
If single tenant store is used then request the new token
for service user.
If multi tenant store is used then request the new token with
trusts.

Note: Both features are available for Keystone V3 API only.
If store.auth_version is not '3' then use old approach to
receive Swift Connections.

DocImpact: Describe how to enable/disable re-authentication
           and add notes about Keystone v3 support only.

Implements bp prevention-of-401-in-swift-driver

Change-Id: Id4e479e29ae8f71ff93f769246989b4b180f5c68
2016-02-26 10:17:36 +03:00
kairat_kushaev 142cf34c2f Implement swift store connection manager
The patch defines implementation of swift connection manager for
swift driver. It allows to receive swift connections and
update them if user token is going to expire soon.
Connection manager for single tenant store uses swift service
user credentials to receive new token.
Connection manager for multi-tenant store uses trusts to
receive new token and initialize a connection.

Please note that this is first part of bp implementation that
defines framework and helpers for re-authentication.
Implementation of keystoneclient initialization and enabling of
re-authentication for swift store available in next patch.

Implements bp prevention-of-401-in-swift-driver

Change-Id: I61b0fcfe284bdfbf4c0558178318c69617ec6127
2016-02-26 10:08:43 +03:00
Jenkins d4eb2c9ed2 Merge "Change approach to request storage url for multi-tenant store" 2016-02-24 21:03:00 +00:00
Jenkins 48927adfdd Merge "Add small image verifier for swift backend" 2016-02-19 13:18:07 +00:00
Brianna Poulos 73a9deaec1 Add small image verifier for swift backend
In the parent patch, the swift driver is supported for images that
are greater than the 'large_object_size.'  This patch adds support
for images that are less than the 'large_object_size.'

Change-Id: Ifaa15b794a7213c1c393288631d071ac66dcbc81
Partial-Bug: #1516031
2016-02-18 07:06:36 +00:00
kairat_kushaev 68762058cc Change approach to request storage url for multi-tenant store
Multi-tenant store doesn't need to fetch swift storage_url from
store location because it can fetch it from service catalog
in user context.
That allows to avoid subtle errors when uploading/downloading
with scheme = 'swift+config'. In the current implementation
multi-tenant store uses location.swift_url to request swift
endpoint but swift_url is keystone endpoint in that case.
The change provides possibility to get rid of this dependency
and consider context as primary source for swift store url.

Closes-Bug: #1511025

Change-Id: I7bc23dfc11900b55f45fe98144d14f883c381c9f
2016-02-12 03:29:06 +03:00
kairat_kushaev 17b7c9a78e Remove unused parameters from swift connection init
glance_store passes some unused parameters such as tenant, auth_version
and others to Multi-tenant store when initializing Swift connection.
The patch removes these parameters from the Connection __init__
method because glance_store doesn't need to pass them - it passes
a valid auth_token to Swift connection (so it doesn't need to
initialize Keystone client and request the token).

Change-Id: I3805f2bb31b7c75d222867aaefefa0f5c0be3847
2016-02-12 02:13:34 +03:00
Jenkins b1e45582d5 Merge "Use url_for from keystoneclient in swift store" 2016-02-11 03:44:11 +00:00