19 Commits

Author SHA1 Message Date
Sirushti Murugesan
376037d371 py3: Fix encoding and use sys.stdin.buffer
* exc.py: Encode body in response before calling replace over it.
* http.py: prepend the bytes literal to the empty string or else
  we hit bug 1342080 again in python 3.
* utils.py: Use sys.stdin.buffer in python 3.

Change-Id: Ieefb8c633658e507486438e5518c5d53e819027d
2016-07-25 20:13:08 +05:30
rahulram
22ce8451a8 Fix Typos in comments
Change-Id: Ib66ec89f6e556093ab00d3f7fb8ad0f3d9912461
2015-08-26 13:41:09 -07:00
Jenkins
3e207dc065 Merge "Fix minor typo in version error message" 2015-03-11 03:12:33 +00: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
Stuart McLaren
eeef7635d7 Fix minor typo in version error message
Change-Id: Ic6441c6952f89fc41c7f41b1baae3f601c0fc87e
Closes-bug: 1396087
2014-11-25 11:04:59 +00:00
AmalaBasha
dbb242b776 Replace old httpclient with requests
This review implements blueprint python-request and replaces the old
http client implementation in favor of a new one based on
python-requests.

Major changes:
* raw_request and json_request removed since everything is now being
  handled by the same method "_request"
* New methods that match HTTP's methods were added:
    - get
    - put
    - post
    - head
    - patch
    - delete
* Content-Type is now being "inferred" based on the data being sent:
    - if it is file-like object it chunks the request
    - if it is a python type not instance of basestring then it'll try
      to serialize it to json
    - Every other case will keep the incoming content-type and will send
      the data as is.
* Glanceclient's HTTPSConnection implementation will be used if
  no-compression flag is set to True.

Co-Author:  Flavio Percoco<flaper87@gmail.com>
Change-Id: I09f70eee3e2777f52ce040296015d41649c2586a
2014-07-10 13:22:05 +05:30
ZhiQiang Fan
2517203975 Replace OpenStack LLC with OpenStack Foundation
Change-Id: I38dcbcf1a6c8efe540fcf5f29e782cb3826e583d
Fixes-Bug: #1214176
2013-09-20 04:05:51 +08:00
Dirk Mueller
62579fbb21 Start using Pyflakes and Hacking
Instead of globally ignoring pyflakes and
hacking warnings, only blacklist those that trigger
very frequently so far, in order to clean them
up in followup commits. Fix and start gating
on the rest already.

Change-Id: Ied7c7250061e3bf379e8286e8ce3b9e4af817faf
2013-06-22 16:00:26 +02:00
Ken'ichi Ohmichi
19d542ef5f Add details to stdout error message.
Current glance command does not show the details of error message.
For example, the glance command shows HTTPBadRequest only if some
necessary parameter is not specified.

 $ glance image-create --file root-fs.img --name cirros-0.3.0-x86_64-uec
 Request returned failure status.
 HTTPBadRequest (HTTP 400)
 $

By only the above message, it is not easy that a user understand the reason
of an error. glance-api server returns the details of reason, but glance
command does not show it.

This patch adds details, which is gotten from glance-api server, to error
message. And a user will be able to understand the reason of a error like
the following:

 $ glance image-create --file root-fs.img --name cirros-0.3.0-x86_64-uec
 Request returned failure status.
 400 Bad Request
 Invalid disk format 'None' for image.
     (HTTP 400)
 $

Fixes bug 1094917

Change-Id: I49192c3ebbc8a70b63dcfcede9fd13f1688388cf
2013-01-01 22:33:15 +09:00
Stuart McLaren
7a5946fd87 Verify that host matches certificate
When using https verify that the Common Name (CN) or
the Subject Alternative Name listed in the server's
certificate match the host we are connected to.

Addresses LP bug 1079692.

Change-Id: I24ea1511a2cbdb7c34ce72ac704d7b5e7d57cec2
2012-11-20 09:56:00 +00:00
Stuart McLaren
556082cd66 Implement blueprint ssl-connect-rework
Use pyOpenSSL for HTTPS connections.

