-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
More intelligent diffing in changes of file.serialize state #48609
More intelligent diffing in changes of file.serialize state #48609
Conversation
Basically I'm OK with the idea.
Maybe shorter?
Maybe just document this point?
Not sure it's a good idea but the simplest way is if it's not a dict make it a dict |
Isn't |
@anlutro I'm ok then. Sorry for misleading |
Cool. I will work on the list stuff as well as docs a bit later today, hopefully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am OK with this change, but the current behavior should be the default. I'd also like @terminalmage to take a look here as well.
salt/states/file.py
Outdated
@@ -6374,6 +6375,7 @@ def serialize(name, | |||
encoding=None, | |||
encoding_errors='strict', | |||
serializer_opts=None, | |||
diff_serializer_data=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be False
by default to keep the previous behavior, yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like anything that helps normalize changes. However, I don't think we need to hide this behavior behind an argument. I'm not sure I understand what changing the format of the diffs in the changes
key of the return data is going to "break".
IMO this behavior should be the new default and we don't need to make it contingent on an argument passed to the state.
OK, after talking to @terminalmage about this offline, I agree with him. We definitely need a mention of the change in the release notes though. |
Okay, cool. I just need to figure out how to do the diffing, then. I can't find anything in |
On second thought, after considering how difficult smartly diffing lists is, maybe I should just not do that... But that might mean that data structures such as lists of dicts or lists of lists of dicts won't get smartly diffed. Maybe I can simply wrap the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anlutro Can you elaborate on what you mean by list diffing? The recursive diffing in dictdiffer does show where lists differ.
To me this looks good as-is, but since I'm not sure where you're coming from, I want to make sure we're on the same page before I approve this PR for merging.
I mean if we have this JSON data: |
Oh OK, so if the data is being serialized and was formed as a list instead of a dict. I guess you could always do type checking like you suggested, but we would still want there to be something in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no much to add here what already has been said.
@anlutro Are you ready for a final review here? I saw that you removed the |
Possibly - I wanted to see if any tests were failing first but seemed like
Jenkins was freaking out.
…On Tue, Aug 28, 2018, 20:03 Mike Place ***@***.***> wrote:
@anlutro <https://github.com/anlutro> Are you ready for a final review
here? I saw that you removed the WIP indicator from the PR title.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#48609 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAJ9Fb078ADucwNSNgJwkephJQ61jCWkks5uVYYFgaJpZM4VRo2O>
.
|
@anlutro I think this test failure is related: https://jenkinsci.saltstack.com/job/pr-kitchen-ubuntu1604-py2/job/PR-48609/10/ Can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is still nothing in ret['changes']
if the data is non-dictionary. We need to have at least something in there for onchanges requisites to work.
@rallytime Ah - fixed that now. Let's see if other failures pop up. @terminalmage Sorry for the late replies, I'm out travelling. |
Ah ok, thanks! |
@anlutro It's still failing, unfortunately: https://jenkinsci.saltstack.com/job/pr-kitchen-ubuntu1604-py3/job/PR-48609/13/ |
@anlutro Any updates here? |
Hey, sorry for going quiet. I see there's a test failure but it doesn't make any sense to me. It looks like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started new tests since the old results are aged out of Jenkins. Pending getting them fixed, I think this is good to merge.
@anlutro It looks like that test run failed. Can you take a look please? https://jenkinsci.saltstack.com/job/pr-kitchen-centos7-py3/job/PR-48609/40/testReport/junit/integration.states.test_file/FileTest/test_serializer_deserializer_opts/ |
I just pushed a commit to this PR to fix the docs build issue, @anlutro. You'll need to pull before you make any more changes. |
I'll rebase this PR in the mean time. |
I found and fixed a problem in this PR, we were including the dictdiffer object in the changes dict and msgpack couldn't serialize it. 1af036a should fix this. |
I wanted some feedback on this minor feature before I tidy it up, write tests etc. - I've confirmed it works with a local checkout of the salt codebase.
Basically I have a JSON config file being generated by a Go application, and I want to manage parts of it with Salt. However, because Python and Go order their JSON differently (order of keys mostly), the diff output is always massive, making it impossible to see what changed.
I found
salt.utils.dictdiffer
which does exactly what I want in this scenario. I added an optional argument tofile.serializer
which switches the behaviour of the state'schanges
output.Some problems/questions which I'd like feedback on:
onchanges
etc.dictdiffer
only works on dicts, but it's possible to serialize other data types such as lists.