Add validation for empty file system backup on Undercloud

This patch works as an addition to the exclude path
when executing an Undercloud backup.

In this case if we exclude all files, there is no need to execute
the task to create the FS backup.

Change-Id: Icd25a8d579151015c9cdf56861d2be933848a723
Closes-Bug: 1767385
This commit is contained in:
Carlos Camacho 2018-05-14 11:25:56 +02:00
parent 2b6efe479e
commit 5578770768
2 changed files with 24 additions and 7 deletions

View File

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

View File

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