This allows:

* Neater loading of system CA files
* Optional disabling of SSL compression

The performance gain from disabling SSL compression is significant
in cases where the image being uploaded/downloaded is in an already
compressed format (eg qcow2).

Related to bp ssl-connect-rework.

Change-Id: I0568b6c95c5fc7b8eafdbd0284e24c453660a55a
2012-10-08 13:51:41 +00:00
isethi
5acd5a6a4a Catches HTTP 300 while printing responses
If glance v1 api is not enabled, and a request is made to it,
it gives a KeyError. This patch catches the 300 error and
displays error message.

Fixes bug 1046607

Change-Id: I0009a5deca3b5dd5ccaeaea90feee21274bfe090
2012-09-10 16:22:45 +00:00
Brian Waldon
3997f977fa Handle communication failures cleanly
Expand exceptions to cover more failures cases. This adds
CommunicationFailure to represent any failures while attempting
to communicate with the remote endpoint. This also adds a new base
exception class BaseException which should be used for all non-HTTP
related failures.

Change-Id: Ie3e1d45c520d816a3f491a85fde94a6c4edf295e
2012-08-10 13:30:13 -07:00
Brian Waldon
354c98b087 Refactor HTTP-related exceptions
* Refactor helper function that builds the map of http status codes
  to local http exceptions - now we don't have to explicitly list
  every single exception name
* Add several exceptions to represent http status codes that were not
  previously represented
* Improve consistency of exceptions naming by prepending 'HTTP' to
  necessary exception names
* Use HTTPException instead of ClientException
* Deprecate old http exceptions (those that aren't prefixed with HTTP)
* Deprecate ClientException
* Deprecate unused NoTokenLookupException and EndpointNotFound
* Add test module to spot-check the from_response helper

Change-Id: Ibc7fef9e2a5b24bd001d183d377901f302d650a9
2012-08-08 11:29:17 -07:00
Brian Waldon
3a68f75b95 Simplify v2 schema lookup
We don't need to look at the container of available schemas in order
to get the one we want. Remove glanceclient.exc.SchemaNotFound as it can
no longer be raised.

Change-Id: Ib49ad58c4fdfc9bc9f535115674d92040a97db65
2012-08-08 11:28:31 -07:00
Brian Waldon
13d80a7e8f Add missing copyright headers
A few files were missing copyright headers:
* glanceclient/common/http.py
* glanceclient/v1/__init__.py
* glanceclient/exc.py

Change-Id: Ibbd53cd49f9367994de66a30601b3aefe1a8d6ee
2012-08-02 14:34:26 -07:00
Brian Waldon
1f44aff399 Add exceptions for 500 and 503 HTTP status codes
Add glance.exc.InternalServerError and .ServiceUnavailable to
represent HTTP statuses 500 and 503. Users will definitely see
these from Glance, so let's be nice and map them to handy
exception classes.

Change-Id: I8e8fcda532455793ea4d0f08a23f7c92b68c186c
2012-07-29 23:11:00 -07:00
Brian Waldon
1e744f162e Replace httplib2 with httplib as http driver
* This allows us to send truly chunked responses to users
* Handle bad connection url schemes with a new InvalidEndpoint exception
* Fixes bug 1023240

Change-Id: I34500987f51d4e0c6e1f89ecf93853de3fcbb1c3
2012-07-23 13:52:12 -07:00
Brian Waldon
53acf1a0ca Establish the supported importable interface
* Consumers of this client should not depend on being able to import
  any module other than glanceclient and glanceclient
* The only attributs of the glanceclient module are Client
  and __version__
* The attributes of the glanceclient.exc modules have yet to be
  locked down
* glanceclient.common.exceptions was replaced with a placeholder
  module until consumers of it are updated

Change-Id: Iea9648cd06906d65764987c1f2ee5a88ebeee748
2012-07-13 18:38:15 -07:00