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

(MODULES-8047) Fix puppet resource chocolateyconfig #146

Merged
merged 1 commit into from
Feb 25, 2019
Merged

(MODULES-8047) Fix puppet resource chocolateyconfig #146

merged 1 commit into from
Feb 25, 2019

Conversation

michaeltlombardi
Copy link

Prior to this commit running puppet resource chocolateyconfig would
fail during the validation block which verified that no config items
were both :present and had an empty :value or were missing :value
altogether.

This is because Chocolatey represents a configuration item which is
using the defaults as an empty string. When collecting instances of
Chocolatey config items from the configuration file, it would find
the items, mark them as :present, and save them with a :value of "".

This would then fail the validation block.

During a puppet apply run the validation block is called before the
instances are fetched - and, therefore, before @property_hash is
populated. This allows us to distinguish between the two calls and error
on any declared resources which specify :ensure as :present but forget
to specify a :value.

This commit moves the validation logic from the type into the provider
in order to allow us to take advantage of the @property_hash information
during a puppet resource run.

This commit also updates the get_config method to treat any discovered
Chocolatey config item with an empty value as :absent - this matches
the behavior of :ensure => :absent which calls choco config unset -
this command replaces the existing value of a config item with an empty
string.

Now when returning the list of Chocolatey configs our model of them is
consistent, with :absent meaning that the configuration item is set
to the default.

This commit does not change the behavior of a puppet apply run.

This commit does include changes to the unit tests to reflect the
moving of the validation logic.

Prior to this commit running `puppet resource chocolateyconfig` would
fail during the validation block which verified that no config items
were both :present *and* had an empty :value or were missing :value
altogether.

This is because Chocolatey represents a configuration item which is
using the defaults as an empty string. When collecting instances of
Chocolatey config items from the configuration file, it would find
the items, mark them as :present, and save them with a :value of "".

This would then fail the validation block.

During a `puppet apply` run the validation block is called before the
instances are fetched - and, therefore, before `@property_hash` is
populated. This allows us to distinguish between the two calls and error
on any declared resources which specify `:ensure` as `:present` but forget
to specify a `:value`.

This commit moves the validation logic from the type into the provider
in order to allow us to take advantage of the @property_hash information
during a `puppet resource` run.

This commit also updates the `get_config` method to treat any discovered
Chocolatey config item with an empty value as `:absent` - this matches
the behavior of `:ensure => :absent` which calls `choco config unset` -
this command replaces the existing value of a config item with an empty
string.

Now when returning the list of Chocolatey configs our model of them is
consistent, with `:absent` meaning that the configuration item is set
to the default.

This commit does not change the behavior of a `puppet apply` run.

This commit *does* include changes to the unit tests to reflect the
moving of the validation logic.
@ThoughtCrhyme ThoughtCrhyme merged commit 80ee252 into puppetlabs:master Feb 25, 2019
@michaeltlombardi michaeltlombardi deleted the ticket/master/MODULES-8047-fix-chococonfig branch August 16, 2019 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants