-
Notifications
You must be signed in to change notification settings - Fork 26
(MODULES-5842) Implement Generic DSC Invoker #12
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
Conversation
b8929e0 to
db16c4e
Compare
|
|
||
| end | ||
|
|
||
| def self.format_string(value) |
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.
I think these format_ helpers can all be private as there are no other callers and all testing is against .format
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.
I had more tests coming in MODULES-6323, or at least I expect whoever implements that ticket will be adding more tests here as we'll be formatting CimInstances
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.
Yeah, I would mark these as private for now... if you need to add a more complex method for CimInstance formatting later and make that public for the sake of testing it individually, you can do that then.
| end | ||
| end | ||
| end | ||
| end No newline at end of file |
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.
nit - missing newline for some reason
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.
newline added
| end | ||
| end | ||
|
|
||
| def self.format_dsc_lite(dsc_value) |
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.
Is the code here the same as format_dsc_value above?
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.
It's the same now, however I expect it to diverge, and since you want the old way sitting next to the new way, I can't change the format_dsc method
| @formatter = PuppetX::PuppetLabs::DscLite::PowerShellHashFormatter | ||
| end | ||
|
|
||
| describe "formating ruby hash to powershell hash string" do |
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.
nit formatting
| end | ||
| end | ||
|
|
||
| newparam(:dsc_resource_properties, :array_matching => :all) do |
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.
Hmm - not sure if :array_matching => :all does anything for us here?
| }.to raise_error(Puppet::ResourceError, /A non-empty name must/) | ||
| end | ||
|
|
||
| [ 'value', 'value with spaces', 'UPPER CASE', '0123456789_-', 'With.Period' ].each do |value| |
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.
Aren't DSC resource naming guidelines stricter than this? I wouldn't expect <space> to be allowed? And I wouldn't expect values starting with numerics?
I'm having a tough time tracking down any specs / docs for the guidelines though - maybe buried somewhere in the CIM spec at https://www.dmtf.org/standards/cim/schemas?
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.
I would think trying to truly validate naming would be a game of catchup we aren't interested in pursuing as we are trying to be loosely typed here, and not get back into the business of validating parts we don't own.
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.
Looking at your code again, thought you had regexes in place for all of these, but I see there's only one for :name.
This is fine, though I don't expect PowerShell class names to be a moving target given they're well defined in the grammar specification. Changing that would be backward-incompatible, so I think the rules are pretty set in stone at this point.
| }.to raise_error(Puppet::ResourceError, /A non-empty name must/) | ||
| end | ||
|
|
||
| [ 'value', 'value with spaces', 'UPPER CASE', '0123456789_-', 'With.Period' ].each do |value| |
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.
Same here for the spaces... PowerShell 3 language spec says this about simple-name:
Probably TMI, but ...
Luis letter, uppercase - http://www.fileformat.info/info/unicode/category/Lu/index.htmLlis letter, lowercase - http://www.fileformat.info/info/unicode/category/Ll/index.htmLtis letter, titlecase - http://www.fileformat.info/info/unicode/category/Lt/index.htmLmis letter, modifier - http://www.fileformat.info/info/unicode/category/Lm/index.htmLois letter, other - http://www.fileformat.info/info/unicode/category/Lo/index.htm
The important part is cannot start with Nd - number, decimal digit - http://www.fileformat.info/info/unicode/category/Nd/index.htm
Even if we don't check whether it starts with a number, I think we can disallow the whitespace.
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.
Same as previous comment
spec/unit/puppet/type/dsc_spec.rb
Outdated
| }.to raise_error(Puppet::Error, /dsc_resource_properties should be a Hash/) | ||
| end | ||
| end | ||
| end No newline at end of file |
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.
nit - missing newline
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.
newline added
|
|
||
| it "requires a hash or array of hashes" do | ||
| expect { | ||
| resource[:dsc_resource_properties] = "hi" |
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.
Still working this out?
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 was part of the exploration for supporting CimInstances, but not fully implemented past being a hash. It was left like this since we ticketed that work in MODULES-6323
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.
If it's a hash shouldn't it be?
resource[:dsc_resource_properties] = { "hi" => "james" }And shouldn't it reject a bare string like "hi"?
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.
Apologies - I don't know what my last comment was about here - you are rejecting a bare string 🤦♂️
| resource[:dsc_resource_properties] = "hi" | ||
| }.to raise_error(Puppet::Error, /dsc_resource_properties should be a Hash/) | ||
| expect { | ||
| resource[:dsc_resource_properties] = ["hi"] |
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.
Hmm - what does an array of hashes mean in this context? Multiple instances of the same resource? That may be complex to implement if that's the intent?
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 was part of the exploration for supporting CimInstances, but not fully implemented past being a hash. It was left like this since we ticketed that work in MODULES-6323
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.
Probably worth punting to next ticket / PR then
e3e3830 to
690bfbe
Compare
This commit adds the `dsc` type and provider, which allows executing DSC Resources without the build system used by the previous pupppet dsc module. This is accomplished by adding a new type that accepts a DSC Resource Name and Module Name, and a un-typed hash of properties. This is passed as is to `Invoke-DscResource`. Unit tests for the type are added, manual verification of these changes are to be done as automated tests are to be added in subsequent tickets
690bfbe to
164eab8
Compare

This commit adds the
dsctype and provider, which allows executingDSC Resources without the build system used by the previous pupppet dsc
module.
This is accomplished by adding a new type that accepts a DSC Resource
Name and Module Name, and a un-typed hash of properties. This is passed
as is to
Invoke-DscResource.Unit tests for the type are added, manual verification of these changes
are to be done as automated tests are to be added in subsequent tickets