]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Remerge common code with glance.
authorAngus Salkeld <asalkeld@redhat.com>
Fri, 16 Mar 2012 01:08:53 +0000 (12:08 +1100)
committerAngus Salkeld <asalkeld@redhat.com>
Fri, 16 Mar 2012 03:14:25 +0000 (14:14 +1100)
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
heat/api/middleware/version_negotiation.py
heat/api/versions.py
heat/common/client.py
heat/common/config.py
heat/common/crypt.py
heat/common/exception.py
heat/common/utils.py

index 181d2788cb30c36ff5e1747d85088c6624e064a4..a4efcc605726e3f92f35d851b888a36c052fa0ef 100644 (file)
@@ -22,9 +22,6 @@ return
 import logging
 import re
 
-import routes
-
-from heat.api import v1
 from heat.api import versions
 from heat.common import wsgi
 
index b0498c9fd495ba07e82d388d6b57345eb05fcd8a..4625dbb713b17da1fd0be8a3f5250db21d303f4f 100644 (file)
@@ -22,8 +22,6 @@ import json
 
 import webob.dec
 
-from heat.common import wsgi
-
 
 class Controller(object):
 
index e667ce2edfb82730ca0e54cc322b38ff6ccad2ed..a3a49d347fc940d563588478d6a4d45c79e1cb7f 100644 (file)
@@ -127,10 +127,23 @@ class SendFileIterator:
                 return self.len
 
         while self.sending:
-            sent = sendfile.sendfile(self.connection.sock.fileno(),
-                                     self.body.fileno(),
-                                     self.offset,
-                                     CHUNKSIZE)
+            try:
+                sent = sendfile.sendfile(self.connection.sock.fileno(),
+                                         self.body.fileno(),
+                                         self.offset,
+                                         CHUNKSIZE)
+            except OSError as e:
+                # suprisingly, sendfile may fail transiently instead of
+                # blocking, in which case we select on the socket in order
+                # to wait on its return to a writeable state before resuming
+                # the send loop
+                if e.errno in (errno.EAGAIN, errno.EBUSY):
+                    wlist = [self.connection.sock.fileno()]
+                    rfds, wfds, efds = select.select([], wlist, [])
+                    if wfds:
+                        continue
+                raise
+
             self.sending = (sent != 0)
             self.offset += sent
             yield OfLength(sent)
@@ -224,19 +237,19 @@ class BaseClient(object):
                          key.
                          If use_ssl is True, and this param is None (the
                          default), then an environ variable
-                         heat_CLIENT_KEY_FILE is looked for. If no such
+                         HEAT_CLIENT_KEY_FILE is looked for. If no such
                          environ variable is found, ClientConnectionError
                          will be raised.
         :param cert_file: Optional PEM-formatted certificate chain file.
                           If use_ssl is True, and this param is None (the
                           default), then an environ variable
-                          heat_CLIENT_CERT_FILE is looked for. If no such
+                          HEAT_CLIENT_CERT_FILE is looked for. If no such
                           environ variable is found, ClientConnectionError
                           will be raised.
         :param ca_file: Optional CA cert file to use in SSL connections
                         If use_ssl is True, and this param is None (the
                         default), then an environ variable
