Example #1
0
 def test_swift_exception(self):
     """Test for case where swift raises an exception."""
     self.openstack_download.side_effect = SwiftError(None)
     self.tarsnap_backup.return_value = True
     do_backup_swift()
     self.openstack_download.assert_called_once_with('/var/cache/backups')
     self.assertTrue(self.tarsnap_backup.called)
     self.heartbeat.assert_not_called()
     self.mail_admins.assert_called_once_with(
         'Error when backing up swift containers',
         'Miscellaneous error while downloading swift containers\n'
         'Please check the server logs, they might contain more details.')
Example #2
0
 def test_swift_exception(self):
     """Test for case where swift raises an exception."""
     self.openstack_download.side_effect = SwiftError(None)
     self.tarsnap_backup.return_value = True
     do_backup_swift()
     self.openstack_download.assert_called_once_with('/var/cache/backups')
     self.assertTrue(self.tarsnap_backup.called)
     self.heartbeat.assert_not_called()
     self.mail_admins.assert_called_once_with(
         'Error when backing up swift containers',
         'Miscellaneous error while downloading swift containers\n'
         'Please check the server logs, they might contain more details.'
     )
Example #3
0
 def test_happy_path_no_heartbeat(self):
     """Test for successful backup, without snitch set."""
     self.openstack_download.return_value = {}
     self.tarsnap_backup.return_value = True
     do_backup_swift()
     self.openstack_download.assert_called_once_with('/var/cache/backups')
     self.tarsnap_backup.assert_called_once_with(
         archive_name=mock.ANY,
         cachedir='/var/cache/tarsnap',
         directory='/var/cache/backups',
         keyfile='/etc/tarsnap.key')
     archive_name = self.tarsnap_backup.call_args[1]['archive_name']
     self.assertTrue(archive_name.startswith("im-swift-backup-"))
     self.heartbeat.assert_not_called()
     self.mail_admins.assert_not_called()
Example #4
0
    def test_swift_errors(self):
        """Test for case where some files couldn't be downloaded."""
        download_return_value = [
            FailedContainer(
                'container-1', 1,
                [
                    {
                        'path': 'non/existing/path', 'pseudodir': True,
                        'error': 'TerribleError', 'traceback': 'No Traceback'
                    }
                ]
            ),
            FailedContainer(
                'container-2', 2,
                [
                    {
                        'path': 'existing/path', 'pseudodir': False,
                        'error': 'MeaningFullError42', 'traceback': 'Very long traceback'
                    },
                    {
                        'path': 'existing/path', 'pseudodir': False,
                        'error': 'BizzareError', 'traceback': 'Not so very long traceback'
                    }
                ]
            )
        ]
        self.openstack_download.return_value = download_return_value

        self.tarsnap_backup.return_value = True
        do_backup_swift()
        self.openstack_download.assert_called_once_with('/var/cache/backups')
        self.assertTrue(self.tarsnap_backup.called)
        self.heartbeat.assert_not_called()
        report = (
            'Following containers failed to download:\n'
            '#. container-1; Failed files: 1.\n'
            'Extra information: \n{extra_info1}'
            '#. container-2; Failed files: 2.\n'
            'Extra information: \n{extra_info2}'
            'Please check the server logs, they might contain more details.'
        ).format(
            extra_info1=download_return_value[0].extra_information,
            extra_info2=download_return_value[1].extra_information
        )
        self.mail_admins.assert_called_once_with(
            'Error when backing up swift containers',
            report
        )
Example #5
0
 def test_happy_path_no_heartbeat(self):
     """Test for successful backup, without snitch set."""
     self.openstack_download.return_value = {}
     self.tarsnap_backup.return_value = True
     do_backup_swift()
     self.openstack_download.assert_called_once_with('/var/cache/backups')
     self.tarsnap_backup.assert_called_once_with(
         archive_name=mock.ANY,
         cachedir='/var/cache/tarsnap',
         directory='/var/cache/backups',
         keyfile='/etc/tarsnap.key'
     )
     archive_name = self.tarsnap_backup.call_args[1]['archive_name']
     self.assertTrue(archive_name.startswith("im-swift-backup-"))
     self.heartbeat.assert_not_called()
     self.mail_admins.assert_not_called()
Example #6
0
 def test_swift_errors(self):
     """Test for case where some files couldn't be downloaded."""
     self.openstack_download.return_value = [
         FailedContainer('container-1', 10),
         FailedContainer('container-2', 5)
     ]
     self.tarsnap_backup.return_value = True
     do_backup_swift()
     self.openstack_download.assert_called_once_with('/var/cache/backups')
     self.assertTrue(self.tarsnap_backup.called)
     self.heartbeat.assert_not_called()
     report = (
         'Following containers failed to download:\n'
         '#. container-1; Failed files: 10.\n'
         '#. container-2; Failed files: 5.\n'
         'Please check the server logs, they might contain more details.'
     )
     self.mail_admins.assert_called_once_with(
         'Error when backing up swift containers',
         report
     )
Example #7
0
 def test_swift_errors(self):
     """Test for case where some files couldn't be downloaded."""
     self.openstack_download.return_value = [
         FailedContainer('container-1', 10),
         FailedContainer('container-2', 5)
     ]
     self.tarsnap_backup.return_value = True
     do_backup_swift()
     self.openstack_download.assert_called_once_with('/var/cache/backups')
     self.assertTrue(self.tarsnap_backup.called)
     self.heartbeat.assert_not_called()
     report = (
         'Following containers failed to download:\n'
         '#. container-1; Failed files: 10.\n'
         '#. container-2; Failed files: 5.\n'
         'Please check the server logs, they might contain more details.'
     )
     self.mail_admins.assert_called_once_with(
         'Error when backing up swift containers',
         report
     )
Example #8
0
 def handle(self, *args, **options):
     do_backup_swift()
Example #9
0
 def handle(self, *args, **options):
     do_backup_swift()