Repository: openvstorage/framework

Issue:
Add vDisk not working for VMWare
`2016-05-26 13:39:36 72900 +0200 - OVS-1 - 23171/140722815354688 - celery/celery.worker.job - 226 - ERROR - Task ovs.vdisk.create_new[dff66fdc-aa3b-41cf-81f2-25f6e51e3f43] raised unexpected: RuntimeError('Could not find datastore',)
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/opt/OpenvStorage/ovs/lib/vdisk.py", line 615, in create_new
    disk_path = hypervisor.create_volume(storagedriver.mountpoint, storagedriver.storage_ip, diskname, size)
  File "/opt/OpenvStorage/ovs/extensions/hypervisor/hypervisors/vmware.py", line 224, in create_volume
    return self.sdk.create_disk(storage_ip, vpool_mountpoint, disk_path, size)
  File "/opt/OpenvStorage/ovs/extensions/hypervisor/apis/vmware/sdk.py", line 50, in new_function
    return function(self, *args, **kwargs)
  File "/opt/OpenvStorage/ovs/extensions/hypervisor/apis/vmware/sdk.py", line 928, in create_disk
    raise RuntimeError('Could not find datastore')
RuntimeError: Could not find datastore`



Discussion:
Above stacktrace was due to not adding the vPool as a datastore on the ESXi node. However, it doesn't work anyway, with following stacktrace:

```
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/opt/OpenvStorage/ovs/lib/vdisk.py", line 625, in create_new
    disk_path = hypervisor.create_volume(storagedriver.mountpoint, storagedriver.storage_ip, diskname, size)
  File "/opt/OpenvStorage/ovs/extensions/hypervisor/hypervisors/vmware.py", line 224, in create_volume
    return self.sdk.create_disk(storage_ip, vpool_mountpoint, disk_path, size)
  File "/opt/OpenvStorage/ovs/extensions/hypervisor/apis/vmware/sdk.py", line 50, in new_function
    return function(self, *args, **kwargs)
  File "/opt/OpenvStorage/ovs/extensions/hypervisor/apis/vmware/sdk.py", line 929, in create_disk
    if self.file_exists(ip, mountpoint, disk_path):
  File "/opt/OpenvStorage/ovs/extensions/hypervisor/apis/vmware/sdk.py", line 1020, in file_exists
    files_on_datastore = self._get_files_on_datastore(ip, mountpoint)
  File "/opt/OpenvStorage/ovs/extensions/hypervisor/apis/vmware/sdk.py", line 979, in _get_files_on_datastore
    return [file.path for file in result.info.result.file]
AttributeError: 'HostDatastoreBrowserSearchResults' object has no attribute 'file'
```


Resolving patch:
diff --git a/ovs/extensions/hypervisor/apis/vmware/sdk.py b/ovs/extensions/hypervisor/apis/vmware/sdk.py
--- a/ovs/extensions/hypervisor/apis/vmware/sdk.py
+++ b/ovs/extensions/hypervisor/apis/vmware/sdk.py
@@ -976,7 +976,9 @@ def _get_files_on_datastore(self, ip, mountpoint, host=None):
         task = self._client.service.SearchDatastore_Task(datastore.browser, '[{0}]'.format(datastore.name), hdbss)
         result = self.get_task_info(task)
         if result.info.state == 'success':
-            return [file.path for file in result.info.result.file]
+            if hasattr(result.info.result, 'file'):
+                return [f.path for f in result.info.result.file]
+            return []
         self._logger.warning(result.info.error.localizedMessage)
         return []
 


Test patch: