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

(FM 8425) - Replace Library Code #134

Merged
merged 5 commits into from
Dec 9, 2019

Conversation

david22swan
Copy link
Member

No description provided.

@codecov-io
Copy link

codecov-io commented Nov 29, 2019

Codecov Report

Merging #134 into master will decrease coverage by 37.45%.
The diff coverage is 40%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #134       +/-   ##
===========================================
- Coverage   73.17%   35.71%   -37.46%     
===========================================
  Files           9        7        -2     
  Lines         492      434       -58     
===========================================
- Hits          360      155      -205     
- Misses        132      279      +147
Impacted Files Coverage Δ
lib/puppet/provider/base_dsc_lite/powershell.rb 23.33% <10%> (-20.07%) ⬇️
lib/facter/powershell_version.rb 66.66% <100%> (-33.34%) ⬇️
...x/puppetlabs/dsc_lite/powershell_hash_formatter.rb 100% <100%> (+10.63%) ⬆️
lib/puppet/type/base_dsc_lite.rb 44.44% <0%> (-55.56%) ⬇️
lib/puppet/feature/dsc_lite.rb 26.92% <0%> (-43.08%) ⬇️
lib/puppet/type/dsc.rb 50.98% <0%> (-40.25%) ⬇️
...b/puppet_x/puppetlabs/dsc_lite/dsc_type_helpers.rb 20.28% <0%> (-13.05%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 118e3be...38b34d4. Read the comment docs.

Copy link
Contributor

@DavidS DavidS left a comment

Choose a reason for hiding this comment

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

Love all the code removals. Two minor comments on improvements possible. Final call for @michaeltlombardi .

PS: also checked the coverage report and there is no significant change (better/worse) in the code touched, so 👍 from me.

.sync.yml Outdated
@@ -20,6 +20,9 @@ Gemfile:
- gem: beaker-testmode_switcher
version: "~> 0.4"
- gem: master_manipulator
optional:
':development':
- gem: 'ruby-pwsh'
Copy link
Contributor

Choose a reason for hiding this comment

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

no project should need the gem AND the module dependency. As a module I'd prefer the module dependency (and fixture). If that leads to issues, we need to fix them further upstream.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is only for the development purposes, not for the shipped project, but I'm happy to double check whether this is necessary!

Copy link
Contributor

Choose a reason for hiding this comment

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

Tested this tonight and the fixtures will help with pdk bundle exec puppet ... calls but not pdk test unit - it will blow up on the requires statement in the provider.

Copy link
Contributor

Choose a reason for hiding this comment

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

that is weiiiird. seems like something in the rspec-puppet chain is not setting up load paths correctly.

lib/puppet/provider/base_dsc_lite/powershell.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

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

Some minor changes and some handling we'll need to do either via monkey patching or creating our own method that leverages prior code and the formatter from the gem util.

@@ -1,8 +1,7 @@
require 'pathname'
require 'json'
if Puppet::Util::Platform.windows?
require_relative '../../../puppet_x/puppetlabs/dsc_lite/powershell_manager'
require_relative '../../../puppet_x/puppetlabs/dsc_lite/powershell_hash_formatter'
require 'ruby-pwsh'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, technically, we can include this without the guard, as loading the ruby-pwsh library won't blow up on non-Windows.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

lib/puppet/provider/base_dsc_lite/powershell.rb Outdated Show resolved Hide resolved
@@ -76,7 +74,7 @@ def exists?
script_content = ps_script_content('test')
Puppet.debug "\n" + self.class.redact_content(script_content)

if !PuppetX::DscLite::PowerShellManager.supported?
if !Pwsh::Manager.pwsh_supported?
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be windows_powershell_supported?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

lib/puppet/provider/base_dsc_lite/powershell.rb Outdated Show resolved Hide resolved
@@ -151,7 +149,7 @@ def self.format_dsc_value(dsc_value)
end

def self.format_dsc_lite(dsc_value)
PuppetX::PuppetLabs::DscLite::PowerShellHashFormatter.format(dsc_value)
Pwsh::Util.format_powershell_value(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.

🤔 this one we may have to do a bit of heavy lifting on as the DSC Lite module had to have additional formatting management for sensitive values and CIM objects.

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unlike practically all other powershell-dependent modules, invoking DSC requires that we handle some very special objects with particular types not matched in ruby, namely CIM instances.

We also need to write a specific handler for converting from a sensitive Puppet object to the appropriate PowerShell object representation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, have returned powershell_hash_formatter.rb, cleaned out everything in it that's mirrored in the gem and added in a call to said gem.
So it will check if it's a Hash or a Puppet::Pops::Types::PSensitiveType::Sensitive and apply the appropriate logic if it is. And if it isn't it will pass it on though to the gems format method.

format_array(dsc_value)
elsif dsc_value.class.name == 'Hash'
format_hash(dsc_value)
elsif dsc_value.class.name == 'Puppet::Pops::Types::PSensitiveType::Sensitive'
Copy link
Contributor

Choose a reason for hiding this comment

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

We may need to monkey patch this method to retain handling sensitive objects.

'@(' + value.map { |m| format(m) }.join(', ') + ')'
end

private_class_method def self.format_hash(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, we may need to borrow from this and format_cim_instance for hashes which are special DSC object types, like credentials or other CIM instances.

@david22swan david22swan closed this Dec 6, 2019
@david22swan david22swan reopened this Dec 6, 2019
This commit adds the pwshlib module / ruby-pwsh gem
as a dependency, updating the development gems list
in the Gemfile, the dependencies in the metadata,
and the fixtures list.

This will enable the module to depend on the updted
library code from the ruby-pwsh gem and pwshlib.
Copy link
Contributor

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

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

This looks good pending a passing adhoc run!

@michaeltlombardi
Copy link
Contributor

Is it just me or is the appveyor run not executing acceptance tests?

https://ci.appveyor.com/project/puppetlabs/puppetlabs-dsc-lite/builds/29365114

😶

David Swan added 3 commits December 9, 2019 09:23
Prior to this commit the PowerShell module providers
depended on a vendored version of the PowerShell code
manager library in the PuppetX namespace.

This commit updates the providers and their tests to
leverage the ruby-pwsh gem from the pwshlib Puppet
module instead. This reduces the amount of maintenance
required and simplifies the code base.
Small improvements to the code
@david22swan
Copy link
Member Author

@michaeltlombardi PDKSync had stripped the acceptance testing out. Have added back in

Specialist formatting code is needed for the module.
Copy link
Contributor

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants