Example #1
0
def test_master_bootstrap(app):
    plugins = setup_plugins(app,
                            dcs_get_database_identifier=None,
                            dcs_lock=True,
                            pg_get_database_identifier='42')
    timeout = app.initialize()
    assert plugins.mock_calls == [
        call.initialize(),
        call.get_my_id(),
        # check if we have a db identifier set
        call.dcs_get_database_identifier(),
        # no, ok, init our db
        call.pg_initdb(),
        # make sure it starts
        call.pg_start(),
        call.pg_get_database_identifier(),
        # lock the database identifier so no-one else gets here
        call.dcs_lock('database_identifier'),
        # while locked make sure there is no id set in the DCS before we got the lock
        call.dcs_get_database_identifier(),
        # Make the first backup while locked with no DCS
        call.pg_backup(),
        # set the database identifier AFTER
        call.dcs_set_database_identifier('42')
    ]
    # shut down cleanly and immediately
    assert timeout == 0
Example #2
0
def test_master_bootstrap(app):
    plugins = setup_plugins(app,
            dcs_get_database_identifier=None,
            dcs_lock=True,
            pg_get_database_identifier='42')
    timeout = app.initialize()
    assert plugins.mock_calls ==  [
            call.initialize(),
            call.get_my_id(),
            # check if we have a db identifier set
            call.dcs_get_database_identifier(),
            # no, ok, init our db
            call.pg_initdb(),
            # make sure it starts
            call.pg_start(),
            call.pg_get_database_identifier(),
            # lock the database identifier so no-one else gets here
            call.dcs_lock('database_identifier'),
            # while locked make sure there is no id set in the DCS before we got the lock
            call.dcs_get_database_identifier(),
            # Make the first backup while locked with no DCS
            call.pg_backup(),
            # set the database identifier AFTER
            call.dcs_set_database_identifier('42')
            ]
    # shut down cleanly and immediately
    assert timeout == 0
Example #3
0
def test_master_boostrap_fails_to_lock_db_id(app):
    plugins = setup_plugins(app,
            dcs_get_database_identifier=None,
            dcs_lock=False,
            pg_get_database_identifier='42')
    timeout = app.initialize()
    assert plugins.mock_calls ==  [
            call.initialize(),
            call.get_my_id(),
            # check if we have a db identifier set
            call.dcs_get_database_identifier(),
            # no, ok, init our db
            call.pg_initdb(),
            # make sure it starts
            call.pg_start(),
            call.pg_get_database_identifier(),
            # lock the database identifier so no-one else gets here
            call.dcs_lock('database_identifier')
            ]
    # shut down cleanly
    assert timeout == 5
Example #4
0
def test_replica_bootstrap(app):
    plugins = setup_plugins(app, dcs_get_database_identifier='1234')
    plugins.pg_get_database_identifier.side_effect = ['42', '1234']
    timeout = app.initialize()
    assert plugins.mock_calls == [
        call.initialize(),
        call.get_my_id(),
        # compare our id with the id in the DCS
        call.dcs_get_database_identifier(),
        call.pg_get_database_identifier(),
        # make sure postgresql is stopped
        call.pg_stop(),
        # postgresql restore
        call.pg_initdb(),
        call.pg_restore(),
        call.pg_setup_replication(None),
        call.pg_get_database_identifier(),
        call.pg_replication_role()
    ]
    # shut down cleanly and immediately
    assert timeout == 0
Example #5
0
def test_master_boostrap_fails_to_lock_db_id(app):
    plugins = setup_plugins(app,
                            dcs_get_database_identifier=None,
                            dcs_lock=False,
                            pg_get_database_identifier='42')
    timeout = app.initialize()
    assert plugins.mock_calls == [
        call.initialize(),
        call.get_my_id(),
        # check if we have a db identifier set
        call.dcs_get_database_identifier(),
        # no, ok, init our db
        call.pg_initdb(),
        # make sure it starts
        call.pg_start(),
        call.pg_get_database_identifier(),
        # lock the database identifier so no-one else gets here
        call.dcs_lock('database_identifier')
    ]
    # shut down cleanly
    assert timeout == 5
Example #6
0
def test_replica_bootstrap(app):
    plugins = setup_plugins(app,
            dcs_get_database_identifier='1234')
    plugins.pg_get_database_identifier.side_effect = ['42', '1234']
    timeout = app.initialize()
    assert plugins.mock_calls ==  [
            call.initialize(),
            call.get_my_id(),
            # compare our id with the id in the DCS
            call.dcs_get_database_identifier(),
            call.pg_get_database_identifier(),
            # make sure postgresql is stopped
            call.pg_stop(),
            # postgresql restore
            call.pg_initdb(),
            call.pg_restore(),
            call.pg_setup_replication(None),
            call.pg_get_database_identifier(),
            call.pg_replication_role()
            ]
    # shut down cleanly and immediately
    assert timeout == 0
Example #7
0
def test_replica_bootstrap_fails_sanity_test(app):
    plugins = setup_plugins(app,
            pg_replication_role='master',
            dcs_get_database_identifier='1234',
            pg_get_database_identifier='42')
    timeout = app.initialize()
    assert plugins.mock_calls ==  [
            call.initialize(),
            call.get_my_id(),
            # compare our id with the id in the DCS
            call.dcs_get_database_identifier(),
            call.pg_get_database_identifier(),
            # make sure postgresql is stopped
            call.pg_stop(),
            # postgresql restore
            call.pg_initdb(),
            call.pg_restore(),
            call.pg_setup_replication(None),
            call.pg_get_database_identifier(),
            call.pg_replication_role(),
            call.pg_reset(),
            ]
    # shut down after 5 seconds to try again
    assert timeout == 5
Example #8
0
def test_replica_bootstrap_fails_sanity_test(app):
    plugins = setup_plugins(app,
                            pg_replication_role='master',
                            dcs_get_database_identifier='1234',
                            pg_get_database_identifier='42')
    timeout = app.initialize()
    assert plugins.mock_calls == [
        call.initialize(),
        call.get_my_id(),
        # compare our id with the id in the DCS
        call.dcs_get_database_identifier(),
        call.pg_get_database_identifier(),
        # make sure postgresql is stopped
        call.pg_stop(),
        # postgresql restore
        call.pg_initdb(),
        call.pg_restore(),
        call.pg_setup_replication(None),
        call.pg_get_database_identifier(),
        call.pg_replication_role(),
        call.pg_reset(),
    ]
    # shut down after 5 seconds to try again
    assert timeout == 5