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

(PDK-946) Passes ensure values to puppet as symbols. #74

Merged
merged 2 commits into from
May 4, 2018
Merged

(PDK-946) Passes ensure values to puppet as symbols. #74

merged 2 commits into from
May 4, 2018

Conversation

da-ar
Copy link

@da-ar da-ar commented May 2, 2018

Providers still deal with ensure values as strings, but puppet is always
passed symbols.

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.

  • Make use of TypeDefinition.ensurable? instead of duplicating the test across the change.
  • Move ensure validation to the initial validation block in L10-L12
  • symbolization happens in multiple places, but should be centralized into def should, and def value, see https://github.com/puppetlabs/puppet-resource_api/pull/62/files
  • Several minor comments

Style:

  • Do not end the commit message subject with punctuation

@@ -101,6 +104,12 @@ def type_definition
raise_missing_params if @missing_params.any?
end

define_method(:validate_ensure) do |options, type|
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this method is not accessing register_type-scoped information, it is cleaner to use a straight def here.

@@ -101,6 +104,12 @@ def type_definition
raise_missing_params if @missing_params.any?
end

define_method(:validate_ensure) do |options, type|
unless type.is_a?(Puppet::Pops::Types::PEnumType) && type.values == %w[absent present] && options[:type] == 'Enum[present, absent]'
Copy link
Contributor

Choose a reason for hiding this comment

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

Comparing the options[:type] string is brittle and redundant. e.g. "Enum[present,absent]" and "Enum[absent, present]" both would be valid ensure definitions, but fail the check.

@@ -101,6 +104,12 @@ def type_definition
raise_missing_params if @missing_params.any?
end

define_method(:validate_ensure) do |options, type|
unless type.is_a?(Puppet::Pops::Types::PEnumType) && type.values == %w[absent present] && options[:type] == 'Enum[present, absent]'
raise Puppet::ResourceError, '`:ensure` attribute must have a type of: `Enum[present, absent]`'
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a Puppet::DevError. It needs to be fixed by the developer before the type/provider is valid.

@@ -82,6 +82,9 @@ def type_definition
@missing_params = []
definition[:attributes].each do |name, options|
type = Puppet::Pops::Types::TypeParser.singleton.parse(options[:type])

validate_ensure(options, type) if name == :ensure
Copy link
Contributor

Choose a reason for hiding this comment

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

Please push this up the the global validations around #L10-L12

@@ -152,6 +161,9 @@ def type_definition
# work around https://tickets.puppetlabs.com/browse/PUP-2368
rs_value ? :true : :false # rubocop:disable Lint/BooleanSymbol
else
if options[:type] == 'Enum[present, absent]' && rs_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 special functionality only needs to happen for the ensure property. gating it on the name, instead of the type is much more robust (see comment about matching above)

@@ -269,6 +281,9 @@ def call_provider(value); end
result[:ensure] = 'absent' if definition[:attributes].key?(:ensure)
end

# puppet needs ensure to be a symbol
result[:ensure] = result[:ensure].to_sym if definition[:attributes].key?(:ensure)
Copy link
Contributor

Choose a reason for hiding this comment

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

The @should value for ensure is symbolized in https://github.com/puppetlabs/puppet-resource_api/pull/74/files#diff-33f447dabde26100aefa52fd359fe9b2R165 , no need to taint the values here.


# fall through to default handling
end

# 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.

debugging statement

when Puppet::Pops::Types::PEnumType, Puppet::Pops::Types::PStringType, Puppet::Pops::Types::PPatternType
when Puppet::Pops::Types::PEnumType
if name == :ensure
value = value.to_sym
Copy link
Contributor

Choose a reason for hiding this comment

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

The @should value for ensure is symbolized in https://github.com/puppetlabs/puppet-resource_api/pull/74/files#diff-33f447dabde26100aefa52fd359fe9b2R165 , no need to taint the values here.

@DavidS
Copy link
Contributor

DavidS commented May 3, 2018

Apologies for not pointing at https://github.com/puppetlabs/puppet-resource_api/pull/62/files earlier!

@DavidS
Copy link
Contributor

DavidS commented May 3, 2018

I've added some changes to avoid the mungify changes. Still needs some more cleanup to revert the name change to mungify, maybe others? too late today.

da-ar and others added 2 commits May 4, 2018 15:34
Providers still deal with ensure values as strings, but puppet is always
passed symbols.
@da-ar da-ar merged commit 75126d6 into puppetlabs:master May 4, 2018
@da-ar da-ar deleted the confused_messages branch May 8, 2018 10:56
@DavidS DavidS added the bug label May 8, 2018
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.

2 participants