Ejemplo n.º 1
0
def test_convert_legacy_parsed_config_splits_space_separated_values():
    flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict)
    source_config = Parsed_config(
        location=OrderedDict(
            [('source_directories', '/home /etc'), ('repository', 'hostname.borg')]
        ),
        storage=OrderedDict(),
        retention=OrderedDict(),
        consistency=OrderedDict([('checks', 'repository archives')]),
    )
    source_excludes = ['/var']
    schema = {'map': defaultdict(lambda: {'map': {}})}

    destination_config = module.convert_legacy_parsed_config(source_config, source_excludes, schema)

    assert destination_config == OrderedDict(
        [
            (
                'location',
                OrderedDict(
                    [
                        ('source_directories', ['/home', '/etc']),
                        ('repositories', ['hostname.borg']),
                        ('exclude_patterns', ['/var']),
                    ]
                ),
            ),
            ('storage', OrderedDict()),
            ('retention', OrderedDict()),
            ('consistency', OrderedDict([('checks', ['repository', 'archives'])])),
        ]
    )
Ejemplo n.º 2
0
def test_convert_legacy_parsed_config_transforms_source_config_to_mapping():
    flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict)
    source_config = Parsed_config(
        location=OrderedDict([('source_directories', '/home'), ('repository', 'hostname.borg')]),
        storage=OrderedDict([('encryption_passphrase', 'supersecret')]),
        retention=OrderedDict([('keep_daily', 7)]),
        consistency=OrderedDict([('checks', 'repository')]),
    )
    source_excludes = ['/var']
    schema = {'map': defaultdict(lambda: {'map': {}})}

    destination_config = module.convert_legacy_parsed_config(source_config, source_excludes, schema)

    assert destination_config == OrderedDict(
        [
            (
                'location',
                OrderedDict(
                    [
                        ('source_directories', ['/home']),
                        ('repositories', ['hostname.borg']),
                        ('exclude_patterns', ['/var']),
                    ]
                ),
            ),
            ('storage', OrderedDict([('encryption_passphrase', 'supersecret')])),
            ('retention', OrderedDict([('keep_daily', 7)])),
            ('consistency', OrderedDict([('checks', ['repository'])])),
        ]
    )
Ejemplo n.º 3
0
def test_convert_legacy_parsed_config_splits_space_separated_values():
    flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict)
    source_config = Parsed_config(
        location=OrderedDict(
            [('source_directories', '/home /etc'), ('repository', 'hostname.borg')]
        ),
        storage=OrderedDict(),
        retention=OrderedDict(),
        consistency=OrderedDict([('checks', 'repository archives')]),
    )
    source_excludes = ['/var']
    schema = {'map': defaultdict(lambda: {'map': {}})}

    destination_config = module.convert_legacy_parsed_config(source_config, source_excludes, schema)

    assert destination_config == OrderedDict(
        [
            (
                'location',
                OrderedDict(
                    [
                        ('source_directories', ['/home', '/etc']),
                        ('repositories', ['hostname.borg']),
                        ('exclude_patterns', ['/var']),
                    ]
                ),
            ),
            ('storage', OrderedDict()),
            ('retention', OrderedDict()),
            ('consistency', OrderedDict([('checks', ['repository', 'archives'])])),
        ]
    )
Ejemplo n.º 4
0
def test_convert_legacy_parsed_config_transforms_source_config_to_mapping():
    flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict)
    source_config = Parsed_config(
        location=OrderedDict([('source_directories', '/home'), ('repository', 'hostname.borg')]),
        storage=OrderedDict([('encryption_passphrase', 'supersecret')]),
        retention=OrderedDict([('keep_daily', 7)]),
        consistency=OrderedDict([('checks', 'repository')]),
    )
    source_excludes = ['/var']
    schema = {'map': defaultdict(lambda: {'map': {}})}

    destination_config = module.convert_legacy_parsed_config(source_config, source_excludes, schema)

    assert destination_config == OrderedDict(
        [
            (
                'location',
                OrderedDict(
                    [
                        ('source_directories', ['/home']),
                        ('repositories', ['hostname.borg']),
                        ('exclude_patterns', ['/var']),
                    ]
                ),
            ),
            ('storage', OrderedDict([('encryption_passphrase', 'supersecret')])),
            ('retention', OrderedDict([('keep_daily', 7)])),
            ('consistency', OrderedDict([('checks', ['repository'])])),
        ]
    )
Ejemplo n.º 5
0
def main():  # pragma: no cover
    try:
        args = parse_arguments(*sys.argv[1:])
        schema = yaml.round_trip_load(open(validate.schema_filename()).read())
        source_config = legacy.parse_configuration(
            args.source_config_filename, legacy.CONFIG_FORMAT
        )
        source_config_file_mode = os.stat(args.source_config_filename).st_mode
        source_excludes = (
            open(args.source_excludes_filename).read().splitlines()
            if args.source_excludes_filename
            else []
        )

        destination_config = convert.convert_legacy_parsed_config(
            source_config, source_excludes, schema
        )

        generate.write_configuration(
            args.destination_config_filename, destination_config, mode=source_config_file_mode
        )

        display_result(args)
    except (ValueError, OSError) as error:
        print(error, file=sys.stderr)
        sys.exit(1)
Ejemplo n.º 6
0
def main():  # pragma: no cover
    try:
        args = parse_arguments(*sys.argv[1:])
        schema = yaml.round_trip_load(open(validate.schema_filename()).read())
        source_config = legacy.parse_configuration(
            args.source_config_filename, legacy.CONFIG_FORMAT
        )
        source_config_file_mode = os.stat(args.source_config_filename).st_mode
        source_excludes = (
            open(args.source_excludes_filename).read().splitlines()
            if args.source_excludes_filename
            else []
        )

        destination_config = convert.convert_legacy_parsed_config(
            source_config, source_excludes, schema
        )

        generate.write_configuration(
            args.destination_config_filename,
            generate.render_configuration(destination_config),
            mode=source_config_file_mode,
        )

        display_result(args)
    except (ValueError, OSError) as error:
        print(error, file=sys.stderr)
        sys.exit(1)