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
This commit is contained in:
Eric Harney 2018-10-10 16:00:59 -04:00
parent 70f331228a
commit fdc10686cf
2 changed files with 17 additions and 0 deletions

View File

@ -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,

View File

@ -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):