From 3293cc930a36a84c59fd68348cfa86dc65392826 Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Tue, 23 Sep 2014 16:58:30 +0100 Subject: [PATCH] VMware: Set vmPathName properly in fake driver When creating a VM, we pass in config.files.vmPathName as '[ds]'. However, when this value is subsequently retrieved from a real vSphere server, it is '[ds] uuid/uuid.vmx'. This change defaults the value of vmPathName if it's a bare datastore name to mirror the behaviour of a real vSphere server. Change-Id: Ide2a4d69fe0ce3214c85b132a8d653f8d5e275f9 --- nova/tests/virt/vmwareapi/fake.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nova/tests/virt/vmwareapi/fake.py b/nova/tests/virt/vmwareapi/fake.py index d2034853f8..b3b99c4966 100644 --- a/nova/tests/virt/vmwareapi/fake.py +++ b/nova/tests/virt/vmwareapi/fake.py @@ -1174,8 +1174,16 @@ class FakeVim(object): """Creates and registers a VM object with the Host System.""" config_spec = kwargs.get("config") pool = kwargs.get('pool') + name = config_spec.name vm_path = ds_util.DatastorePath.parse(config_spec.files.vmPathName) + # Fill in the default path to the vmx file if we were only given a + # datastore. Note that if you create a VM with vmPathName '[foo]', when + # you retrieve vmPathName it will be '[foo] uuid/uuid.vmx'. Hence we + # use vm_path below for the stored value of vmPathName. + if vm_path.rel_path == '': + vm_path = vm_path.join(name, name + '.vmx') + for key, value in _db_content["Datastore"].iteritems(): if value.get('summary.name') == vm_path.datastore: ds = key @@ -1189,11 +1197,11 @@ class FakeVim(object): devices.append(device_change.device) host = _db_content["HostSystem"].keys()[0] - vm_dict = {"name": config_spec.name, + vm_dict = {"name": name, "ds": [ds], "runtime_host": host, "powerstate": "poweredOff", - "vmPathName": config_spec.files.vmPathName, + "vmPathName": str(vm_path), "numCpu": config_spec.numCPUs, "mem": config_spec.memoryMB, "extra_config": config_spec.extraConfig,