def test_snapshot_error():
    fsm = SnapshotLifecycle(target_directory='/mnt/lvm_test',
                            snapshot_mountpoint='/tmp/mysnapshot/')
    # be naughty and chdir to the snapshot after its mounted
    # this will cause a failure on the unmount phase
    fsm.add_callback('backup', _do_naughty_things)
    assert_raises(LVMError, fsm.run)
Beispiel #2
0
def test_snapshot_error():
    fsm = SnapshotLifecycle(target_directory='/mnt/lvm_test',
                            snapshot_mountpoint='/tmp/mysnapshot/')
    # be naughty and chdir to the snapshot after its mounted
    # this will cause a failure on the unmount phase
    fsm.add_callback('backup', _do_naughty_things)
    assert_raises(LVMError, fsm.run)
Beispiel #3
0
def mysql_snapshot_lifecycle(destination=sys.stdout,
                             snapshot_name=None,
                             snapshot_size=None,
                             snapshot_mountpoint=None,
                             mysql_auth=None,
                             flush_tables=True,
                             extra_flush_tables=True,
                             innodb_recovery=False,
                             replication_info_callback=None):
    """Setup a Lvm state for a MySQL environment"""

    helper = mysqlhelper.connect(**mysql_auth)
    target_directory = helper.variable('datadir')
    lifecycle = SnapshotLifecycle(target_directory,
                                  snapshot_name=snapshot_name,
                                  snapshot_size=snapshot_size,
                                  snapshot_mountpoint=snapshot_mountpoint)
    archiver = TarBackup(dst=destination)
    # backup() should be run after everything else
    lifecycle.add_callback('backup', archiver.backup, priority=99)

    # setup lock/unlock tables based on flush settings
    manager = MySQLManager(mysqlhelper=helper,
                           flush_tables=flush_tables,
                           extra_flush_tables=extra_flush_tables)
    lifecycle.add_callback('presnapshot', manager.lock, priority=50)
    if replication_info_callback:
        lifecycle.add_callback('presnapshot', 
                               lambda: replication_info_callback(helper),
                               priority=99)
    lifecycle.add_callback('postsnapshot', manager.unlock)

    # we could skip this, but instead we have the callback
    # log an explicit "We skipped innodb recovery"
    if innodb_recovery:
        ibrecovery = InnoDBRecovery()
        # ibrecovery should run before any other backup process,
        # so we lower the callback priority
        lifecycle.add_callback('backup', ibrecovery.run_recovery, priority=0)

    return lifecycle
def test_bad_remove():
    fsm = SnapshotLifecycle(target_directory='/mnt/lvm_test',
                            snapshot_mountpoint='/tmp/mysnapshot')
    fsm.add_callback('preremove', _do_remount)
    assert_raises(AssertionError, fsm.run)
Beispiel #5
0
def test_bad_remove():
    fsm = SnapshotLifecycle(target_directory='/mnt/lvm_test',
                            snapshot_mountpoint='/tmp/mysnapshot')
    fsm.add_callback('preremove', _do_remount)
    assert_raises(AssertionError, fsm.run)