示例#1
0
    def test_arguments(self, monkeypatch):
        fakeargparse = FakeArgparse()
        fakeargparse = fakeargparse.ArgumentParser()
        fakedistutils = FakeDistutils()
        fakedistutilsspawn = fakedistutils.spawn()

        monkeypatch.setattr(argparse, 'ArgumentParser', fakeargparse)

        platform = sys.platform
        assert backup_arguments() is not False

        sys.__dict__['platform'] = 'darwin'
        pytest.raises(Exception, backup_arguments)
        monkeypatch.setattr(distspawn, 'find_executable',
                            fakedistutilsspawn.find_executable)
        assert backup_arguments() is not False
        sys.__dict__['platform'] = platform
示例#2
0
    def test_arguments(self, monkeypatch):
        fakeargparse = FakeArgparse()
        fakeargparse = fakeargparse.ArgumentParser()
        fakedistutils = FakeDistutils()
        fakedistutilsspawn = fakedistutils.spawn()

        monkeypatch.setattr(
            argparse, 'ArgumentParser', fakeargparse)

        platform = sys.platform
        assert backup_arguments() is not False

        sys.__dict__['platform'] = 'darwin'
        pytest.raises(Exception, backup_arguments)
        monkeypatch.setattr(
            distspawn, 'find_executable', fakedistutilsspawn.find_executable)
        assert backup_arguments() is not False
        sys.__dict__['platform'] = platform
示例#3
0
    def test_no_lvm_level0(self):
        """
        Maximum level filesystem backup

        freezerc --action backup
                 --path-to-backup /var/log
                 --backup-name rsync-var-log-test-XX
                 --container var-log-test-XX
        """
        # Set arguments
        test_args = {
            #'proxy' : '',
            'action' : 'backup',
            'src_file' : copy(self.tmp_path),
            'backup_name' : str(uuid.uuid4()),
            'container' : str(uuid.uuid4())
        }
        (backup_args, _) = arguments.backup_arguments(test_args)
        self.assertEqual(backup_args.mode, 'fs')
        self.assertEqual(backup_args.max_backup_level, 0)
        main.freezer_main(backup_args)
        backup_args = swift.get_containers_list(backup_args)
        name_list = [item['name'] for item in backup_args.containers_list]
        self.assertTrue(backup_args.container in name_list)
        self.assertTrue(backup_args.container_segments in name_list)
        fdict_before = self.snap_tmp_tree_sha1(self.tmp_files)
        self.damage_tmp_tree(self.tmp_files)
        # Restore
        test_args = {
            #'proxy' : '',
            'action' : 'restore',
            'restore_abs_path' : copy(self.tmp_path),
            'backup_name' : copy(backup_args.backup_name),
            'container' : copy(backup_args.container)
        }
        (restore_args, _) = arguments.backup_arguments(test_args)
        self.assertEqual(backup_args.mode, 'fs')
        main.freezer_main(restore_args)
        fdict_after = self.snap_tmp_tree_sha1(self.tmp_files)
        self.assertEqual(len(self.tmp_files), len(fdict_before))
        self.assertEqual(len(self.tmp_files), len(fdict_after))
        for key in self.tmp_files:
            self.assertTrue(os.path.isfile(key))
            self.assertEqual(key + fdict_before[key], key + fdict_after[key])
示例#4
0
文件: main.py 项目: sckevmit/freezer
def main():
    """Freezerc binary main execution"""

    (backup_args, opt_args) = backup_arguments()
    try:
        if backup_args.version:
            print "freezer version {0}".format(backup_args.__version__)
            sys.exit(1)

        if len(sys.argv) < 2:
            opt_args.print_help()
            sys.exit(1)

        freezer_main(backup_args)

    except ValueError as err:
        return fail(1, err, backup_args.quiet)
    except ImportError as err:
        return fail(1, err, backup_args.quiet)
    except Exception as err:
        return fail(1, err, backup_args.quiet)
示例#5
0
def test_backup_mode_mysql():

    # THE WHOLE TEST NEED TO BE CHANGED USING MOCK!!
    # Return backup options and arguments
    backup_args = backup_arguments()
示例#6
0
文件: main.py 项目: lmtwga/freezer
from freezer.bandwidth import monkeypatch_socket_bandwidth
from freezer import job
from freezer.arguments import backup_arguments
from freezer.osclients import ClientManager
from freezer import swift
from freezer import local
from freezer import ssh
from freezer import utils
from freezer.engine import tar_engine
from freezer import winutils

# Initialize backup options
from freezer.validator import Validator

(backup_args, arg_parse) = backup_arguments()


def freezer_main(args={}):
    """Freezer main loop for job execution.
    """
    global backup_args, arg_parse

    def configure_log_file_using_defaults():
        """ Configure log file for freezer """

        dry_run_message = ""
        if backup_args.dry_run:
            dry_run_message = "[DRY_RUN] "

        def configure_logging(file_name):
示例#7
0
Hudson ([email protected]).
========================================================================

Freezer main execution function
"""

from freezer import job
from freezer.arguments import backup_arguments
from freezer.utils import create_dir
import os
import subprocess
import logging
import sys

# Initialize backup options
(backup_args, arg_parse) = backup_arguments()


def configure_log_file_using_defaults():
    """ Configure log file for freezer """

    dry_run_message = ''
    if backup_args.dry_run:
        dry_run_message = '[DRY_RUN] '

    def configure_logging(file_name):
        expanded_file_name = os.path.expanduser(file_name)
        expanded_dir_name = os.path.dirname(expanded_file_name)
        create_dir(expanded_dir_name, do_log=False)
        logging.basicConfig(
            filename=expanded_file_name,
示例#8
0
def test_backup_mode_mysql():

    # THE WHOLE TEST NEED TO BE CHANGED USING MOCK!!
    # Return backup options and arguments
    backup_args = backup_arguments()
示例#9
0
def test_backup_arguments():

    backup_args, arg_parser = backup_arguments()
    assert backup_args.tar_path is not False
    assert backup_args.mode is ('fs' or 'mysql' or 'mongo')
示例#10
0
    def test_lvm_level0(self):
        """
        LVM snapshot filesystem backup

        freezerc --action backup
                 --lvm-srcvol /dev/freezer-test1-volgroup/freezer-test1-vol
                 --lvm-dirmount /tmp/freezer-test-lvm-snapshot
                 --lvm-volgroup freezer-test1-volgroup
                 --lvm-snapsize 1M
                 --file-to-backup /mnt/freezer-test-lvm/lvm_test_XXXX/
                 --container UUID
                 --exclude "\*.lock"
                 --backup-name UUID
        """
        # Set arguments
        lvm_path = '/mnt/freezer-test-lvm'
        self.tmp_path = tempfile.mkdtemp(prefix='lvm_test_', dir=lvm_path)
        self.create_tmp_tree(self.tmp_path)
        test_args = {
            #'proxy' : '',
            'action' : 'backup',
            'lvm_srcvol' : '/dev/freezer-test1-volgroup/freezer-test1-vol',
            'lvm_dirmount' : '/tmp/freezer-test-lvm-snapshot',
            'lvm_volgroup' : 'freezer-test1-volgroup',
            'lvm_snapsize' : '1M',
            'exclude' : '*.lock',
            'src_file' : copy(self.tmp_path),
            'backup_name' : str(uuid.uuid4()),
            'container' : str(uuid.uuid4())
        }
        (backup_args, _) = arguments.backup_arguments(test_args)
        # Make sure default value for MODE is filesystem
        self.assertEqual(backup_args.mode, 'fs')
        # Check that if not explicitly defined the MAX-BACKUP is 0
        self.assertEqual(backup_args.max_backup_level, 0)
        # Call the actual BACKUP
        main.freezer_main(backup_args)
        # Retrieve a list of all container data on Swift
        backup_args = swift.get_containers_list(backup_args)
        # Filter only the container names from all other data
        name_list = [item['name'] for item in backup_args.containers_list]
        # Amke sure that we have created a container with the desired name
        # in Swift
        self.assertTrue(backup_args.container in name_list)
        # Ensure that the SEGMENTS container is found on Swift as well
        self.assertTrue(backup_args.container_segments in name_list)
        # Create a file => SAH1 hash dictionary that will recored file
        # hashes before any files being modified or deleted
        fdict_before = self.snap_tmp_tree_sha1(self.tmp_files)
        # Delete and modify random files in the test directory
        # structure
        self.damage_tmp_tree(self.tmp_files)
        # RESTORE section
        # Create RESTORE action dictionary to be passed to
        # arguments.backup_arguments() they will emulate the
        # command line arguments
        test_args = {
            #'proxy' : '',
            'action' : 'restore',
            'restore_abs_path' : copy(self.tmp_path),
            'backup_name' : copy(backup_args.backup_name),
            'container' : copy(backup_args.container)
        }
        (restore_args, _) = arguments.backup_arguments(test_args)
        self.assertEqual(restore_args.mode, 'fs')
        # Call RESTORE on Freezer code base
        main.freezer_main(restore_args)
        fdict_after = self.snap_tmp_tree_sha1(self.tmp_files)
        self.assertEqual(len(self.tmp_files), len(fdict_before))
        # Check if cout of all original files match recovered files
        # plus the number of deleted .LOCK files which were not restored
        self.assertEqual(len(self.tmp_files), len(fdict_after) +
            len([x for x in self.tmp_deleted if x.endswith('.lock')]))
        for key in self.tmp_files:
            if key.endswith('.lock') and key in self.tmp_deleted:
                self.assertFalse(os.path.isfile(key))
            elif key.endswith('.lock') and key in self.tmp_modified:
                self.assertNotEqual(key + fdict_before[key], key + fdict_after[key])
            else:
                self.assertTrue(os.path.isfile(key))
                self.assertEqual(key + fdict_before[key], key + fdict_after[key])