Skip to content

Conversation

@jpogran
Copy link
Contributor

@jpogran jpogran commented Dec 18, 2017

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

@jpogran jpogran force-pushed the MODULES-5842-generic-dsc branch from b8929e0 to db16c4e Compare December 18, 2017 18:54

end

def self.format_string(value)
Copy link
Contributor

@Iristyle Iristyle Dec 18, 2017

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

Copy link
Contributor Author

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

Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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|
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@Iristyle Iristyle Dec 19, 2017

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|
Copy link
Contributor

@Iristyle Iristyle Dec 18, 2017

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:

image

Probably TMI, but ...

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment

}.to raise_error(Puppet::Error, /dsc_resource_properties should be a Hash/)
end
end
end No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - missing newline

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still working this out?

Copy link
Contributor Author

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

Copy link
Contributor

@Iristyle Iristyle Dec 19, 2017

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"?

Copy link
Contributor

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"]
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

@jpogran jpogran force-pushed the MODULES-5842-generic-dsc branch 2 times, most recently from e3e3830 to 690bfbe Compare December 19, 2017 14:22
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
@jpogran jpogran force-pushed the MODULES-5842-generic-dsc branch from 690bfbe to 164eab8 Compare January 3, 2018 18:03
@Iristyle Iristyle closed this in 2a2ba13 Jan 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants