Merge lp:~rconradharris/nova/lp742229 into lp:~hudson-openstack/nova/trunk

Proposed by Rick Harris
Status: Merged
Approved by: Jay Pipes
Approved revision: 887
Merged at revision: 891
Proposed branch: lp:~rconradharris/nova/lp742229
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 130 lines (+78/-15)
2 files modified
nova/api/openstack/servers.py (+23/-15)
nova/tests/api/openstack/test_servers.py (+55/-0)
To merge this branch: bzr merge lp:~rconradharris/nova/lp742229
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Josh Kearney (community) Approve
Review via email: mp+54810@code.launchpad.net

Description of the change

disk_format is now an ImageService property. Adds tests to prevent regression.

To post a comment you must log in.
Revision history for this message
Josh Kearney (jk0) wrote :

Big pimpin'.

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

lgtm2

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/api/openstack/servers.py'
--- nova/api/openstack/servers.py 2011-03-24 22:32:00 +0000
+++ nova/api/openstack/servers.py 2011-03-25 04:54:23 +0000
@@ -502,33 +502,41 @@
502 return dict(actions=actions)502 return dict(actions=actions)
503503
504 def _get_kernel_ramdisk_from_image(self, req, image_id):504 def _get_kernel_ramdisk_from_image(self, req, image_id):
505 """Retrevies kernel and ramdisk IDs from Glance505 """Fetch an image from the ImageService, then if present, return the
506506 associated kernel and ramdisk image IDs.
507 Only 'machine' (ami) type use kernel and ramdisk outside of the507 """
508 image.508 context = req.environ['nova.context']
509 """509 image_meta = self._image_service.show(context, image_id)
510 # FIXME(sirp): Since we're retrieving the kernel_id from an510 # NOTE(sirp): extracted to a separate method to aid unit-testing, the
511 # image_property, this means only Glance is supported.511 # new method doesn't need a request obj or an ImageService stub
512 # The BaseImageService needs to expose a consistent way of accessing512 kernel_id, ramdisk_id = self._do_get_kernel_ramdisk_from_image(
513 # kernel_id and ramdisk_id513 image_meta)
514 image = self._image_service.show(req.environ['nova.context'], image_id)514 return kernel_id, ramdisk_id
515515
516 if image['status'] != 'active':516 @staticmethod
517 def _do_get_kernel_ramdisk_from_image(image_meta):
518 """Given an ImageService image_meta, return kernel and ramdisk image
519 ids if present.
520
521 This is only valid for `ami` style images.
522 """
523 image_id = image_meta['id']
524 if image_meta['status'] != 'active':
517 raise exception.Invalid(525 raise exception.Invalid(
518 _("Cannot build from image %(image_id)s, status not active") %526 _("Cannot build from image %(image_id)s, status not active") %
519 locals())527 locals())
520528
521 if image['disk_format'] != 'ami':529 if image_meta['properties']['disk_format'] != 'ami':
522 return None, None530 return None, None
523531
524 try:532 try:
525 kernel_id = image['properties']['kernel_id']533 kernel_id = image_meta['properties']['kernel_id']
526 except KeyError:534 except KeyError:
527 raise exception.NotFound(535 raise exception.NotFound(
528 _("Kernel not found for image %(image_id)s") % locals())536 _("Kernel not found for image %(image_id)s") % locals())
529537
530 try:538 try:
531 ramdisk_id = image['properties']['ramdisk_id']539 ramdisk_id = image_meta['properties']['ramdisk_id']
532 except KeyError:540 except KeyError:
533 raise exception.NotFound(541 raise exception.NotFound(
534 _("Ramdisk not found for image %(image_id)s") % locals())542 _("Ramdisk not found for image %(image_id)s") % locals())
535543
=== modified file 'nova/tests/api/openstack/test_servers.py'
--- nova/tests/api/openstack/test_servers.py 2011-03-24 20:31:04 +0000
+++ nova/tests/api/openstack/test_servers.py 2011-03-25 04:54:23 +0000
@@ -26,6 +26,7 @@
2626
27from nova import context27from nova import context
28from nova import db28from nova import db
29from nova import exception
29from nova import flags30from nova import flags
30from nova import test31from nova import test
31import nova.api.openstack32import nova.api.openstack
@@ -1260,3 +1261,57 @@
1260 server = dom.childNodes[0]1261 server = dom.childNodes[0]
1261 self.assertEquals(server.nodeName, 'server')1262 self.assertEquals(server.nodeName, 'server')
1262 self.assertTrue(server.getAttribute('adminPass').startswith('fake'))1263 self.assertTrue(server.getAttribute('adminPass').startswith('fake'))
1264
1265
1266class TestGetKernelRamdiskFromImage(test.TestCase):
1267 """
1268 If we're building from an AMI-style image, we need to be able to fetch the
1269 kernel and ramdisk associated with the machine image. This information is
1270 stored with the image metadata and return via the ImageService.
1271
1272 These tests ensure that we parse the metadata return the ImageService
1273 correctly and that we handle failure modes appropriately.
1274 """
1275
1276 def test_status_not_active(self):
1277 """We should only allow fetching of kernel and ramdisk information if
1278 we have a 'fully-formed' image, aka 'active'
1279 """
1280 image_meta = {'id': 1, 'status': 'queued'}
1281 self.assertRaises(exception.Invalid, self._get_k_r, image_meta)
1282
1283 def test_not_ami(self):
1284 """Anything other than ami should return no kernel and no ramdisk"""
1285 image_meta = {'id': 1, 'status': 'active',
1286 'properties': {'disk_format': 'vhd'}}
1287 kernel_id, ramdisk_id = self._get_k_r(image_meta)
1288 self.assertEqual(kernel_id, None)
1289 self.assertEqual(ramdisk_id, None)
1290
1291 def test_ami_no_kernel(self):
1292 """If an ami is missing a kernel it should raise NotFound"""
1293 image_meta = {'id': 1, 'status': 'active',
1294 'properties': {'disk_format': 'ami', 'ramdisk_id': 1}}
1295 self.assertRaises(exception.NotFound, self._get_k_r, image_meta)
1296
1297 def test_ami_no_ramdisk(self):
1298 """If an ami is missing a ramdisk it should raise NotFound"""
1299 image_meta = {'id': 1, 'status': 'active',
1300 'properties': {'disk_format': 'ami', 'kernel_id': 1}}
1301 self.assertRaises(exception.NotFound, self._get_k_r, image_meta)
1302
1303 def test_ami_kernel_ramdisk_present(self):
1304 """Return IDs if both kernel and ramdisk are present"""
1305 image_meta = {'id': 1, 'status': 'active',
1306 'properties': {'disk_format': 'ami', 'kernel_id': 1,
1307 'ramdisk_id': 2}}
1308 kernel_id, ramdisk_id = self._get_k_r(image_meta)
1309 self.assertEqual(kernel_id, 1)
1310 self.assertEqual(ramdisk_id, 2)
1311
1312 @staticmethod
1313 def _get_k_r(image_meta):
1314 """Rebinding function to a shorter name for convenience"""
1315 kernel_id, ramdisk_id = \
1316 servers.Controller._do_get_kernel_ramdisk_from_image(image_meta)
1317 return kernel_id, ramdisk_id