summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatt.dietz@rackspace.com <>2011-03-07 23:51:20 +0000
committermatt.dietz@rackspace.com <>2011-03-07 23:51:20 +0000
commite39995def6a2a11cdd430b0e6f603b493be5542b (patch)
treeff5d420a67bcba87de69021f4b7f8de0bfd0eaa1
parent2f0845b7b80081d18ee268b94fe38326f3c5401e (diff)
downloadnova-e39995def6a2a11cdd430b0e6f603b493be5542b.tar.gz
nova-e39995def6a2a11cdd430b0e6f603b493be5542b.tar.xz
nova-e39995def6a2a11cdd430b0e6f603b493be5542b.zip
Some more refactoring and a tighter unit test
-rw-r--r--nova/tests/test_xenapi.py14
-rw-r--r--nova/tests/xenapi/stubs.py15
-rw-r--r--nova/virt/xenapi/vmops.py30
-rw-r--r--nova/virt/xenapi_conn.py4
4 files changed, 39 insertions, 24 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index f5b154a51..919a38c06 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -360,16 +360,22 @@ class XenAPIMigrateInstance(test.TestCase):
db_fakes.stub_out_db_instance_api(self.stubs)
stubs.stub_out_get_target(self.stubs)
xenapi_fake.reset()
+ self.manager = manager.AuthManager()
+ self.user = self.manager.create_user('fake', 'fake', 'fake',
+ admin=True)
+ self.project = self.manager.create_project('fake', 'fake', 'fake')
self.values = {'name': 1, 'id': 1,
- 'project_id': 'fake',
- 'user_id': 'fake',
+ 'project_id': self.project.id,
+ 'user_id': self.user.id,
'image_id': 1,
- 'kernel_id': 2,
- 'ramdisk_id': 3,
+ 'kernel_id': None,
+ 'ramdisk_id': None,
'instance_type': 'm1.large',
'mac_address': 'aa:bb:cc:dd:ee:ff',
}
stubs.stub_out_migration_methods(self.stubs)
+ glance_stubs.stubout_glance_client(self.stubs,
+ glance_stubs.FakeGlance)
def test_migrate_disk_and_power_off(self):
instance = db.instance_create(self.values)
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index 28037c2ba..d8e358611 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -225,6 +225,17 @@ class FakeSessionForMigrationTests(fake.SessionBase):
def __init__(self, uri):
super(FakeSessionForMigrationTests, self).__init__(uri)
+ def VDI_get_by_uuid(*args):
+ return 'hurr'
+
+ def VM_start(self, _1, ref, _2, _3):
+ vm = fake.get_record('VM', ref)
+ if vm['power_state'] != 'Halted':
+ raise fake.Failure(['VM_BAD_POWER_STATE', ref, 'Halted',
+ vm['power_state']])
+ vm['power_state'] = 'Running'
+ vm['is_a_template'] = False
+ vm['is_control_domain'] = False
def stub_out_migration_methods(stubs):
def fake_get_snapshot(self, instance):
@@ -251,7 +262,7 @@ def stub_out_migration_methods(stubs):
def fake_destroy(*args, **kwargs):
pass
- def fake_spawn_with_disk(*args, **kwargs):
+ def fake_reset_network(*args, **kwargs):
pass
stubs.Set(vmops.VMOps, '_destroy', fake_destroy)
@@ -261,5 +272,5 @@ def stub_out_migration_methods(stubs):
stubs.Set(vm_utils.VMHelper, 'get_vdi_for_vm_safely', fake_get_vdi)
stubs.Set(xenapi_conn.XenAPISession, 'wait_for_task', lambda x, y, z: None)
stubs.Set(vm_utils.VMHelper, 'get_sr_path', fake_get_sr_path)
+ stubs.Set(vmops.VMOps, 'reset_network', fake_reset_network)
stubs.Set(vmops.VMOps, '_shutdown', fake_shutdown)
- stubs.Set(vmops.VMOps, 'spawn_with_disk', fake_spawn_with_disk)
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index e658de7f3..7fe1f6ff0 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -72,13 +72,19 @@ class VMOps(object):
LOG.debug(_("Starting instance %s"), instance.name)
self._session.call_xenapi('VM.start', vm_ref, False, False)
- def spawn(self, instance):
- self._spawn(instance, disk=None)
-
- def spawn_with_disk(self, instance, vdi_uuid):
- self._spawn(instance, disk=vdi_uuid)
+ def create_disk(self, instance):
+ user = AuthManager().get_user(instance.user_id)
+ project = AuthManager().get_project(instance.project_id)
+ disk_image_type = VMHelper.determine_disk_image_type(instance)
+ vdi_uuid = VMHelper.fetch_image(self._session, instance.id,
+ instance.image_id, user, project, disk_image_type)
+ return vdi_uuid
- def _spawn(self, instance, disk):
+ def spawn(self, instance):
+ vdi_uuid = self.create_disk(instance)
+ self._spawn_with_disk(instance, vdi_uuid=vdi_uuid)
+
+ def _spawn_with_disk(self, instance, vdi_uuid):
"""Create VM instance"""
instance_name = instance.name
vm = VMHelper.lookup(self._session, instance_name)
@@ -101,17 +107,9 @@ class VMOps(object):
vdi_ref = kernel = ramdisk = pv_kernel = None
# Are we building from a pre-existing disk?
- if not disk:
- #if kernel is not present we must download a raw disk
-
- disk_image_type = VMHelper.determine_disk_image_type(instance)
- vdi_uuid = VMHelper.fetch_image(self._session, instance.id,
- instance.image_id, user, project, disk_image_type)
- vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', vdi_uuid)
-
- else:
- vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', disk)
+ vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', vdi_uuid)
+ disk_image_type = VMHelper.determine_disk_image_type(instance)
if disk_image_type == ImageType.DISK_RAW:
# Have a look at the VDI and see if it has a PV kernel
pv_kernel = VMHelper.lookup_image(self._session, instance.id,
diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py
index 9965accad..b63a5f8c3 100644
--- a/nova/virt/xenapi_conn.py
+++ b/nova/virt/xenapi_conn.py
@@ -160,9 +160,9 @@ class XenAPIConnection(object):
def finish_resize(self, instance, disk_info):
"""Completes a resize, turning on the migrated instance"""
- cow_uuid = self._vmops.attach_disk(instance, disk_info['base_copy'],
+ vdi_uuid = self._vmops.attach_disk(instance, disk_info['base_copy'],
disk_info['cow'])
- self._vmops.spawn_with_disk(instance, cow_uuid)
+ self._vmops._spawn_with_disk(instance, vdi_uuid)
def snapshot(self, instance, image_id):
""" Create snapshot from a running VM instance """