diff options
| author | Dan Prince <dan.prince@rackspace.com> | 2011-03-31 09:29:07 -0400 |
|---|---|---|
| committer | Dan Prince <dan.prince@rackspace.com> | 2011-03-31 09:29:07 -0400 |
| commit | e90b0cf99cda9b93e93db88fbb2204a1bfcd3897 (patch) | |
| tree | 90e35f0407a6b9abe22ff8987cd4ba540bc80d1a | |
| parent | 176d98aa179b174c4e4a5621f723ef7b9145e3cb (diff) | |
| parent | eda275741f5865a1bf58d0176b36d4d99bfeb015 (diff) | |
| download | nova-e90b0cf99cda9b93e93db88fbb2204a1bfcd3897.tar.gz nova-e90b0cf99cda9b93e93db88fbb2204a1bfcd3897.tar.xz nova-e90b0cf99cda9b93e93db88fbb2204a1bfcd3897.zip | |
Merge w/ trunk.
| -rw-r--r-- | nova/api/openstack/faults.py | 1 | ||||
| -rw-r--r-- | nova/rpc.py | 13 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_faults.py | 122 | ||||
| -rw-r--r-- | nova/virt/hyperv.py | 4 | ||||
| -rw-r--r-- | nova/virt/vmwareapi/vim.py | 15 | ||||
| -rw-r--r-- | nova/virt/vmwareapi_conn.py | 3 |
6 files changed, 130 insertions, 28 deletions
diff --git a/nova/api/openstack/faults.py b/nova/api/openstack/faults.py index 0e9c4b26f..940bd8771 100644 --- a/nova/api/openstack/faults.py +++ b/nova/api/openstack/faults.py @@ -60,6 +60,7 @@ class Fault(webob.exc.HTTPException): serializer = wsgi.Serializer(metadata) content_type = req.best_match_content_type() self.wrapped_exc.body = serializer.serialize(fault_data, content_type) + self.wrapped_exc.content_type = content_type return self.wrapped_exc diff --git a/nova/rpc.py b/nova/rpc.py index 388f78d69..be7cb3f37 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -74,7 +74,12 @@ class Connection(carrot_connection.BrokerConnection): """Recreates the connection instance This is necessary to recover from some network errors/disconnects""" - del cls._instance + try: + del cls._instance + except AttributeError, e: + # The _instance stuff is for testing purposes. Usually we don't use + # it. So don't freak out if it doesn't exist. + pass return cls.instance() @@ -125,10 +130,12 @@ class Consumer(messaging.Consumer): # NOTE(vish): This is catching all errors because we really don't # want exceptions to be logged 10 times a second if some # persistent failure occurs. - except Exception: # pylint: disable=W0703 + except Exception, e: # pylint: disable=W0703 if not self.failed_connection: - LOG.exception(_("Failed to fetch message from queue")) + LOG.exception(_("Failed to fetch message from queue: %s" % e)) self.failed_connection = True + else: + LOG.exception(_("Unhandled exception %s" % e)) def attach_to_eventlet(self): """Only needed for unit tests!""" diff --git a/nova/tests/api/openstack/test_faults.py b/nova/tests/api/openstack/test_faults.py index 7667753f4..9746e8168 100644 --- a/nova/tests/api/openstack/test_faults.py +++ b/nova/tests/api/openstack/test_faults.py @@ -15,6 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. +import json + import webob import webob.dec import webob.exc @@ -24,35 +26,115 @@ from nova.api.openstack import faults class TestFaults(test.TestCase): + """Tests covering `nova.api.openstack.faults:Fault` class.""" - def test_fault_parts(self): - req = webob.Request.blank('/.xml') - f = faults.Fault(webob.exc.HTTPBadRequest(explanation='scram')) - resp = req.get_response(f) + def _prepare_xml(self, xml_string): + """Remove characters from string which hinder XML equality testing.""" + xml_string = xml_string.replace(" ", "") + xml_string = xml_string.replace("\n", "") + xml_string = xml_string.replace("\t", "") + return xml_string - first_two_words = resp.body.strip().split()[:2] - self.assertEqual(first_two_words, ['<badRequest', 'code="400">']) - body_without_spaces = ''.join(resp.body.split()) - self.assertTrue('<message>scram</message>' in body_without_spaces) + def test_400_fault_xml(self): + """Test fault serialized to XML via file-extension and/or header.""" + requests = [ + webob.Request.blank('/.xml'), + webob.Request.blank('/', headers={"Accept": "application/xml"}), + ] - def test_retry_header(self): - req = webob.Request.blank('/.xml') - exc = webob.exc.HTTPRequestEntityTooLarge(explanation='sorry', - headers={'Retry-After': 4}) - f = faults.Fault(exc) - resp = req.get_response(f) - first_two_words = resp.body.strip().split()[:2] - self.assertEqual(first_two_words, ['<overLimit', 'code="413">']) - body_sans_spaces = ''.join(resp.body.split()) - self.assertTrue('<message>sorry</message>' in body_sans_spaces) - self.assertTrue('<retryAfter>4</retryAfter>' in body_sans_spaces) - self.assertEqual(resp.headers['Retry-After'], 4) + for request in requests: + fault = faults.Fault(webob.exc.HTTPBadRequest(explanation='scram')) + response = request.get_response(fault) + + expected = self._prepare_xml(""" + <badRequest code="400"> + <message>scram</message> + </badRequest> + """) + actual = self._prepare_xml(response.body) + + self.assertEqual(response.content_type, "application/xml") + self.assertEqual(expected, actual) + + def test_400_fault_json(self): + """Test fault serialized to JSON via file-extension and/or header.""" + requests = [ + webob.Request.blank('/.json'), + webob.Request.blank('/', headers={"Accept": "application/json"}), + ] + + for request in requests: + fault = faults.Fault(webob.exc.HTTPBadRequest(explanation='scram')) + response = request.get_response(fault) + + expected = { + "badRequest": { + "message": "scram", + "code": 400, + }, + } + actual = json.loads(response.body) + + self.assertEqual(response.content_type, "application/json") + self.assertEqual(expected, actual) + + def test_413_fault_xml(self): + requests = [ + webob.Request.blank('/.xml'), + webob.Request.blank('/', headers={"Accept": "application/xml"}), + ] + + for request in requests: + exc = webob.exc.HTTPRequestEntityTooLarge + fault = faults.Fault(exc(explanation='sorry', + headers={'Retry-After': 4})) + response = request.get_response(fault) + + expected = self._prepare_xml(""" + <overLimit code="413"> + <message>sorry</message> + <retryAfter>4</retryAfter> + </overLimit> + """) + actual = self._prepare_xml(response.body) + + self.assertEqual(expected, actual) + self.assertEqual(response.content_type, "application/xml") + self.assertEqual(response.headers['Retry-After'], 4) + + def test_413_fault_json(self): + """Test fault serialized to JSON via file-extension and/or header.""" + requests = [ + webob.Request.blank('/.json'), + webob.Request.blank('/', headers={"Accept": "application/json"}), + ] + + for request in requests: + exc = webob.exc.HTTPRequestEntityTooLarge + fault = faults.Fault(exc(explanation='sorry', + headers={'Retry-After': 4})) + response = request.get_response(fault) + + expected = { + "overLimit": { + "message": "sorry", + "code": 413, + "retryAfter": 4, + }, + } + actual = json.loads(response.body) + + self.assertEqual(response.content_type, "application/json") + self.assertEqual(expected, actual) def test_raise(self): + """Ensure the ability to raise `Fault`s in WSGI-ified methods.""" @webob.dec.wsgify def raiser(req): raise faults.Fault(webob.exc.HTTPNotFound(explanation='whut?')) + req = webob.Request.blank('/.xml') resp = req.get_response(raiser) + self.assertEqual(resp.content_type, "application/xml") self.assertEqual(resp.status_int, 404) self.assertTrue('whut?' in resp.body) diff --git a/nova/virt/hyperv.py b/nova/virt/hyperv.py index a1ed5ebbf..13f403a66 100644 --- a/nova/virt/hyperv.py +++ b/nova/virt/hyperv.py @@ -485,3 +485,7 @@ class HyperVConnection(driver.ComputeDriver): def poll_rescued_instances(self, timeout): pass + + def update_available_resource(self, ctxt, host): + """This method is supported only by libvirt.""" + return diff --git a/nova/virt/vmwareapi/vim.py b/nova/virt/vmwareapi/vim.py index ba14f1512..1c850595d 100644 --- a/nova/virt/vmwareapi/vim.py +++ b/nova/virt/vmwareapi/vim.py @@ -21,10 +21,14 @@ Classes for making VMware VI SOAP calls. import httplib
-from suds import WebFault
-from suds.client import Client
-from suds.plugin import MessagePlugin
-from suds.sudsobject import Property
+try:
+ suds = True
+ from suds import WebFault
+ from suds.client import Client
+ from suds.plugin import MessagePlugin
+ from suds.sudsobject import Property
+except ImportError:
+ suds = False
from nova import flags
from nova.virt.vmwareapi import error_util
@@ -75,6 +79,9 @@ class Vim: protocol: http or https
host : ESX IPAddress[:port] or ESX Hostname[:port]
"""
+ if not suds:
+ raise Exception(_("Unable to import suds."))
+
self._protocol = protocol
self._host_name = host
wsdl_url = FLAGS.vmwareapi_wsdl_loc
diff --git a/nova/virt/vmwareapi_conn.py b/nova/virt/vmwareapi_conn.py index 87c3fa299..20c1b2b45 100644 --- a/nova/virt/vmwareapi_conn.py +++ b/nova/virt/vmwareapi_conn.py @@ -47,6 +47,7 @@ from nova.virt.vmwareapi import vim from nova.virt.vmwareapi import vim_util
from nova.virt.vmwareapi.vmops import VMWareVMOps
+
LOG = logging.getLogger("nova.virt.vmwareapi_conn")
FLAGS = flags.FLAGS
@@ -109,7 +110,7 @@ class VMWareESXConnection(object): def __init__(self, host_ip, host_username, host_password,
api_retry_count, scheme="https"):
session = VMWareAPISession(host_ip, host_username, host_password,
- api_retry_count, scheme=scheme)
+ api_retry_count, scheme=scheme)
self._vmops = VMWareVMOps(session)
def init_host(self, host):
|
