Commit Graph

185 Commits

Author SHA1 Message Date
Brian Rosmaita 4511a445d0 Add image-list filter for multihash
This was missed when multihash support was added to the glanceclient.
The os_hash_value is an indexed field in the API.

Includes a release note.

Closes-bug: #1788271

Change-Id: Ibfe28b8c644967b7e0295dfd3f55c3ae1b0cbb2d
2019-01-17 14:22:48 -05:00
Zuul c4c92ecb51 Merge "Show the backend store info" 2018-11-15 07:31:18 +00:00
Liang Fang 5fb14f5ebb Show the backend store info
When running "glance -v image-list" there's no store info listed, so
user cannot know the type of the backend. This patch added an new option
"--include-stores" and is to add the store id to the output of "glance
image-list --include-stores".

The final output may like:
+-----+------+-------------+-----+----------+--------+-----+------+
| ID  | Name | Disk_format | ... | Size     | Status |Owner|Stores|
+-----+------+-------------+-----+----------+--------+-----+------+
| xxx | img1 | raw         | ... | 10737418 | active | xxx | ceph |
| xxx | img2 | raw         | ... | 5086345  | active | xxx | file |
+-----+------+-------------+-----+----------+--------+-----+------+

Change-Id: If86ef714c3aa03ce43ef29f26892f431f4766560
Co-authored-by: Jack Ding <jack.ding@windriver.com>
Signed-off-by: Liang Fang <liang.a.fang@intel.com>
2018-11-08 17:50:26 -08:00
imacdonn 1156346dc2 Don't quote colon in HTTP headers
Since the introduction of quoting of header content in
https://review.openstack.org/568698, the 'x-image-meta-location' header
has been broken, because urllib.quote() is really intended to be applied
to only the path section of a URL, but in this case, it gets applied to
the entire URL, and catches the colon that separates the scheme from the
remainder of the URL.

This change adds the colon to the list of characters that should not get
quoted. Since a colon can be directly represented in ASCII, this should
not invalidate the previous change.

Change-Id: I76a1c9a361b6c9f6eb95ae766b8c3bcf2267703a
Closes-Bug: #1788942
2018-11-01 21:38:19 +00:00
Brian Rosmaita 8fd7e8c664 Use "multihash" for data download validation
When the Glance "multihash" is available on an image, the
glanceclient should use it instead of MD5 to validate data
downloads.  For cases in which the multihash specifies an
algorithm not available to the client, an option is added
to the image-download command that will allow fallback to
the legacy MD5 checksum verification.

Change-Id: I4ee6e5071eca08d3bbedceda2acc170e7ed21a6b
Closes-bug: #1788323
2018-09-07 14:50:24 -04:00
wangxiyuan eba4bb06d9 Skip quote '=' for token header
If the token is encoded by base64, it may contain '=' char
as well.

We should skip quoting it.

Change-Id: I1ca63d251fa366f0e8e58128d45b729a2489b65c
Partial-Bug: #1783290
2018-07-26 11:41:27 +08:00
Zuul c26c6380d0 Merge "Do not quote '+' for token header" 2018-07-25 20:39:53 +00:00
Abhishek Kekane d7fbd0a516 Add support for hide old images
Added --hidden argument to list, create and
update call.

Related to blueprint hidden-images
Change-Id: I1f2dcaa545c9da883186b20a96a70c7df994b994
2018-07-25 10:27:28 -04:00
wangxiyuan 818362147d Do not quote '+' for token header
The token in request header may contain url char, such as '+',
if quote it, '+' will change to '%2B' which will lead to 401 error.

Our CI doesn't notice this bug because Keystone use fernet token
which doesn't contain url char by default. But token format in
keystone is plugable, some out-tree token formats may contain
url char (for example, PKI/PKIZ token).

So we should skip quote token to avoiding information changing.

Closes-bug: #1783290
Change-Id: I5aa71b3e2b9b19581e46ccf8a80eda5d637f17d1
2018-07-25 16:22:43 +08:00
Zuul ccbd86ba13 Merge "Unit tests for multi-store support" 2018-07-25 00:55:36 +00:00
Zuul ac378e0254 Merge "Add multi-store support" 2018-07-25 00:39:14 +00:00
Abhishek Kekane ce5a929b9b Unit tests for multi-store support
Related to blueprint multi-store