-                        heat_CLIENT_CA_FILE is looked for.
+                        HEAT_CLIENT_CA_FILE is looked for.
         :param insecure: Optional. If set then the server's certificate
                          will not be verified.
         """
@@ -263,11 +276,11 @@ class BaseClient(object):
         connect_kwargs = {}
         if self.use_ssl:
             if self.key_file is None:
-                self.key_file = os.environ.get('heat_CLIENT_KEY_FILE')
+                self.key_file = os.environ.get('HEAT_CLIENT_KEY_FILE')
             if self.cert_file is None:
-                self.cert_file = os.environ.get('heat_CLIENT_CERT_FILE')
+                self.cert_file = os.environ.get('HEAT_CLIENT_CERT_FILE')
             if self.ca_file is None:
-                self.ca_file = os.environ.get('heat_CLIENT_CA_FILE')
+                self.ca_file = os.environ.get('HEAT_CLIENT_CA_FILE')
 
             # Check that key_file/cert_file are either both set or both unset
             if self.cert_file is not None and self.key_file is None:
@@ -275,7 +288,7 @@ class BaseClient(object):
                         "and you have supplied a cert, "
                         "however you have failed to supply either a "
                         "key_file parameter or set the "
-                        "heat_CLIENT_KEY_FILE environ variable")
+                        "HEAT_CLIENT_KEY_FILE environ variable")
                 raise exception.ClientConnectionError(msg)
 
             if self.key_file is not None and self.cert_file is None:
@@ -283,7 +296,7 @@ class BaseClient(object):
                         "and you have supplied a key, "
                         "however you have failed to supply either a "
                         "cert_file parameter or set the "
-                        "heat_CLIENT_CERT_FILE environ variable")
+                        "HEAT_CLIENT_CERT_FILE environ variable")
                 raise exception.ClientConnectionError(msg)
 
             if (self.key_file is not None and
@@ -506,6 +519,10 @@ class BaseClient(object):
                 raise TypeError('Unsupported image type: %s' % body.__class__)
 
             res = c.getresponse()
+
+            def _retry(res):
+                return res.getheader('Retry-After')
+
             status_code = self.get_status_code(res)
             if status_code in self.OK_RESPONSE_CODES:
                 return res
@@ -523,8 +540,13 @@ class BaseClient(object):
                 raise exception.Invalid(res.read())
             elif status_code == httplib.MULTIPLE_CHOICES:
                 raise exception.MultipleChoices(body=res.read())
+            elif status_code == httplib.REQUEST_ENTITY_TOO_LARGE:
+                raise exception.LimitExceeded(retry=_retry(res),
+                                              body=res.read())
             elif status_code == httplib.INTERNAL_SERVER_ERROR:
                 raise Exception("Internal Server error: %s" % res.read())
+            elif status_code == httplib.SERVICE_UNAVAILABLE:
+                raise exception.ServiceUnavailable(retry=_retry(res))
             elif status_code == httplib.REQUEST_URI_TOO_LONG:
                 raise exception.RequestUriTooLong(body=res.read())
             else:
index b412e1f8d37dca3c45a8420b99648ede2bb64fcf..e09381fd3cd2ed29efdad1d16845e59b2343a55c 100644 (file)
@@ -168,8 +168,6 @@ def load_paste_app(conf, app_name=None):
         # Setup logging early
         setup_logging(conf)
 
-        logger = logging.getLogger(app_name)
-
         app = wsgi.paste_deploy_app(conf_file, app_name, conf)
 
         # Log the options used when starting if we're in debug mode...
index d34f49f9b9e4fc6a619e79b002e0eb03aa63e7de..f666fc0cfe9e42458d8cca97be391d6b7c0d4bbf 100644 (file)
@@ -19,8 +19,6 @@ Routines for URL-safe encrypting/decrypting
 """
 
 import base64
-import string
-import os
 
 from Crypto.Cipher import AES
 from Crypto import Random
index 8e4ef7a7ed72237c32343f04501643b640192057..bf33872984b73c5bc0b491dfc508f337957f2962 100644 (file)
@@ -141,6 +141,27 @@ class MultipleChoices(HeatException):
                 "means that you have not included a version indicator in a "
                 "request URI.\n\nThe body of response returned:\n%(body)s")
 
+class LimitExceeded(HeatException):
+    message = _("The request returned a 413 Request Entity Too Large. This "
+                "generally means that rate limiting or a quota threshold was "
+                "breached.\n\nThe response body:\n%(body)s")
+
+    def __init__(self, *args, **kwargs):
+        self.retry_after = (int(kwargs['retry']) if kwargs.get('retry')
+                            else None)
+        super(LimitExceeded, self).__init__(*args, **kwargs)
+
+
+class ServiceUnavailable(HeatException):
+    message = _("The request returned a 503 ServiceUnavilable. This "
+                "generally occurs on service overload or other transient "
+                "outage.")
+
+    def __init__(self, *args, **kwargs):
+        self.retry_after = (int(kwargs['retry']) if kwargs.get('retry')
+                            else None)
+        super(ServiceUnavailable, self).__init__(*args, **kwargs)
+
 class RequestUriTooLong(HeatException):
     message = _("The URI was too long.")
 
index 1f8604d1ec6317b5051a384a3b09e9fa0cb60667..728d4f2d8370b5889f20385a7e9633ed34eae777 100644 (file)
@@ -22,13 +22,10 @@ System-level utilities and helper functions.
 
 import datetime
 import errno
-import inspect
 import logging
 import os
 import platform
-import random
 import subprocess
-import socket
 import sys
 import uuid
 
@@ -327,9 +324,11 @@ def get_terminal_size():
         if not height_width:
             try:
                 p = subprocess.Popen(['stty', 'size'],
-                                    shell=false,
+                                    shell=False,
                                     stdout=subprocess.PIPE)
-                return tuple(int(x) for x in p.communicate()[0].split())
+                result = p.communicate()
+                if p.returncode == 0:
+                    return tuple(int(x) for x in result[0].split())
             except:
                 pass