KeyError: 'sum' in module.file
Looks like 39f1749ff1e2ba2d6df943d32b43ed29d28b34c8 is causing file.managed to throw an exception, at least when running state.highstate test=True. It looks a little like #8653, but I don't think it's the same issue.
I'm not sure what the intent of that commit was, otherwise I'd take a stab at fixing it.
----------
ID: module-ssh-server-file-config
Function: file.managed
Name: /etc/sshd_config
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/salt/state.py", line 1403, in call
**cdata['kwargs'])
File "/usr/local/lib/python2.7/site-packages/salt/states/file.py", line 1235, in managed
**kwargs
File "/usr/local/lib/python2.7/site-packages/salt/modules/file.py", line 2510, in check_managed
group, mode, saltenv, template, contents)
File "/usr/local/lib/python2.7/site-packages/salt/modules/file.py", line 2554, in check_file_meta
if source_sum['hsum'] != lstats['sum']:
KeyError: 'sum'
Started: 09:06:58.987959
Duration: 14 ms
Changes:
----------
$ salt --versions-report
Salt: 2014.1.0-5587-ge096df9 (Hydrogen)
Python: 2.7.6 (default, May 1 2014, 08:58:40)
Jinja2: 2.7.2
M2Crypto: 0.22
msgpack-python: 0.4.2
msgpack-pure: Not Installed
pycrypto: 2.6.1
PyYAML: 3.11
PyZMQ: 14.2.0
ZMQ: 4.0.4
$ uname -a
Darwin jasonrm.local 13.1.0 Darwin Kernel Version 13.1.0: Wed Apr 2 23:52:02 PDT 2014; root:xnu-2422.92.1~2/RELEASE_X86_64 x86_64
Thanks for the report! We'll get this resolved. @jacksontj Input?
bug waiting to happen, turns out that function doesn't pass the hash_type down, so it was relying on the default of md5 (meaning if you passed a sha1 for example, it would always be different). Looks like we are missing a unit test here :)
@jacksontj why was this change to the interface made? There are states and modules throughout Salt that are expecting the 'sum' key in there.
@jacksontj Well, your new pull request does pass it down now. But the default of None is I think still dangerous. If that value is ever None, things will break. I think we still need to default to md5 and then pass through the hash type.
(Or at least, test=True will break)
Actually, I think the fix here would be if sum is None, then we check opts for the hashing mechanism. We just want that hash to always be in there, to avoid breakage somewhere else, methinks.
The reason is 2 part. One if you don't pass it we guess and give you something that may not be comparable (sha1 for example). And secondly, we always hash the file even if we just set perms (which is slow if its a big file).
What we could do is return sum = none if you don't pass it in, but coming up with a has is (IMO) a bad idea On May 2, 2014 10:11 AM, "Colton Myers" [email protected] wrote:
(Or at least, test=True will break)
— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/12478#issuecomment-42055025 .
That makes sense. In that case, we just need to comb through and see if this is going to bite us anywhere else. And add a test=True test for file.managed.
Alright, I've looked a bit more, and I think I'm good with your fix. @UtahDave and @jasonrm, could you potentially test with @jacksontj's patch in the pull request linked above? I think it should fix your issue, just wanted to make sure.
@basepi yep, #12492 fixes my original issue. Thanks all for looking into this.
No problem. Thanks @jacksontj for looking into this, sorry for my knee-jerk reaction. Hate file state breakage. =)
No worries :) apologies for breaking it, tests passed somehow when we merged it in On May 2, 2014 11:00 AM, "Colton Myers" [email protected] wrote:
No problem. Thanks @jacksontj https://github.com/jacksontj for looking into this, sorry for my knee-jerk reaction. Hate file state breakage. =)
— Reply to this email directly or view it on GitHubhttps://github.com/saltstack/salt/issues/12478#issuecomment-42059891 .