~cerberus/nova/disk_config

« back to all changes in this revision

Viewing changes to nova/tests/test_libvirt.py

  • Committer: matt.dietz at rackspace
  • Date: 2011-09-21 19:48:25 UTC
  • mfrom: (1511.1.98 nova)
  • Revision ID: matt.dietz@rackspace.com-20110921194825-zv1w4qonfh6o1j2u
Merge from trunk, updated failing tests and pep8

Show diffs side-by-side

added added

removed removed

Lines of Context:
269
269
        instance_data = dict(self.test_instance)
270
270
        self._check_xml_and_container(instance_data)
271
271
 
272
 
    def test_snapshot(self):
273
 
        if not self.lazy_load_library_exists():
274
 
            return
275
 
 
276
 
        self.flags(image_service='nova.image.fake.FakeImageService')
277
 
 
278
 
        # Start test
279
 
        image_service = utils.import_object(FLAGS.image_service)
280
 
 
281
 
        # Assuming that base image already exists in image_service
282
 
        instance_ref = db.instance_create(self.context, self.test_instance)
283
 
        properties = {'instance_id': instance_ref['id'],
284
 
                      'user_id': str(self.context.user_id)}
285
 
        snapshot_name = 'test-snap'
286
 
        sent_meta = {'name': snapshot_name, 'is_public': False,
287
 
                     'status': 'creating', 'properties': properties}
288
 
        # Create new image. It will be updated in snapshot method
289
 
        # To work with it from snapshot, the single image_service is needed
290
 
        recv_meta = image_service.create(context, sent_meta)
291
 
 
292
 
        self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
293
 
        connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
294
 
        self.mox.StubOutWithMock(connection.utils, 'execute')
295
 
        connection.utils.execute = self.fake_execute
296
 
 
297
 
        self.mox.ReplayAll()
298
 
 
299
 
        conn = connection.LibvirtConnection(False)
300
 
        conn.snapshot(self.context, instance_ref, recv_meta['id'])
301
 
 
302
 
        snapshot = image_service.show(context, recv_meta['id'])
303
 
        self.assertEquals(snapshot['properties']['image_state'], 'available')
304
 
        self.assertEquals(snapshot['status'], 'active')
 
272
    def test_snapshot_in_raw_format(self):
 
273
        if not self.lazy_load_library_exists():
 
274
            return
 
275
 
 
276
        self.flags(image_service='nova.image.fake.FakeImageService')
 
277
 
 
278
        # Start test
 
279
        image_service = utils.import_object(FLAGS.image_service)
 
280
 
 
281
        # Assuming that base image already exists in image_service
 
282
        instance_ref = db.instance_create(self.context, self.test_instance)
 
283
        properties = {'instance_id': instance_ref['id'],
 
284
                      'user_id': str(self.context.user_id)}
 
285
        snapshot_name = 'test-snap'
 
286
        sent_meta = {'name': snapshot_name, 'is_public': False,
 
287
                     'status': 'creating', 'properties': properties}
 
288
        # Create new image. It will be updated in snapshot method
 
289
        # To work with it from snapshot, the single image_service is needed
 
290
        recv_meta = image_service.create(context, sent_meta)
 
291
 
 
292
        self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
 
293
        connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
 
294
        self.mox.StubOutWithMock(connection.utils, 'execute')
 
295
        connection.utils.execute = self.fake_execute
 
296
 
 
297
        self.mox.ReplayAll()
 
298
 
 
299
        conn = connection.LibvirtConnection(False)
 
300
        conn.snapshot(self.context, instance_ref, recv_meta['id'])
 
301
 
 
302
        snapshot = image_service.show(context, recv_meta['id'])
 
303
        self.assertEquals(snapshot['properties']['image_state'], 'available')
 
304
        self.assertEquals(snapshot['status'], 'active')
 
305
        self.assertEquals(snapshot['disk_format'], 'raw')
 
306
        self.assertEquals(snapshot['name'], snapshot_name)
 
307
 
 
308
    def test_snapshot_in_qcow2_format(self):
 
309
        if not self.lazy_load_library_exists():
 
310
            return
 
311
 
 
312
        self.flags(image_service='nova.image.fake.FakeImageService')
 
313
        self.flags(snapshot_image_format='qcow2')
 
314
 
 
315
        # Start test
 
316
        image_service = utils.import_object(FLAGS.image_service)
 
317
 
 
318
        # Assuming that base image already exists in image_service
 
319
        instance_ref = db.instance_create(self.context, self.test_instance)
 
320
        properties = {'instance_id': instance_ref['id'],
 
321
                      'user_id': str(self.context.user_id)}
 
322
        snapshot_name = 'test-snap'
 
323
        sent_meta = {'name': snapshot_name, 'is_public': False,
 
324
                     'status': 'creating', 'properties': properties}
 
325
        # Create new image. It will be updated in snapshot method
 
326
        # To work with it from snapshot, the single image_service is needed
 
327
        recv_meta = image_service.create(context, sent_meta)
 
328
 
 
329
        self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
 
330
        connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
 
331
        self.mox.StubOutWithMock(connection.utils, 'execute')
 
332
        connection.utils.execute = self.fake_execute
 
333
 
 
334
        self.mox.ReplayAll()
 
335
 
 
336
        conn = connection.LibvirtConnection(False)
 
337
        conn.snapshot(self.context, instance_ref, recv_meta['id'])
 
338
 
 
339
        snapshot = image_service.show(context, recv_meta['id'])
 
340
        self.assertEquals(snapshot['properties']['image_state'], 'available')
 
341
        self.assertEquals(snapshot['status'], 'active')
 
342
        self.assertEquals(snapshot['disk_format'], 'qcow2')
305
343
        self.assertEquals(snapshot['name'], snapshot_name)
306
344
 
307
345
    def test_snapshot_no_image_architecture(self):