]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
VMware: Handles no datastores case
authorKartik Bommepally <kbommepally@vmware.com>
Tue, 24 Sep 2013 10:58:10 +0000 (03:58 -0700)
committerKartik Bommepally <kbommepally@vmware.com>
Tue, 24 Sep 2013 10:58:10 +0000 (03:58 -0700)
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

cinder/tests/test_vmware_vmdk.py
cinder/volume/drivers/vmware/volumeops.py

index bc2c097e0f3edf5d0677b6a3a52cc61ad17b49c2..973ed75e341fe75be8aca51004374f206f4ee793 100644 (file)
@@ -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
index 06b332b9ffbbefc2ada29421068d7ef7910da245..a407e00f0e8ec54876a498a528372ba760ad407e 100644 (file)
@@ -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