Change-Id: Ib22cc5fd4eee0326c307abb236ef31a39edfa6a6
2018-07-24 11:02:19 +00:00
Abhishek Kekane 71bfd7bfad Add multi-store support
Added multi-store support. User can now use '--backend'
option to pass desired store while creating, uploading or
importing image to speific store backend.

Added new command 'stores-info' which will return available
stores information to the user.

Related to blueprint multi-store
Change-Id: I7370094fc4ed47205b5a86a18b22aaa7b9457e5b
2018-07-24 10:54:18 +00:00
Abhishek Kekane 1f1a8176ce Add support for multihash
Related to blueprint multihash

Change-Id: Iff4a5fe224b5d47255d7f23f65bbc08468f47f02
2018-07-23 11:06:57 +00:00
Doug Hellmann e484311923 update shell tests to not rely on the serialization order of a dict
Under python 3 with ordering randomized we cannot depend on the JSON
output matching exactly. Instead we de-serialize the data structure
that was written and compare the structures, which will always match.

Change-Id: I134b62413a7cde25f3efda6a2452c1e3d11d41d0
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2018-06-07 17:51:28 -04:00
Cyril Roelandt abfe0f4bf3 Image show: print human readable string when the virtual size is unknown
Currently, when the virtual size of an image is not known, "None" is displayed.
To a regular user, it feels like a programming error. We try and make things
clearer by using a "human readable" string instead.

Change-Id: Id7b8799356857d9bc58cc8a3677024fe1a7f4f56
Partial-Bug: #1665037
2018-05-31 18:52:20 +02:00
Zuul 1ef5e5d169 Merge "Removes unicode 'u' response from "glance image-tag-update"" 2018-05-18 16:23:20 +00:00
Brian Rosmaita ee029a9b92 Handle HTTP headers per RFC 8187
According to RFC 8187, HTTP headers should use 7-bit ASCII encoding.
The glanceclient was encoding them as UTF-8, which can leave the 8th
bit nonzero when representing unicode, and which presents problems
for any recipient following the standard and decoding the headers as
ASCII.

This change requires keystoneauth1 3.6.2, which has a fix for a
bug that made it unable to handle bytes in headers.  The dependency
is a patch bumping the keystoneauth1 version in upper-constraints.

Depends-on: https://review.openstack.org/#/c/569138/

Change-Id: I0d14974126fcb20e23a37347f4f1756c323cf2f5
Closes-bug: #1766235
2018-05-17 15:53:34 -04:00
Zuul 939e532a3a Merge "Update local copy of image schema for 2.6" 2018-04-11 04:34:37 +00:00
Brian Rosmaita e89fcae346 Update local copy of image schema for 2.6
Update the local copy of the image schema to reflect Image API 2.6.

Change-Id: Ib0e56027927880d0fa198ffd8ea4b57e39f9d0fe
Closes-bug: #1762044
Depends-on: https://review.openstack.org/#/c/559501/
2018-04-08 14:48:36 -04:00
Brian Rosmaita 46dd4dd60f Make image-import fail faster
Add checks to image-import command so that it provides better user
feedback in failure situations.

Change-Id: I8b6b32c3d1d1a745aa68ff8dc629419dff9bb130
Closes-bug: #1758718
2018-04-04 14:36:13 -04:00
Brian Rosmaita 79543a67ed Make image-create-via-import fail faster
Add checks to the image-create-via-import commmand so that it provides
better user feedback and doesn't begin the import workflow unless the
input has a chance of succeeding.  Preserves backward compatibility
with the current image-create command by (1) allowing an image record
only to be created when no import-method is specified AND no data is
supplied, and (2) doing the glance-direct workflow when no import-
method is specified AND data is provided.  Also adds the ability for
the import-method to be set as an env var OS_IMAGE_IMPORT_METHOD.

Change-Id: I0a225f5471a9311217b5d90ebb5fd415c369129a
Closes-bug: #1758149
2018-04-04 13:51:40 -04:00
Brian Rosmaita dc3ee4aedb Fix intermittent v2 shell unit test failures
The do_image_download code has a check to make sure that there's
a place to put the data (either filename or stdout redirect) before
initiating the download.  The location of this check was moved by
change I841bebeda38814235079429eca0b1e5fd2f04dae to happen at the
beginning of the function.  The two intermittently failing tests
do not explicitly address the check condition, and as a result the
tests do exit early, but before they can check what they're supposed
to be testing.

Closes-bug: #1759951

Change-Id: I3c85bb358f669504b364d55618c21382b7a2a66b
2018-03-29 17:28:44 -04:00
Zuul bf820a1896 Merge "Remove usage of ordereddict" 2018-03-26 16:10:27 +00:00
Brian Rosmaita 6cd537e274 Check for container,disk_format on web-download
Fail image-create-via-import requests for the web-download import
method that don't include values for container_format or disk_format.

Closes-bug: #1757927

Change-Id: Ic5c81916823ff32f2dbddd32b40e825de0697dc9
2018-03-22 01:16:41 -04:00
PranaliD aedabec9e4 Add support for web-download import method
This change adds support for 'web-download' import method
to 'image-import' and 'create-image-via-import' call.
To use this 'web-download' import method, user needs to pass
--uri option 'a valid uri to external image to import in glance'
to 'image-import' and 'create-image-via-imaport' calls.

Co-authored-by: Pranali Deore <pdeore@redhat.com>
Co-authored-by: Erno Kuvaja <jokke@usr.fi>

Change-Id: I0e1d18844f64723608288de473e97710798eb602
2018-03-21 15:09:13 +00:00
Dirk Mueller 5916702cb2 Remove usage of ordereddict
This was only needed for Python < 2.7, but glanceclient's setup.cfg
already declares compatibility only with 2.7.

Change-Id: I80d42abf5dd5565da424a90a93545ba82ef7a58d
2018-03-08 10:30:31 +01:00
Abijitha Nadagouda 195add500b Removes unicode 'u' response from "glance image-tag-update"
"glance image-tag-update" command returns unicoded response
for lists. Therefore it requires print_list method from util
class to handle such case. Added unicode_key_value_to_string()
method to remove extra 'u' from lists and dictionaries. This
fix is inspired from cinderclient's implementation.

Change-Id: I16a04e8d34f7629f72fe389456001ca1db9335ea
Closes-bug: #1534046
2018-02-02 10:36:27 +05:30
Rui Yuan Dou 8e862b6018 Remove deprecated ssl options
Old deprecated ssl options block the new keystoneauth parser get the
correct value, should be removed.

Change-Id: Ie080f9a8fa7f4407b1fcbb7fb7c763152c5ec295
Closes-Bug: 1697163
2018-01-17 08:50:57 +08:00
Stephen Finucane 4dcbc30e31 Compare against 'RequestIdProxy.wrapped'
Due to the 'glanceclient.common.utils.add_req_id_to_object' decorator,
an instance of 'glanceclient.common.utils.RequestIdProxy' is returned
for most calls in glanceclient. If we wish to compare to None, we have
to compare the contents of this wrapper and not the wrapper itself.

Unit tests are updated to highlight this.

Change-Id: I7dadf32d37ac2bda33a92c71d5882e9f23e38a82
Closes-Bug: #1736759
2018-01-02 11:36:02 +00:00
Ravi Shekhar Jethani 1df55dd952 Validate input args before trying image download
Currently client is contacting glance service even if the
caller has niether specified any redirection nor '--file'
option. This unnecessary request although isn't causing
any critical issues but can be avoided by simply doing
input validation first.

TrivialFix

Change-Id: I841bebeda38814235079429eca0b1e5fd2f04dae
2017-07-24 14:54:57 +05:30
Jenkins a53b302764 Merge "Replace assertTrue(isinstance()) with assertIsInstance()" 2017-06-30 21:03:45 +00:00
Jenkins 05453b19b2 Merge "Replace six.iteritems() with .items()" 2017-06-28 14:49:38 +00:00
Doug Hellmann c8a7a5d56d allow unhandled exceptions to cause test errors
Hiding the unhandled exception in the test with a failure makes it
harder to debug the problem. Let them pass unhandled so the test reports
an ERROR instead of FAILURE.

Change-Id: I4e435a6d276fdf161dac28f08c2c7efedd1d6385
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2017-06-26 10:59:29 -04:00
Van Hung Pham 7791110b2f Replace assertTrue(isinstance()) with assertIsInstance()
Some of tests use different method of assertTrue(isinstance(A, B))
or assertEqual(type(A), B). The correct way is to use
assertIsInstance(A, B) provided by test tools.

Change-Id: Ibb5e5f848c5632f7c1895c47b8c1a938f2c746c3
2017-06-14 11:03:10 +07:00
Jenkins d67b33b2e5 Merge "Allow global_request_id in Client constructor" 2017-06-01 17:22:55 +00:00
Sean Dague ec76e254da Allow global_request_id in Client constructor
This allows us to pass in a global_request_id in the client
constructor so that subsequent calls with this client pass that to the
servers. This enables cross project request_id tracking.

oslo spec I65de8261746b25d45e105394f4eeb95b9cb3bd42

Change-Id: Iea1e754a263a01dae5ed598fdda134394aff54b0
2017-06-01 14:32:03 +00:00
Abhishek Kekane 60c06d526c Downloading image with --progress fails
Downloading image with --progress fails with "RequestIdProxy object is
not an iterator". This is because to display download progress
VerboseFileWrapper in progressbar requires object of IterableWithLength,
but after support of returning request-id [1] to caller it returns
RequestIdProxy object which is wrapped around IterableWithLength
and response.

To resolve this issue overridden next and __next__ methods in
RequestIdProxy so that it can act as iterator for python 2.x
and 3.x as well.

[1] 610177a779

Closes-Bug: #1670464
Change-Id: I188e67c2487b7e4178ea246f02154bbcbc35a2b1
2017-05-29 17:56:11 +05:30
Jenkins 3338ed91d4 Merge "Downloading image with --progress fails for python3" 2017-05-29 11:54:55 +00:00
ckonstanski 03900522d4 v2: Content-Type: application/octet-stream header always added
The bug: any existing Content-Type header cannot be found because the
call to headers.get() fails. Therefore we end up with two Content-Type
headers because a new one (applicaion/octet-stream) gets added
unconditionally. The cause: the strings (keys and values) in the headers
dict are converted from unicode sequences of type <str> to utf-8
sequences of type <bytes>. This happens in safe_encode()
(oslo_utils/encodeutils.py:66). <str> != <bytes> even if they appear to
have the same characters.

Hence, for python 3.x, _set_common_request_kwargs() adds content-type
to header even if custom content-type is set in the request.

This results in unsupported media type exception when glance client
is used with keystoneauth and python 3.x

The fix: follow the directions in encode_headers().
It says to do this just before sending the request. Honor this principle;
do not encode headers and then perform more business logic on them.

Change-Id: Idf6079b32f70bc171f5016467048e917d42f296d
Closes-bug: #1641239
Co-Authored-By: Pushkar Umaranikar <pushkar.umaranikar@intel.com>
2017-05-19 19:02:00 +00:00
Eric Fried 7df87fd4a2 Convert IOError from requests
This requests commit [1] changed the behavior when a nonexistent cacert
file is passed in: now it raises IOError.  This is getting through
glanceclient.common.http.HTTPClient._request, which used to raise
CommunicationError in this scenario.

Even though there is arguably a better exception than CommunicationError
to represent this condition (like maybe IOError), for backward
compatibility this change set converts IOError to CommunicationError.

We also improve the unit test to raise the original exception if the
expected conditions aren't met; this improves debugability.

[1] https://github.com/kennethreitz/requests/commit/7d8b87c37f3a5fb993fd83eda6888ac217cd108e

Change-Id: I6a2cf4c6d041b67d3509153b4cef18b459263648
Closes-Bug: #1692085
2017-05-19 14:59:58 -04:00
Abhishek Kekane bb2a5e946f Downloading image with --progress fails for python3
Downloading image with --progress fails for python3 with,
TypeError: 'IterableWithLength' object is not an iterator. This
is because IterableWithLength class does not implemented python3
compatible __next__ method.

