Navigation Menu

Skip to content

Commit

Permalink
VMware: Handles no datastores case
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kartik Bommepally committed Sep 24, 2013
1 parent 180513d commit 04608f9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions cinder/tests/test_vmware_vmdk.py
Expand Up @@ -97,6 +97,17 @@ def __init__(self, tree=None, name=None,
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."""

Expand Down Expand Up @@ -406,6 +417,26 @@ def test_get_dss_rp(self):
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
Expand Down
3 changes: 2 additions & 1 deletion cinder/volume/drivers/vmware/volumeops.py
Expand Up @@ -154,7 +154,8 @@ def get_dss_rp(self, host):
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
Expand Down

0 comments on commit 04608f9

Please sign in to comment.