Skip to content

(MODULES-1723) Update Registry module for Puppet 4 / Ruby 2.1.5 / Unicode #72

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

Iristyle
Copy link
Contributor

No description provided.

@Iristyle Iristyle force-pushed the ticket/master/MODULES-1723-ruby-2-compatibility branch 7 times, most recently from 7e2e40f to 6406285 Compare February 19, 2015 19:53
@Iristyle Iristyle changed the title (DO NOT MERGE) (MODULES-1723) Update Registry module for Puppet 4 / Ruby 2.1.5 / UTF-8 (DO NOT MERGE) (MODULES-1723) Update Registry module for Puppet 4 / Ruby 2.1.5 / Unicode Feb 19, 2015
@Iristyle
Copy link
Contributor Author

A bit more work to do on this one, but if you want to take a first pass @ferventcoder

@ferventcoder
Copy link
Contributor

Will take a look tomorrow when I'm back "in the office." :)

@Iristyle
Copy link
Contributor Author

@cyberious feel free to take an early peek as well if you have a minute

end

beaker_version = ENV['BEAKER_VERSION'] || '~> 2.2'
group :acceptance do
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use :system_tests as this is a pattern that the modules team has already adopted. https://github.com/puppetlabs/puppetlabs-concat/blob/master/Gemfile#L25

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@cyberious
Copy link
Contributor

@Iristyle yeah we have standardized on :system_tests as a group. We actually have this specified in our modulesync script defaults. https://github.com/puppetlabs/modulesync_configs/blob/master/config_defaults.yml

@Iristyle Iristyle force-pushed the ticket/master/MODULES-1723-ruby-2-compatibility branch from 6406285 to eb42c1b Compare February 24, 2015 00:37
@cyberious
Copy link
Contributor

Tests are now passing.

@Iristyle Iristyle force-pushed the ticket/master/MODULES-1723-ruby-2-compatibility branch from eb42c1b to 1df77dd Compare February 24, 2015 01:16
@cyberious
Copy link
Contributor

Rakefile needed updating to get the spec running see #74

@@ -49,6 +51,8 @@ def values
# Only try and get the values for this key if the key itself exists.
if exists? then
hive.open(subkey, Win32::Registry::KEY_READ | access) do |reg|
# TODO: tests for this since each_value triggers LOCALE conversion on Ruby 2.1.5
# require 'pry'; binding.pry
Copy link
Contributor

Choose a reason for hiding this comment

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

This must be part of the WIP.

Copy link
Contributor

Choose a reason for hiding this comment

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

Leaving a note here so you don't forget to remove these lines.

@Iristyle Iristyle force-pushed the ticket/master/MODULES-1723-ruby-2-compatibility branch 2 times, most recently from b3bd0d2 to b1ebc86 Compare March 10, 2015 06:18
@Iristyle
Copy link
Contributor Author

@ferventcoder / @joshcooper might want to take a gander at this... Now that I've flushed out tests, I'm pulling in a lot more code from Puppet than I originally planned on (reg_enum_value in particular drags in a lot of additional stuff).

I'm thinking now that it might be better to just write some small helpers that call in to Puppet on 4+ / Ruby 2.1.5 or preserve existing behavior by using Win32::Registry for backward compatibility (assuming new tests pass on 1.9.3 / 2.0.0)

# https://github.com/ruby/ruby/blob/v2_1_5/ext/win32/lib/win32/registry.rb#L323-L329
# therefore, use our own code instead of hklm.delete_value

# TODO: don't like registry_value tests depending on registry_key type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we have 3 choices here:

  • Go a little heavier weight / include ref to a separate class and use the registry_key provider
  • Use the Win32 API directly (or from the provider base class)
  • Use Win32::Registry to call delete, which we know fails on Ruby 2.1.5

I went with option 1 for now, but I'm leaning toward reimplementing as option 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For 9db94e2, this is the only easy way of doing this. In a subsequent commit this could be rewritten to use the methods on ProviderBase instead, but not sure that's worth it.

