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

Fix autorequire case sensitivity #14

Conversation

jeffmccune
Copy link
Contributor

Ready for review.

This change set changes the behavior of autorequire in the registry_key and
registry_value types to be case insensitive and preserving. Without these
changes we do not properly autorequire in the following manifest:

registry_key { 'HKLM\Software\Vendor\PUPPETLABS':
  ensure => present,
}
registry_value { 'HKLM\Software\Vendor\puppetlabs\ValueString':
  data => "Hello World!",
}


matching_resource_keys = catalog.resource_keys.collect do |rsrc_type, rsrc_id|
rsrc_id if (rsrc_type == desired_type) && (rsrc_id =~ /^#{parent_keypath.to_s}$/i)
end.compact
Copy link
Contributor

Choose a reason for hiding this comment

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

This concerns me as we're scanning all of the resource keys in the catalog for each component in the registry key path. Shouldn't we stop at the first match?

With that said, I think the whole issue could be resolved by simply downcasing the paths at munge time. We already save off the subkey (in its original case) and use that when create/open/destroying keys/values (so it will be case-preserving).

    munge do |path|
      Puppet::Modules::Registry::RegistryValuePath.new(path).canonical.downcase
    end

@jeffmccune
Copy link
Contributor Author

4eff6d8 appears to be working and satisfies the test case.

Still need to do a bit more clean up before this is ready to merge though.

@jeffmccune
Copy link
Contributor Author

@joshcooper OK, all spec tests passing, new specs added, acceptance tests added with pretty good coverage.

Ready for review.

Without this patch the behavior of a registry_value auto requiring
parent registry_key resources does not work when the parent resources do
not share the same letter case as the value.

For example, the value fails to require the key in this scenario:

    registry_key { 'HKLM\Software\Vendor\PUPPETLABS':
      ensure => present,
    }
    registry_value { 'HKLM\Software\Vendor\puppetlabs\ValueString':
      data => "Hello World!",
    }

The root cause of this problem is that Puppet treats all resource
identifier keys as case sensitive and the registry types ascend their
`path` attribute looking up resources using the string provided by the
user in the path parameter.

This patch fixes the problem by aliasing every registry_key and
registry_value resource using the downcase version of the path
attribute.  Other resources are expected to look up related resources in
the catalog using the downcase version of the path parameter.

This solves the problem because we now have an internally consistent,
case insensitive identifier.

We preserve case for the user by not munging the case of the path
parameter itself.  Instead we simply alias the downcase version in the
catalog.
joshcooper added a commit that referenced this pull request May 16, 2012
…orequire_case_sensitivity

Fix autorequire case sensitivity
@joshcooper joshcooper merged commit b059067 into puppetlabs:master May 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants