From fdc10686cf77e981ba5dc7107d545095c36a2a95 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Wed, 10 Oct 2018 16:00:59 -0400 Subject: [PATCH] NFS Backup: Avoid TypeError in os-brick when not configured If backup_share is not set, a TypeError is raised from os-brick, because this code is run before the config options are validated. Don't try to initialize the path if this is not set. Closes-Bug: #1797227 Change-Id: I96e104f0e0da0257c48bbaffc2b436f670ccdb76 --- cinder/backup/drivers/nfs.py | 5 +++++ cinder/tests/unit/backup/drivers/test_backup_nfs.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/cinder/backup/drivers/nfs.py b/cinder/backup/drivers/nfs.py index 002d85eda03..c5bc2a3fcaa 100644 --- a/cinder/backup/drivers/nfs.py +++ b/cinder/backup/drivers/nfs.py @@ -73,6 +73,11 @@ class NFSBackupDriver(posix.PosixBackupDriver): value=val) def _init_backup_repo_path(self): + if self.backup_share is None: + LOG.info("_init_backup_repo_path: " + "backup_share is not set in configuration") + return + remotefsclient = remotefs_brick.RemoteFsClient( 'nfs', self._root_helper, diff --git a/cinder/tests/unit/backup/drivers/test_backup_nfs.py b/cinder/tests/unit/backup/drivers/test_backup_nfs.py index ff45fb1430a..c65d0131fcc 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_nfs.py +++ b/cinder/tests/unit/backup/drivers/test_backup_nfs.py @@ -135,6 +135,18 @@ class BackupNFSShareTestCase(test.TestCase): mock_execute.assert_has_calls(mock_execute_calls, any_order=True) self.assertEqual(len(mock_execute_calls), mock_execute.call_count) + def test_init_backup_repo_path_unconfigured(self): + """RemoteFsClient is not created if backup_share unset""" + self.override_config('backup_share', None) + + mock_remotefsclient = mock.Mock() + self.mock_object(remotefs_brick, 'RemoteFsClient') + + driver = nfs.NFSBackupDriver(self.ctxt) + driver._init_backup_repo_path() + + self.assertEqual(0, mock_remotefsclient.call_count) + def fake_md5(arg): class result(object):