Comment 0 for bug 1290807

Revision history for this message
Feng Xi Yan (yanfengxi) wrote : Resize on vCenter failed becausee of _VM_REFS_CACHE

This code is for ice-house latest code version.

The resize action in vmware environment always failed.

The reason is that nova resized the ****-orign rather than the new cloned vm.

It is caused by the outdated vm_ref in _VM_REFS_CACHE.

In nova/virt/vmwareapi/vmops.py:

def finish_migration(self, context, migration, instance, disk_info,
                         network_info, image_meta, resize_instance=False,
                         block_device_info=None, power_on=True):
        """Completes a resize, turning on the migrated instance."""
        if resize_instance:
            client_factory = self._session._get_vim().client.factory
            vm_ref = vm_util.get_vm_ref(self._session, instance)
            vm_resize_spec = vm_util.get_vm_resize_spec(client_factory,
                                                        instance)
            reconfig_task = self._session._call_method(
                                            self._session._get_vim(),
                                            "ReconfigVM_Task", vm_ref,
                                            spec=vm_resize_spec)
           .......

From this code, we can see we get vm_ref by vm_util.get_vm_ref.

In nova/virt/vmwareapi/vm_util.py

@vm_ref_cache_from_instance
def get_vm_ref(session, instance):
    """Get reference to the VM through uuid or vm name."""
    uuid = instance['uuid']
    vm_ref = (_get_vm_ref_from_vm_uuid(session, uuid) or
                  _get_vm_ref_from_extraconfig(session, uuid) or
                  _get_vm_ref_from_uuid(session, uuid) or
                  _get_vm_ref_from_name(session, instance['name']))
    if vm_ref is None:
        raise exception.InstanceNotFound(instance_id=uuid)
    return vm_ref

The "get_vm_ref" method is decorated by "vm_ref_cache_from_instance".
"vm_ref_cache_from_instance" will firstly check cache variable _VM_REFS_CACHE. But _VM_REFS_CACHE contains a outdated vm_ref keyed by our instance_uuid, because the virtual machine's name is changed.