Commit Graph

61 Commits

Author SHA1 Message Date
wangxiyuan bf02b048bf Support image deletion in batches in v2
Client doesn't support image deletion in batches in v2 now.
It's useful. So it's need to add it.

Change-Id: Idf5a6890b3fd01a65fecab2033b21367c30bc6b1
Closes-bug:#1485407
2015-10-10 10:18:02 +08:00
Jenkins d90c7d6896 Merge "Use dictionary literal for dictionary creation" 2015-10-09 21:11:42 +00:00
Jenkins c567edc2b2 Merge "Added unit tests for 'Unicode support shell client'" 2015-10-09 16:20:37 +00:00
Jenkins 8c0c3c9ed4 Merge "Replace exception_to_str with oslo.utils function" 2015-09-30 18:10:40 +00:00
Jenkins 385085eb55 Merge "Fix human readable when size is None" 2015-09-28 11:49:14 +00:00
Darja Shakhray abf0381e36 Added unit tests for 'Unicode support shell client'
Added unit tests for https://review.openstack.org/#/c/206037/

Change-Id: I78369fadeb8fee6434a4d5d9ded7e9e877043487
Closes-bug: #1499390
2015-09-28 12:24:23 +03:00
Flavio Percoco c31c136557 No auth when token and endpoint are passed
The latest change to the auth_required logic introduced a bug were even
when the token and endpoint were passed, authentication was being
required.

This patch fixes that issue and makes sure that authentication is not
required when these 2 arguements are present.

Closes-bug: #1499540

Change-Id: I4c9c15ba526378970da5461511ed922d42c5a9f9
2015-09-25 10:59:54 +02:00
Ankit Agrawal 557acb1815 Use dictionary literal for dictionary creation
Dictionary creation could be rewritten as a dictionary literal.
for example:

expect_namespace = {}
expect_namespace['namespace'] = 'MyNamespace'
expect_namespace['protected'] = True

could be rewritten as

expect_namespace = {
    'namespace': 'MyNamespace',
    'protected': True
}

TrivialFix

Change-Id: I76265c26861916ed01cadb62e9201aa871183566
2015-09-24 06:31:32 -07:00
kairat_kushaev c6addc722c Replace exception_to_str with oslo.utils function
The oslo.utils function has exception_to_unicode that can
replace glance util function exception_to_str.
So we don't to have this exception_to_str function in glance
anymore.

Change-Id: I332bc55558087920fdd6ae2d822bece5166f5ba6
2015-09-22 15:40:02 +03:00
Jenkins 9f8163ec82 Merge "Don't get the image before deleting it" 2015-09-18 10:03:27 +00:00
Jenkins 3651d5c02e Merge "Add parsing the endpoint URL" 2015-09-16 18:14:29 +00:00
Flavio Percoco b8a881f5ea Don't get the image before deleting it
The client currently downloads the image metadata to check if it's deleted
or not. This logic belongs to the server and it's already implemented
there. Instead of getting the image, send the delete request and catch
the 404 error, which is already raised by the server.

Change-Id: I1e6ef42340f8e380ff99b9d6ca7ea416e0eebfbc
Closes-bug: #1496305
2015-09-16 09:34:34 +00:00
Stuart McLaren 3d3d8296c4 Fix human readable when size is None
If an image size is null don't stack trace when listing.

Change-Id: Iba18470edbe032d1d01380372d57fa17adef5f7e
Closes-bug: 1495632
2015-09-14 17:27:43 +00:00
Erno Kuvaja 160825f909 Fixes CLI client called without subcommands
If CLI client is called without any subcommands or arguments it will
fail with """'Namespace' object has no attribute 'command'""". This
is coming from the getattr which does not have alternate value
specified.

Closes-Bug: #1494259

Change-Id: I461f0d4a91f3af2224bafc14a88572a8e4a3c051
2015-09-11 12:56:08 +00:00
Flavio Percoco 5026774bd1 Don't make help require auth parameters
The `help` command was behaving a bit funky. This patch re-orders the
code a bit so that the `help` command will be parsed at the very
beginning before running other commands and checks.

It also allows to get help without downloading/checking schemas and
without requiring auth credentials (previously required by the schema
operations).

Change-Id: Ib7b10d4d80f15e6b75bb8644d7d916bef09413d6
Closes-bug: #1490457
2015-09-09 10:47:13 +00:00
Jenkins 5507d84901 Merge "Consider --os-token when using v2" 2015-09-08 21:01:04 +00:00
Jenkins f387929878 Merge "Check if v2 is available and fallback" 2015-09-08 20:45:52 +00:00
Takashi NATSUME 19480df10a Add parsing the endpoint URL
Add parsing the endpoint URL and check the path string only
in order to decide the API version.

Change-Id: Ib0a035f3bed31e2162a1231a5f5dcc3907d37243
Closes-Bug: #1489727
2015-09-08 20:52:45 +09:00
David Edery 75ec9033c2 check for None value in utils.safe_header
In case that a sensetive header (that should be obscured by its SHA1
hash) is None, the safe_header throws an exception which fails the
calling process and by that may harm the functionality.

Change-Id: I56944a382fd546eba0a6dd6d6b1cecf83b1dc106
Closes-Bug: #1491311
2015-09-08 00:24:36 +03:00
Flavio Percoco 1322fbc5d8 Consider --os-token when using v2
The `_cache_schemas` call currently forces authentication even when the
`auth_token` and `os_image_url` are passed. Instead of handling forced
authentications, let the client use the passed arguments and
authenticate only once if needed.

This was not caught by the existing tests because the call to
`_cache_schemas` was mocked.

Change-Id: I93cec9a68cafc0992d14dab38114d03e25f1e5da
Closes-bug: #1490462
2015-09-04 13:31:55 +02:00
Flavio Percoco 47423ebbb2 Check if v2 is available and fallback
We have a basic implementation for a fallback mechanism that will use v1
rather than v2 when downloading schema files from glance-api fails.
However, this is not sound. If the schemas are cached already, we won't
check if v2 is available and fail to fallback.

This patch fixes the aforementioned issue by getting the list of
available versions from the server only when the API versions was not
explicitly specified through the CLI. That is, for all commands that
don't pass `--os-image-api-version 2`, we'll check v2's availability and
we'll fallback to v1 if it isn't available.

This patch also changes how we handle `/versions` calls in the client.
The server has been, incorrectly, replying to requests to `/version`
with a 300 error, which ended up in the client re-raising such
exception. While I think 300 shouldn't raise an exception, I think we
should handle that in a spearate patch. Therefore, this patch just
avoids raising such exception when `/version` is explicitly called.

This fallback behaviour and the check on `/versions` will be removed in
future versions of the client. The later depends on this bug[0] being
fixed.

[0] https://bugs.launchpad.net/glance/+bug/1491350

Closes-bug: #1489381
Change-Id: Ibeba6bc86db2a97b8a2b4bd042248464cd792e5e
2015-09-04 13:31:55 +02:00
Flavio Percoco 1e2274aef0 Password should be prompted once
There's a corner case where password may be requested twice. In a fresh
environment, when schemas have not be downloaded for v2, the client will
ask for a password to download the schemas and then it'll ask for the
password again to run the actual command. This happens because we parse
the CLI arguments twice to make sure we're parsing them for the right
client version.

This patch checks if the password is unset in the newly parsed arguments
and if it's been set in the previously parsed ones. In this case it
keeps the set password. I believe this approach is safer than re-using
the already parsed arguements which may have been parsed for a different
API version (might happen because we fallback to v1 if v2 is not
available).

Change-Id: I080253170e3e84a90363e5bb494cf137895fe2e7
Closes-bug: #1488892
2015-09-01 18:03:41 +02:00
Stuart McLaren 618637a5bd Remove custom SSL compression handling
Custom SSL handling was introduced because disabling SSL layer compression
provided an approximately five fold performance increase in some
cases. Without SSL layer compression disabled the image transfer would be
CPU bound -- with the CPU performing the DEFLATE algorithm.  This would
typically limit image transfers to < 20 MB/s. When --no-ssl-compression
was specified the client would not negotiate any compression algorithm
during the SSL handshake with the server which would remove the CPU
bottleneck and transfers could approach wire speed.

In order to support '--no-ssl-compression' two totally separate code
paths exist depending on whether this is True or False.  When SSL
compression is disabled, rather than using the standard 'requests'
library, we enter some custom code based on pyopenssl and httplib in
order to disable compression.

This patch/spec proposes removing the custom code because:

* It is a burden to maintain

 Eg adding new code such as keystone session support is more complicated

* It can introduce additional failure modes

 We have seen some bugs related to the 'custom' certificate checking

* Newer Operating Systems disable SSL for us.

 Eg. While Debian 7 defaulted to compression 'on', Debian 8 has compression
 'off'. This makes both servers and client less likely to have compression
 enabled.

