Exemple #1
0
def remove_database_dumps(databases, log_prefix, location_config,
                          dry_run):  # pragma: no cover
    '''
    Remove all database dump files for this hook regardless of the given databases. Use the log
    prefix in any log entries. Use the given location configuration dict to construct the
    destination path. If this is a dry run, then don't actually remove anything.
    '''
    dump.remove_database_dumps(make_dump_path(location_config), 'PostgreSQL',
                               log_prefix, dry_run)
Exemple #2
0
def remove_database_dumps(databases, log_prefix, location_config, dry_run):  # pragma: no cover
    '''
    Remove the database dumps for the given databases. The databases are supplied as a sequence of
    dicts, one dict describing each database as per the configuration schema. Use the log prefix in
    any log entries. Use the given location configuration dict to construct the destination path. If
    this is a dry run, then don't actually remove anything.
    '''
    dump.remove_database_dumps(
        make_dump_path(location_config), databases, 'MySQL', log_prefix, dry_run
    )
Exemple #3
0
def test_remove_database_dumps_without_dump_path_present_skips_removal():
    flexmock(module.os.path).should_receive('expanduser').and_return(
        'databases/localhost')
    flexmock(module.os.path).should_receive('exists').and_return(False)
    flexmock(module.shutil).should_receive('rmtree').never()

    module.remove_database_dumps('databases',
                                 'SuperDB',
                                 'test.yaml',
                                 dry_run=False)
Exemple #4
0
def test_remove_database_dumps_removes_dump_path():
    flexmock(module.os.path).should_receive('expanduser').and_return(
        'databases/localhost')
    flexmock(module.os.path).should_receive('exists').and_return(True)
    flexmock(module.shutil).should_receive('rmtree').with_args(
        'databases/localhost').once()

    module.remove_database_dumps('databases',
                                 'SuperDB',
                                 'test.yaml',
                                 dry_run=False)
Exemple #5
0
def test_remove_database_dumps_removes_dump_in_directory_format():
    databases = [{'name': 'foo'}]
    flexmock(module).should_receive('make_database_dump_filename').with_args(
        'databases', 'foo', None
    ).and_return('databases/localhost/foo')

    flexmock(module.os.path).should_receive('isdir').and_return(True)
    flexmock(module.os).should_receive('remove').never()
    flexmock(module.shutil).should_receive('rmtree').with_args('databases/localhost/foo').once()
    flexmock(module.os).should_receive('listdir').with_args('databases/localhost').and_return([])
    flexmock(module.os).should_receive('rmdir').with_args('databases/localhost').once()

    module.remove_database_dumps('databases', databases, 'SuperDB', 'test.yaml', dry_run=False)
Exemple #6
0
def test_remove_database_dumps_removes_dump_for_each_database():
    databases = [{'name': 'foo'}, {'name': 'bar'}]
    flexmock(module).should_receive('make_database_dump_filename').with_args(
        'databases', 'foo', None
    ).and_return('databases/localhost/foo')
    flexmock(module).should_receive('make_database_dump_filename').with_args(
        'databases', 'bar', None
    ).and_return('databases/localhost/bar')

    flexmock(module.os.path).should_receive('isdir').and_return(False)
    flexmock(module.os).should_receive('remove').with_args('databases/localhost/foo').once()
    flexmock(module.os).should_receive('remove').with_args('databases/localhost/bar').once()
    flexmock(module.os).should_receive('listdir').with_args('databases/localhost').and_return(
        ['bar']
    ).and_return([])

    flexmock(module.os).should_receive('rmdir').with_args('databases/localhost').once()

    module.remove_database_dumps('databases', databases, 'SuperDB', 'test.yaml', dry_run=False)
Exemple #7
0
def test_remove_database_dumps_with_dry_run_skips_removal():
    databases = [{'name': 'foo'}, {'name': 'bar'}]
    flexmock(module.os).should_receive('rmdir').never()
    flexmock(module.os).should_receive('remove').never()

    module.remove_database_dumps('databases', databases, 'SuperDB', 'test.yaml', dry_run=True)
Exemple #8
0
def test_remove_database_dumps_without_databases_does_not_raise():
    module.remove_database_dumps('databases', [], 'SuperDB', 'test.yaml', dry_run=False)