284
286
def test_spawn_raw_glance(self):
285
287
FLAGS.xenapi_image_service = 'glance'
286
self._test_spawn(1, None, None)
288
self._test_spawn(glance_stubs.FakeGlance.IMAGE_RAW, None, None)
290
def test_spawn_vhd_glance(self):
291
FLAGS.xenapi_image_service = 'glance'
292
self._test_spawn(glance_stubs.FakeGlance.IMAGE_VHD, None, None)
288
294
def test_spawn_glance(self):
289
295
FLAGS.xenapi_image_service = 'glance'
290
self._test_spawn(1, 2, 3)
296
self._test_spawn(glance_stubs.FakeGlance.IMAGE_MACHINE,
297
glance_stubs.FakeGlance.IMAGE_KERNEL,
298
glance_stubs.FakeGlance.IMAGE_RAMDISK)
292
300
def tearDown(self):
293
301
super(XenAPIVMTestCase, self).tearDown()
337
345
def tearDown(self):
338
346
super(XenAPIDiffieHellmanTestCase, self).tearDown()
349
class XenAPIMigrateInstance(test.TestCase):
351
Unit test for verifying migration-related actions
355
super(XenAPIMigrateInstance, self).setUp()
356
self.stubs = stubout.StubOutForTesting()
357
FLAGS.target_host = '127.0.0.1'
358
FLAGS.xenapi_connection_url = 'test_url'
359
FLAGS.xenapi_connection_password = 'test_pass'
360
db_fakes.stub_out_db_instance_api(self.stubs)
361
stubs.stub_out_get_target(self.stubs)
363
self.values = {'name': 1, 'id': 1,
364
'project_id': 'fake',
369
'instance_type': 'm1.large',
370
'mac_address': 'aa:bb:cc:dd:ee:ff',
372
stubs.stub_out_migration_methods(self.stubs)
374
def test_migrate_disk_and_power_off(self):
375
instance = db.instance_create(self.values)
376
stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests)
377
conn = xenapi_conn.get_connection(False)
378
conn.migrate_disk_and_power_off(instance, '127.0.0.1')
380
def test_attach_disk(self):
381
instance = db.instance_create(self.values)
382
stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests)
383
conn = xenapi_conn.get_connection(False)
384
conn.attach_disk(instance, {'base_copy': 'hurr', 'cow': 'durr'})
387
class XenAPIDetermineDiskImageTestCase(test.TestCase):
389
Unit tests for code that detects the ImageType
392
super(XenAPIDetermineDiskImageTestCase, self).setUp()
393
glance_stubs.stubout_glance_client(self.stubs,
394
glance_stubs.FakeGlance)
396
class FakeInstance(object):
399
self.fake_instance = FakeInstance()
400
self.fake_instance.id = 42
402
def assert_disk_type(self, disk_type):
403
dt = vm_utils.VMHelper.determine_disk_image_type(
405
self.assertEqual(disk_type, dt)
407
def test_instance_disk(self):
409
If a kernel is specified then the image type is DISK (aka machine)
411
FLAGS.xenapi_image_service = 'objectstore'
412
self.fake_instance.image_id = glance_stubs.FakeGlance.IMAGE_MACHINE
413
self.fake_instance.kernel_id = glance_stubs.FakeGlance.IMAGE_KERNEL
414
self.assert_disk_type(vm_utils.ImageType.DISK)
416
def test_instance_disk_raw(self):
418
If the kernel isn't specified, and we're not using Glance, then
421
FLAGS.xenapi_image_service = 'objectstore'
422
self.fake_instance.image_id = glance_stubs.FakeGlance.IMAGE_RAW
423
self.fake_instance.kernel_id = None
424
self.assert_disk_type(vm_utils.ImageType.DISK_RAW)
426
def test_glance_disk_raw(self):
428
If we're using Glance, then defer to the image_type field, which in
429
this case will be 'raw'.
431
FLAGS.xenapi_image_service = 'glance'
432
self.fake_instance.image_id = glance_stubs.FakeGlance.IMAGE_RAW
433
self.fake_instance.kernel_id = None
434
self.assert_disk_type(vm_utils.ImageType.DISK_RAW)
436
def test_glance_disk_vhd(self):
438
If we're using Glance, then defer to the image_type field, which in
439
this case will be 'vhd'.
441
FLAGS.xenapi_image_service = 'glance'
442
self.fake_instance.image_id = glance_stubs.FakeGlance.IMAGE_VHD
443
self.fake_instance.kernel_id = None
444
self.assert_disk_type(vm_utils.ImageType.DISK_VHD)