From: Kartik Bommepally Date: Tue, 24 Sep 2013 10:58:10 +0000 (-0700) Subject: VMware: Handles no datastores case X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=04608f9126d2bc34abff7a80afe7ad1a39679a04;p=openstack-build%2Fcinder-build.git VMware: Handles no datastores case If the host does not have datastores mounted or is in maintenance mode then it reports empty datastores list. Modified code to ignore such cases. Fixes bug: 1229653 Change-Id: I8f076d7b652181988b45738664a0d549c0b5ff9b --- diff --git a/cinder/tests/test_vmware_vmdk.py b/cinder/tests/test_vmware_vmdk.py index bc2c097e0..973ed75e3 100644 --- a/cinder/tests/test_vmware_vmdk.py +++ b/cinder/tests/test_vmware_vmdk.py @@ -97,6 +97,17 @@ class FakeSnapshotTree(object): self.childSnapshotList = childSnapshotList +class FakeElem(object): + def __init__(self, prop_set=None): + self.propSet = prop_set + + +class FakeProp(object): + def __init__(self, name=None, val=None): + self.name = name + self.val = val + + class VMwareEsxVmdkDriverTestCase(test.TestCase): """Test class for VMwareEsxVmdkDriver.""" @@ -406,6 +417,26 @@ class VMwareEsxVmdkDriverTestCase(test.TestCase): m.UnsetStubs() m.VerifyAll() + def test_get_dss_rp_without_datastores(self): + """Test get_dss_rp without datastores.""" + m = self.mox + m.StubOutWithMock(api.VMwareAPISession, 'vim') + self._session.vim = self._vim + m.StubOutWithMock(self._session, 'invoke_api') + host = FakeObject() + props = [FakeElem(prop_set=[FakeProp(name='datastore')])] + self._session.invoke_api(vim_util, 'get_object_properties', + self._vim, host, + ['datastore', 'parent']).AndReturn(props) + self._session.invoke_api(vim_util, 'get_object_property', + self._vim, mox.IgnoreArg(), 'resourcePool') + + m.ReplayAll() + self.assertRaises(error_util.VimException, self._volumeops.get_dss_rp, + host) + m.UnsetStubs() + m.VerifyAll() + def test_get_parent(self): """Test get_parent.""" # Not recursive diff --git a/cinder/volume/drivers/vmware/volumeops.py b/cinder/volume/drivers/vmware/volumeops.py index 06b332b9f..a407e00f0 100644 --- a/cinder/volume/drivers/vmware/volumeops.py +++ b/cinder/volume/drivers/vmware/volumeops.py @@ -154,7 +154,8 @@ class VMwareVolumeOps(object): compute_resource = None for elem in props: for prop in elem.propSet: - if prop.name == 'datastore': + if prop.name == 'datastore' and prop.val: + # Consider only if datastores are present under host datastores = prop.val.ManagedObjectReference elif prop.name == 'parent': compute_resource = prop.val