254 Commits

Author SHA1 Message Date
Jamie Lennox
27f70bbd58 Remove keystoneclient mocks
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
2015-03-28 14:19:52 +11:00
Jamie Lennox
02b1a05226 Replace mox in tests with requests-mock
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
2015-03-28 14:16:00 +11:00
Kamil Rykowski
13b5a5ade1 Remove redundant FakeSchemaAPI __init__ method
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
2015-03-26 12:42:18 +00:00
Jenkins
6db625f287 Merge "Extend images CLI v2 with new sorting syntax" 2015-03-16 20:12:42 +00:00
Jenkins
82143e26d3 Merge "Add the ability to specify the sort dir for each key" 2015-03-16 20:11:50 +00:00
Jenkins
c32a41415d Merge "Adds the ability to sort images with multiple keys" 2015-03-16 20:11:34 +00:00
Mike Fedosin
3f3066be97 Extend images CLI v2 with new sorting syntax
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
2015-03-16 19:31:49 +03:00
Mike Fedosin
bbd27d5276 Add the ability to specify the sort dir for each key
Adds client code to consume API modified in change
Ib43b53abfba7cb5789d916a014376cf38fc5245b

Extends CLI for v2 with multiple sort dirs
Example:
glance --os-image-api-version 2 image-list \
--sort-key name --sort-dir asc --sort-key size --sort-dir desc

Implements-blueprint: glance-sorting-enhancements
DocImpact
Depends-On: Ib43b53abfba7cb5789d916a014376cf38fc5245b
Change-Id: Ia20716f3c75299f796879299da317b2e81496088
2015-03-16 14:29:06 +03:00
Mike Fedosin
fc79467ff6 Adds the ability to sort images with multiple keys
Adds client code to consume API modified in change
Ib7a6aeb2df3bc5d23fe8e070290b5bfcab00c0f5

Extends CLI for v2 with multiple sort keys
Example:
glance --os-image-api-version 2 image-list --sort-key name --sort-key size

Implements-blueprint: glance-sorting-enhancements
Change-Id: If79779a4c52c8dc5c4f39192d3d247335a76ba24
DocImpact
Closes-Bug: 1221274
2015-03-13 18:35:00 +03:00
Steve Lewis
f6f573316c Apply expected patch format when updating tags in v2.images
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
2015-03-12 15:18:20 -07:00
Jenkins
2858645cef Merge "Unit tests covering missing username or password" 2015-03-10 13:22:43 +00:00
Jenkins
c7c4ac9e85 Merge "v2: Allow upload from stdin on image-create" 2015-03-06 19:55:15 +00:00
Jenkins
ab52bf3ce2 Merge "Unify using six.moves.range rename everywhere" 2015-03-04 16:29:50 +00:00
Jenkins
5ce1de9da4 Merge "https: Prevent leaking sockets for some operations" 2015-03-04 08:38:19 +00:00
Louis Taylor
96871b975b Fix tests failing if keystone is running locally
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
2015-03-02 17:19:16 +00:00
Jenkins
99c46d64a0 Merge "Strip json and html from error messages" 2015-03-01 16:19:15 +00:00
Jenkins
db0179f5c4 Merge "Register our own ConnectionPool without globals" 2015-02-26 21:29:06 +00:00
Erno Kuvaja
2d67dfa97a Unify using six.moves.range rename everywhere
Mainly to improve consistency, use range() from six.moves
renames across glance.

Behaves consistently like py2 xrange() and py3 range().

