#32: Fix for upgrade-borgmatic-config converting check_last option as a string instead of an integer.

This commit is contained in:
Dan Helfman 2017-07-24 08:41:02 -07:00
parent 7c77a5a8a5
commit c38f7a3693
4 changed files with 25 additions and 7 deletions

6
NEWS
View file

@ -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 1.1.0

View file

@ -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 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. 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 Where integer types exist in the given section schema, convert their values to integers.
returned CommentedMap.
''' '''
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 return destination_section_config
@ -39,7 +45,7 @@ def convert_legacy_parsed_config(source_config, source_excludes, schema):
location['repositories'] = [location.pop('repository')] location['repositories'] = [location.pop('repository')]
location['exclude_patterns'] = source_excludes 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(' ') destination_config['consistency']['checks'] = source_config.consistency['checks'].split(' ')
# Add comments to each section, and then add comments to the fields in each section. # Add comments to each section, and then add comments to the fields in each section.

View file

@ -10,6 +10,16 @@ from borgmatic.config import convert as module
Parsed_config = namedtuple('Parsed_config', ('location', 'storage', 'retention', 'consistency')) 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(): def test_convert_legacy_parsed_config_transforms_source_config_to_mapping():
flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict) flexmock(module.yaml.comments).should_receive('CommentedMap').replace_with(OrderedDict)
source_config = Parsed_config( source_config = Parsed_config(

View file

@ -1,7 +1,7 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
VERSION = '1.1.1.dev0' VERSION = '1.1.1'
setup( setup(