Closed Clebam closed 6 months ago
👍🏼 I've definitely encountered exactly this and it is a huge blocker from adopting dsc resources.
@Clebam apologies for the delay in response. This might take some time for our team to look at and implement. This repo is open source however, so you can raise a PR with your fix if you wish and we can get it out faster! Thanks for raising this.
@jordanbreen28 I just validated the fix for this and the updated code works for me. Just a short test on one Enum on one Windows Server. @Clebam please open a PR for this!
Describe the Bug
When the casing of a value inside an Enum does not match what puppet retrieves on the system, it reapplies the value.
Expected Behavior
Among the casing accepted in the Enum (generally PascalCased and lowercased, ie Enum['MyValue', 'myvalue']), both should be idempotent.
Steps to Reproduce
Steps to reproduce the behavior:
Environment
Additional Context
I opened a related issue previously (https://github.com/puppetlabs/ruby-pwsh/issues/254) and had a discussion on slack (here https://puppetcommunity.slack.com/archives/CFD8Z9A4T/p1696342031154069) I also commented here recently https://github.com/puppetlabs/ruby-pwsh/pull/131#issuecomment-1852779233
I made a few more test and was able to better understand the issue.
First of all the issue comes from this commit: https://github.com/puppetlabs/ruby-pwsh/pull/131/commits/0dd07145566f0c221c5cc462944e42d7ed5e51df#diff-2ab4c6b5047cd9e5464cf56d34d7953e1aee0facd20a4739cd767dbb335abfcbR82
The behavior before the commit implied that the system could return a value that was not in the Enum (as described here : https://github.com/puppetlabs/ruby-pwsh/issues/127)
So the fix overrides the System value with the manifest value if the type of the current parameter is an Enum.
However this implies another bug. The value in the manifest will be compared to the value in the System after the canonicalization. And the casing of the manifest and the casing of the System value may not match and will produce a change at each run.
I will try to describe step by step how it works
All of what I describe from step 1 to step 5 is in the
canonicalize
function inedsc_base_provider.rb
The step 4 and 5 specifically are linked to this piece of code : https://github.com/puppetlabs/ruby-pwsh/pull/131/commits/0dd07145566f0c221c5cc462944e42d7ed5e51df#diff-2ab4c6b5047cd9e5464cf56d34d7953e1aee0facd20a4739cd767dbb335abfcbR82I tried a fix that seem to both fix my issue (constant change) and the former (System Value not being in enum) with a few changes
The whole idea is to check if the value returned by the System is in the Enum or not. If not ==> use manifest value
This avoids constant change from happening but protects from wrong values being tested against the Enum. It should be noted that the former issue with value not being in the Enum is an error on the external module itself. The Enum should have listed the values returned by the system