Skip to content

Commit

Permalink
Merge pull request #50750 from bewing/pepa12
Browse files Browse the repository at this point in the history
Fix last key detection in pillar.pepa`key_value_to_tree`
  • Loading branch information
Erik Johnson authored Dec 10, 2018
2 parents cb85d5d + 9931a41 commit dcdb9b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions salt/pillar/pepa.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ def key_value_to_tree(data):
for flatkey, value in six.iteritems(data):
t = tree
keys = flatkey.split(__opts__['pepa_delimiter'])
for key in keys:
if key == keys[-1]:
for i, key in enumerate(keys, 1):
if i == len(keys):
t[key] = value
else:
t = t.setdefault(key, {})
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/pillar/test_pepa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
from collections import OrderedDict

# Import Salt Testing libs
from tests.support.unit import TestCase

# Import Salt Libs
import salt.pillar.pepa as pepa


class PepaPillarTestCase(TestCase):
def test_repeated_keys(self):
expected_result = {
"foo": {
"bar": {
"foo": True,
"baz": True,
},
},
}
data = OrderedDict([
('foo..bar..foo', True),
('foo..bar..baz', True),
])
result = pepa.key_value_to_tree(data)
self.assertDictEqual(result, expected_result)

0 comments on commit dcdb9b2

Please sign in to comment.