diff options
author | Tim Pownall <pownalltim@gmail.com> | 2015-03-28 02:41:22 +0000 |
---|---|---|
committer | Tim Pownall <pownalltim@gmail.com> | 2015-04-07 05:25:09 +0000 |
commit | 31f208423405ed50bb5b32977071f917ac3ce26d (patch) | |
tree | 057753ff987875ef60de04b96147c665906bbafe | |
parent | bf70df295b0529da9f4381f52fc94d328fa2fdb3 (diff) | |
download | nova-31f208423405ed50bb5b32977071f917ac3ce26d.tar.gz |
xenapi: pull vm_mode and auto_disk_config from image when rescue.
Updating vmops.py to pull vm_mode and auto_disk_config from the image
during rescue mode to ensure the vm is properly built based on the image
properties in the image_meta dictionary.
Change-Id: I29c89e9a17f9a170dbe61e4fe14672d481c4fb78
Closes-Bug: 1432913
-rw-r--r-- | nova/tests/unit/virt/xenapi/test_vmops.py | 17 | ||||
-rw-r--r-- | nova/tests/unit/virt/xenapi/test_xenapi.py | 23 | ||||
-rw-r--r-- | nova/virt/xenapi/vmops.py | 32 |
3 files changed, 51 insertions, 21 deletions
diff --git a/nova/tests/unit/virt/xenapi/test_vmops.py b/nova/tests/unit/virt/xenapi/test_vmops.py index 172881b17c..64578399a8 100644 --- a/nova/tests/unit/virt/xenapi/test_vmops.py +++ b/nova/tests/unit/virt/xenapi/test_vmops.py @@ -331,12 +331,13 @@ class SpawnTestCase(VMOpsTestBase): self.vmops._ensure_enough_free_mem(instance) self.vmops._create_vm_record(context, instance, name_label, di_type, kernel_file, - ramdisk_file, image_meta).AndReturn(vm_ref) + ramdisk_file, image_meta, rescue).AndReturn(vm_ref) step += 1 self.vmops._update_instance_progress(context, instance, step, steps) - self.vmops._attach_disks(instance, vm_ref, name_label, vdis, di_type, - network_info, rescue, admin_password, injected_files) + self.vmops._attach_disks(instance, image_meta, vm_ref, name_label, + vdis, di_type, network_info, rescue, + admin_password, injected_files) if attach_pci_dev: fake_dev = { 'created_at': None, @@ -477,14 +478,15 @@ class SpawnTestCase(VMOpsTestBase): instance, name_label).AndReturn((kernel_file, ramdisk_file)) vm_ref = "fake_vm_ref" + rescue = False self.vmops._create_vm_record(context, instance, name_label, di_type, kernel_file, - ramdisk_file, image_meta).AndReturn(vm_ref) + ramdisk_file, image_meta, rescue).AndReturn(vm_ref) if resize_instance: self.vmops._resize_up_vdis(instance, vdis) - self.vmops._attach_disks(instance, vm_ref, name_label, vdis, di_type, - network_info, False, None, None) + self.vmops._attach_disks(instance, image_meta, vm_ref, name_label, + vdis, di_type, network_info, False, None, None) self.vmops._attach_mapped_block_devices(instance, block_device_info) pci_manager.get_instance_pci_devs(instance).AndReturn([]) @@ -953,13 +955,14 @@ class CreateVMRecordTestCase(VMOpsTestBase): device_id = "0002" image_properties = {"xenapi_device_id": device_id} image_meta = {"properties": image_properties} + rescue = False session = "session" self.vmops._session = session mock_get_vm_device_id.return_value = device_id mock_determine_vm_mode.return_value = "vm_mode" self.vmops._create_vm_record(context, instance, name_label, - disk_image_type, kernel_file, ramdisk_file, image_meta) + disk_image_type, kernel_file, ramdisk_file, image_meta, rescue) mock_get_vm_device_id.assert_called_with(session, image_properties) mock_create_vm.assert_called_with(session, instance, name_label, diff --git a/nova/tests/unit/virt/xenapi/test_xenapi.py b/nova/tests/unit/virt/xenapi/test_xenapi.py index 6d0fd5ccbf..5a86156411 100644 --- a/nova/tests/unit/virt/xenapi/test_xenapi.py +++ b/nova/tests/unit/virt/xenapi/test_xenapi.py @@ -1279,7 +1279,8 @@ iface eth0 inet6 static conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False) image_meta = {'id': IMAGE_VHD, - 'disk_format': 'vhd'} + 'disk_format': 'vhd', + 'properties': {'vm_mode': 'xen'}} conn.rescue(self.context, instance, [], image_meta, '') vm = xenapi_fake.get_record('VM', vm_ref) @@ -1304,8 +1305,8 @@ iface eth0 inet6 static instance = self._create_instance(obj=True) session = get_session() image_meta = {'id': IMAGE_VHD, - 'disk_format': 'vhd'} - + 'disk_format': 'vhd', + 'properties': {'vm_mode': 'xen'}} vm_ref = vm_utils.lookup(session, instance['name']) vdi_ref, vdi_rec = vm_utils.get_vdi_for_vm_safely(session, vm_ref) @@ -2316,9 +2317,11 @@ class XenAPIAutoDiskConfigTestCase(stubs.XenAPITestBase): vdi_uuid = session.call_xenapi('VDI.get_record', vdi_ref)['uuid'] vdis = {'root': {'uuid': vdi_uuid, 'ref': vdi_ref}} - - self.conn._vmops._attach_disks(instance, vm_ref, instance['name'], - vdis, disk_image_type, "fake_nw_inf") + image_meta = {'id': 'null', + 'disk_format': 'vhd', + 'properties': {'vm_mode': 'xen'}} + self.conn._vmops._attach_disks(instance, image_meta, vm_ref, + instance['name'], vdis, disk_image_type, "fake_nw_inf") self.assertEqual(marker["partition_called"], called) @@ -2433,10 +2436,12 @@ class XenAPIGenerateLocal(stubs.XenAPITestBase): if disk_image_type == vm_utils.ImageType.DISK_ISO: vdi_key = 'iso' vdis = {vdi_key: {'uuid': vdi_uuid, 'ref': vdi_ref}} - self.called = False - self.conn._vmops._attach_disks(instance, vm_ref, instance['name'], - vdis, disk_image_type, "fake_nw_inf") + image_meta = {'id': 'null', + 'disk_format': 'vhd', + 'properties': {'vm_mode': 'xen'}} + self.conn._vmops._attach_disks(instance, image_meta, vm_ref, + instance['name'], vdis, disk_image_type, "fake_nw_inf") self.assertTrue(self.called) def test_generate_swap(self): diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index bb8c1fe33d..85582c21cf 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -457,7 +457,7 @@ class VMOps(object): if resize: self._resize_up_vdis(instance, vdis) - self._attach_disks(instance, vm_ref, name_label, vdis, + self._attach_disks(instance, image_meta, vm_ref, name_label, vdis, disk_image_type, network_info, rescue, admin_password, injected_files) if not first_boot: @@ -502,7 +502,7 @@ class VMOps(object): kernel_file, ramdisk_file): vm_ref = self._create_vm_record(context, instance, name_label, disk_image_type, kernel_file, - ramdisk_file, image_meta) + ramdisk_file, image_meta, rescue) def undo_create_vm(): self._destroy(instance, vm_ref, network_info=network_info) @@ -643,7 +643,7 @@ class VMOps(object): raise exception.InsufficientFreeMemory(uuid=instance['uuid']) def _create_vm_record(self, context, instance, name_label, disk_image_type, - kernel_file, ramdisk_file, image_meta): + kernel_file, ramdisk_file, image_meta, rescue=False): """Create the VM record in Xen, making sure that we do not create a duplicate name-label. Also do a rough sanity check on memory to try to short-circuit a potential failure later. (The memory @@ -651,6 +651,15 @@ class VMOps(object): that are in progress.) """ mode = vm_utils.determine_vm_mode(instance, disk_image_type) + # NOTE(tpownall): If rescue mode then we should try to pull the vm_mode + # value from the image properties to ensure the vm is built properly. + if rescue: + rescue_vm_mode = image_meta['properties'].get('vm_mode', None) + if rescue_vm_mode is None: + LOG.debug("Failed to pull vm_mode from rescue_image_ref.") + else: + mode = vm_mode.canonicalize(rescue_vm_mode) + if instance.vm_mode != mode: # Update database with normalized (or determined) value instance.vm_mode = mode @@ -665,7 +674,7 @@ class VMOps(object): use_pv_kernel, device_id) return vm_ref - def _attach_disks(self, instance, vm_ref, name_label, vdis, + def _attach_disks(self, instance, image_meta, vm_ref, name_label, vdis, disk_image_type, network_info, rescue=False, admin_password=None, files=None): flavor = instance.get_flavor() @@ -684,7 +693,20 @@ class VMOps(object): else: root_vdi = vdis['root'] - if instance['auto_disk_config']: + auto_disk_config = instance['auto_disk_config'] + # NOTE(tpownall): If rescue mode we need to ensure that we're + # pulling the auto_disk_config value from the image properties so + # that we can pull it from the rescue_image_ref. + if rescue: + rescue_auto_disk_config = image_meta['properties'].get( + 'auto_disk_config', None) + if rescue_auto_disk_config is None: + LOG.debug("Failed to pull auto_disk_config value from" + "image.") + else: + auto_disk_config = rescue_auto_disk_config + + if auto_disk_config: LOG.debug("Auto configuring disk, attempting to " "resize root disk...", instance=instance) vm_utils.try_auto_configure_disk(self._session, |