@Iristyle Iristyle force-pushed the ticket/master/MODULES-1723-ruby-2-compatibility branch 4 times, most recently from aa9108f to b3821f9 Compare March 10, 2015 23:56
end
else
# TODO: expectations around never calling this are not working
require 'pry'; binding.pry
Copy link
Contributor

Choose a reason for hiding this comment

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

So what you are saying is, do not merge? ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Need to remove binding.pry

Copy link
Contributor

Choose a reason for hiding this comment

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

yup.

@ferventcoder
Copy link
Contributor

  • Ruby 2.1.5-x64 /4.x - good
  • Ruby 1.9.3 / 3.7.3 - flaky - I'm going to dive in a bit

def from_string_to_wide_string(str, &block)
self.class.from_string_to_wide_string(str, &block)
end

Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming this was reintroduced for compatibility with older puppet versions :)

@ferventcoder
Copy link
Contributor

So this technically looks okay, the TODOs should be cleaned up - and the Puppet 3.7.3 / Ruby 1.9.3 combination is failing on this for me:

  1) Puppet::Type::Registry_key::ProviderRegistry#purge_values does not use Rubys each_value, which unnecessarily string encodes
     Failure/Error: reg_key.provider.destroy
     RuntimeError:
       Failed to delete registry key: Registry_key[hklm\SOFTWARE\Puppet Labs\PuppetRegProviderTest\Unicode-1fbfbba7-5ec3-4dfc-a48f-5cf2b91e23ac](provider=registry)
     # ./lib/puppet/provider/registry_key/registry.rb:45:in `block in destroy'
     # ./lib/puppet_x/puppetlabs/registry/provider_base.rb:61:in `block in from_string_to_wide_string'
     # ./lib/puppet_x/puppetlabs/registry/provider_base.rb:58:in `initialize'
     # ./lib/puppet_x/puppetlabs/registry/provider_base.rb:58:in `new'
     # ./lib/puppet_x/puppetlabs/registry/provider_base.rb:58:in `from_string_to_wide_string'
     # ./lib/puppet_x/puppetlabs/registry/provider_base.rb:139:in `from_string_to_wide_string'
     # ./lib/puppet/provider/registry_key/registry.rb:42:in `destroy'
     # ./spec/unit/puppet/provider/registry_key_spec.rb:70:in `block (3 levels) in <top (required)>'

It's not a fluke - it's not deleting the registry key that it creates. It based in the after block when it is trying ti clean up. Well it could be a fluke. As an easy fix...

@ferventcoder
Copy link
Contributor

I think something may be broken and the custom type is not using 64bit keys automatically anymore - normally a 32: prefix should be required to get to the 32 bit keys, but I don't see that in the test.

From https://github.com/puppetlabs/puppetlabs-registry/#custom-type-registry_key:
"If Puppet is running on a 64-bit system, the 32-bit registry key can be explicitly managed using a prefix. For example: '32:HKLM\Software'."

@ferventcoder
Copy link
Contributor

Actually after researching, I think that there is a test now actually surfaced a pre-existing bug. After looking back through the changes several times I don't see anything that would have introduced a regression.

@Iristyle Iristyle force-pushed the ticket/master/MODULES-1723-ruby-2-compatibility branch from db1d2de to 0e5eaa7 Compare March 25, 2015 15:30
@cyberious
Copy link
Contributor

Can't run through jenkins right now, please rebase from master as it has a fix in Rakefile when beaker is not loaded.

@ferventcoder
Copy link
Contributor

@cyberious This is still ticketed as do not merge so we are good.

 - Beaker 2.4 will actually be required to test AIO packages
 - Without Beaker in isolation, there is no way to actually install
   the bundle for this module on Windows, since Beaker contains gems
   with native extensions that don't compile on Ruby 2.1.5 and Windows
   (unf_ext in particular).

   With this change, we can now install the gems to be used for
   local integration testing with:

   bundle install --path .bundle/gems --without=system_tests
@Iristyle Iristyle force-pushed the ticket/master/MODULES-1723-ruby-2-compatibility branch from 0e5eaa7 to 38a8c47 Compare March 25, 2015 17:06
@Iristyle Iristyle changed the title (DO NOT MERGE) (MODULES-1723) Update Registry module for Puppet 4 / Ruby 2.1.5 / Unicode (MODULES-1723) Update Registry module for Puppet 4 / Ruby 2.1.5 / Unicode Mar 25, 2015
@Iristyle
Copy link
Contributor Author

