diff --git a/tripleo_common/actions/undercloud.py b/tripleo_common/actions/undercloud.py index 745ceb36e..339a702bf 100644 --- a/tripleo_common/actions/undercloud.py +++ b/tripleo_common/actions/undercloud.py @@ -161,14 +161,18 @@ class CreateFileSystemBackup(base.Action): """ % (self.outfile, separated_string, self.outfile) proc_failed = False - try: - subprocess.check_call(script, shell=True) - except subprocess.CalledProcessError: - proc_failed = True - msg = 'File system backup failed' - os.remove(self.outfile) + if self.sources_path: + try: + subprocess.check_call(script, shell=True) + except subprocess.CalledProcessError: + proc_failed = True + msg = 'File system backup failed' + os.remove(self.outfile) + else: + msg = ('File system backup created succesfully at: %s' + % self.outfile) else: - msg = 'File system backup created succesfully at: ' + self.outfile + msg = 'File system backup has no files to backup' if proc_failed: # Delete failed backup here diff --git a/tripleo_common/tests/actions/test_undercloud.py b/tripleo_common/tests/actions/test_undercloud.py index 2fccb4cf1..ece06f40b 100644 --- a/tripleo_common/tests/actions/test_undercloud.py +++ b/tripleo_common/tests/actions/test_undercloud.py @@ -101,6 +101,9 @@ class CreateFileSystemBackupTest(base.TestCase): self.fsback = undercloud.CreateFileSystemBackup( '/home/stack/,/etc/hosts', '/var/tmp/undercloud-backup-ef9b_H') + self.fsemptyback = undercloud.CreateFileSystemBackup( + '', + '/var/tmp/undercloud-backup-ef9b_H') @mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client') @mock.patch('subprocess.check_call') @@ -120,6 +123,16 @@ class CreateFileSystemBackupTest(base.TestCase): '\n ') mock_check_call.assert_called_once_with(assert_string, shell=True) + @mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client') + @mock.patch('subprocess.check_call') + def test_create_empty_file_system_backup( + self, + mock_check_call, + mock_get_object_client): + self.fsemptyback.logger = mock.Mock() + self.fsemptyback.run(mock_get_object_client) + mock_check_call.assert_not_called() + class CreateBackupDirTest(base.TestCase):