From c38f7a3693260b45ec914247940837de45fcd063 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 24 Jul 2017 08:41:02 -0700 Subject: [PATCH] #32: Fix for upgrade-borgmatic-config converting check_last option as a string instead of an integer. --- NEWS | 6 ++++-- borgmatic/config/convert.py | 14 ++++++++++---- borgmatic/tests/unit/config/test_convert.py | 10 ++++++++++ setup.py | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index eb863866..a580bdc0 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ -1.1.1.dev0 +1.1.1 - * + * #32: Fix for upgrade-borgmatic-config converting check_last option as a string instead of an + integer. + * Fix for upgrade-borgmatic-config erroring when consistency checks option is not present. 1.1.0 diff --git a/borgmatic/config/convert.py b/borgmatic/config/convert.py index 832d7d31..923ec484 100644 --- a/borgmatic/config/convert.py +++ b/borgmatic/config/convert.py @@ -10,10 +10,16 @@ def _convert_section(source_section_config, section_schema): Given a legacy Parsed_config instance for a single section, convert it to its corresponding yaml.comments.CommentedMap representation in preparation for actual serialization to YAML. - Additionally, use the section schema as a source of helpful comments to include within the - returned CommentedMap. + Where integer types exist in the given section schema, convert their values to integers. ''' - destination_section_config = yaml.comments.CommentedMap(source_section_config) + destination_section_config = yaml.comments.CommentedMap([ + ( + option_name, + int(option_value) + if section_schema['map'].get(option_name, {}).get('type') == 'int' else option_value + ) + for option_name, option_value in source_section_config.items() + ]) return destination_section_config @@ -39,7 +45,7 @@ def convert_legacy_parsed_config(source_config, source_excludes, schema): location['repositories'] = [location.pop('repository')] location['exclude_patterns'] = source_excludes - if source_config.consistency['checks']: + if source_config.consistency.get('checks'): destination_config['consistency']['checks'] = source_config.consistency['checks'].split(' ') # Add comments to each section, and then add comments to the fields in each section. diff --git a/borgmatic/tests/unit/config/test_convert.py b/borgmatic/tests/unit/config/test_convert.py index 827ecdbc..58693ab2 100644 --- a/borgmatic/tests/unit/config/test_convert.py +++ b/borgmatic/tests/unit/config/test_convert.py @@ -10,6 +10,16 @@ from borgmatic.config import convert as module Parsed_config = namedtuple('Parsed_config', ('location', 'storage', 'retention', 'consistency')) +def test_convert_section_generates_integer_value_for_integer_type_in_schema(): + flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict) + source_section_config = OrderedDict([('check_last', '3')]) + section_schema = {'map': {'check_last': {'type': 'int'}}} + + destination_config = module._convert_section(source_section_config, section_schema) + + assert destination_config == OrderedDict([('check_last', 3)]) + + 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( diff --git a/setup.py b/setup.py index b89ce267..9796fc4e 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages -VERSION = '1.1.1.dev0' +VERSION = '1.1.1' setup(