Change-Id: I7c573a3a9775f454b98d25f2a14f8e9f5f4ac432
2015-02-25 12:17:24 +00:00
Jenkins
654ba87a89 Merge "Glance image delete output" 2015-02-20 14:48:49 +00:00
Jenkins
72f0bc3579 Merge "Update HTTPS certificate handling for pep-0476" 2015-02-19 17:58:58 +00:00
Stuart McLaren
ef9fd9fca0 https: Prevent leaking sockets for some operations
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
2015-02-18 12:31:24 +00:00
Abhishek Talwar
f7cdc3eefe Glance image delete output
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>
2015-02-17 11:27:24 +01:00
d34dh0r53
01caf4e734 Strip json and html from error messages
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
2015-02-16 10:01:53 -06:00
Michal Dulko
b47925eda1 Unit tests covering missing username or password
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
2015-02-09 14:32:17 +01:00
Ian Cordasco
7ee96cbe39 Register our own ConnectionPool without globals
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
2015-02-06 13:49:13 -06:00
Jenkins
1c37721287 Merge "Return 130 for keyboard interrupt" 2015-02-06 16:23:21 +00:00
Jenkins
0272106717 Merge "Close streamed requests explicitly" 2015-02-06 12:16:46 +00:00
Rakesh H S
96ff6e46c4 Return 130 for keyboard interrupt
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
2015-02-05 05:08:59 +00:00
Ian Cordasco
db743e3635 Ignore NoneType when encoding headers
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
2015-02-03 13:22:44 -06:00
Jenkins
4bfd8d5097 Merge "Remove openstack.common.strutils" 2015-02-02 04:49:32 +00:00
Flavio Percoco
93c9bc1fe0 Add a --limit parameter to list operations
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
2015-01-29 10:37:55 +00:00
Louis Taylor
b818826420 Remove openstack.common.strutils
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
2015-01-27 19:22:42 +00:00
Ian Cordasco
f2107512ee Close streamed requests explicitly
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
2015-01-15 17:20:57 -06:00
Jamie Lennox
62df6c669f Handle HTTP byte returns in python 3
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
2015-01-14 12:32:07 +10:00
Stuart McLaren
6d21959e15 v2: Allow upload from stdin on image-create
For example:

$ glance --os-image-api-version 2 image-create < /tmp/data

This is consistent with v1.

DocImpact
Closes-bug: 1408033

Change-Id: Ifed4ece9e4e02a46d80b49a8e4fc372f1a304241
2015-01-07 17:47:31 +00:00
Louis Taylor
df02ee8e2a Fix Requests breaking download progress bar
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
2015-01-04 20:52:00 +00:00
Jenkins
7ce1ff9325 Merge "Add os_ prefix to project_domain_name/id" 2015-01-04 10:40:07 +00:00
James Page
b96f613026 Update HTTPS certificate handling for pep-0476
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
2014-12-19 13:01:32 +00:00
Travis Tripp
9a4d8580e8 Support Pagination for namespace list
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
2014-12-10 23:21:41 -07:00
Flavio Percoco
3989cd202d Support schema types with non-str value
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
2014-12-10 13:23:36 +01:00
Flavio Percoco
9829d7b6b9 Don't require version to create Client instance
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
2014-12-09 14:45:06 +00:00
Oleksii Chuprykov
bd73a5482c Add os_ prefix to project_domain_name/id
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
2014-12-09 11:34:57 +00:00
Jenkins
69981798bc Merge "Send identity_headers through the wire" 2014-12-03 12:08:40 +00:00
Erno Kuvaja
8e02b2a641 Allow --file in image-create with v2 Image API
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
2014-11-26 09:34:48 +00:00
Flavio Percoco
5080d10099 Send identity_headers through the wire
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
2014-11-25 10:01:39 +00:00
Jenkins
3b6754a8cc Merge "Adds tty password entry for glanceclient" 2014-11-25 09:38:15 +00:00
Jenkins
265bb4aa17 Merge "Add bash completion to glance client" 2014-11-20 10:06:53 +00:00
Jenkins
9a4fec4a1e Merge "Refactor method of constructing dicts in some tests" 2014-11-20 09:53:56 +00:00
Jenkins
46bfeb4f2c Merge "Don't set X-Auth-Token key in http session header if no token provided" 2014-11-20 09:53:49 +00:00
Louis Taylor
4194a55a09 Add --property-filter option to v2 image-list
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
2014-11-14 10:45:31 +00:00