]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Log an error on nfs mount failure
authorAlex Meade <mr.alex.meade@gmail.com>
Thu, 7 Aug 2014 14:08:36 +0000 (10:08 -0400)
committerAlex Meade <mr.alex.meade@gmail.com>
Thu, 11 Sep 2014 01:48:44 +0000 (20:48 -0500)
Change from a log warning to a log error when an nfs driver
cannot mount the backend share. Add tests to ensure the error is
logged correctly.

Change-Id: Id9d51aebe349e7a4e09d1211b17efd8d47af97f5

cinder/brick/remotefs/remotefs.py
cinder/test.py
cinder/tests/test_nfs.py
cinder/volume/drivers/remotefs.py

index 50c6bf84abdb359206727ac7d88d7d103e6b707b..b20ebb96aba4a78ae3dda49d8d05dd1a7492831f 100755 (executable)
@@ -133,7 +133,7 @@ class RemoteFsClient(object):
             except Exception as e:
                 mnt_errors[mnt_type] = six.text_type(e)
                 LOG.debug('Failed to do %s mount.', mnt_type)
-        raise exception.BrickException(_("NFS mount failed for share %(sh)s."
+        raise exception.BrickException(_("NFS mount failed for share %(sh)s. "
                                          "Error - %(error)s")
                                        % {'sh': nfs_share,
                                           'error': mnt_errors})
index 3c5321fb1e5880e5778b22d5feb68062c6237b98..5f36942bcf18ae46ad3c3ec2d5ea0af0569a690e 100644 (file)
@@ -28,6 +28,7 @@ import tempfile
 import uuid
 
 import fixtures
+import mock
 import mox
 from oslo.config import cfg
 from oslo.messaging import conffixture as messaging_conffixture
@@ -239,6 +240,19 @@ class TestCase(testtools.TestCase):
         self._services.append(svc)
         return svc
 
+    def mock_object(self, obj, attr_name, new_attr=None, **kwargs):
+        """Use python mock to mock an object attribute
+
+        Mocks the specified objects attribute with the given value.
+        Automatically performs 'addCleanup' for the mock.
+
+        """
+        if not new_attr:
+            new_attr = mock.Mock()
+        patcher = mock.patch.object(obj, attr_name, new_attr, **kwargs)
+        patcher.start()
+        self.addCleanup(patcher.stop)
+
     # Useful assertions
     def assertDictMatch(self, d1, d2, approx_equal=False, tolerance=0.001):
         """Assert two dicts are equivalent.
index d9f9ad8b59b5d112a2c1c2a141a6a5b65c727b56..f3693ab3f5d07327f76c45d34a55586cc4cff121 100644 (file)
@@ -1,4 +1,3 @@
-
 # Copyright (c) 2012 NetApp, Inc.
 # All Rights Reserved.
 #
@@ -323,26 +322,28 @@ class NfsDriverTestCase(test.TestCase):
 
     def test_ensure_shares_mounted_should_not_save_mounting_with_error(self):
         """_ensure_shares_mounted should not save share if failed to mount."""
-        mox = self._mox
-        drv = self._driver
 
-        mox.StubOutWithMock(drv, '_read_config_file')
         config_data = []
         config_data.append(self.TEST_NFS_EXPORT1)
-        drv._read_config_file(self.TEST_SHARES_CONFIG_FILE).\
-            AndReturn(config_data)
+        self._driver.configuration.nfs_shares_config =\
+            self.TEST_SHARES_CONFIG_FILE
 
-        mox.StubOutWithMock(drv, '_ensure_share_mounted')
-        drv.configuration.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE
-        drv._ensure_share_mounted(self.TEST_NFS_EXPORT1).AndRaise(Exception())
+        self.mock_object(self._driver, '_read_config_file',
+                         mock.Mock(return_value=config_data))
+        self.mock_object(self._driver, '_ensure_share_mounted',
+                         mock.Mock(side_effect=Exception()))
+        self.mock_object(remotefs, 'LOG')
 
-        mox.ReplayAll()
+        self._driver._ensure_shares_mounted()
 
-        drv._ensure_shares_mounted()
+        self.assertEqual(0, len(self._driver._mounted_shares))
+        self._driver._read_config_file.assert_called_once_with(
+            self.TEST_SHARES_CONFIG_FILE)
 
-        self.assertEqual(0, len(drv._mounted_shares))
+        self._driver._ensure_share_mounted.assert_called_once_with(
+            self.TEST_NFS_EXPORT1)
 
-        mox.VerifyAll()
+        self.assertEqual(1, remotefs.LOG.error.call_count)
 
     def test_setup_should_throw_error_if_shares_config_not_configured(self):
         """do_setup should throw error if shares config is not configured."""
index 3a07c1a6ae79bed414d8a125f59707108806a002..d72d57f5d6d8e8d4897f4d5b0c19df8eccf646d1 100644 (file)
@@ -149,7 +149,7 @@ class RemoteFSDriver(driver.VolumeDriver):
                 self._ensure_share_mounted(share)
                 self._mounted_shares.append(share)
             except Exception as exc:
-                LOG.warning(_('Exception during mounting %s') % (exc,))
+                LOG.error(_('Exception during mounting %s') % (exc,))
 
         LOG.debug('Available shares %s' % self._mounted_shares)