From 92feff73674d261797f46728df721e57e4b74eee Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Tue, 7 Aug 2018 13:46:35 -0400 Subject: [PATCH] Tests: Add unit tests for nfs mount race Add unit tests to cover 2f32c98 RemoteFS: don't fail in do_mount if already mounted Change-Id: Ieddcc1138d9a069b96d06c4bf0b93bd6b4cd6a45 --- os_brick/tests/remotefs/test_remotefs.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/os_brick/tests/remotefs/test_remotefs.py b/os_brick/tests/remotefs/test_remotefs.py index 8c891402b..92ba0f7f5 100644 --- a/os_brick/tests/remotefs/test_remotefs.py +++ b/os_brick/tests/remotefs/test_remotefs.py @@ -82,6 +82,24 @@ class RemoteFsClientTestCase(base.TestCase): self.assertEqual(mock_do_mount.call_count, 0) self.assertEqual(mock_execute.call_count, 0) + @mock.patch.object(priv_rootwrap, 'execute') + def test_mount_race(self, mock_execute): + err_msg = 'mount.nfs: /var/asdf is already mounted' + mock_execute.side_effect = putils.ProcessExecutionError(stderr=err_msg) + client = remotefs.RemoteFsClient("nfs", root_helper='true', + nfs_mount_point_base='/var/asdf') + client._do_mount('nfs', '192.0.2.20:/share', '/var/asdf') + + @mock.patch.object(priv_rootwrap, 'execute') + def test_mount_failure(self, mock_execute): + err_msg = 'mount.nfs: nfs broke' + mock_execute.side_effect = putils.ProcessExecutionError(stderr=err_msg) + client = remotefs.RemoteFsClient("nfs", root_helper='true', + nfs_mount_point_base='/var/asdf') + self.assertRaises(putils.ProcessExecutionError, + client._do_mount, + 'nfs', '192.0.2.20:/share', '/var/asdf') + def _test_no_mount_point(self, fs_type): self.assertRaises(exception.InvalidParameterValue, remotefs.RemoteFsClient,