voxpupuli / puppet-windowsfeature

Library that uses ServerAdministration api that comes with Windows Server 2008 and Windows Server 2012 to add / remove windows features
https://forge.puppet.com/puppet/windowsfeature
MIT License
30 stars 50 forks source link

Changed PS convert from JSON to CSV for older PS compatibility. Closes #57. #58

Closed matthewrstone closed 8 years ago

matthewrstone commented 8 years ago

Closes #57

petems commented 8 years ago

@matthewrstone Awesome! I guess this is the fix for #57? You mind updating the specs, just need to change the stub and the json fixtures to CSVs, then Travis will green-ify

matthewrstone commented 8 years ago

@petems Yeah, sorry, lost the comment for 57 in the second squash.

I'm getting lost on the tests...The fixture being replaced is a JSON array. This new code should get a CSV from powershell and parse that to a Ruby array of features, so wouldn't I want the fixture to be that final ruby array instead of the CSV? Or do I write the expectation that powershell is returning the CSV and do the parsing in the test?

petems commented 8 years ago

The second, the idea is you mock out anything that Ruby can't run in a vacuum, so you replace the CSV returned from the powershell command in the fixture, then you're testing that the Ruby code written does what it's supposed to 👍

petems commented 8 years ago

There's a few RuboCop linting things, you can prob fix most with rubocop -a 👍

matthewrstone commented 8 years ago

unrelated question - has anyone ever burned an effigy of rubocop?

petems commented 8 years ago

🤖 👮 🔥

matthewrstone commented 8 years ago

Anything else needed on this one?

petems commented 8 years ago

I think this is good, I'm not sure I have an old enough 2008 box to test this on, is it possible to force an older install?

matthewrstone commented 8 years ago

I did some work to switch this over from CSV to XML and it's testing clean over here but some of the tests through Travis are bombing out trying to download gems...

https://travis-ci.org/voxpupuli/puppet-windowsfeature/jobs/153470757

Harumpf.

bbriggs commented 8 years ago

hooray!

james-powis commented 7 years ago

@matthewrstone I am still not seeing 2008r2 support being functional after this change

PS C:\Program Files\Puppet Labs\Puppet\sys\ruby\bin> puppet resource windowsfeature --debug --verbose --trace
Debug: Runtime environment: puppet_version=4.5.2, ruby_version=2.1.8, run_mode=user, default_encoding=IBM437
Debug: Facter: searching for custom fact "kernel".
Debug: Facter: searching for kernel.rb in C:/ProgramData\PuppetLabs\puppet\cache\lib\facter.
Debug: Facter: searching for kernel.rb in C:/ProgramData\PuppetLabs\puppet\cache\lib\facter.
Debug: Facter: fact "facterversion" has resolved to "3.2.0".
Debug: Facter: initializing WMI
Debug: Facter: searching "C:\ProgramData\PuppetLabs\facter\facts.d" for external facts.
Debug: Facter: no external facts were found.
Debug: Facter: setting fact "env_windows_installdir" based on the value of environment variable "FACTER_env_windows_inst
alldir".
Debug: Facter: fact "env_windows_installdir" has resolved to "C:\Program Files\Puppet Labs\Puppet".
Debug: Facter: resolving kernel facts.
Debug: Facter: fact "kernel" has resolved to "windows".
Debug: Facter: fact "kernelrelease" has resolved to "6.1.7601".
Debug: Facter: fact "kernelmajversion" has resolved to "6.1".
Debug: Facter: fact "kernelversion" has resolved to "6.1.7601".
Debug: Facter: searching for custom fact "kernelmajversion".
Debug: Facter: searching for kernelmajversion.rb in C:/ProgramData\PuppetLabs\puppet\cache\lib\facter.
Debug: Facter: searching for kernelmajversion.rb in C:/ProgramData\PuppetLabs\puppet\cache\lib\facter.
Debug: Executing: 'C:\Windows\system32\WindowsPowershell\v1.0\powershell.exe Import-Module ServerManager; Get-WindowsFea
ture | ConvertTo-XML -As String -Depth 4 -NoTypeInformation'
Error: Could not run: malformed XML: missing tag start
Line: 4808
Position: 199234
Last 80 unconsumed characters:
< /Property>     <Property Name="Depth">3</Property>     <Property Name="DependsO
C:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/parsers/baseparser.rb:374:in `pull_event'
C:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/parsers/baseparser.rb:184:in `pull'
C:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/parsers/treeparser.rb:22:in `parse'
C:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/document.rb:287:in `build'
C:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/2.1.0/rexml/document.rb:44:in `initialize'
C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/windowsfeature/default.rb:32:in `new'
C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/windowsfeature/default.rb:32:in `instances'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/type.rb:1168:in `block in instances'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/type.rb:1161:in `collect'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/type.rb:1161:in `instances'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/indirector/resource/ral.rb:24:in `search'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/indirector/indirection.rb:269:in `search'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application/resource.rb:221:in `find_or_save_resources'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application/resource.rb:136:in `main'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application.rb:352:in `run_command'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application.rb:344:in `block in run'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util.rb:540:in `exit_on_fail'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/application.rb:344:in `run'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util/command_line.rb:128:in `run'
C:/Program Files/Puppet Labs/Puppet/puppet/lib/puppet/util/command_line.rb:72:in `execute'
C:/Program Files/Puppet Labs/Puppet/puppet/bin/puppet:5:in `<main>'

I have tossed some debug code in and tested, the xml returned from dropping to powershell but rexml keeps throwing errors... At this point I am losing my mind so any advice would be much appreciated.

cpeirens commented 7 years ago

If all you care about is the Name and Installed values, then change the powershell calls to the following. There's no need for depth more than 2, and the errors you're seeing are caused by other elements (path, I think, that may be too long, I dunno). Either way, only pull back what you want.

result = if win2008 == true
           ps('Import-Module ServerManager; Get-WindowsFeature | Select-Object -Property Name, Installed | ConvertTo-XML -As String -Depth 2 -NoTypeInformation')
         else
           ps('Get-WindowsFeature | Select-Object -Property Name, Installed | ConvertTo-XML -As String -Depth 2 -NoTypeInformation')
         end