diff options
author | Johannes Kulik <johannes.kulik@sap.com> | 2021-04-14 15:52:09 +0200 |
---|---|---|
committer | Johannes Kulik <johannes.kulik@sap.com> | 2021-04-14 16:12:41 +0200 |
commit | cf4b152b6b9ec137b49d903aa0f4ccc821a087cc (patch) | |
tree | ada0564bf6ae8ec278808a817d78e6e8060f0af8 /nova | |
parent | 6ce1272a62b6593f9b8474a93a0b41a18a13a80f (diff) | |
download | nova-cf4b152b6b9ec137b49d903aa0f4ccc821a087cc.tar.gz |
vmware: Handle empty list attributes on vSphere objects
We want to switch the SOAP library backing oslo.vmware [1] and the new
library differs in how empty lists are returned. The old library SUDS
didn't set attributes if they were empty lists. The new library sets
those attributes to empty lists.
Therefore, every check with `hasattr()` that later on accesses a single
element instead of iterating over the whole list needs to be changed to
also check that the list contains elements. This ensures compatiblity
between the backend library versions.
[1] https://specs.openstack.org/openstack/oslo-specs/specs/victoria/oslo-vmware-soap-library-switch.html
Change-Id: I9322037cd47ace83fbcb19bbbe051e2feb9af2c7
Diffstat (limited to 'nova')
-rw-r--r-- | nova/virt/vmwareapi/ds_util.py | 2 | ||||
-rw-r--r-- | nova/virt/vmwareapi/vm_util.py | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/nova/virt/vmwareapi/ds_util.py b/nova/virt/vmwareapi/ds_util.py index 4cff1f98dd..dd52e36272 100644 --- a/nova/virt/vmwareapi/ds_util.py +++ b/nova/virt/vmwareapi/ds_util.py @@ -395,7 +395,7 @@ def file_size(session, ds_browser, ds_path, file_name): datastorePath=str(ds_path), searchSpec=search_spec) task_info = session._wait_for_task(search_task) - if hasattr(task_info.result, 'file'): + if hasattr(task_info.result, 'file') and task_info.result.file: return task_info.result.file[0].fileSize diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index 84bb4d7450..1baed66197 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -1069,7 +1069,7 @@ def _get_allocated_vnc_ports(session): "VirtualMachine", [VNC_CONFIG_KEY]) while result: for obj in result.objects: - if not hasattr(obj, 'propSet'): + if not hasattr(obj, 'propSet') or not obj.propSet: continue dynamic_prop = obj.propSet[0] option_value = dynamic_prop.val @@ -1328,7 +1328,7 @@ def get_cluster_ref_by_name(session, cluster_name): """Get reference to the vCenter cluster with the specified name.""" all_clusters = get_all_cluster_mors(session) for cluster in all_clusters: - if (hasattr(cluster, 'propSet') and + if (hasattr(cluster, 'propSet') and cluster.propSet and cluster.propSet[0].val == cluster_name): return cluster.obj |