Commit Graph

213 Commits

Author SHA1 Message Date
kairat_kushaev 6b9133c9b6 Import i18n functions directly
As stated in i18n guide it is normal to import i18n functions
(_, _LW..)  directly and we can include i18n functions in
hacking exceptions.
Also there is no need to make exceptions for six moves
because pep8 passes correctly without it.

Change-Id: I9c9aa490f1447bb7ae221809df7bc110c27d1336
2015-10-16 11:26:11 +03:00
Jenkins 2fcff11b90 Merge "Add support for setting Accept-Language header" 2015-10-14 15:25:03 +00:00
Frode Nordahl ca050ed4c1 Add support for setting Accept-Language header
DocImpact

Closes-Bug: 1480529
Change-Id: I35a37d55edb700a5993bd5cc352335a87a15e47a
2015-10-14 12:57:07 +00:00
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 542941cef0 Merge "Fix Typos in comments" 2015-09-30 18:34:02 +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
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 3651d5c02e Merge "Add parsing the endpoint URL" 2015-09-16 18:14:29 +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
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 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
rahulram 22ce8451a8 Fix Typos in comments
Change-Id: Ib66ec89f6e556093ab00d3f7fb8ad0f3d9912461
2015-08-26 13:41:09 -07: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
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 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
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
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
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
Stuart McLaren bd0aa0672e Fix https stack trace on python 3.4 client
When using the client with python 3.4 and no ssl compression the following
stack trace ocurrs:

 TypeError: startswith first arg must be bytes or a tuple of bytes, not str

Closes-bug: 1442883
Related-bug: 1357430
Change-Id: I8e28f0bb1f3e866f11851247ce31470ca8c2af4f
2015-04-11 11:04:23 +00:00
Stuart McLaren c698b4e322 Fix client when using no ssl compression
Since the release of the 0.16.1 client, using the 'no ssl compression'
option, whether on the command line, or via the library -- Nova does this by
default -- a stack trace was generated.

Closes-bug: 1442664
Related-bug: 1357430

Change-Id: I2b8ddcb0a7ae3cfccdfc20d3ba476f3b4f4ec32d
2015-04-11 11:03:54 +00:00
yatin karel c149a94ee1 glance image-show now have --human-readable option
Added option '--human-readable' to image-show cli which allows users
to display image size in human-readable format.

Change-Id: Ic3452ce4560d3cf90fa7f59f98e5ff42e804f8c9
Closes-Bug: #1434381
2015-03-22 17:26:55 +05:30
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
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 93ca39ba18 Merge "Reduce the set of supported client SSL ciphers" 2015-02-23 16:06:48 +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
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 60e7beb28b Merge "Change oslo.utils to oslo_utils" 2015-02-06 12:44:17 +00:00
Jenkins 0272106717 Merge "Close streamed requests explicitly" 2015-02-06 12:16:46 +00:00
Louis Taylor e99e0c8690 Change oslo.utils to oslo_utils
The oslo.utils libraries are moving away from namespace packages.

This requires oslo.utils>=1.2.0

bp drop-namespace-packages

Change-Id: I803df61e91eabb96329d859aef6bea03530fb84f
2015-02-05 22:27:16 +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
Louis Taylor 878bdcbdbc Remove openstack.common.importutils
This module now lives in oslo.utils, so import it from there.

Change-Id: I41fa4897fc820596fb010336044ff4c493017d5a
2015-01-28 02:12:18 +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
Jenkins dac71b4be9 Merge "Curl statements to include globoff for IPv6 URLs" 2015-01-08 14:58:41 +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