* Newer combinations of 'requests' and 'python' do this for us

 Requests disables compression when backed by a version of python which
 supports it (>= 2.7.9). This makes clients more likely to disable
 compression out-of-the-box.

* It is (in principle) possible to do this on older versions too

 If pyopenssl, ndg-httpsclient and pyasn1 are installed on older
 operating system/python combinations, the requests library should
 disable SSL compression on the client side.

* Systems that have SSL compression enabled may be vulnerable to the CRIME
(https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2012-4929) attack.
Installations which are security conscious should be running the Glance
server with SSL disabled.

Full Spec: https://review.openstack.org/#/c/187674
Blueprint: remove-custom-client-ssl-handling

Change-Id: I7e7761fc91b0d6da03939374eeedd809534f6edf
2015-08-26 12:26:21 +00:00
Jenkins 17375a422c Merge "V2: Do not validate image schema when listing" 2015-08-20 17:28:21 +00:00
Gorka Eguileor 8d118ccedc Require disk and container format on image-create
Currently glanceclient doesn't enforce disk-format or container-format
presence in the command line on image-create when providing image data
(with --file, --location, --copy-from), which means that the POST
request is made with the whole image and error is reported by Glance
API.

This post enforces presence of those arguments when image data is
provided so we can get the error quicker and avoid sending unnecessary
data over the network.

Change-Id: I5914fa9cfef190a028b374005adbf3a804b1b677
Closes-Bug: #1309272
2015-08-14 09:59:17 +02:00
Jenkins 13af690396 Merge "Use API v2 as default" 2015-08-13 23:43:59 +00:00
Jenkins 89b2dc58da Merge "Ship the default image schema in the client" 2015-08-12 11:49:45 +00:00
Flavio Percoco 3949e0e918 Ship the default image schema in the client
Now that we have stable branches for clients, it's easier to keep track
of the current default image's schema in Glance and update it
respectively. This patch adds the current image schema, including the
schema-properties.

One good reason to do this is to be able to react when a running Glance
instance is not around to be introspected. It's really unfortunate that
things like help text can't be rendered when there image schema is not
available in the system.

We could keep the schema in a json file but rather than shipping data
files with glanceclient we can just have it in the python modules.

Change-Id: I9b8cc1d18d6717ccf991fb8149ab13c06d653ee4
Closes-bug: #1481729
2015-08-12 11:10:54 +02:00
Fei Long Wang 181131ef2e Use API v2 as default
Now we have claimed v2 is the current API version of Glance,
we should change the Glance client as well to be consistent
with Glance server.

DocImpact

Change-Id: I09c9e409d149e2d797785591183e06c13229b7f7
2015-08-11 14:01:28 +12:00
Stuart McLaren 43769d6cc7 V2: Do not validate image schema when listing
Previously when listing images via v2, the first image of each batch
was validated against the v2 schema.

This could lead to unpredictable behaviour where a particular image
which failed the schema check may or may not be the first of a batch.

In some cases it also meant that operation by one user could affect the
ability of another other to list images.

Change-Id: I22974a3e3d9cbdd254099780752ae45ff2a557af
Closes-bug: 1477910
2015-08-10 10:24:57 +00:00
Jenkins 8af084d5a3 Merge "Support for Metadata Definition Catalog for Tags" 2015-08-06 16:08:04 +00:00
Jenkins 6d28b513e3 Merge "Add unicode support for properties values in v2 shell" 2015-08-03 23:20:19 +00:00
Darja Shakhray 22868aa9bb Add unicode support for properties values in v2 shell
This code allows to set unicode values to v2 properties.

Change-Id: I5f9c29a3e458808dd95375c7557dfce0c4f09038
Closes-bug: #1475769
2015-08-03 13:09:43 +00:00
Jenkins 4712765689 Merge "Fix failure to create glance https connection pool" 2015-07-29 20:39:37 +00:00
Haikel Guemar c41dcc9f43 Fix failure to create glance https connection pool
Due to a typo in an attribute named, an Attribute error is raised
causing failure in connection to glance through HTTPS

Urllib3 PoolManager class has a connection_pool_kw attribute
but not connection_kw

Closes-Bug: #1479020
Change-Id: Id4d6a5bdcf971d09e80043fd2ab399e208fd931c
2015-07-28 17:53:09 +02:00
Darja Shakhray ec0f2dfd85 Enable flake8 checks
This commit enables new flake8 checks:
* E265  block comment should start with '# '
* H405  multi line docstring summary not separated with an empty line
* E123  closing bracket does not match indentation of opening bracket's line
* H238  old style class declaration, use new style (inherit from `object`)
* E128  continuation line under-indented for visual indent
and makes related changes in the code.