Added __next__ method for python3 compatibility.

Change-Id: Ic2114180fac26e9a60678f06612be733e8671bdb
Closes-Bug: #1671365
2017-05-18 11:42:35 +05:30
Abhishek Kekane 87e4f7646f x-openstack-request-id logged twice in logs
In the recent release of keystoneauth1 2.18.0 provision is made to log
x-openstack-request-id for session client. Once this new library is synced
in openstack projects, the x-openstack-request-id will be logged twice
on the console if session client is used.

For example,
$ glance --debug image-list

DEBUG:keystoneauth.session:GET call to image for
http://10.232.48.204:9292/v2/schemas/image used request id
req-96a3f203-c605-4c96-a31d-f1199d41705c

DEBUG:glanceclient.common.http:GET call to glance-api for
http://10.232.48.204:9292/v2/schemas/image used request id
req-96a3f203-c605-4c96-a31d-f1199d41705c

Above log will be logged twice on the console.

Removed logging of x-openstack-request-id in case of SessionClient as it
is already logged in keystoneauth1. x-openstack-request-id will only be
logged once on console if HTTPClient is used.

Depends-On: I492b331ff3da8d0b91178bf0d5fe1d3702f15bd7
Closes-Bug: #1657351
Change-Id: I64258f997dc060113f53682aee74bdd40a346e54
2017-02-22 01:49:22 +05:30
ji-xuepeng 5fca39dbde Replace six.iteritems() with .items()
1.As mentioned in [1], we should avoid usingg
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: I71c13040318eca6e5ed993e8aa03f8003986a71c
2017-02-08 16:33:46 +08:00
Jenkins 99cbde26ac Merge "Add support for community images" 2017-01-23 22:19:37 +00:00
Jenkins a76fdcd20a Merge "Add request id to returned objects" 2017-01-23 22:19:31 +00:00
Ravi Jethani 610177a779 Add request id to returned objects
Adding two classes RequestIdProxy and GeneratorProxy derived from
wrapt.ObjectProxy to wrap objects returned from the API.

GeneratorProxy class is used to wrap generator objects returned
by cases like images.list() etc. whereas RequestIdProxy class is
used to wrap non-generator object cases like images.create() etc.

In all cases the returned object will have the same behavior as
the wrapped(original) object. However now the returned objects
will have an extra property 'request_ids' which is a list of
exactly one request id.

For generator cases the request_ids property will be an empty list
until the underlying generator is invoked at-least once.

Co-Authored-By: Abhishek Kekane <abhishek.kekane@nttdata.com>

Closes-Bug: #1525259
Blueprint: return-request-id-to-caller
Change-Id: If8c0e0843270ff718a37ca2697afeb8da22aa3b1
2017-01-20 14:50:42 +05:30
Evgeny Antyshev 6ab6a740ff Add ploop in disk_format
"ploop" image format is supported in upstream Glance
https://review.openstack.org/341633

And similar patch has been added in python-openstackclient:
https://review.openstack.org/411405

Co-Authored-By: yuyafei <yu.yafei@zte.com.cn>
Change-Id: I1471224df97cf5fecfe7f02e549855af81c45848
Related-Bug: 1650342
2017-01-19 14:31:01 +00:00
Jenkins 8f8df1cced Merge "Handle formatting of subcommand name in error output" 2017-01-13 19:35:35 +00:00
Ian Cordasco 81039a1e36 Handle formatting of subcommand name in error output
On Python 2, decoding all arguments leads to the possibility that users
that use the wrong command or mistype the name will see error output
with a unicode string's representation instead of one without it. To
avoid this we try and find the first non-option string in the argument
list and replace it with an string that is not text only on Python 2. If
we encoded the string at all times, then users installing glanceclient
on Python 3 would see b'invalid-subcommand' instead. That's as bad as
seeing u'invalid-subcommand' on Python 2.

Closes-bug: 1533090
Change-Id: I018769e159a607ebb233902cbeb13b95ca417190
2017-01-11 07:33:34 -06:00