VMware: fix compute node exception when no hosts in cluster

Commit 4033c0c9c1 casues the
regression. The result was a empty string and not None.
That is suds returns a Text object and not None.

Change-Id: I79e70e300f40eb3561cf56478d578f0f8cda273e
Closes-bug: #1383305
(cherry picked from commit 419096ec19)
This commit is contained in:
Gary Kotton 2014-10-20 06:37:14 -07:00
parent e98738d55a
commit 4dd50808bf
2 changed files with 13 additions and 1 deletions

View File

@ -311,6 +311,16 @@ class DsUtilTestCase(test.NoDBTestCase):
ds_util.get_datastore,
self.session, 'fake-cluster')
def test_get_datastore_no_host_in_cluster(self):
def fake_call_method(module, method, *args, **kwargs):
return ''
with mock.patch.object(self.session, '_call_method',
fake_call_method):
self.assertRaises(exception.DatastoreNotFound,
ds_util.get_datastore,
self.session, 'fake-cluster')
def _test_is_datastore_valid(self, accessible=True,
maintenance_mode="normal",
type="VMFS",

View File

@ -248,7 +248,9 @@ def get_datastore(session, cluster, datastore_regex=None):
vim_util,
"get_dynamic_property", cluster,
"ClusterComputeResource", "datastore")
if datastore_ret is None:
# If there are no hosts in the cluster then an empty string is
# returned
if not datastore_ret:
raise exception.DatastoreNotFound()
data_store_mors = datastore_ret.ManagedObjectReference