summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin L. Mitchell <kevin.mitchell@rackspace.com>2011-08-25 21:56:45 +0000
committerKevin L. Mitchell <kevin.mitchell@rackspace.com>2011-08-25 21:56:45 +0000
commit2cf0b67e08e1608bd717ffadd41d5029db2b4a3a (patch)
treea7c0e4f75391220ce906c20a72ece22e96b31b94
parent847d6aecb64d7abece4d4f426f26a9561ffb1e51 (diff)
downloadnova-2cf0b67e08e1608bd717ffadd41d5029db2b4a3a.tar.gz
nova-2cf0b67e08e1608bd717ffadd41d5029db2b4a3a.tar.xz
nova-2cf0b67e08e1608bd717ffadd41d5029db2b4a3a.zip
Fix glance image authorization check now that glance can do authorization checks on its own; use correct image service when looking for ramdisk, etc.; fix a couple of PEP8 errors
-rw-r--r--nova/api/openstack/create_instance_helper.py6
-rw-r--r--nova/image/glance.py14
-rw-r--r--nova/ipv6/account_identifier.py3
-rw-r--r--nova/tests/test_ipv6.py2
4 files changed, 20 insertions, 5 deletions
diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py
index 483ff4985..c428a8209 100644
--- a/nova/api/openstack/create_instance_helper.py
+++ b/nova/api/openstack/create_instance_helper.py
@@ -98,7 +98,7 @@ class CreateInstanceHelper(object):
try:
image_service, image_id = nova.image.get_image_service(image_href)
kernel_id, ramdisk_id = self._get_kernel_ramdisk_from_image(
- req, image_id)
+ req, image_service, image_id)
images = set([str(x['id']) for x in image_service.index(context)])
assert str(image_id) in images
except Exception, e:
@@ -248,12 +248,12 @@ class CreateInstanceHelper(object):
msg = _("Server name is an empty string")
raise exc.HTTPBadRequest(explanation=msg)
- def _get_kernel_ramdisk_from_image(self, req, image_id):
+ def _get_kernel_ramdisk_from_image(self, req, image_service, image_id):
"""Fetch an image from the ImageService, then if present, return the
associated kernel and ramdisk image IDs.
"""
context = req.environ['nova.context']
- image_meta = self._image_service.show(context, image_id)
+ image_meta = image_service.show(context, image_id)
# NOTE(sirp): extracted to a separate method to aid unit-testing, the
# new method doesn't need a request obj or an ImageService stub
kernel_id, ramdisk_id = self._do_get_kernel_ramdisk_from_image(
diff --git a/nova/image/glance.py b/nova/image/glance.py
index 9060f6a91..16f803218 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -269,6 +269,20 @@ class GlanceImageService(service.BaseImageService):
image_meta = _convert_from_string(image_meta)
return image_meta
+ @staticmethod
+ def _is_image_available(context, image_meta):
+ """Check image availability.
+
+ Under Glance, images are always available if the context has
+ an auth_token. Otherwise, we fall back to the superclass
+ method.
+
+ """
+ if hasattr(context, 'auth_token') and context.auth_token:
+ return True
+ return service.BaseImageService._is_image_available(context,
+ image_meta)
+
# utility functions
def _convert_timestamps_to_datetimes(image_meta):
diff --git a/nova/ipv6/account_identifier.py b/nova/ipv6/account_identifier.py
index 27bb01988..8a08510ac 100644
--- a/nova/ipv6/account_identifier.py
+++ b/nova/ipv6/account_identifier.py
@@ -39,7 +39,8 @@ def to_global(prefix, mac, project_id):
except TypeError:
raise TypeError(_('Bad prefix for to_global_ipv6: %s') % prefix)
except NameError:
- raise TypeError(_('Bad project_id for to_global_ipv6: %s') % project_id)
+ raise TypeError(_('Bad project_id for to_global_ipv6: %s') %
+ project_id)
def to_mac(ipv6_address):
diff --git a/nova/tests/test_ipv6.py b/nova/tests/test_ipv6.py
index 04c1b5598..e1ba4aafb 100644
--- a/nova/tests/test_ipv6.py
+++ b/nova/tests/test_ipv6.py
@@ -48,7 +48,7 @@ class IPv6RFC2462TestCase(test.TestCase):
def test_to_global_with_bad_prefix(self):
bad_prefix = '82'
self.assertRaises(TypeError, ipv6.to_global,
- bad_prefix,
+ bad_prefix,
'2001:db8::216:3eff:fe33:4455',
'test')