Example #1
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)
Example #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)
Example #3
0
def _test_run():
    fsm = SnapshotLifecycle('/mnt/lvm_test')
    fsm.run()
Example #4
0
def test_good_snapshot():
    fsm = SnapshotLifecycle(target_directory='/mnt/lvm_test',
                            snapshot_mountpoint='/tmp/mysnapshot')
    fsm.run()
Example #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)
Example #6
0
def _test_lv_notfound():
    fsm = SnapshotLifecycle()
    fsm.lvname = 'dba/epicfail' # This LV shouldn't exist
    assert_raises(TypeError, fsm.run)
Example #7
0
def test_good_snapshot():
    fsm = SnapshotLifecycle(target_directory='/mnt/lvm_test',
                            snapshot_mountpoint='/tmp/mysnapshot')
    fsm.run()
Example #8
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)
Example #9
0
def test_bad_snapshot_mountpoint():
    fsm = SnapshotLifecycle(target_directory='/mnt/lvm_test',
                            snapshot_mountpoint='/tmp/foo/bar/baz')
    assert_raises(EnvironmentError, fsm.run)
Example #10
0
def test_overallocated_snapshot():
    fsm = SnapshotLifecycle(target_directory='/mnt/lvm_test',
                            snapshot_mountpoint='/tmp/mysnapshot/',
                            snapshot_size='768M')
    assert_raises(EnvironmentError, fsm.run)
Example #11
0
def _test_lv_notfound():
    fsm = SnapshotLifecycle()
    fsm.lvname = 'dba/epicfail'  # This LV shouldn't exist
    assert_raises(TypeError, fsm.run)
Example #12
0
def test_lvmfsm_misconfigured():
    """Test attempting to snapshot a directory not on an lvm device"""
    fsm = SnapshotLifecycle(target_directory='/home')
    assert_raises(LVMError, fsm.run)
Example #13
0
def _test_run():
    fsm = SnapshotLifecycle('/mnt/lvm_test')
    fsm.run()
Example #14
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