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

(GH-145) Add insync? and invoke_test_method to dsc provider #124

Merged
merged 1 commit into from
Jun 28, 2021
Merged

(GH-145) Add insync? and invoke_test_method to dsc provider #124

merged 1 commit into from
Jun 28, 2021

Conversation

michaeltlombardi
Copy link
Contributor

Prior to this PR the DSC base provider had no way to handle resource level insync checks and could only rely on the default property-by-property insync checks in Puppet::Property. This fell short in cases where such a check could not work, such as in cases where the DSC Resource does not return the expected values in Get or had a mismatch between its API spec and the implementation.

This PR:

  1. Adds a new class variable, @@cached_test_results
  2. Adds a new accessor method, cached_test_results, to retrieve the cache
  3. Adds a new insync? method which can be called by the resource API; for more info, see Allow custom insync? checking for resources puppet-resource_api#225. This method only handles custom insync validation for a resource which has the validation_mode specified as resource and otherwise defaults to the existing behavior. If the validation_mode is specified as resource however, it instead first checks the test result cache for whether or not the resource is in the desired state and, if the resource has not already been cached, calls invoke_test_method and returns that result.
  4. Adds a new invoke_test_method method which passes the should hash of the resource to Invoke-DscResource similarly to the existing invoke_set_method; unlike with set, however, it caches the name and whether or not the resource is in the desired state and then returns true if in the desired state and otherwise false. In cases where something goes wrong, it writes an error and returns nil.

This PR includes new unit tests for the additional methods.

This PR makes progress towards but does not alone implement puppetlabs/Puppet.Dsc#145; it is also blocked on the RSAPI changes in puppetlabs/puppet-resource_api#225.

@michaeltlombardi
Copy link
Contributor Author

Blocked on the next releases of Puppet (6.23.0 and 7.?.? and the PDK which incorporates them).

@michaeltlombardi
Copy link
Contributor Author

This has been unblocked by the release of Puppet 6.23.0 and 7.8.0 - unit tests pass and manual verification has been completed. Automated tests on the builder have passed to validate this functionality

@michaeltlombardi michaeltlombardi marked this pull request as ready for review June 28, 2021 02:11
@michaeltlombardi michaeltlombardi requested a review from a team as a code owner June 28, 2021 02:11
Prior to this commit the DSC base provider had no way to handle resource
level insync checks and could only rely on the default property-by-property
insync checks in Puppet::Property. This fell short in cases where such a
check could not work, such as in cases where the DSC Resource does not
return the expected values in Get or had a mismatch between its API spec
and the implementation.

This commit:

1. Adds a class variable, `@@cached_test_results`
2. Adds an accessor method, `cached_test_results`, to retrieve the cache
3. Adds the `insync?` method which can be called by the resource API;
   for more info, see puppetlabs/puppet-resource_api#225. This method
   only handles custom insync validation for a resource which has the
   `validation_mode` specified as `resource` and otherwise defaults to
   the existing behavior. If the `validation_mode` *is* specified as
   `resource`, it instead first checks the test result cache for
   whether or not the resource is in the desired state and, if the
   resource has not already been cached, calls `invoke_test_method` and
   returns that result.
4. Adds the `invoke_test_method` method which passes the `should`
   hash of the resource to `Invoke-DscResource` similarly to the extant
   `invoke_set_method`; unlike with `set`, however, it caches the name
   and whether or not the resource is in the desired state and then it
   returns `true` if in the desired state and otherwise `false` with a
   descriptive change message. In cases where something goes wrong, it
   returns `nil` and causes Puppet to fall back on the default property-
   by-property comparison logic.

This commit includes new unit tests for the additional methods.

This commit makes progress towards but does not alone implement
puppetlabs/Puppet.Dsc#145.
@david22swan david22swan merged commit 2ce2144 into puppetlabs:main Jun 28, 2021
@michaeltlombardi michaeltlombardi deleted the gh-145/main/insync branch June 28, 2021 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants