-
Notifications
You must be signed in to change notification settings - Fork 27
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-7178) Report types dynamically #69
(MODULES-7178) Report types dynamically #69
Conversation
|
Given a site.pp on a 2018.1.2 master (which contains the patch for PUP-8746 at puppetlabs/puppet#6838, which is part of Puppet 5.5.2 and 5.5.3) The behavior is as desired: To repro, I provisioned using the following procedure: Once provisioned, I modified the
|
lib/puppet/type/dsc.rb
Outdated
| @@ -4,6 +4,15 @@ | |||
| require Pathname.new(__FILE__).dirname + '../../' + 'puppet/type/base_dsc_lite' | |||
| require Pathname.new(__FILE__).dirname + '../../puppet_x/puppetlabs/dsc_lite/dsc_type_helpers' | |||
|
|
|||
| def type | |||
| # for the sake of report status, masquerade as a different type | |||
| ("Dsc_" + parameters[:resource_name].value).to_sym | |||
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.
Huh... TIL ... I thought you needed to use .intern
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.
Changing to DscLite_ as the prefix to prevent collisions with existing DSC module.
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.
To canonicalize the type name, I think we should do a parameters[:resource_name].value.capitalize
|
Those tests you mentioned seem to cover most of where I think the "unintended consequences" would come about. I would also consider adding in a resource name collision on purpose to see what happens. e.g. And possibly two resources with the same title Both in an agent only and a master/agent setup. To see what the fall out would be. |
f89af75
to
bc487d2
Compare
lib/puppet/type/dsc.rb
Outdated
| def type | ||
| # in the event this value is consumed early in the lifecycle / before | ||
| # parameters have been populated, use 'unspecified' | ||
| name = ( parameters[:resource_name].nil? || parameters[:resource_name].value.nil? || parameters[:resource_name].value.match?(/\W/) ) ? |
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 extra check can be removed once https://tickets.puppetlabs.com/browse/MODULES-7485 is fixed.
- Prior to this commit, all types would report the `dsc` type as their
identity. This is problematic for the sake of reporting as every type
of resource is grouped together under `dsc`, rather than the specific
`resource_name` modeled in a manifest.
This new approach allows for types to report under something more
useful that indicates the original DSC resource type specified in the
resource_name attribute.
For instance, given a manifest with the following resources:
dsc { 'sample_file':
resource_name => 'File',
module => 'PSDesiredStateConfiguration',
properties => {
ensure => 'present',
contents => 'hello',
destinationpath => 'c:\\test.txt',
}
}
dsc { 'lmhosts':
resource_name => 'Service',
module => 'PSDesiredStateConfiguration',
properties => {
name => 'lmhosts',
ensure => 'present',
state => 'running',
}
}
The report now shows:
* Dsc_lite_file[sample_file] Unchanged
* Dsc_lite_service[lmhosts] Unchanged
Instead of what it previously reported:
* Dsc[sample_file] Unchanged
* Dsc[lmhosts] Unchanged
- Selection of the PowerShell code was previously determined by type,
but given it has changed to being specified as :Dsc_lite_XXXX, its
not as easy to do that anymore. Instead, add a simple boolean
property to the generic dsc wrapper that may be checked instead.
- Note that parameter validation for `module`, `resource_name` and
properties does not currently work, but will be fixed in another
ticket by adding a global validator. The `type` method performs some
additional guarding around usage of the `resource_name` parameter
for 2 reasons:
* It's unclear if the parser or other logic in Puppet uses the type
name without the resource being instantiated fully with values from
a manifest
* Due to the incorrect validation, the PE console errors with the
following message when `resource_name` is left unspecified:
undefined method `value` for nil:NilClass
bc487d2
to
87e841e
Compare




Determine if new tests can / should be addedbasic specs addedShouldCanonicalized by callingresource_namebe canonicalized? i.e. DoesFiLeshow up differently thanfile... do we care? (Report logic already callscapitalizeand the report looks fine, but should the internal tracking maintain state differently?)downcaseon theresource_nameproperty so that case differences don't matter internally.Make sure nothing else weird happens in the system when the type reports as
:dsc_fooinstead of:dsc.Are there any other dependencies on the symbolThere are no other usages of:dsc?:dscMake sure that behavior on an older PE install is reasonable (without the PUP-8746 / puppetlabs/puppet@28240e5 fix) - it may end up behaving partially correctly if metrics summary is out of sync with actual resource typesScreenshots / explanation below. Behavior is OK and as expected.Test in conjunction with the DSC resource that may refer to the same types (should we useVetted this with @michaeltlombardi - didn't include screenshots, but it was necessary to prefix withDscLite_instead ofDsc_for the prefix?)dsc_lite_to avoid collisions with DSC modulePrior to this commit, all types would report the
dsctype as theiridentity. This is problematic for the sake of reporting as every type
of resource is grouped together under
dsc, rather than the specificresource_namemodeled in a manifest.This new approach allows for types to report under something more
useful that indicates the original DSC resource type specified in the
resource_name attribute.
For instance, given a manifest with the following resources:
The report now shows:
Instead of what it previously reported:
Selection of the PowerShell code was previously determined by type,
but given it has changed to being specified as :Dsc_lite_XXXX, its
not as easy to do that anymore. Instead, add a simple boolean
property to the generic dsc wrapper that may be checked instead.
Note that parameter validation for
module,resource_nameandproperties does not currently work, but will be fixed in another
ticket by adding a global validator. The
typemethod performs someadditional guarding around usage of the
resource_nameparameterfor 2 reasons:
name without the resource being instantiated fully with values from
a manifest
following message when
resource_nameis left unspecified:undefined method
valuefor nil:NilClass