Ok @ferventcoder / @cyberious - final validation - run this through CI and I think we're good to merge.

@Iristyle Iristyle force-pushed the ticket/master/MODULES-1723-ruby-2-compatibility branch from 76d2626 to 14f4d58 Compare March 25, 2015 17:20
Iristyle and others added 4 commits March 25, 2015 13:56
 - New tests to demonstrate Ruby 2.1.5 failures for:

   - Win32::Registry#delete_value which always fails based on passing
     wide character UTF-16LE strings to an ANSI Api (used in the
     registry_value provider destroy method)
     Ruby bug filed at https://bugs.ruby-lang.org/issues/10820

   - Win32::Registry#each_key enumeration which initiates unnecessary
     locale conversion (used in registry_key provider .values method)

 - Note that these tests were crafted specifically to introduce failures
   of Ruby 2.1.5 code, and do not introduce failures when run against
   Ruby 2.0.0.  The non-ASCII test is guarded to only run in Ruby 2.1
   as it doesn't affect Ruby 2.0 or Ruby 2.2 and can write corrupt data
   to the registry under Ruby 1.9.3 due to Ruby using Windows ANSI APIs.

 - Ensure that when creating registry keys with Ruby to specify
   KEY_WOW64_64KEY to control the location of the key.  When using the
   module provider code, this is the default specified for deletion.
   When these don't match, the key delete attempt may fail based on
   bitness of the Ruby process.
 - Ensure that under Ruby 2.1.x that problematic method calls to
   Win32::Registry are not made.  This was made in a separate commit
   because unfortunately Mocha's any_instance will actually hide other
   errors (which are visible in the prior commit).

   Once code has been changed to alter code paths under other Ruby
   versions, the guarding will be changed accordingly.
 - Switch to using RegQueryValueExW and RegDeleteKeyExW instead of their
   ANSI counterparts
 - Since Ruby 2.1.5 is broken with respec to calling delete_key and
   delete_value, add our own code for RegDeleteValueW to be used.
   Ensure that all deletions of registry keys go through the API rather
   than Ruby.
 - Implement a helper method for converting Ruby strings to UTF-16LE
   strings and for creating an unmanaged LCPWSTR pointer for use in FFI
   calls given a Ruby string.  This code appears in Puppet itself, but
   for compatibility reasons, the Registry module cannot rely on the
   Puppet version that defines it.
 - Implement an each_value inside of the provider base code that either
   uses Rubys Win32::Registry#each_value in Ruby 2.0 and lower, or uses
   the Puppet 4 implementation if available.  This provides existing
   behavior for older versions of Puppet / Ruby which don't have LOCALE
   conversion issues, and the correct behavior for Puppet 4.  This was
   implemented this way to avoid dragging in a lot of duplicated FFI
   code from Puppet 4 introduced via:

   puppetlabs/puppet@b46ede7
 - Previously, the purge_values tests were only for Ruby 2.1, where we
   know that there are issues in Win32::Registry.
 - Add tests that demonstrate that other versions of Ruby / Puppet work
   as well.
@Iristyle Iristyle force-pushed the ticket/master/MODULES-1723-ruby-2-compatibility branch from 14f4d58 to 868e77e Compare March 25, 2015 20:59
@ferventcoder
Copy link
Contributor

I'm plus 1 to merge. Now if Travis CI will give a green light

@Iristyle
Copy link
Contributor Author

Travis Y U So Slow?

@ferventcoder
Copy link
Contributor

...

@ferventcoder
Copy link
Contributor

Its like the energizer bunny in reverse

cyberious added a commit that referenced this pull request Mar 25, 2015
…2-compatibility

(MODULES-1723) Update Registry module for Puppet 4 / Ruby 2.1.5 / Unicode
@cyberious cyberious merged commit d85701f into puppetlabs:master Mar 25, 2015
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.

4 participants