Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Pillar files into OrderedDict to preserve source order #17284

Merged
merged 1 commit into from
Nov 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion salt/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import salt.log
import salt.crypt
from salt.exceptions import SaltReqTimeoutError
from salt.utils.odict import OrderedDict
import six

# Import third party libs
Expand Down Expand Up @@ -92,7 +93,11 @@ def loads(self, msg):
Run the correct loads serialization format
'''
try:
return msgpack.loads(msg, use_list=True)
# msgpack >= 0.2.0 supports object_pairs_hook parameter to return an OrderedDict
if msgpack.version >= (0, 2, 0):
return msgpack.loads(msg, use_list=True, object_pairs_hook=OrderedDict)
else:
return msgpack.loads(msg, use_list=True)
except Exception as exc:
log.critical('Could not deserialize msgpack message: {0}'
'This often happens when trying to read a file not in binary mode.'
Expand Down
4 changes: 2 additions & 2 deletions salt/pillar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def render_pillar(self, matches):
Extract the sls pillar files from the matches and render them into the
pillar
'''
pillar = {}
pillar = OrderedDict()
errors = []
for saltenv, pstates in matches.items():
mods = set()
Expand Down Expand Up @@ -578,7 +578,7 @@ def compile_pillar(self, ext=True, pillar_dirs=None):
top, terrors = self.get_top()
if ext:
if self.opts.get('ext_pillar_first', False):
self.opts['pillar'] = self.ext_pillar({}, pillar_dirs)
self.opts['pillar'] = self.ext_pillar(OrderedDict(), pillar_dirs)
matches = self.top_matches(top)
pillar, errors = self.render_pillar(matches)
pillar = self.merge_sources(pillar, self.opts['pillar'])
Expand Down
4 changes: 3 additions & 1 deletion salt/utils/dictupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import collections
import six

# Import salt libs
from salt.utils.odict import OrderedDict

def update(dest, upd):
for key, val in six.iteritems(upd):
if isinstance(val, collections.Mapping):
ret = update(dest.get(key, {}), val)
ret = update(dest.get(key, OrderedDict()), val)
dest[key] = ret
else:
dest[key] = upd[key]
Expand Down