Change-Id: Ie993afc930f6b74d7a990bcaa9fc0e9f5ba1585c
2015-07-21 17:08:27 +03:00
Kamil Rykowski d9d586942b Extend unittests coverage for v2 tasks module
Add new tests for v2 tasks module to cover following cases:
- getting list of tasks using the marker
- getting list of tasks using sort_key & sort_dir keys

Change-Id: Ic126999ebb16e51cc472fe8f86dfe1fced0bc016
Closes-Bug: 1433637
2015-07-20 07:25:45 +00:00
Wayne Okuma c0e90fa2bd Support for Metadata Definition Catalog for Tags
This set provides API and shell commands support for:
- CRUD on metadef_tags;

Change-Id: I09bdf43edee6fff615d223f1a6df7c15a1e40565
Implements: blueprint metadefs-tags-cli
DocImpact
2015-07-16 14:00:50 -07:00
wangxiyuan b48ff98e16 Fix exception message in Http.py
In common.http.py, the exception RequestTimeout has
wrong message.This patch fixed it.

Change-Id: Ie8ff188b9c82ce424cb8177278f36e4d1275b306
2015-07-14 09:01:12 +08:00
Jenkins 16ab18b64d Merge "Fix an issue with broken test on ci" 2015-07-13 21:34:19 +00:00
Mike Fedosin e240bddd5a Fix an issue with broken test on ci
Several tests with cert verification are broken. This
code fixes it by setting right imports. Also some typos
are fixed too.

Change-Id: Ie014f90714c3dabee65459fd704dd11b1770c7de
Closed-Bug: #1472234
2015-07-13 17:54:41 +03:00
rico.lin e976032a95 Remove usage of assert_called_once on Mock objects
mock 1.1.0 was released on 10 July 2015 which prevents users from using
non-existent assertion methods. This broke the test in the diff.

Co-Authored-By: Ian Cordasco <graffatcolmingov@gmail.com>
Closes-Bug: #1473454
Change-Id: I162b76bbd7d96c96787a8dd8f9642ca1c80c596a
2015-07-10 15:57:51 -05:00
Corey Bryant 1b93adc8fb Account for dictionary order in test_shell.py
Change-Id: Id15f3d642e8fcbd663f12b32f52b6014e32574a5
Closes-Bug: 1468485
2015-06-29 10:22:13 -04:00
Jenkins cc38f51086 Merge "Add v2 support for the marker attribute" 2015-06-22 04:52:27 +00:00
Brad Pokorny ea01f13be2 Add v2 support for the marker attribute
The v2 Glance client implementation ignores the marker attribute if
it's passed to the client as part of the kwargs.  Include support
for the attribute, as the v1 client supports it and it makes it
easier to work with the Glance client.

Change-Id: Ifaa59129bc4178212b890ea591673cb154e0f110
Closes-bug: 1465373
2015-06-19 15:03:37 -07:00
Cindy Pallares 997c12d3ab Import only modules and update tox.ini
As stated in the OpenStack Hacking Guidelines, it is prefered
that only modules should be imported.

Also updated tox.ini to ignore opestack/common among others.

Change-Id: I2f0a603c31052eadee581c11880c0ec6bd392829
2015-06-17 10:56:37 -05:00
Jenkins 71d8528364 Merge "Close iterables at the end of iteration" 2015-06-16 19:01:18 +00:00
Jenkins 0d22e821f9 Merge "Add parameter 'changes-since' for image-list of v1" 2015-06-15 18:11:27 +00:00
Robert Collins 43621dc1ac Close iterables at the end of iteration
This fixes a bug where if iteration is interrupted, we're stuck until
the iterable is garbage collected, which can be a very long time (e.g. if
the iterable is held in an exception stack frame).

Co-authored-by: Stuart McLaren <stuart.mclaren@hp.com>

Change-Id: Ibe9990e8c337c117a978b1cd8ec388c4bc6d3b4b
Closes-bug: 1461678
2015-06-11 18:11:39 +00:00
Jamie Lennox 5ce9c7dc96 Make glanceclient accept a session object
To make this work we create a different HTTPClient that extends the
basic keystoneclient Adapter. The Adapter is a standard set of
parameters that all clients should know how to use like region_name and
user_agent. We extend this with the glance specific response
manipulation like loading and sending iterables.

Implements: bp session-objects
Change-Id: Ie8eb4bbf7d1a037099a6d4b272cab70525fbfc85
2015-06-11 13:11:56 +00:00