Merge "Add check_process() for mysqldump"
This commit is contained in:
commit
9077ba742f
@ -44,6 +44,22 @@ class MySQLDump(base.BackupRunner):
|
|||||||
' --opt' + user_and_pass)
|
' --opt' + user_and_pass)
|
||||||
return cmd + self.zip_cmd + self.encrypt_cmd
|
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):
|
class InnoBackupEx(base.BackupRunner):
|
||||||
"""Implementation of Backup Strategy for InnoBackupEx."""
|
"""Implementation of Backup Strategy for InnoBackupEx."""
|
||||||
@ -71,10 +87,11 @@ class InnoBackupEx(base.BackupRunner):
|
|||||||
LOG.debug('Checking innobackupex process output.')
|
LOG.debug('Checking innobackupex process output.')
|
||||||
with open('/tmp/innobackupex.log', 'r') as backup_log:
|
with open('/tmp/innobackupex.log', 'r') as backup_log:
|
||||||
output = backup_log.read()
|
output = backup_log.read()
|
||||||
LOG.info(output)
|
|
||||||
if not output:
|
if not output:
|
||||||
LOG.error("Innobackupex log file empty.")
|
LOG.error("Innobackupex log file empty.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
LOG.debug(output)
|
||||||
last_line = output.splitlines()[-1].strip()
|
last_line = output.splitlines()[-1].strip()
|
||||||
if not re.search('completed OK!', last_line):
|
if not re.search('completed OK!', last_line):
|
||||||
LOG.error("Innobackupex did not complete successfully.")
|
LOG.error("Innobackupex did not complete successfully.")
|
||||||
|
@ -558,3 +558,21 @@ class BackupAgentTest(trove_testtools.TestCase):
|
|||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
AttributeError,
|
AttributeError,
|
||||||
agent.execute_backup, TroveContext(), bkup_info, 'location')
|
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())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user