summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-05-04 02:47:42 +0000
committerGerrit Code Review <review@openstack.org>2016-05-04 02:47:43 +0000
commitcd81512f87476b0bad29db379d3b92b22723cd2e (patch)
treebb6a083bd6e48f4ef92afc715d8623657b7af7b2
parent43b6a2f049be1114548f2e1c83c063c8ed70b4c7 (diff)
parent8a9f711c082e564fb5ac2f983a4616652f5b4d3d (diff)
downloadnova-stable/kilo.tar.gz
Merge "VMware: Use virtual disk size instead of image size" into stable/kilokilo-eol2015.1.4stable/kilo
-rw-r--r--nova/tests/unit/virt/vmwareapi/fake.py1
-rw-r--r--nova/tests/unit/virt/vmwareapi/test_vmops.py3
-rw-r--r--nova/virt/vmwareapi/ds_util.py19
-rw-r--r--nova/virt/vmwareapi/vmops.py17
4 files changed, 40 insertions, 0 deletions
diff --git a/nova/tests/unit/virt/vmwareapi/fake.py b/nova/tests/unit/virt/vmwareapi/fake.py
index 35f1dd5f21..3bb660028c 100644
--- a/nova/tests/unit/virt/vmwareapi/fake.py
+++ b/nova/tests/unit/virt/vmwareapi/fake.py
@@ -1396,6 +1396,7 @@ class FakeVim(object):
for file in matched_files:
matched = DataObject()
matched.path = file
+ matched.fileSize = 1024
result.file.append(matched)
task_mdo = create_task(method, "success", result=result)
else:
diff --git a/nova/tests/unit/virt/vmwareapi/test_vmops.py b/nova/tests/unit/virt/vmwareapi/test_vmops.py
index 2c99cbd921..91b67e57a3 100644
--- a/nova/tests/unit/virt/vmwareapi/test_vmops.py
+++ b/nova/tests/unit/virt/vmwareapi/test_vmops.py
@@ -1803,7 +1803,9 @@ class VMwareVMOpsTestCase(test.NoDBTestCase):
@mock.patch.object(ds_util, 'file_move')
@mock.patch.object(vm_util, 'copy_virtual_disk')
@mock.patch.object(vmops.VMwareVMOps, '_delete_datastore_file')
+ @mock.patch.object(vmops.VMwareVMOps, '_update_image_size')
def test_cache_sparse_image(self,
+ mock_update_image_size,
mock_delete_datastore_file,
mock_copy_virtual_disk,
mock_file_move):
@@ -1822,6 +1824,7 @@ class VMwareVMOpsTestCase(test.NoDBTestCase):
self._session, self._dc_info.ref,
sparse_disk_path,
DsPathMatcher(target_disk_path))
+ mock_update_image_size.assert_called_once_with(vi)
def test_get_storage_policy_none(self):
flavor = objects.Flavor(name='m1.small',
diff --git a/nova/virt/vmwareapi/ds_util.py b/nova/virt/vmwareapi/ds_util.py
index d447715594..a7011d0c5d 100644
--- a/nova/virt/vmwareapi/ds_util.py
+++ b/nova/virt/vmwareapi/ds_util.py
@@ -364,6 +364,11 @@ def search_datastore_spec(client_factory, file_name):
"""Builds the datastore search spec."""
search_spec = client_factory.create('ns0:HostDatastoreBrowserSearchSpec')
search_spec.matchPattern = [file_name]
+ search_spec.details = client_factory.create('ns0:FileQueryFlags')
+ search_spec.details.fileOwner = False
+ search_spec.details.fileSize = True
+ search_spec.details.fileType = False
+ search_spec.details.modification = False
return search_spec
@@ -386,6 +391,20 @@ def file_exists(session, ds_browser, ds_path, file_name):
return file_exists
+def file_size(session, ds_browser, ds_path, file_name):
+ """Returns the size of the specified file."""
+ client_factory = session.vim.client.factory
+ search_spec = search_datastore_spec(client_factory, file_name)
+ search_task = session._call_method(session.vim,
+ "SearchDatastore_Task",
+ ds_browser,
+ datastorePath=str(ds_path),
+ searchSpec=search_spec)
+ task_info = session._wait_for_task(search_task)
+ if hasattr(task_info.result, 'file'):
+ return task_info.result.file[0].fileSize
+
+
def mkdir(session, ds_path, dc_ref):
"""Creates a directory at the path specified. If it is just "NAME",
then a directory with this name is created at the topmost level of the
diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py
index 32de30e77d..e796c3e772 100644
--- a/nova/virt/vmwareapi/vmops.py
+++ b/nova/virt/vmwareapi/vmops.py
@@ -419,6 +419,9 @@ class VMwareVMOps(object):
self._move_to_cache(vi.dc_info.ref,
tmp_image_ds_loc.parent,
vi.cache_image_folder)
+ # The size of the image is different from the size of the virtual
+ # disk. We want to use the latter.
+ self._update_image_size(vi)
def _cache_flat_image(self, vi, tmp_image_ds_loc):
self._move_to_cache(vi.dc_info.ref,
@@ -552,6 +555,20 @@ class VMwareVMOps(object):
dc_info, size,
adapter_type, path)
+ def _update_image_size(self, vi):
+ """Updates the file size of the specified image."""
+ # The size of the Glance image is different from the deployed VMDK
+ # size for sparse, streamOptimized and OVA images. We need to retrieve
+ # the size of the flat VMDK and update the file_size property of the
+ # image. This ensures that further operations involving size checks
+ # and disk resizing will work as expected.
+ ds_browser = self._get_ds_browser(vi.datastore.ref)
+ flat_file = "%s-flat.vmdk" % vi.ii.image_id
+ new_size = ds_util.file_size(self._session, ds_browser,
+ vi.cache_image_folder, flat_file)
+ if new_size is not None:
+ vi.ii.file_size = new_size
+
def spawn(self, context, instance, image_meta, injected_files,
admin_password, network_info, block_device_info=None,
power_on=True):