You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
states.file.managed returns empty changes dict in test mode #45895
Corerelates to code central or existential to SaltP1Priority 1bugbroken, incorrect, or confusing behaviorseverity-medium3rd level, incorrect or bad functionality, confusing and lacks a work around
The file.managed state function often returns an empty changes dict when run with test=true. In fact, the only time a non-empty changes dict is returned is when there will be a change to the file content. All other managed changes (e.g. owner, group, mode) will return an empty changes dict, which causes several requisites to misbehave, including wait, listen, prereq, and onchanges
This error was introduced with PR #26134 when the changes dict was renamed to pchanges, resulting in and empty changes dict in all cases.
It was partially fixed with PR #26982, which populated the changes dict for file content differences, which is probably why this has gone unnoticed for so long.
The real problem seems to be the original change from changes to pchanges introduced by @thatch45. No other state modules use pchanges, and I don't see any other code that makes use of a pchanges key in the returned dictionary. It seems to me that the changes made in PR #26134 should be reverted entirely.
I am not aware of any active effort to expand it either and, to be honest, I don't quite understand the intricacies of pchanges as well as I would like. To the best of my knowledge, it's not documented very well either as I ran into some issues about what the expected behavior is when I was trying to debug some tests with @twangboy a couple of months ago.
@thatch45@cachedout@terminalmage@garethgreenaway Do any of you have more to add about this? What is the intended difference between pchanges and changes? Are there plans for expansion? If so, we need to make sure pchanges behaves appropriately with the various state requisites.
I wasn't involved with pchanges and don't fully understand its use. I think this was intended to be used by prereq requisites though maybe? I believe @whiteinge was at least partially involved in adding pchanges so maybe he could chime in.
Yeah, what Tom said. pchanges provides a place for programmatically consumable information as an alternative to the semi-common practice of stuffing things into the comment field as string.
E.g., file.managed would append the diff as a string to the comment field in test=true mode -- the changes field must remain empty since no changes were actually made. Having that valuable info in a string made it difficult to consume without parsing.
To Nicole's question, if pchanges should continue to get built out:
The highstate outputter should always display it for test=true runs and optionally display it for regular runs.
changes must be empty for test=true.
pchanges (predictive changes) should always be populated for test=true runs.
IMO, pchanges should always be populated and changes should be additionally populated for non-dry-runs so that they can be compared. But this is debatable.
changes and pchanges should be structurally the same "shape" so they can be compared against each other directly.
Usually changes and pchanges will be identical but sometimes changes might contain additional information. E.g., pchanges can predict the result of adding a new system user but only after actually adding the user can some kinds of information be learned, such as whether the system assigned a default umask and other kinds of post-task defaults.
I see that the question around whether pchanges is a helpful addition or not requires more discussion, but I would like to first address the issue at hand:
When an empty changes dict is returned, the prereq requisite fails, as well as several other requisites in test mode, i.e. wait, listen, onchanges.
Do we agree that this should be addressed as a bug?
Team, everything that @whiteinge described sounds very cool. In the meantime, it seems that prereq and other expected behaviors are broken. @thatch45, would it be practical for us to revert this change until pchanges has been expanded further?
@amendlik, thanks for raising this, especially pointing out how prereq breaks in this scenario. I see how that could be potentially very bad.
local:
----------
ID: create-file
Function: file.managed
Name: /tmp/demo-file
Result: None
Comment: The file /tmp/demo-file is set to be changed
Started: 12:38:27.422568
Duration: 11.318 ms
Changes:
----------
ID: delete-file
Function: file.absent
Name: /tmp/demo-file
Result: True
Comment: State was not run because none of the onchanges reqs changed
Changes:
Summary for local
------------
Succeeded: 2 (unchanged=1)
Failed: 0
------------
Total states run: 2
Total run time: 11.318 ms
Notice the delete-file state says 'State was not run because none of the onchanges reqs changed'. This is because the file.managed state returns an empty changes dict when run with test=true.
Result when run with test=false:
local:
----------
ID: create-file
Function: file.managed
Name: /tmp/demo-file
Result: True
Comment: Empty file
Started: 12:36:21.929767
Duration: 4.201 ms
Changes:
----------
mode:
0666
new:
file /tmp/demo-file created
----------
ID: delete-file
Function: file.absent
Name: /tmp/demo-file
Result: True
Comment: Removed file /tmp/demo-file
Started: 12:36:21.934233
Duration: 0.323 ms
Changes:
----------
removed:
/tmp/demo-file
Summary for local
------------
Succeeded: 2 (changed=2)
Failed: 0
------------
Total states run: 2
Total run time: 4.524 ms
Notice that when run with test=falseboth states execute. This is because the changes dict is populated when test=false.
After talking about this a little more with @cachedout today, this is a bug as it stands currently, and we should fix the original issue.
As far as the pchanges migration question goes for other state modules, we should start moving in that direction, but that particular issue/move does not need to be handled right now, just the main issue reported here can be fixed first.
@terminalmage Can you take a look at this one after you're finished with the work you're doing on the runtests.py + Jenkins project?
In my opinion, all references to pchanges should be removed until there is clear direction on that point and a plan to implement support across all state modules. That said, I am not going to throw a fit over an unused variable (but your linter might).
But, I think we're missing the bigger picture here. Please reread these comments:
This comment by @amendlik, which says that service.running and pkg.installed have the same problem. How many other states have this problem? Shouldn't we fix them all? Can we be doing more with testing and documentation to address this holistically?
This comment by @whiteinge which says that contributors are violating the API intentionally. This is something that should be resolved sooner than later. Either the API is confusing and should be changed, or the API is fine and it should be used as documented. Allowing developers to continue to violate it is untenable.
Dry-run changes usage has always been schizophrenic -- people complain when it's populated because it looks like something did change, and people complain when it's empty because then you can't test requisites that depend on that within a dry-run.
Dry-run changes behavior differs between execution functions and has changed over time even within the same function. Best to define in writing once and for all what the best tradeoff is, then fix all the wrong functions over time.
changes by itself isn't sufficient to satisfy both the use-cases we need for a dry-run, thus the introduction of pchanges and mock=true. But a half-implemented pchanges isn't doing anyone any favors. If now isn't a good time to work on those features then they should probably be pulled out.
I personally lean towards removing pchanges, since it would not involve messing with the state compiler (which would need to be done in order to make the onchanges requisites work in test mode). This would require us to set whatever we were tracking as pchanges in the changes key before returning a None result in test mode, but that would not be difficult.
However, pchanges is used in a few dozen files, so removing it altogether would not be something I'm comfortable with doing in a point release.
As a compromise, as a bugfix I could convert the pchanges use to changes when file states are run in test mode, which would make those requisites work. Then, the work of removing the rest of the pchanges usage could be done in develop and would be part of the Neon release (spring 2019).
For things like pkg states, we would have to implement a changes key for those states when running in test mode. The one caveat here is that this would often be inaccurate since installing a package routinely pulls in additional dependencies. However, if that is clearly documented, I don't think it's a big deal, as the mere fact that we have something in the changes key when returning in test mode would make onchanges requisites which depend on pkg work.
I'd like to add my voice to this. We wasted two sysadmin days and created a 60 second website outage across our customers because of this breakage.
salt developers need to be far more aware that making significant breaking changes in stable releases creates an overall impression that salt is unreliable. In this case, it was known that prereq was completely broken for file.managed and yet nothing appears in the documentation or release notes to state that the prereq feature has been dropped from salt 2018.3. The problem has been known since February, two months before the release.
I'm unclear what problem pchanges tried to solve. But breaking dependency management in salt should be considered a really big deal.
We can cope with changes being inaccurate from time to time, as long as it is consistently inaccurate. And I'm happy to submit PR requests to make file.archive give us changes in test mode when used with a source hash, or for other modules we come across.
#49832 is targeted for the develop branch. Given that this is a recognized bug in current versions, it would be best to back-port the changes to all supported branches.
It's also a pretty significant change, which is why it's in develop. Once we've given it some time in develop to the point we're confident it won't break, we'll consider backporting.
@terminalmage I am really surprised to see that this fix did not make it into the Fluorine release. This issue was introduced in 2015, reported over a year ago, and fixed 5 months ago. Do we really need to wait another 8-12 months for the next major release to get this resolved?
This is up to @saltstack/team-core to approve for backporting. We had already reached the freeze for Fluorine by the time the PR was opened. The release was delayed by the holidays and by SaltConf, so it came out later than expected.
Corerelates to code central or existential to SaltP1Priority 1bugbroken, incorrect, or confusing behaviorseverity-medium3rd level, incorrect or bad functionality, confusing and lacks a work around
Activity
gtmanfred commentedon Feb 7, 2018
@saltstack/team-core can i get some comments on what the plans are for pchanges?
Because a good point is brought up here, it isn't used everywhere yet, and I am not aware of any active effort to expand on it.
Thanks,
Daniel
amendlik commentedon Feb 12, 2018
@gtmanfred, any update on this?
gtmanfred commentedon Feb 12, 2018
I am waiting on input from the rest of the core team on this.
rallytime commentedon Feb 12, 2018
I am not aware of any active effort to expand it either and, to be honest, I don't quite understand the intricacies of
pchangesas well as I would like. To the best of my knowledge, it's not documented very well either as I ran into some issues about what the expected behavior is when I was trying to debug some tests with @twangboy a couple of months ago.@thatch45 @cachedout @terminalmage @garethgreenaway Do any of you have more to add about this? What is the intended difference between pchanges and changes? Are there plans for expansion? If so, we need to make sure pchanges behaves appropriately with the various state requisites.
terminalmage commentedon Mar 9, 2018
I wasn't involved with pchanges and don't fully understand its use. I think this was intended to be used by
prereqrequisites though maybe? I believe @whiteinge was at least partially involved in adding pchanges so maybe he could chime in.thatch45 commentedon Mar 9, 2018
The idea for
pchangeswas that we would put potential changes in there when we run withtest=Truerallytime commentedon Mar 9, 2018
Isn't that what
changesdoes? With theoldandnewkeys and thenresult=None?whiteinge commentedon Mar 9, 2018
Yeah, what Tom said.
pchangesprovides a place for programmatically consumable information as an alternative to the semi-common practice of stuffing things into thecommentfield as string.E.g.,
file.managedwould append the diff as a string to thecommentfield intest=truemode -- thechangesfield must remain empty since no changes were actually made. Having that valuable info in a string made it difficult to consume without parsing.To Nicole's question, if
pchangesshould continue to get built out:highstateoutputter should always display it fortest=trueruns and optionally display it for regular runs.changesmust be empty fortest=true.pchanges(predictive changes) should always be populated fortest=trueruns.pchangesshould always be populated andchangesshould be additionally populated for non-dry-runs so that they can be compared. But this is debatable.changesandpchangesshould be structurally the same "shape" so they can be compared against each other directly.changesandpchangeswill be identical but sometimeschangesmight contain additional information. E.g.,pchangescan predict the result of adding a new system user but only after actually adding the user can some kinds of information be learned, such as whether the system assigned a defaultumaskand other kinds of post-task defaults.amendlik commentedon Mar 20, 2018
I see that the question around whether
pchangesis a helpful addition or not requires more discussion, but I would like to first address the issue at hand:When an empty
changesdict is returned, theprereqrequisite fails, as well as several other requisites in test mode, i.e.wait,listen,onchanges.Do we agree that this should be addressed as a bug?
amendlik commentedon Apr 5, 2018
@gtmanfred Any updates?
grichmond-salt commentedon Apr 9, 2018
Team, everything that @whiteinge described sounds very cool. In the meantime, it seems that
prereqand other expected behaviors are broken. @thatch45, would it be practical for us to revert this change until pchanges has been expanded further?@amendlik, thanks for raising this, especially pointing out how
prereqbreaks in this scenario. I see how that could be potentially very bad.amendlik commentedon Apr 24, 2018
Here is an example of how an empty
changesdictionary breaks theonchangesrequisite when run withtest=true:State file:
Result when run with
test=true:Notice the
delete-filestate says 'State was not run because none of the onchanges reqs changed'. This is because thefile.managedstate returns an emptychangesdict when run withtest=true.Result when run with
test=false:Notice that when run with
test=falseboth states execute. This is because thechangesdict is populated whentest=false.rallytime commentedon Apr 27, 2018
After talking about this a little more with @cachedout today, this is a bug as it stands currently, and we should fix the original issue.
As far as the
pchangesmigration question goes for other state modules, we should start moving in that direction, but that particular issue/move does not need to be handled right now, just the main issue reported here can be fixed first.@terminalmage Can you take a look at this one after you're finished with the work you're doing on the runtests.py + Jenkins project?
14 remaining items
gtmanfred commentedon Aug 13, 2018
We have gotten into this argument before, now the bottom is incorrect.
That logic will need to be changed as well.
grichmond-salt commentedon Aug 13, 2018
Great catch, @gtmanfred!
amendlik commentedon Aug 13, 2018
In my opinion, all references to
pchangesshould be removed until there is clear direction on that point and a plan to implement support across all state modules. That said, I am not going to throw a fit over an unused variable (but your linter might).But, I think we're missing the bigger picture here. Please reread these comments:
service.runningandpkg.installedhave the same problem. How many other states have this problem? Shouldn't we fix them all? Can we be doing more with testing and documentation to address this holistically?whiteinge commentedon Aug 13, 2018
Agree with @amendlik points here.
Dry-run
changesusage has always been schizophrenic -- people complain when it's populated because it looks like something did change, and people complain when it's empty because then you can't test requisites that depend on that within a dry-run.Dry-run
changesbehavior differs between execution functions and has changed over time even within the same function. Best to define in writing once and for all what the best tradeoff is, then fix all the wrong functions over time.changesby itself isn't sufficient to satisfy both the use-cases we need for a dry-run, thus the introduction ofpchangesandmock=true. But a half-implementedpchangesisn't doing anyone any favors. If now isn't a good time to work on those features then they should probably be pulled out.amendlik commentedon Aug 14, 2018
Be sure to also remove the documentation for
pchangesintroduced in 0e705d2terminalmage commentedon Aug 21, 2018
I personally lean towards removing
pchanges, since it would not involve messing with the state compiler (which would need to be done in order to make theonchangesrequisites work in test mode). This would require us to set whatever we were tracking aspchangesin thechangeskey before returning aNoneresult in test mode, but that would not be difficult.However, pchanges is used in a few dozen files, so removing it altogether would not be something I'm comfortable with doing in a point release.
As a compromise, as a bugfix I could convert the
pchangesuse tochangeswhen file states are run in test mode, which would make those requisites work. Then, the work of removing the rest of the pchanges usage could be done in develop and would be part of theNeonrelease (spring 2019).For things like pkg states, we would have to implement a
changeskey for those states when running in test mode. The one caveat here is that this would often be inaccurate since installing a package routinely pulls in additional dependencies. However, if that is clearly documented, I don't think it's a big deal, as the mere fact that we have something in thechangeskey when returning in test mode would makeonchangesrequisites which depend onpkgwork.Thoughts?
angeloudy commentedon Sep 25, 2018
pchangesis causingprereqmisbehaving #49753ari commentedon Sep 25, 2018
I'd like to add my voice to this. We wasted two sysadmin days and created a 60 second website outage across our customers because of this breakage.
salt developers need to be far more aware that making significant breaking changes in stable releases creates an overall impression that salt is unreliable. In this case, it was known that
prereqwas completely broken for file.managed and yet nothing appears in the documentation or release notes to state that theprereqfeature has been dropped from salt 2018.3. The problem has been known since February, two months before the release.I'm unclear what problem
pchangestried to solve. But breaking dependency management in salt should be considered a really big deal.We can cope with
changesbeing inaccurate from time to time, as long as it is consistently inaccurate. And I'm happy to submit PR requests to makefile.archivegive us changes in test mode when used with a source hash, or for other modules we come across.terminalmage commentedon Sep 29, 2018
See #49832
amendlik commentedon Sep 29, 2018
#49832 is targeted for the
developbranch. Given that this is a recognized bug in current versions, it would be best to back-port the changes to all supported branches.terminalmage commentedon Oct 1, 2018
It's also a pretty significant change, which is why it's in develop. Once we've given it some time in develop to the point we're confident it won't break, we'll consider backporting.
lordcirth commentedon Mar 7, 2019
@terminalmage Any news on this backport? Not having diffs is quite annoying.
amendlik commentedon Mar 8, 2019
@terminalmage I am really surprised to see that this fix did not make it into the Fluorine release. This issue was introduced in 2015, reported over a year ago, and fixed 5 months ago. Do we really need to wait another 8-12 months for the next major release to get this resolved?
terminalmage commentedon Mar 26, 2019
This is up to @saltstack/team-core to approve for backporting. We had already reached the freeze for Fluorine by the time the PR was opened. The release was delayed by the holidays and by SaltConf, so it came out later than expected.