Merge "Add check_process() for mysqldump"

This commit is contained in:
Zuul 2019-01-10 03:14:46 +00:00 committed by Gerrit Code Review
commit 9077ba742f
2 changed files with 36 additions and 1 deletions

View File

@ -44,6 +44,22 @@ class MySQLDump(base.BackupRunner):
' --opt' + user_and_pass)
return cmd + self.zip_cmd + self.encrypt_cmd
def check_process(self):
"""Check the output from mysqldump ignoring 'Warning'."""
LOG.debug('Checking mysqldump process output.')
with open('/tmp/mysqldump.log', 'r') as backup_log:
output = backup_log.read()
if not output:
return True
LOG.debug(output)
for line in output.splitlines():
if not re.search('Warning', line.strip()):
LOG.error("Mysqldump did not complete successfully.")
return False
return True
class InnoBackupEx(base.BackupRunner):
"""Implementation of Backup Strategy for InnoBackupEx."""
@ -71,10 +87,11 @@ class InnoBackupEx(base.BackupRunner):
LOG.debug('Checking innobackupex process output.')
with open('/tmp/innobackupex.log', 'r') as backup_log:
output = backup_log.read()
LOG.info(output)
if not output:
LOG.error("Innobackupex log file empty.")
return False
LOG.debug(output)
last_line = output.splitlines()[-1].strip()
if not re.search('completed OK!', last_line):
LOG.error("Innobackupex did not complete successfully.")

View File

@ -558,3 +558,21 @@ class BackupAgentTest(trove_testtools.TestCase):
self.assertRaises(
AttributeError,
agent.execute_backup, TroveContext(), bkup_info, 'location')
def test_backup_mysqldump_check_process(self):
mysql_dump = mysql_impl.MySQLDump(
'abc', extra_opts='')
str_will_be_true = 'Warning: Using a password ' \
'on the command line interface can be insecure.'
str_will_be_false = 'ERROR: mysqldump command did not succeed.'
with mock.patch('trove.guestagent.strategies.backup.mysql_impl.open',
mock.mock_open(read_data='')):
self.assertTrue(mysql_dump.check_process())
with mock.patch('trove.guestagent.strategies.backup.mysql_impl.open',
mock.mock_open(read_data=str_will_be_true)):
self.assertTrue(mysql_dump.check_process())
with mock.patch('trove.guestagent.strategies.backup.mysql_impl.open',
mock.mock_open(read_data=str_will_be_false)):
self.assertFalse(mysql_dump.check_process())