def test_backup_incremental_bad_metadata(self): with patch.object(backupagent, 'get_storage_strategy', return_value=MockSwift): agent = backupagent.BackupAgent() bkup_info = { 'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', 'parent': { 'location': 'fake', 'checksum': 'md5' } } self.assertRaises(AttributeError, agent.execute_backup, TroveContext(), bkup_info, 'location')
def test_execute_backup(self): """This test should ensure backup agent ensures that backup and storage is not running resolves backup instance starts backup starts storage reports status """ backup = mock(DBBackup) when(DatabaseModelBase).find_by(id='123').thenReturn(backup) when(backup).save().thenReturn(backup) agent = backupagent.BackupAgent() agent.execute_backup(context=None, backup_id='123', runner=MockBackup) verify(DatabaseModelBase).find_by(id='123') self.assertThat(backup.state, Is(BackupState.COMPLETED)) self.assertThat(backup.location, Equals('http://mockswift/v1/database_backups/123')) verify(backup, times=3).save()
def test_execute_backup(self): """This test should ensure backup agent ensures that backup and storage is not running resolves backup instance starts backup starts storage reports status """ agent = backupagent.BackupAgent() backup_info = { 'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', 'datastore': 'mysql', 'datastore_version': '5.5' } agent.execute_backup(context=None, backup_info=backup_info, runner=MockBackup) self.assertTrue( conductor_api.API.update_backup.called_once_with( ANY, backup_id=backup_info['id'], state=BackupState.NEW)) self.assertTrue( conductor_api.API.update_backup.called_once_with( ANY, backup_id=backup_info['id'], size=ANY, state=BackupState.BUILDING)) self.assertTrue( conductor_api.API.update_backup.called_once_with( ANY, backup_id=backup_info['id'], checksum=ANY, location=ANY, note=ANY, backup_type=backup_info['type'], state=BackupState.COMPLETED))
def test_execute_restore(self): """This test should ensure backup agent resolves backup instance determines backup/restore type transfers/downloads data and invokes the restore module reports status """ when(backupagent).get_storage_strategy(any(), any()).thenReturn(MockStorage) when(backupagent).get_restore_strategy( 'InnoBackupEx', any()).thenReturn(MockRestoreRunner) agent = backupagent.BackupAgent() bkup_info = { 'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', } agent.execute_restore(TroveContext(), bkup_info, '/var/lib/mysql')
def test_execute_lossy_backup(self): """This test verifies that incomplete writes to swift will fail.""" when(MockSwift).save(any(), any()).thenReturn( (False, 'Error', 'y', 'z')) agent = backupagent.BackupAgent() backup_info = { 'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', } self.assertRaises(backupagent.BackupError, agent.execute_backup, context=None, backup_info=backup_info, runner=MockLossyBackup) self.assertTrue( conductor_api.API.update_backup.called_once_with( any(), backup_id=backup_info['id'], state=BackupState.FAILED))
def test_execute_lossy_backup(self, mock_logging): """This test verifies that incomplete writes to swift will fail.""" with patch.object(MockSwift, 'save', return_value=(False, 'Error', 'y', 'z')): agent = backupagent.BackupAgent() backup_info = { 'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', 'datastore': 'mysql', 'datastore_version': '5.5' } self.assertRaises(backupagent.BackupError, agent.execute_backup, context=None, backup_info=backup_info, runner=MockLossyBackup) conductor_api.API.update_backup.assert_has_calls([ call(ANY, backup_id=backup_info['id'], sent=ANY, size=ANY, state=BackupState.BUILDING), call(ANY, backup_id=backup_info['id'], checksum='y', location='z', note='Error', sent=ANY, size=ANY, backup_type=MockLossyBackup.backup_type, state=BackupState.FAILED, success=False) ])
def test_execute_backup(self): """This test should ensure backup agent ensures that backup and storage is not running resolves backup instance starts backup starts storage reports status """ agent = backupagent.BackupAgent() backup_info = {'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', 'datastore': 'mysql', 'datastore_version': '5.5' } agent.execute_backup(context=None, backup_info=backup_info, runner=MockBackup) conductor_api.API.update_backup.assert_has_calls([ call( ANY, backup_id=backup_info['id'], sent=ANY, size=ANY, state=BackupState.BUILDING ), call( ANY, backup_id=backup_info['id'], checksum='fake-checksum', location=ANY, note='w00t', sent=ANY, size=ANY, backup_type=MockBackup.backup_type, state=BackupState.COMPLETED, success=True ) ])
def test_backup_incremental_metadata(self): with patch.object(backupagent, 'get_storage_strategy', return_value=MockSwift): MockStorage.save_metadata = Mock() with patch.object(MockSwift, 'load_metadata', return_value={'lsn': '54321'}): meta = { 'lsn': '12345', 'parent_location': 'fake', 'parent_checksum': 'md5', } mysql_impl.InnoBackupExIncremental.metadata = MagicMock( return_value=meta) mysql_impl.InnoBackupExIncremental.run = MagicMock( return_value=True) mysql_impl.InnoBackupExIncremental.__exit__ = MagicMock( return_value=True) agent = backupagent.BackupAgent() bkup_info = { 'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', 'parent': { 'location': 'fake', 'checksum': 'md5' } } agent.execute_backup(TroveContext(), bkup_info, '/var/lib/mysql') self.assertTrue( MockStorage.save_metadata.called_once_with(ANY, meta))
def test_execute_restore(self): """This test should ensure backup agent resolves backup instance determines backup/restore type transfers/downloads data and invokes the restore module reports status """ with patch.object(backupagent, 'get_storage_strategy', return_value=MockStorage): with patch.object(backupagent, 'get_restore_strategy', return_value=MockRestoreRunner): agent = backupagent.BackupAgent() bkup_info = {'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', } agent.execute_restore(TroveContext(), bkup_info, '/var/lib/mysql/data')
def test_execute_bad_process_backup(self): agent = backupagent.BackupAgent() backup_info = { 'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', 'datastore': 'mysql', 'datastore_version': '5.5' } self.assertRaises(backupagent.BackupError, agent.execute_backup, context=None, backup_info=backup_info, runner=MockCheckProcessBackup) self.assertTrue( conductor_api.API.update_backup.called_once_with( ANY, backup_id=backup_info['id'], state=BackupState.NEW)) self.assertTrue( conductor_api.API.update_backup.called_once_with( ANY, backup_id=backup_info['id'], size=ANY, state=BackupState.BUILDING)) self.assertTrue( conductor_api.API.update_backup.called_once_with( ANY, backup_id=backup_info['id'], checksum=ANY, location=ANY, note=ANY, backup_type=backup_info['type'], state=BackupState.FAILED))
def test_execute_restore(self): """This test should ensure backup agent resolves backup instance determines backup/restore type transfers/downloads data and invokes the restore module reports status """ backup = mock(DBBackup) backup.location = "/backup/location/123" backup.backup_type = 'InnoBackupEx' when(utils).execute(contains('sudo rm -rf')).thenReturn(None) when(utils).clean_out(any()).thenReturn(None) when(backupagent).get_storage_strategy(any(), any()).thenReturn(MockStorage) when(backupagent).get_restore_strategy( 'InnoBackupEx', any()).thenReturn(MockRestoreRunner) when(DatabaseModelBase).find_by(id='123').thenReturn(backup) when(backup).save().thenReturn(backup) agent = backupagent.BackupAgent() agent.execute_restore(TroveContext(), '123', '/var/lib/mysql')
def test_backup_incremental_metadata(self, mock_logging, get_storage_strategy_mock, save_mock, load_metadata_mock, get_datadir_mock): meta = { 'lsn': '12345', 'parent_location': 'fake', 'parent_checksum': 'md5', } with patch.multiple(mysql_impl.InnoBackupExIncremental, metadata=MagicMock(return_value=meta), _run=MagicMock(return_value=True), __exit__=MagicMock(return_value=True)): agent = backupagent.BackupAgent() expected_metadata = { 'datastore': 'mysql', 'datastore_version': 'bo.gus' } bkup_info = { 'id': '123', 'location': 'fake-location', 'type': 'InnoBackupEx', 'checksum': 'fake-checksum', 'parent': { 'location': 'fake', 'checksum': 'md5' } } bkup_info.update(expected_metadata) agent.execute_backup(TroveContext(), bkup_info, '/var/lib/mysql/data') save_mock.assert_called_once_with(ANY, ANY, metadata=expected_metadata)