From 70e4d73778d448cb7f122bc0a2a0c43a78fff46a Mon Sep 17 00:00:00 2001 From: John Tran Date: Wed, 8 Jun 2011 15:23:33 -0700 Subject: added a test for allocate_address & added error handling for api instead of returning 'UnknownError', will give information 'AllocateAddressError: NoMoreAddresses --- nova/api/ec2/__init__.py | 6 ++++++ nova/tests/test_cloud.py | 10 ++++++++++ 2 files changed, 16 insertions(+) (limited to 'nova') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index 1915d007d..459ecb442 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -348,6 +348,12 @@ class Executor(wsgi.Application): LOG.debug(_('KeyPairExists raised: %s'), unicode(ex), context=context) return self._error(req, context, type(ex).__name__, unicode(ex)) + except rpc.RemoteError as ex: + LOG.debug(_('RemoteError raised: %s'), ex.exc_type, + context=context) + if ex.exc_type == 'NoMoreAddresses': + return self._error(req, context, 'AllocateAddressError', + ex.exc_type) except Exception as ex: extra = {'environment': req.environ} LOG.exception(_('Unexpected error raised: %s'), unicode(ex), diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index ba133c860..d6d90e873 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -115,6 +115,16 @@ class CloudTestCase(test.TestCase): public_ip=address) db.floating_ip_destroy(self.context, address) + def test_allocate_address(self): + address = "10.10.10.10" + allocate = self.cloud.allocate_address + db.floating_ip_create(self.context, + {'address': address, + 'host': self.network.host}) + self.assertEqual(allocate(self.context)['publicIp'], address) + db.floating_ip_destroy(self.context, address) + self.assertRaises(rpc.RemoteError, allocate, self.context) + def test_associate_disassociate_address(self): """Verifies associate runs cleanly without raising an exception""" address = "10.10.10.10" -- cgit From 3764be9d65483a9e431b69f37e3516fa20961362 Mon Sep 17 00:00:00 2001 From: John Tran Date: Wed, 8 Jun 2011 17:15:35 -0700 Subject: raises exception.NoFloatingIpsDefined instead of UnknownError --- nova/api/ec2/cloud.py | 8 ++++++-- nova/tests/test_cloud.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'nova') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 316298c39..6c5dba8ed 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -39,6 +39,7 @@ from nova import flags from nova import ipv6 from nova import log as logging from nova import network +from nova import rpc from nova import utils from nova import volume from nova.api.ec2 import ec2utils @@ -872,8 +873,11 @@ class CloudController(object): def allocate_address(self, context, **kwargs): LOG.audit(_("Allocate address"), context=context) - public_ip = self.network_api.allocate_floating_ip(context) - return {'publicIp': public_ip} + try: + public_ip = self.network_api.allocate_floating_ip(context) + return {'publicIp': public_ip} + except rpc.RemoteError: + raise exception.NoFloatingIpsDefined def release_address(self, context, public_ip, **kwargs): LOG.audit(_("Release address %s"), public_ip, context=context) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index d6d90e873..7cb13c919 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -123,7 +123,8 @@ class CloudTestCase(test.TestCase): 'host': self.network.host}) self.assertEqual(allocate(self.context)['publicIp'], address) db.floating_ip_destroy(self.context, address) - self.assertRaises(rpc.RemoteError, allocate, self.context) + self.assertRaises(exception.NoFloatingIpsDefined, allocate, + self.context) def test_associate_disassociate_address(self): """Verifies associate runs cleanly without raising an exception""" -- cgit From b11cf9bc7b1b9792bdab77aa72dc6163f3e44ca1 Mon Sep 17 00:00:00 2001 From: John Tran Date: Wed, 8 Jun 2011 17:17:40 -0700 Subject: removing custom exception, instead using NoFloatingIpsDefined --- nova/api/ec2/__init__.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'nova') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index 459ecb442..1915d007d 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -348,12 +348,6 @@ class Executor(wsgi.Application): LOG.debug(_('KeyPairExists raised: %s'), unicode(ex), context=context) return self._error(req, context, type(ex).__name__, unicode(ex)) - except rpc.RemoteError as ex: - LOG.debug(_('RemoteError raised: %s'), ex.exc_type, - context=context) - if ex.exc_type == 'NoMoreAddresses': - return self._error(req, context, 'AllocateAddressError', - ex.exc_type) except Exception as ex: extra = {'environment': req.environ} LOG.exception(_('Unexpected error raised: %s'), unicode(ex), -- cgit From 8096ee6c79c608fd84e016d5da7663549a95896f Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 9 Jun 2011 03:35:59 +0000 Subject: Support multiple glance-api servers --- nova/flags.py | 6 ++++-- nova/image/__init__.py | 7 ++++++- nova/image/glance.py | 24 +++++++++++++++++------- nova/virt/images.py | 7 +++++-- nova/virt/xenapi/vm_utils.py | 13 +++++++++---- 5 files changed, 41 insertions(+), 16 deletions(-) (limited to 'nova') diff --git a/nova/flags.py b/nova/flags.py index d5090edba..51f0536e8 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -270,8 +270,10 @@ DEFINE_list('region_list', DEFINE_string('connection_type', 'libvirt', 'libvirt, xenapi or fake') DEFINE_string('aws_access_key_id', 'admin', 'AWS Access ID') DEFINE_string('aws_secret_access_key', 'admin', 'AWS Access Key') -DEFINE_integer('glance_port', 9292, 'glance port') -DEFINE_string('glance_host', '$my_ip', 'glance host') +# NOTE(sirp): my_ip interpolation doesn't work within nested structures +DEFINE_list('glance_api_servers', + [('127.0.0.1', 9292)], + 'list of glance servers available to nova') DEFINE_integer('s3_port', 3333, 's3 port') DEFINE_string('s3_host', '$my_ip', 's3 host (for infrastructure)') DEFINE_string('s3_dmz', '$my_ip', 's3 dmz ip (for instances)') diff --git a/nova/image/__init__.py b/nova/image/__init__.py index 93d83df24..a27d649d4 100644 --- a/nova/image/__init__.py +++ b/nova/image/__init__.py @@ -22,6 +22,7 @@ import nova from nova import exception from nova import utils from nova import flags +from nova.image import glance as glance_image_service FLAGS = flags.FLAGS @@ -48,6 +49,8 @@ def get_default_image_service(): return ImageService() +# FIXME(sirp): perhaps this should be moved to nova/images/glance so that we +# keep Glance specific code together for the most part def get_glance_client(image_href): """Get the correct glance client and id for the given image_href. @@ -62,7 +65,9 @@ def get_glance_client(image_href): """ image_href = image_href or 0 if str(image_href).isdigit(): - glance_client = GlanceClient(FLAGS.glance_host, FLAGS.glance_port) + glance_host, glance_port = \ + glance_image_service.pick_glance_api_server() + glance_client = GlanceClient(glance_host, glance_port) return (glance_client, int(image_href)) try: diff --git a/nova/image/glance.py b/nova/image/glance.py index 61308431d..b68415844 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -20,6 +20,7 @@ from __future__ import absolute_import import datetime +import random from glance.common import exception as glance_exception @@ -39,6 +40,15 @@ FLAGS = flags.FLAGS GlanceClient = utils.import_class('glance.client.Client') +def pick_glance_api_server(): + """Return which Glance API server to use for the request + + Returns (host, port) + """ + host, port = random.choice(FLAGS.glance_api_servers) + return host, port + + class GlanceImageService(service.BaseImageService): """Provides storage and retrieval of disk image objects within Glance.""" @@ -50,13 +60,13 @@ class GlanceImageService(service.BaseImageService): SERVICE_IMAGE_ATTRS = service.BaseImageService.BASE_IMAGE_ATTRS +\ GLANCE_ONLY_ATTRS - def __init__(self, client=None): - # FIXME(sirp): can we avoid dependency-injection here by using - # stubbing out a fake? - if client is None: - self.client = GlanceClient(FLAGS.glance_host, FLAGS.glance_port) - else: - self.client = client + @property + def client(self): + # NOTE(sirp): we want to load balance each request across glance + # servers. Since GlanceImageService is a long-lived object, `client` + # is made to choose a new server each time via this property. + glance_host, glance_port = pick_glance_api_server() + return GlanceClient(glance_host, glance_port) def index(self, context, filters=None, marker=None, limit=None): """Calls out to Glance for a list of images available.""" diff --git a/nova/virt/images.py b/nova/virt/images.py index de7ac61df..e6f3d3c9e 100644 --- a/nova/virt/images.py +++ b/nova/virt/images.py @@ -23,6 +23,7 @@ Handling of VM disk images. from nova import context from nova import flags +from nova.image import glance as glance_image_service import nova.image from nova import log as logging from nova import utils @@ -48,7 +49,9 @@ def fetch(image_href, path, _user, _project): # of retrieving the image using this method. def image_url(image): if FLAGS.image_service == "nova.image.glance.GlanceImageService": - return "http://%s:%s/images/%s" % (FLAGS.glance_host, - FLAGS.glance_port, image) + glance_host, glance_port = \ + glance_image_service.pick_glance_api_server() + return "http://%s:%s/images/%s" % (glance_host, glance_port, image) + return "http://%s:%s/_images/%s/image" % (FLAGS.s3_host, FLAGS.s3_port, image) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 98668e6ae..ccde6cbfe 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -33,6 +33,7 @@ import glance.client from nova import exception from nova import flags import nova.image +from nova.image import glance as glance_image_service from nova import log as logging from nova import utils from nova.auth.manager import AuthManager @@ -358,10 +359,12 @@ class VMHelper(HelperBase): os_type = instance.os_type or FLAGS.default_os_type + glance_host, glance_port = \ + glance_image_service.pick_glance_api_server() params = {'vdi_uuids': vdi_uuids, 'image_id': image_id, - 'glance_host': FLAGS.glance_host, - 'glance_port': FLAGS.glance_port, + 'glance_host': glance_host, + 'glance_port': glance_port, 'sr_path': cls.get_sr_path(session), 'os_type': os_type} @@ -409,9 +412,11 @@ class VMHelper(HelperBase): # here (under Python 2.6+) and pass them as arguments uuid_stack = [str(uuid.uuid4()) for i in xrange(2)] + glance_host, glance_port = \ + glance_image_service.pick_glance_api_server() params = {'image_id': image, - 'glance_host': FLAGS.glance_host, - 'glance_port': FLAGS.glance_port, + 'glance_host': glance_host, + 'glance_port': glance_port, 'uuid_stack': uuid_stack, 'sr_path': cls.get_sr_path(session)} -- cgit From 463e0388308760dbf3bf2b3fa901d8076d002f91 Mon Sep 17 00:00:00 2001 From: John Tran Date: Thu, 9 Jun 2011 00:01:42 -0700 Subject: matched the inner exception specifically, instead of catching all RemoteError exceptions --- nova/api/ec2/cloud.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'nova') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 6c5dba8ed..84a83d8e6 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -876,8 +876,11 @@ class CloudController(object): try: public_ip = self.network_api.allocate_floating_ip(context) return {'publicIp': public_ip} - except rpc.RemoteError: - raise exception.NoFloatingIpsDefined + except rpc.RemoteError as ex: + if ex.exc_type == 'NoMoreAddresses': + raise exception.NoFloatingIpsDefined + else: + raise def release_address(self, context, public_ip, **kwargs): LOG.audit(_("Release address %s"), public_ip, context=context) -- cgit From eda8a1aaa2cf7cc31c7fda4723849feee3bc6766 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 9 Jun 2011 14:43:24 +0000 Subject: Fixing the tests --- nova/image/glance.py | 12 ++++++++++-- nova/tests/image/test_glance.py | 11 ++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'nova') diff --git a/nova/image/glance.py b/nova/image/glance.py index b68415844..f82c0f4a3 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -60,14 +60,22 @@ class GlanceImageService(service.BaseImageService): SERVICE_IMAGE_ATTRS = service.BaseImageService.BASE_IMAGE_ATTRS +\ GLANCE_ONLY_ATTRS - @property - def client(self): + _client = None + + def _get_client(self): # NOTE(sirp): we want to load balance each request across glance # servers. Since GlanceImageService is a long-lived object, `client` # is made to choose a new server each time via this property. + if self._client is not None: + return self._client glance_host, glance_port = pick_glance_api_server() return GlanceClient(glance_host, glance_port) + def _set_client(self, client): + self._client = client + + client = property(_get_client, _set_client) + def index(self, context, filters=None, marker=None, limit=None): """Calls out to Glance for a list of images available.""" # NOTE(sirp): We need to use `get_images_detailed` and not diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py index 041da1e13..033b8389c 100644 --- a/nova/tests/image/test_glance.py +++ b/nova/tests/image/test_glance.py @@ -17,6 +17,7 @@ import datetime +import stubout import unittest from nova import context @@ -60,12 +61,16 @@ class BaseGlanceTest(unittest.TestCase): NOW_DATETIME = datetime.datetime(2010, 10, 11, 10, 30, 22) def setUp(self): - # FIXME(sirp): we can probably use stubs library here rather than - # dependency injection + self.stubs = stubout.StubOutForTesting() self.client = StubGlanceClient(None) - self.service = glance.GlanceImageService(self.client) + self.service = glance.GlanceImageService() + self.stubs.Set(self.service, 'client', self.client) self.context = context.RequestContext(None, None) + def tearDown(self): + self.stubs.UnsetAll() + super(BaseGlanceTest, self).tearDown() + def assertDateTimesFilled(self, image_meta): self.assertEqual(image_meta['created_at'], self.NOW_DATETIME) self.assertEqual(image_meta['updated_at'], self.NOW_DATETIME) -- cgit From e307bf5dd60dc84587f76d88956499ee1f1013fb Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 9 Jun 2011 21:36:20 +0000 Subject: Fixing code per review comments --- nova/flags.py | 4 ++-- nova/image/glance.py | 7 +++++-- nova/tests/image/test_glance.py | 9 +-------- nova/virt/images.py | 12 ------------ nova/virt/xenapi/vm_utils.py | 3 ++- 5 files changed, 10 insertions(+), 25 deletions(-) (limited to 'nova') diff --git a/nova/flags.py b/nova/flags.py index 545cf90fe..acfcf8d68 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -272,8 +272,8 @@ DEFINE_string('aws_access_key_id', 'admin', 'AWS Access ID') DEFINE_string('aws_secret_access_key', 'admin', 'AWS Access Key') # NOTE(sirp): my_ip interpolation doesn't work within nested structures DEFINE_list('glance_api_servers', - [('127.0.0.1', 9292)], - 'list of glance servers available to nova') + ['127.0.0.1:9292'], + 'list of glance api servers available to nova (host:port)') DEFINE_integer('s3_port', 3333, 's3 port') DEFINE_string('s3_host', '$my_ip', 's3 host (for infrastructure)') DEFINE_string('s3_dmz', '$my_ip', 's3 dmz ip (for instances)') diff --git a/nova/image/glance.py b/nova/image/glance.py index f82c0f4a3..5712215bb 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -45,7 +45,9 @@ def pick_glance_api_server(): Returns (host, port) """ - host, port = random.choice(FLAGS.glance_api_servers) + host_port = random.choice(FLAGS.glance_api_servers) + host, port_str = host_port.split(':') + port = int(port_str) return host, port @@ -60,7 +62,8 @@ class GlanceImageService(service.BaseImageService): SERVICE_IMAGE_ATTRS = service.BaseImageService.BASE_IMAGE_ATTRS +\ GLANCE_ONLY_ATTRS - _client = None + def __init__(self, client=None): + self._client = client def _get_client(self): # NOTE(sirp): we want to load balance each request across glance diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py index 033b8389c..223e7ae57 100644 --- a/nova/tests/image/test_glance.py +++ b/nova/tests/image/test_glance.py @@ -17,7 +17,6 @@ import datetime -import stubout import unittest from nova import context @@ -61,16 +60,10 @@ class BaseGlanceTest(unittest.TestCase): NOW_DATETIME = datetime.datetime(2010, 10, 11, 10, 30, 22) def setUp(self): - self.stubs = stubout.StubOutForTesting() self.client = StubGlanceClient(None) - self.service = glance.GlanceImageService() - self.stubs.Set(self.service, 'client', self.client) + self.service = glance.GlanceImageService(client=self.client) self.context = context.RequestContext(None, None) - def tearDown(self): - self.stubs.UnsetAll() - super(BaseGlanceTest, self).tearDown() - def assertDateTimesFilled(self, image_meta): self.assertEqual(image_meta['created_at'], self.NOW_DATETIME) self.assertEqual(image_meta['updated_at'], self.NOW_DATETIME) diff --git a/nova/virt/images.py b/nova/virt/images.py index e6f3d3c9e..40bf6107c 100644 --- a/nova/virt/images.py +++ b/nova/virt/images.py @@ -43,15 +43,3 @@ def fetch(image_href, path, _user, _project): elevated = context.get_admin_context() metadata = image_service.get(elevated, image_id, image_file) return metadata - - -# TODO(vish): xenapi should use the glance client code directly instead -# of retrieving the image using this method. -def image_url(image): - if FLAGS.image_service == "nova.image.glance.GlanceImageService": - glance_host, glance_port = \ - glance_image_service.pick_glance_api_server() - return "http://%s:%s/images/%s" % (glance_host, glance_port, image) - - return "http://%s:%s/_images/%s/image" % (FLAGS.s3_host, FLAGS.s3_port, - image) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index ccde6cbfe..b9d4346e4 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -581,7 +581,8 @@ class VMHelper(HelperBase): Returns: A single filename if image_type is KERNEL_RAMDISK A list of dictionaries that describe VDIs, otherwise """ - url = images.image_url(image) + url = "http://%s:%s/_images/%s/image" % (FLAGS.s3_host, FLAGS.s3_port, + image) LOG.debug(_("Asking xapi to fetch %(url)s as %(access)s") % locals()) if image_type == ImageType.KERNEL_RAMDISK: fn = 'get_kernel' -- cgit From 361fd763eb0cf3e62e0184dafd0f4a024e1871f5 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 9 Jun 2011 21:50:34 +0000 Subject: Adding caveat --- nova/image/glance.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'nova') diff --git a/nova/image/glance.py b/nova/image/glance.py index 5712215bb..6e058ab2f 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -43,6 +43,10 @@ GlanceClient = utils.import_class('glance.client.Client') def pick_glance_api_server(): """Return which Glance API server to use for the request + This method provides a very primitive form of load-balancing suitable for + testing and sandbox environments. In production, it would be better to use + one IP and route that to a real load-balancer. + Returns (host, port) """ host_port = random.choice(FLAGS.glance_api_servers) -- cgit From e763a0ac8981bdbee44c054c6be08b9f1a5d634d Mon Sep 17 00:00:00 2001 From: John Tran Date: Fri, 10 Jun 2011 10:24:24 -0700 Subject: style change --- nova/tests/test_cloud.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 7cb13c919..c8313a5d3 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -123,7 +123,8 @@ class CloudTestCase(test.TestCase): 'host': self.network.host}) self.assertEqual(allocate(self.context)['publicIp'], address) db.floating_ip_destroy(self.context, address) - self.assertRaises(exception.NoFloatingIpsDefined, allocate, + self.assertRaises(exception.NoFloatingIpsDefined, + allocate, self.context) def test_associate_disassociate_address(self): -- cgit From 0e7a2042cc5922bb014a77080ec0bdb93bbf575c Mon Sep 17 00:00:00 2001 From: John Tran Date: Fri, 10 Jun 2011 10:28:03 -0700 Subject: raise instance instead of class --- nova/api/ec2/cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 84a83d8e6..5ed473b73 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -878,7 +878,7 @@ class CloudController(object): return {'publicIp': public_ip} except rpc.RemoteError as ex: if ex.exc_type == 'NoMoreAddresses': - raise exception.NoFloatingIpsDefined + raise exception.NoFloatingIpsDefined() else: raise -- cgit From 05fecdf873a5c02dcb13c841304df872411d4183 Mon Sep 17 00:00:00 2001 From: John Tran Date: Fri, 10 Jun 2011 11:10:58 -0700 Subject: added new exception more descriptive of not having available floating addresses avail for allocation --- nova/api/ec2/cloud.py | 2 +- nova/exception.py | 4 ++++ nova/tests/test_cloud.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'nova') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 5ed473b73..e1c65ae40 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -878,7 +878,7 @@ class CloudController(object): return {'publicIp': public_ip} except rpc.RemoteError as ex: if ex.exc_type == 'NoMoreAddresses': - raise exception.NoFloatingIpsDefined() + raise exception.NoMoreFloatingIps() else: raise diff --git a/nova/exception.py b/nova/exception.py index 69b3e0359..1571dd032 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -376,6 +376,10 @@ class NoFloatingIpsDefinedForInstance(NoFloatingIpsDefined): message = _("Zero floating ips defined for instance %(instance_id)s.") +class NoMoreFloatingIps(NotFound): + message = _("Zero floating ips available.") + + class KeypairNotFound(NotFound): message = _("Keypair %(keypair_name)s not found for user %(user_id)s") diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index c8313a5d3..13046f861 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -123,7 +123,7 @@ class CloudTestCase(test.TestCase): 'host': self.network.host}) self.assertEqual(allocate(self.context)['publicIp'], address) db.floating_ip_destroy(self.context, address) - self.assertRaises(exception.NoFloatingIpsDefined, + self.assertRaises(exception.NoMoreFloatingIps, allocate, self.context) -- cgit From e986887d513855d5a5fd6ca90998860f67fcb1d3 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Fri, 10 Jun 2011 15:28:17 -0400 Subject: force utf-8 encoding on toprettyxml call for XMLDictSerializer --- nova/api/openstack/wsgi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index ddf4e6fa9..6760735c4 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -225,7 +225,7 @@ class XMLDictSerializer(DictSerializer): if not xmlns and self.xmlns: node.setAttribute('xmlns', self.xmlns) - return node.toprettyxml(indent=' ') + return node.toprettyxml(indent=' ', encoding='utf-8') def _to_xml_node(self, doc, metadata, nodename, data): """Recursive method to convert data members to XML nodes.""" -- cgit From 92423564aa24124b0144264d6cd1c57c78eaf5dd Mon Sep 17 00:00:00 2001 From: William Wolf Date: Fri, 10 Jun 2011 16:41:14 -0400 Subject: return body correctly as object instead of a string, with tests, also check for empty body on requests that need a body --- nova/api/openstack/server_metadata.py | 11 +++++++++-- nova/api/openstack/wsgi.py | 4 ++++ nova/tests/api/openstack/test_server_metadata.py | 25 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) (limited to 'nova') diff --git a/nova/api/openstack/server_metadata.py b/nova/api/openstack/server_metadata.py index b38b84a2a..c17d77d46 100644 --- a/nova/api/openstack/server_metadata.py +++ b/nova/api/openstack/server_metadata.py @@ -37,12 +37,18 @@ class Controller(object): meta_dict[key] = value return dict(metadata=meta_dict) + def _check_body(self, body): + if not body: + expl = _('No Request Body') + raise exc.HTTPBadRequest(explanation=expl) + def index(self, req, server_id): """ Returns the list of metadata for a given instance """ context = req.environ['nova.context'] return self._get_metadata(context, server_id) def create(self, req, server_id, body): + self._check_body(body) context = req.environ['nova.context'] metadata = body.get('metadata') try: @@ -51,9 +57,10 @@ class Controller(object): metadata) except quota.QuotaError as error: self._handle_quota_error(error) - return req.body + return body def update(self, req, server_id, id, body): + self._check_body(body) context = req.environ['nova.context'] if not id in body: expl = _('Request body and URI mismatch') @@ -68,7 +75,7 @@ class Controller(object): except quota.QuotaError as error: self._handle_quota_error(error) - return req.body + return body def show(self, req, server_id, id): """ Return a single metadata item """ diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index ddf4e6fa9..8c30cdeb9 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -348,16 +348,20 @@ class Resource(wsgi.Application): LOG.debug("%(method)s %(url)s" % {"method": request.method, "url": request.url}) + print "CALL" try: action, action_args, accept = self.deserializer.deserialize( request) except exception.InvalidContentType: return webob.exc.HTTPBadRequest(_("Unsupported Content-Type")) + print "CALL2" action_result = self.dispatch(request, action, action_args) + print "ACTION RESULT:", action_result, isinstance(action_result, str) #TODO(bcwaldon): find a more elegant way to pass through non-dict types if type(action_result) is dict: + print "DICT" response = self.serializer.serialize(action_result, accept) else: response = action_result diff --git a/nova/tests/api/openstack/test_server_metadata.py b/nova/tests/api/openstack/test_server_metadata.py index c4d1d4fd8..b583d40fe 100644 --- a/nova/tests/api/openstack/test_server_metadata.py +++ b/nova/tests/api/openstack/test_server_metadata.py @@ -89,6 +89,7 @@ class ServerMetaDataTest(unittest.TestCase): res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) self.assertEqual('value1', res_dict['metadata']['key1']) def test_index_no_data(self): @@ -99,6 +100,7 @@ class ServerMetaDataTest(unittest.TestCase): res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) self.assertEqual(0, len(res_dict['metadata'])) def test_show(self): @@ -109,6 +111,7 @@ class ServerMetaDataTest(unittest.TestCase): res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) self.assertEqual('value5', res_dict['key5']) def test_show_meta_not_found(self): @@ -140,8 +143,19 @@ class ServerMetaDataTest(unittest.TestCase): res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) self.assertEqual('value1', res_dict['metadata']['key1']) + def test_create_empty_body(self): + self.stubs.Set(nova.db.api, 'instance_metadata_update_or_create', + return_create_instance_metadata) + req = webob.Request.blank('/v1.1/servers/1/meta') + req.environ['api.version'] = '1.1' + req.method = 'POST' + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(400, res.status_int) + def test_update_item(self): self.stubs.Set(nova.db.api, 'instance_metadata_update_or_create', return_create_instance_metadata) @@ -152,9 +166,20 @@ class ServerMetaDataTest(unittest.TestCase): req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(200, res.status_int) + self.assertEqual('application/json', res.headers['Content-Type']) res_dict = json.loads(res.body) self.assertEqual('value1', res_dict['key1']) + def test_update_item_empty_body(self): + self.stubs.Set(nova.db.api, 'instance_metadata_update_or_create', + return_create_instance_metadata) + req = webob.Request.blank('/v1.1/servers/1/meta/key1') + req.environ['api.version'] = '1.1' + req.method = 'PUT' + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(400, res.status_int) + def test_update_item_too_many_keys(self): self.stubs.Set(nova.db.api, 'instance_metadata_update_or_create', return_create_instance_metadata) -- cgit From cbaa94ac255cde729bae3257da6657a114755224 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Fri, 10 Jun 2011 16:43:13 -0400 Subject: got rid of prints for debugging --- nova/api/openstack/wsgi.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'nova') diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 8c30cdeb9..ddf4e6fa9 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -348,20 +348,16 @@ class Resource(wsgi.Application): LOG.debug("%(method)s %(url)s" % {"method": request.method, "url": request.url}) - print "CALL" try: action, action_args, accept = self.deserializer.deserialize( request) except exception.InvalidContentType: return webob.exc.HTTPBadRequest(_("Unsupported Content-Type")) - print "CALL2" action_result = self.dispatch(request, action, action_args) - print "ACTION RESULT:", action_result, isinstance(action_result, str) #TODO(bcwaldon): find a more elegant way to pass through non-dict types if type(action_result) is dict: - print "DICT" response = self.serializer.serialize(action_result, accept) else: response = action_result -- cgit From 8146b92f7d81eada6408f939ef25cb5393650008 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Fri, 10 Jun 2011 18:39:58 -0400 Subject: adding support for cusom serialization methods --- nova/api/openstack/wsgi.py | 11 +++++++---- nova/tests/api/openstack/test_wsgi.py | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'nova') diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index ddf4e6fa9..e71b80e2c 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -189,7 +189,10 @@ class DictSerializer(object): def serialize(self, data, action='default'): """Find local serialization method and encode response body.""" - action_method = getattr(self, action, self.default) + if action is None: + action_method = self.default + else: + action_method = getattr(self, action, self.default) return action_method(data) def default(self, data): @@ -296,7 +299,7 @@ class ResponseSerializer(object): } self.serializers.update(serializers or {}) - def serialize(self, response_data, content_type): + def serialize(self, response_data, content_type, action='default'): """Serialize a dict into a string and wrap in a wsgi.Request object. :param response_data: dict produced by the Controller @@ -307,7 +310,7 @@ class ResponseSerializer(object): response.headers['Content-Type'] = content_type serializer = self.get_serializer(content_type) - response.body = serializer.serialize(response_data) + response.body = serializer.serialize(response_data, action) return response @@ -358,7 +361,7 @@ class Resource(wsgi.Application): #TODO(bcwaldon): find a more elegant way to pass through non-dict types if type(action_result) is dict: - response = self.serializer.serialize(action_result, accept) + response = self.serializer.serialize(action_result, accept, action) else: response = action_result diff --git a/nova/tests/api/openstack/test_wsgi.py b/nova/tests/api/openstack/test_wsgi.py index ebbdc9409..0329ab218 100644 --- a/nova/tests/api/openstack/test_wsgi.py +++ b/nova/tests/api/openstack/test_wsgi.py @@ -171,11 +171,11 @@ class XMLDeserializerTest(test.TestCase): class ResponseSerializerTest(test.TestCase): def setUp(self): class JSONSerializer(object): - def serialize(self, data): + def serialize(self, data, action='default'): return 'pew_json' class XMLSerializer(object): - def serialize(self, data): + def serialize(self, data, action='default'): return 'pew_xml' self.serializers = { @@ -211,11 +211,11 @@ class ResponseSerializerTest(test.TestCase): class RequestDeserializerTest(test.TestCase): def setUp(self): class JSONDeserializer(object): - def deserialize(self, data): + def deserialize(self, data, action='default'): return 'pew_json' class XMLDeserializer(object): - def deserialize(self, data): + def deserialize(self, data, action='default'): return 'pew_xml' self.deserializers = { -- cgit From bd31a85575ce53dfa80f414dd359b3bdb2855292 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Mon, 13 Jun 2011 08:53:34 -0400 Subject: check for none and empty string, this way empty dicts/lists will be ok --- nova/api/openstack/server_metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/api/openstack/server_metadata.py b/nova/api/openstack/server_metadata.py index c17d77d46..57666f6b7 100644 --- a/nova/api/openstack/server_metadata.py +++ b/nova/api/openstack/server_metadata.py @@ -38,7 +38,7 @@ class Controller(object): return dict(metadata=meta_dict) def _check_body(self, body): - if not body: + if body == None or body == "": expl = _('No Request Body') raise exc.HTTPBadRequest(explanation=expl) -- cgit From 67e11fa809c83f25af9d09eac1bbe1c69a22a311 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 13 Jun 2011 10:10:45 -0400 Subject: fixed bug 796619 --- nova/crypto.py | 3 ++- nova/tests/test_crypto.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/crypto.py b/nova/crypto.py index bdc32482a..8d535f426 100644 --- a/nova/crypto.py +++ b/nova/crypto.py @@ -176,7 +176,8 @@ def revoke_certs_by_project(project_id): def revoke_certs_by_user_and_project(user_id, project_id): """Revoke certs for user in project.""" admin = context.get_admin_context() - for cert in db.certificate_get_all_by_user(admin, user_id, project_id): + for cert in db.certificate_get_all_by_user_and_project(admin, + user_id, project_id): revoke_cert(cert['project_id'], cert['file_name']) diff --git a/nova/tests/test_crypto.py b/nova/tests/test_crypto.py index 945d78794..1356ec8b8 100644 --- a/nova/tests/test_crypto.py +++ b/nova/tests/test_crypto.py @@ -16,7 +16,10 @@ Tests for Crypto module. """ +import mox + from nova import crypto +from nova import db from nova import test @@ -46,3 +49,69 @@ class SymmetricKeyTestCase(test.TestCase): plain = decrypt(cipher_text) self.assertEquals(plain_text, plain) + + +class RevokeCertsTest(test.TestCase): + + def test_revoke_certs_by_user_and_project(self): + user_id = 'test_user' + project_id = 2 + file_name = 'test_file' + + certificates = [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] + + self.mox.StubOutWithMock(db, 'certificate_get_all_by_user_and_project') + db.certificate_get_all_by_user_and_project(mox.IgnoreArg(), \ + user_id, project_id).AndReturn(certificates) + + self.mox.StubOutWithMock(crypto, 'revoke_cert') + crypto.revoke_cert(project_id, mox.IgnoreArg()) + + self.mox.ReplayAll() + + crypto.revoke_certs_by_user_and_project(user_id, project_id) + + self.mox.VerifyAll() + + def test_revoke_certs_by_user(self): + user_id = 'test_user' + project_id = 2 + file_name = 'test_file' + + certificates = [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] + + self.mox.StubOutWithMock(db, 'certificate_get_all_by_user') + db.certificate_get_all_by_user(mox.IgnoreArg(), \ + user_id).AndReturn(certificates) + + self.mox.StubOutWithMock(crypto, 'revoke_cert') + crypto.revoke_cert(project_id, mox.IgnoreArg()) + + self.mox.ReplayAll() + + crypto.revoke_certs_by_user(user_id) + + self.mox.VerifyAll() + + def test_revoke_certs_by_project(self): + user_id = 'test_user' + project_id = 2 + file_name = 'test_file' + + certificates = [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] + + self.mox.StubOutWithMock(db, 'certificate_get_all_by_project') + db.certificate_get_all_by_project(mox.IgnoreArg(), \ + project_id).AndReturn(certificates) + + self.mox.StubOutWithMock(crypto, 'revoke_cert') + crypto.revoke_cert(project_id, mox.IgnoreArg()) + + self.mox.ReplayAll() + + crypto.revoke_certs_by_project(project_id) + + self.mox.VerifyAll() -- cgit From f2ca12fc5ea236bb8940acce80065a3bcbe37d2a Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 13 Jun 2011 15:03:26 -0400 Subject: wsgi can now handle dispatching action None more elegantly --- nova/api/openstack/wsgi.py | 13 ++++++------- nova/tests/api/openstack/test_wsgi.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'nova') diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index e71b80e2c..385ae4625 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -60,8 +60,9 @@ class TextDeserializer(object): def deserialize(self, datastring, action='default'): """Find local deserialization method and parse request body.""" - action_method = getattr(self, action, self.default) - return action_method(datastring) + action_method = getattr(self, str(action), self.default) + output = action_method(datastring) + return output def default(self, datastring): """Default deserialization code should live here""" @@ -189,11 +190,9 @@ class DictSerializer(object): def serialize(self, data, action='default'): """Find local serialization method and encode response body.""" - if action is None: - action_method = self.default - else: - action_method = getattr(self, action, self.default) - return action_method(data) + action_method = getattr(self, str(action), self.default) + output = action_method(data) + return output def default(self, data): """Default serialization code should live here""" diff --git a/nova/tests/api/openstack/test_wsgi.py b/nova/tests/api/openstack/test_wsgi.py index 0329ab218..5ec7712dd 100644 --- a/nova/tests/api/openstack/test_wsgi.py +++ b/nova/tests/api/openstack/test_wsgi.py @@ -89,6 +89,13 @@ class DictSerializerTest(test.TestCase): serializer.default = lambda x: 'trousers' self.assertEqual(serializer.serialize({}, 'update'), 'trousers') + def test_dispatch_action_None(self): + serializer = wsgi.DictSerializer() + serializer.create = lambda x: 'pants' + serializer.default = lambda x: 'trousers' + self.assertEqual(serializer.serialize({}, None), 'trousers') + + class XMLDictSerializerTest(test.TestCase): def test_xml(self): @@ -123,6 +130,12 @@ class TextDeserializerTest(test.TestCase): deserializer.default = lambda x: 'trousers' self.assertEqual(deserializer.deserialize({}, 'update'), 'trousers') + def test_dispatch_action_None(self): + deserializer = wsgi.TextDeserializer() + deserializer.create = lambda x: 'pants' + deserializer.default = lambda x: 'trousers' + self.assertEqual(deserializer.deserialize({}, None), 'trousers') + class JSONDeserializerTest(test.TestCase): def test_json(self): -- cgit From 83df6e50fa90620dd7510e1a06d9128d4de7cb29 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 13 Jun 2011 15:08:00 -0400 Subject: removing unnecessary lines --- nova/api/openstack/wsgi.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'nova') diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 385ae4625..6cb73d8bf 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -61,8 +61,7 @@ class TextDeserializer(object): def deserialize(self, datastring, action='default'): """Find local deserialization method and parse request body.""" action_method = getattr(self, str(action), self.default) - output = action_method(datastring) - return output + return action_method(datastring) def default(self, datastring): """Default deserialization code should live here""" @@ -191,8 +190,7 @@ class DictSerializer(object): def serialize(self, data, action='default'): """Find local serialization method and encode response body.""" action_method = getattr(self, str(action), self.default) - output = action_method(data) - return output + return action_method(data) def default(self, data): """Default serialization code should live here""" -- cgit From bdfded59fda6716adbbcf981a45d1ed90aa23f89 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 13 Jun 2011 15:18:55 -0400 Subject: Improved tests --- nova/tests/test_crypto.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'nova') diff --git a/nova/tests/test_crypto.py b/nova/tests/test_crypto.py index 1356ec8b8..8eaef3293 100644 --- a/nova/tests/test_crypto.py +++ b/nova/tests/test_crypto.py @@ -17,6 +17,7 @@ Tests for Crypto module. """ import mox +import stubout from nova import crypto from nova import db @@ -53,20 +54,31 @@ class SymmetricKeyTestCase(test.TestCase): class RevokeCertsTest(test.TestCase): + def setUp(self): + super(RevokeCertsTest, self).setUp() + self.stubs = stubout.StubOutForTesting() + + def tearDown(self): + self.stubs.UnsetAll() + super(RevokeCertsTest, self).tearDown() + def test_revoke_certs_by_user_and_project(self): user_id = 'test_user' project_id = 2 file_name = 'test_file' - certificates = [{"user_id": user_id, "project_id": project_id, - "file_name": file_name}] + def mock_certificate_get_all_by_user_and_project(context, + user_id, + project_id): + + return [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] - self.mox.StubOutWithMock(db, 'certificate_get_all_by_user_and_project') - db.certificate_get_all_by_user_and_project(mox.IgnoreArg(), \ - user_id, project_id).AndReturn(certificates) + self.stubs.Set(db, 'certificate_get_all_by_user_and_project', + mock_certificate_get_all_by_user_and_project) self.mox.StubOutWithMock(crypto, 'revoke_cert') - crypto.revoke_cert(project_id, mox.IgnoreArg()) + crypto.revoke_cert(project_id, file_name) self.mox.ReplayAll() @@ -79,12 +91,13 @@ class RevokeCertsTest(test.TestCase): project_id = 2 file_name = 'test_file' - certificates = [{"user_id": user_id, "project_id": project_id, - "file_name": file_name}] + def mock_certificate_get_all_by_user(context, user_id): + + return [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] - self.mox.StubOutWithMock(db, 'certificate_get_all_by_user') - db.certificate_get_all_by_user(mox.IgnoreArg(), \ - user_id).AndReturn(certificates) + self.stubs.Set(db, 'certificate_get_all_by_user', + mock_certificate_get_all_by_user) self.mox.StubOutWithMock(crypto, 'revoke_cert') crypto.revoke_cert(project_id, mox.IgnoreArg()) @@ -100,12 +113,13 @@ class RevokeCertsTest(test.TestCase): project_id = 2 file_name = 'test_file' - certificates = [{"user_id": user_id, "project_id": project_id, - "file_name": file_name}] + def mock_certificate_get_all_by_project(context, project_id): + + return [{"user_id": user_id, "project_id": project_id, + "file_name": file_name}] - self.mox.StubOutWithMock(db, 'certificate_get_all_by_project') - db.certificate_get_all_by_project(mox.IgnoreArg(), \ - project_id).AndReturn(certificates) + self.stubs.Set(db, 'certificate_get_all_by_project', + mock_certificate_get_all_by_project) self.mox.StubOutWithMock(crypto, 'revoke_cert') crypto.revoke_cert(project_id, mox.IgnoreArg()) -- cgit From 431b9d52f2eb325c8be90d45d102c9e238d02325 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 13 Jun 2011 15:24:02 -0400 Subject: pep8 --- nova/tests/test_crypto.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'nova') diff --git a/nova/tests/test_crypto.py b/nova/tests/test_crypto.py index 8eaef3293..6c25b396e 100644 --- a/nova/tests/test_crypto.py +++ b/nova/tests/test_crypto.py @@ -67,15 +67,15 @@ class RevokeCertsTest(test.TestCase): project_id = 2 file_name = 'test_file' - def mock_certificate_get_all_by_user_and_project(context, + def mock_certificate_get_all_by_user_and_project(context, user_id, project_id): - return [{"user_id": user_id, "project_id": project_id, + return [{"user_id": user_id, "project_id": project_id, "file_name": file_name}] - self.stubs.Set(db, 'certificate_get_all_by_user_and_project', - mock_certificate_get_all_by_user_and_project) + self.stubs.Set(db, 'certificate_get_all_by_user_and_project', + mock_certificate_get_all_by_user_and_project) self.mox.StubOutWithMock(crypto, 'revoke_cert') crypto.revoke_cert(project_id, file_name) @@ -91,12 +91,12 @@ class RevokeCertsTest(test.TestCase): project_id = 2 file_name = 'test_file' - def mock_certificate_get_all_by_user(context, user_id): + def mock_certificate_get_all_by_user(context, user_id): - return [{"user_id": user_id, "project_id": project_id, + return [{"user_id": user_id, "project_id": project_id, "file_name": file_name}] - self.stubs.Set(db, 'certificate_get_all_by_user', + self.stubs.Set(db, 'certificate_get_all_by_user', mock_certificate_get_all_by_user) self.mox.StubOutWithMock(crypto, 'revoke_cert') @@ -115,10 +115,10 @@ class RevokeCertsTest(test.TestCase): def mock_certificate_get_all_by_project(context, project_id): - return [{"user_id": user_id, "project_id": project_id, + return [{"user_id": user_id, "project_id": project_id, "file_name": file_name}] - self.stubs.Set(db, 'certificate_get_all_by_project', + self.stubs.Set(db, 'certificate_get_all_by_project', mock_certificate_get_all_by_project) self.mox.StubOutWithMock(crypto, 'revoke_cert') -- cgit From bebeaa6b0bf69c0a4017d429e79174401df28550 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Mon, 13 Jun 2011 15:20:43 -0500 Subject: Removed clocksource=jiffies from PV_args. --- nova/tests/test_xenapi.py | 2 +- nova/virt/xenapi/vm_utils.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'nova') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 3a175b106..d1c88287a 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -331,7 +331,7 @@ class XenAPIVMTestCase(test.TestCase): def check_vm_params_for_linux(self): self.assertEquals(self.vm['platform']['nx'], 'false') - self.assertEquals(self.vm['PV_args'], 'clocksource=jiffies') + self.assertEquals(self.vm['PV_args'], '') self.assertEquals(self.vm['PV_bootloader'], 'pygrub') # check that these are not set diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index b9d4346e4..11da221f2 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -157,7 +157,6 @@ class VMHelper(HelperBase): rec['PV_ramdisk'] = ramdisk else: # 2. Use kernel within the image - rec['PV_args'] = 'clocksource=jiffies' rec['PV_bootloader'] = 'pygrub' else: # 3. Using hardware virtualization -- cgit From f3381ee03355d8800d229efb7f799df9e6c915e2 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 13 Jun 2011 21:14:26 -0400 Subject: pep8 --- nova/api/openstack/limits.py | 2 +- nova/compute/api.py | 2 +- nova/tests/scheduler/test_host_filter.py | 8 ++++---- nova/tests/scheduler/test_least_cost_scheduler.py | 8 ++++---- nova/tests/scheduler/test_zone_aware_scheduler.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'nova') diff --git a/nova/api/openstack/limits.py b/nova/api/openstack/limits.py index dc2bc6bbc..fede96e33 100644 --- a/nova/api/openstack/limits.py +++ b/nova/api/openstack/limits.py @@ -99,7 +99,7 @@ def create_resource(version='1.0'): serializers = { 'application/xml': wsgi.XMLDictSerializer(xmlns=xmlns, - metadata=metadata) + metadata=metadata), } return wsgi.Resource(controller, serializers=serializers) diff --git a/nova/compute/api.py b/nova/compute/api.py index b0949a729..5afc0480a 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -281,7 +281,7 @@ class API(base.Base): 'instance_type': instance_type, 'filter': filter_class, 'blob': zone_blob, - 'num_instances': num_instances + 'num_instances': num_instances, } rpc.cast(context, diff --git a/nova/tests/scheduler/test_host_filter.py b/nova/tests/scheduler/test_host_filter.py index 07817cc5a..10eafde08 100644 --- a/nova/tests/scheduler/test_host_filter.py +++ b/nova/tests/scheduler/test_host_filter.py @@ -133,11 +133,11 @@ class HostFilterTestCase(test.TestCase): raw = ['or', ['and', ['<', '$compute.host_memory_free', 30], - ['<', '$compute.disk_available', 300] + ['<', '$compute.disk_available', 300], ], ['and', ['>', '$compute.host_memory_free', 70], - ['>', '$compute.disk_available', 700] + ['>', '$compute.disk_available', 700], ] ] cooked = json.dumps(raw) @@ -183,12 +183,12 @@ class HostFilterTestCase(test.TestCase): self.assertTrue(hf.filter_hosts(self.zone_manager, json.dumps([]))) self.assertTrue(hf.filter_hosts(self.zone_manager, json.dumps({}))) self.assertTrue(hf.filter_hosts(self.zone_manager, json.dumps( - ['not', True, False, True, False] + ['not', True, False, True, False], ))) try: hf.filter_hosts(self.zone_manager, json.dumps( - 'not', True, False, True, False + 'not', True, False, True, False, )) self.fail("Should give KeyError") except KeyError, e: diff --git a/nova/tests/scheduler/test_least_cost_scheduler.py b/nova/tests/scheduler/test_least_cost_scheduler.py index 506fa62fb..9a5318aee 100644 --- a/nova/tests/scheduler/test_least_cost_scheduler.py +++ b/nova/tests/scheduler/test_least_cost_scheduler.py @@ -44,7 +44,7 @@ class WeightedSumTestCase(test.TestCase): hosts = [ FakeHost(1, 512 * MB, 100), FakeHost(2, 256 * MB, 400), - FakeHost(3, 512 * MB, 100) + FakeHost(3, 512 * MB, 100), ] weighted_fns = [ @@ -96,7 +96,7 @@ class LeastCostSchedulerTestCase(test.TestCase): def test_noop_cost_fn(self): FLAGS.least_cost_scheduler_cost_functions = [ - 'nova.scheduler.least_cost.noop_cost_fn' + 'nova.scheduler.least_cost.noop_cost_fn', ] FLAGS.noop_cost_fn_weight = 1 @@ -110,7 +110,7 @@ class LeastCostSchedulerTestCase(test.TestCase): def test_cost_fn_weights(self): FLAGS.least_cost_scheduler_cost_functions = [ - 'nova.scheduler.least_cost.noop_cost_fn' + 'nova.scheduler.least_cost.noop_cost_fn', ] FLAGS.noop_cost_fn_weight = 2 @@ -124,7 +124,7 @@ class LeastCostSchedulerTestCase(test.TestCase): def test_fill_first_cost_fn(self): FLAGS.least_cost_scheduler_cost_functions = [ - 'nova.scheduler.least_cost.fill_first_cost_fn' + 'nova.scheduler.least_cost.fill_first_cost_fn', ] FLAGS.fill_first_cost_fn_weight = 1 diff --git a/nova/tests/scheduler/test_zone_aware_scheduler.py b/nova/tests/scheduler/test_zone_aware_scheduler.py index 9f70b9dbc..37c6488cc 100644 --- a/nova/tests/scheduler/test_zone_aware_scheduler.py +++ b/nova/tests/scheduler/test_zone_aware_scheduler.py @@ -201,7 +201,7 @@ class ZoneAwareSchedulerTestCase(test.TestCase): 'instance_properties': {}, 'instance_type': {}, 'filter_driver': 'nova.scheduler.host_filter.AllHostsFilter', - 'blob': "Non-None blob data" + 'blob': "Non-None blob data", } result = sched.schedule_run_instance(None, 1, request_spec) -- cgit