The majority of the mocks on keystoneclient are not needed. Instead we
use the fixtures that keystoneclient provides to create well formed
responses and use requests_mock to stub out those values when accessed.
This is a closer to real usage pattern and the way that most client
projects are now handling keystoneclient auth.
Change-Id: I294aca1d11c9c5cfb4b82ad16476af4000efee1c
requests-mock is a tool specifically designed for mocking responses from
the requests library. Use that instead of handling mox and mock
ourselves.
Change-Id: Ifd855b8d6c1b401e29ac210593c48d2da87a571b
Currently, the FakeSchemaAPI in tests/utils has an overriden __init__
method which simply calls super of FakeAPI and doesn't perform any extra
operations. This is redundant, because same effect will be achieved when
__init__ definition is omitted in FakeSchemaAPI. Additionally it uses
'cls' as first param instead of 'self' which breaks naming convention.
Change-Id: I3e72adfbc7b67076748f640d74507ff28c6060d7
Closes-Bug: 1418508
This code enables new syntax for sorting output with multiple
keys and directions based on API Working group sorting
guidelines.
It's a client code to consume API modified in change
Ie4ccfefa0492a3ac94cc7e22201f2f2be5c1cdbb
Example:
glance --os-image-api-version 2 --sort name:desc,size:asc
Implements-blueprint: glance-sorting-enhancements
DocImpact
Depends-On: Ie4ccfefa0492a3ac94cc7e22201f2f2be5c1cdbb
Change-Id: I36a9fa9f0508fea1235de2ac3a0d6a093e1af635
Currently, glanceclient.v2.update builds a patch request that does not
match glance API.
This patch overrides the default behaviour to customize the patch
request with the right format for the API.
Co-Authored-By: Steve Lewis <steve.lewis@rackspace.com>
Fixes bug 1306774
Change-Id: If0739ac285da1e741bfa40b6c719331a5ce49319
This mocks out the call to python-keystoneclient's Session.get_token(),
preventing any actual calls being made to a keystone service, running or
not.
Change-Id: I24b0874d8e67b46b7c2294d4ac54efa861561dff
Closes-bug: 1423170
Mainly to improve consistency, use range() from six.moves
renames across glance.
Behaves consistently like py2 xrange() and py3 range().
Change-Id: I7c573a3a9775f454b98d25f2a14f8e9f5f4ac432
Other OpenStack services which instantiate a 'https' glanceclient using
ssl_compression=False and insecure=False (eg Nova, Cinder) are leaking
sockets due to glanceclient not closing the connection to the Glance
server.
This could happen for a sub-set of calls, eg 'show', 'delete', 'update'.
netstat -nopd would show the sockets would hang around forever:
... 127.0.0.1:9292 ESTABLISHED 9552/python off (0.00/0/0)
urllib's ConnectionPool relies on the garbage collector to tear down
sockets which are no longer in use. The 'verify_callback' function used to
validate SSL certs was holding a reference to the VerifiedHTTPSConnection
instance which prevented the sockets being torn down.
Change-Id: Idb3e68151c48ed623ab89d05d88ea48465429838
Closes-bug: 1423165
Deleting an already deleted image using admin user is throwing an
error "404 Not Found" which is confusing. Deleting an image that does
not exist throws "No image with a name or ID of 'image-id' exists."
Updated the code so that trying to delete an already deleted image
throws "No image with an ID of 'image-id' exists." error.
Closes-Bug: #1333119
Change-Id: I8f9a6174663337a0f48aafa029a4339c32eb2134
Co-Authored-By: Abhishek Talwar <abhishek.talwar@tcs.com>
Co-Authored-By: Kamil Rykowski <kamil.rykowski@intel.com>
Error messages were being passed with either JSON or HTML formatting
leading to an unpleasant user experience. This strips the JSON or HTML
tags and presents the clean error message to the user.
Rewrote the lispy function to be more pythonic, added test cases
and cleaned up some pep8 violations.
Removed commented out cruft from a previous version of this
patch.
Changed the HTML details from a set to a list in order to ensure
the ordering of the exception details.
Added code to eliminate the duplicate detail messages from the list
and reordered the assertion string to match actual output.
Refactored duplicate elimination code to be more readable and
reliable.
Some reworking of the duplication elimination loop to make it
more readable.
Removed unneeded conditional to filter out empty elements.
Change-Id: I79985b3e305cb30328a3c16b025315a8e969243d
Closes-Bug: 1398838
After fixing message displayed when client is executed without
required environment variables exported (OS_USERNAME, OS_PASSWORD,
OS_PROJECT_NAME, OS_AUTH_URL) regression tests should be added. I've
also fixed an issue causing tests using make_env method to always use
FAKE_V2_ENV, even in ShellTestWithKeystoneV3Auth.
Change-Id: I800c8fa11ee45d19f179bd030426db86a93d9f6a
Closes-Bug: 1419788
Partial-Bug: 1355252
Currently, on systems like Fedora and Debian, it is possible to import
urllib3 as well as requests.packages.urllib3. They functionally point to
the same code but sys.modules considers them to be separate items. When
downstream packagers unvendor urllib3 from requests, they also change
all the imports inside of the package. So if the code imports urllib3
from requests.packages.urllib3 and modifies globals in a submodule, that
will not be visible to requests since it has been rewritten to use
urllib3 (not requests.packages.urllib3). By handling this logic
ourselves, we can issue a release until upstream packages and requests
can fix this and cut a new release.
Change-Id: Ic77ce8a06d9d148a899b4b8695990fca8fdaefc5
Closes-bug: 1396550
When keyboard interrupt is received by glanceclient, the return code as
of now is 1.
But since the client was terminated by an keyboard interrupt, the return
code should be 130. (http://tldp.org/LDP/abs/html/exitcodes.html)
It is useful when people are writing automation test cases and want to
validate based on the return code.
Change-Id: Ia70116ab6f0708a0ce6eeaed07c1e7a56e68c9f4
Closes-Bug: #1373231
Some generated header values may in fact be None. Trying to encode None
causes the client to fail with an exception and cannot be worked around
by the user.
Change-Id: I638b1fba0ef9a07d726445d8c2cdd774140f5b83
Closes-bug: 1415935
In v2, we use the link header during paginations to know when there are
more images available in the server that could be returned in the same
request. This way, it's possible to iterate over the generator returned
by list and consume the images in the server.
However, it's currently not possible to tell glanceclient the exact
number of images we want, which basically means that it'll *always* go
through the whole list of images in the server unless the limit is
implemented by the consumer.
DocImpact
Change-Id: I9f65a40d4eafda6320e5c7d94d03fcd1bbc93e33
Closes-bug: #1415035
This module now lives in oslo.utils, so import it from there instead.
Co-Authored-By: Ian Cordasco <ian.cordasco@rackspace.com>
Change-Id: Ib35dc840992433542490670781badd9529ec8947
If we don't explicitly close a response after streaming its download,
then we can run into HTTPConnectionPool full warnings. It also will hurt
performance if we have to continuously create new sockets for new
responses. Calling close will return the connection to the pool so it
can be reused. Note this is only necessary when streaming a response. If
we don't stream it, then requests will return the connection to the pool
for us.
Change-Id: I803bd4dd0e769c233501d5e5ff07a19705fbe233
Closes-bug: 1341777
The returns from requests' response.content is a bytes type. Under
python 3 this fails in error handling and string conversion. The
response.text variable should be used to treat a response body as a
string.
Closes-Bug: #1407531
Change-Id: Ifd588b5f6820ef21beb186d88d0b3f1a267695aa
For example:
$ glance --os-image-api-version 2 image-create < /tmp/data
This is consistent with v1.
DocImpact
Closes-bug: 1408033
Change-Id: Ifed4ece9e4e02a46d80b49a8e4fc372f1a304241
The move to the requests library (dbb242b) broke the progress bar during
downloading an image with --progress enabled, due to requests returning
a generator, which has no __len__ function. This patch adds an iterable
wrapper which provides the length, sourced from Content-Length headers.
Closes-Bug: #1384664
Change-Id: I48598a824396bc6e7cba69eb3ce32e7c8f30a18a
This pep (included in python 2.7.9) changes the behaviour of SSL
certificate chain handling to be more py3 like.
Include required new exception behaviour in the list of
exceptions to translate under py2.
https://github.com/python/peps/blob/master/pep-0476.txt
Closes-Bug: 1404227
Change-Id: I7da1a13d1ec861a07fd96684d0431508a214a2c8
The rest api metadefs/namespaces supports pagination using the parameters
of limit, marker, sort_dir, & sort_key. However, the glance client isn't
passing those parameters through (they come in as kwargs). This is
preventing pagination from working properly in horizon.
This is affecting Horizon support: https://review.openstack.org/#/c/104063/
Change-Id: Ib349cf3a3a437eb1711f350b37d0bd0e7d01330a
Closes-Bug: 1381816
Change I75da1e9309e0f7ef8839dea3ec9c99c58edc5d63 introduced some
properties' types which are not string. This broke the `schema_args`
utility since lists are not hashable and there was no support for such
type values.
This patch fixes this issue with a very glance specific strategy in
which this values are assumed to have a `null` type and another type -
string, integer, etc. The fix ignores `null` options and it takes the
first non-null type as the valid one.
The patch adds support for enum types that accept `None`
Closes-bug: #1401032
Change-Id: I250e8912aca262a56c54ac59bb24f917e5d8cfce
We currently require a version to always be passed to discover the
client version that should be loaded. However, this information is
commonly present in the URL instead. The current behavior forces
consumers of the library to keep the required version around and/or to
strip it themselves from the URL.
This patch relaxes that requirement by making the version a keyword and
requesting instead an endpoint to be passed. The patch gives priority to
the version in the endpoint and falls back to the keyword if the later is
not present.
Follow-up patches will improve this code making it interact a bit more
with the endpoint's catalog.
Closes-bug: #1395714
Change-Id: I4ada9e724ac4709429e502b5a006604ca0453f61
Running glance without defining --os-tenant-id and
--os-tenant-name leads to AttributeError. Add os_ prefix
to project_domain_name and project_domain_id because args
object doesn't have them
Closes-Bug: #1384759
Change-Id: Id85569aad538efcf327312d9936bb6463279ce34
Allows passing --file and --progress to glance image-create with Image API v2.
if --file is present the image-create effectively calls image-upload with the
newly created image's id and the '--file' + '--progress' paramaters. The image
metadata will be printed after the upload call instead of after creation.
In a case argumented file does not exist the image will not be created and
error will be printed instead.
DocImpact
Closes-Bug: #1324067
Change-Id: I5d41fb2bbeb4e56213ae8696b84bf96b749414f8
Change I09f70eee3e2777f52ce040296015d41649c2586a, introduced a bug where
the identity_headers are not added to the request headers anymore
causing the former to be completely ignored and useless.
This patch fixes that issue by restoring the previous code. A new test
has been added to avoid regressions.
Closes-bug: #1394965
Change-Id: I1b1633636448398cf3f41217f1d671b43ebd9946
The option is present in the v1 shell, but missing from the v2 shell. This
allows the user to filter based on any image property.
Example:
$ glance --os-image-api-version 2 image-list --property-filter os_distro=NixOS
DocImpact
Closes-Bug: #1383326
Change-Id: Ia65a08520e3eaf3ecd9b9018be9f6a8e2d3d4f0b