Merge lp:~vishvananda/nova/lp824433 into lp:~hudson-openstack/nova/milestone-proposed

Proposed by Vish Ishaya
Status: Merged
Approved by: Vish Ishaya
Approved revision: 1530
Merged at revision: 1182
Proposed branch: lp:~vishvananda/nova/lp824433
Merge into: lp:~hudson-openstack/nova/milestone-proposed
Diff against target: 173 lines (+84/-44)
2 files modified
nova/tests/test_libvirt.py (+71/-33)
nova/virt/libvirt/connection.py (+13/-11)
To merge this branch: bzr merge lp:~vishvananda/nova/lp824433
Reviewer Review Type Date Requested Status
OpenStack release team Pending
Review via email: mp+76092@code.launchpad.net

Description of the change

Fixes the handling of snapshotting in libvirt driver to actually use the proper image type instead of using raw for everything. Also cleans up an unneeded flag. Based on doude's initial work.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/tests/test_libvirt.py'
--- nova/tests/test_libvirt.py 2011-09-16 17:36:43 +0000
+++ nova/tests/test_libvirt.py 2011-09-19 20:04:46 +0000
@@ -340,39 +340,77 @@
340 instance_data = dict(self.test_instance)340 instance_data = dict(self.test_instance)
341 self._check_xml_and_container(instance_data)341 self._check_xml_and_container(instance_data)
342342
343 def test_snapshot(self):343 def test_snapshot_in_raw_format(self):
344 if not self.lazy_load_library_exists():344 if not self.lazy_load_library_exists():
345 return345 return
346346
347 self.flags(image_service='nova.image.fake.FakeImageService')347 self.flags(image_service='nova.image.fake.FakeImageService')
348348
349 # Start test349 # Start test
350 image_service = utils.import_object(FLAGS.image_service)350 image_service = utils.import_object(FLAGS.image_service)
351351
352 # Assuming that base image already exists in image_service352 # Assuming that base image already exists in image_service
353 instance_ref = db.instance_create(self.context, self.test_instance)353 instance_ref = db.instance_create(self.context, self.test_instance)
354 properties = {'instance_id': instance_ref['id'],354 properties = {'instance_id': instance_ref['id'],
355 'user_id': str(self.context.user_id)}355 'user_id': str(self.context.user_id)}
356 snapshot_name = 'test-snap'356 snapshot_name = 'test-snap'
357 sent_meta = {'name': snapshot_name, 'is_public': False,357 sent_meta = {'name': snapshot_name, 'is_public': False,
358 'status': 'creating', 'properties': properties}358 'status': 'creating', 'properties': properties}
359 # Create new image. It will be updated in snapshot method359 # Create new image. It will be updated in snapshot method
360 # To work with it from snapshot, the single image_service is needed360 # To work with it from snapshot, the single image_service is needed
361 recv_meta = image_service.create(context, sent_meta)361 recv_meta = image_service.create(context, sent_meta)
362362
363 self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')363 self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
364 connection.LibvirtConnection._conn.lookupByName = self.fake_lookup364 connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
365 self.mox.StubOutWithMock(connection.utils, 'execute')365 self.mox.StubOutWithMock(connection.utils, 'execute')
366 connection.utils.execute = self.fake_execute366 connection.utils.execute = self.fake_execute
367367
368 self.mox.ReplayAll()368 self.mox.ReplayAll()
369369
370 conn = connection.LibvirtConnection(False)370 conn = connection.LibvirtConnection(False)
371 conn.snapshot(self.context, instance_ref, recv_meta['id'])371 conn.snapshot(self.context, instance_ref, recv_meta['id'])
372372
373 snapshot = image_service.show(context, recv_meta['id'])373 snapshot = image_service.show(context, recv_meta['id'])
374 self.assertEquals(snapshot['properties']['image_state'], 'available')374 self.assertEquals(snapshot['properties']['image_state'], 'available')
375 self.assertEquals(snapshot['status'], 'active')375 self.assertEquals(snapshot['status'], 'active')
376 self.assertEquals(snapshot['disk_format'], 'raw')
377 self.assertEquals(snapshot['name'], snapshot_name)
378
379 def test_snapshot_in_qcow2_format(self):
380 if not self.lazy_load_library_exists():
381 return
382
383 self.flags(image_service='nova.image.fake.FakeImageService')
384 self.flags(snapshot_image_format='qcow2')
385
386 # Start test
387 image_service = utils.import_object(FLAGS.image_service)
388
389 # Assuming that base image already exists in image_service
390 instance_ref = db.instance_create(self.context, self.test_instance)
391 properties = {'instance_id': instance_ref['id'],
392 'user_id': str(self.context.user_id)}
393 snapshot_name = 'test-snap'
394 sent_meta = {'name': snapshot_name, 'is_public': False,
395 'status': 'creating', 'properties': properties}
396 # Create new image. It will be updated in snapshot method
397 # To work with it from snapshot, the single image_service is needed
398 recv_meta = image_service.create(context, sent_meta)
399
400 self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
401 connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
402 self.mox.StubOutWithMock(connection.utils, 'execute')
403 connection.utils.execute = self.fake_execute
404
405 self.mox.ReplayAll()
406
407 conn = connection.LibvirtConnection(False)
408 conn.snapshot(self.context, instance_ref, recv_meta['id'])
409
410 snapshot = image_service.show(context, recv_meta['id'])
411 self.assertEquals(snapshot['properties']['image_state'], 'available')
412 self.assertEquals(snapshot['status'], 'active')
413 self.assertEquals(snapshot['disk_format'], 'qcow2')
376 self.assertEquals(snapshot['name'], snapshot_name)414 self.assertEquals(snapshot['name'], snapshot_name)
377415
378 def test_snapshot_no_image_architecture(self):416 def test_snapshot_no_image_architecture(self):
379417
=== modified file 'nova/virt/libvirt/connection.py'
--- nova/virt/libvirt/connection.py 2011-09-18 19:24:46 +0000
+++ nova/virt/libvirt/connection.py 2011-09-19 20:04:46 +0000
@@ -125,8 +125,10 @@
125 'Define block migration behavior.')125 'Define block migration behavior.')
126flags.DEFINE_integer('live_migration_bandwidth', 0,126flags.DEFINE_integer('live_migration_bandwidth', 0,
127 'Define live migration behavior')127 'Define live migration behavior')
128flags.DEFINE_string('qemu_img', 'qemu-img',128flags.DEFINE_string('snapshot_image_format', None,
129 'binary to use for qemu-img commands')129 'Snapshot image format (valid options are : '
130 'raw, qcow2, vmdk, vdi).'
131 'Defaults to same as source image')
130flags.DEFINE_string('libvirt_vif_type', 'bridge',132flags.DEFINE_string('libvirt_vif_type', 'bridge',
131 'Type of VIF to create.')133 'Type of VIF to create.')
132flags.DEFINE_string('libvirt_vif_driver',134flags.DEFINE_string('libvirt_vif_driver',
@@ -391,10 +393,7 @@
391 def snapshot(self, context, instance, image_href):393 def snapshot(self, context, instance, image_href):
392 """Create snapshot from a running VM instance.394 """Create snapshot from a running VM instance.
393395
394 This command only works with qemu 0.14+, the qemu_img flag is396 This command only works with qemu 0.14+
395 provided so that a locally compiled binary of qemu-img can be used
396 to support this command.
397
398 """397 """
399 virt_dom = self._lookup_by_name(instance['name'])398 virt_dom = self._lookup_by_name(instance['name'])
400399
@@ -420,8 +419,11 @@
420 arch = base['properties']['architecture']419 arch = base['properties']['architecture']
421 metadata['properties']['architecture'] = arch420 metadata['properties']['architecture'] = arch
422421
423 if 'disk_format' in base:422 source_format = base.get('disk_format') or 'raw'
424 metadata['disk_format'] = base['disk_format']423 image_format = FLAGS.snapshot_image_format or source_format
424 if FLAGS.use_cow_images:
425 source_format = 'qcow2'
426 metadata['disk_format'] = image_format
425427
426 if 'container_format' in base:428 if 'container_format' in base:
427 metadata['container_format'] = base['container_format']429 metadata['container_format'] = base['container_format']
@@ -444,12 +446,12 @@
444 # Export the snapshot to a raw image446 # Export the snapshot to a raw image
445 temp_dir = tempfile.mkdtemp()447 temp_dir = tempfile.mkdtemp()
446 out_path = os.path.join(temp_dir, snapshot_name)448 out_path = os.path.join(temp_dir, snapshot_name)
447 qemu_img_cmd = (FLAGS.qemu_img,449 qemu_img_cmd = ('qemu-img',
448 'convert',450 'convert',
449 '-f',451 '-f',
450 'qcow2',452 source_format,
451 '-O',453 '-O',
452 'raw',454 image_format,
453 '-s',455 '-s',
454 snapshot_name,456 snapshot_name,
455 disk_path,457 disk_path,

Subscribers

People subscribed via source and target branches