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

BREAKING: Drop puppet 3 support. Replace validate_* functions with Puppet 4 data type validations #264

Merged
merged 2 commits into from
Feb 21, 2017

Conversation

jkroepke
Copy link
Contributor

@jkroepke jkroepke commented Feb 19, 2017

Added Puppet Data types for every parameter.

remove deprecated validate_* and is_* functions from stdlib.

Copy link
Contributor Author

@jkroepke jkroepke left a comment

Choose a reason for hiding this comment

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

There are some lint check results which does not make sense.

@@ -67,7 +67,9 @@
$file_path = $path
}

validate_absolute_path($file_path)
if $file_path !~ Stdlib::Compat::Absolute_path {
fail("archive::artifactory[${name}]: \$name or \$archive_path must be an absolute path!")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

manifests/artifactory.pp:71:trailing_comma:WARNING:missing trailing comma after last element

manifests/go.pp Outdated
@@ -26,7 +26,9 @@
$file_path = $path
}

validate_absolute_path($file_path)
if $file_path !~ Stdlib::Compat::Absolute_path {
fail("archive::go[${name}]: \$name or \$archive_path must be an absolute path!")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

manifests/go.pp:30:trailing_comma:WARNING:missing trailing comma after last element

@alexjfisher
Copy link
Member

When using Optional, do parameters still need to default to undef?

@jkroepke
Copy link
Contributor Author

Optional[X] is just an alias to Variant[Undef, X].

See: https://docs.puppet.com/puppet/4.9/lang_data_abstract.html#optional

So it's still request to set a default value unless you want to have required parameters.

We can discuss about non undef values for example cleanup should be true; https://github.com/voxpupuli/puppet-archive/blob/master/lib/puppet/type/archive.rb#L121 but it should be a own issue/pr.

@alexjfisher
Copy link
Member

@jkroepke Yeah, ok. I did a bit more digging. The reason this, (for example), works is that the ntp module also uses 'data in modules' and defaults the parameter to undef by using ~ in the yaml here.

@jkroepke
Copy link
Contributor Author

@alexjfisher correct. But the ntp module used the already deprecated hiera v4 as demo.

Data in modules is imho a task for the puppet 5 age.

@alexjfisher
Copy link
Member

@jkroepke Good work opening the puppet-lint issue. Meanwhile, (and so we can get this merged), how about using control-comments to disable the check? You can also include why you've disabled the check.

For the sake of your memory (and your coworkers), any text in your comment after lint:ignore: will be considered the reason for ignoring the check and will be displayed when showing ignored problems.

@jkroepke
Copy link
Contributor Author

@alexjfisher Done

@jkroepke
Copy link
Contributor Author

@alexjfisher I have no idea, how to use modern facts on the line like here:

Facter.stubs(:value).with(:osfamily).returns 'RedHat'

How to modify it to use facts[os][family] ?

@jkroepke
Copy link
Contributor Author

@alexjfisher Does it make sense to check failures like

 1) archive::nexus nexus archive with allow_insecure => 'foobar' should fail to compile and raise an error matching /"foobar" is not a boolean/
     Failure/Error: it { is_expected.to compile.and_raise_error(%r{"foobar" is not a boolean}) }
       error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Archive::Nexus[/tmp/artifact.war]: parameter 'allow_insecure' expects a Boolean value, got String at line 1 on node testing-docker-98956c12-9e09-4fc4-86af-1202defc7162.ec2.internal
     # ./spec/defines/nexus_spec.rb:150:in `block (3 levels) in <top (required)>'

If yes, I haven't the knowlage to adjust this test. Sorry.

@alexjfisher
Copy link
Member

@jkroepke That test does need to be fixed, but it should be pretty simple. "foobar" is not a boolean is the puppet error that the validate_bool function would have spat out. As such I think all you need to do is update the regular expression to match the new compilation error output. ie try replacing this line with...

it { is_expected.to compile.and_raise_error(%r{parameter 'allow_insecure' expects a Boolean value, got String}) }

@alexjfisher
Copy link
Member

@jkroepke That looks better. I don't understand why one of the combinations still failed. Very odd... Maybe something to do with the recently introduced parallel rspec??

@alexjfisher
Copy link
Member

and thanks for the rebase/squash!

@alexjfisher
Copy link
Member

@jkroepke Other than squashing, did you make any other changes? Tests are all green this time.

@jkroepke
Copy link
Contributor Author

jkroepke commented Feb 20, 2017

¯\_(ツ)_/¯

Now its fine.

@jkroepke
Copy link
Contributor Author

Other than squashing, did you make any other changes? Tests are all green this time.

No, just a squash.

Copy link
Member

@alexjfisher alexjfisher left a comment

Choose a reason for hiding this comment

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

LGTM. I've asked on IRC if anyone else would like to review too. IMO, changes to puppet-archive probably deserve a bit more scrutiny than most other modules.

@alexjfisher alexjfisher changed the title Puppet 4 validations Replace validate_* functions with Puppet 4 data type validations Feb 20, 2017
Copy link
Contributor

@igalic igalic 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 very good!
I would however consider reusing (and enriching) our Tea module

Optional[String] $extract_path = undef,
Optional[String] $creates = undef,
Optional[Boolean] $cleanup = undef,
Optional[Stdlib::Compat::Absolute_path] $archive_path = undef,
Copy link
Contributor

Choose a reason for hiding this comment

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

how about we use Tea::Absolutepath here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hum, why you want to add additional dependencies? The stdlib data types based on the tea types. Not?

Copy link

Choose a reason for hiding this comment

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

The ::compat:: types are specifically designed to match the horror that was the validate_ function that went before. There is Stdlib::Absolutepath to do better path checking.

Copy link
Contributor

Choose a reason for hiding this comment

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

so we should then, officially, deprecate Tea in favour for Stdlib… not that it was ever in widespread use to begin with…

i hope

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improve standards instead build a own world. That why i'm doing this PR. :)

@alexjfisher
Copy link
Member

I've reworded the PR title as it'll probably get used in the changelog when that's next updated.

Copy link
Member

@sacres sacres left a comment

Choose a reason for hiding this comment

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

Thanks for the hard work on this! I think we should specify puppetversion >= 4.6.1 rather than 4.4.0.

Copy link
Member

@sacres sacres left a comment

Choose a reason for hiding this comment

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

Thanks!

@bastelfreak bastelfreak merged commit dba7f0f into voxpupuli:master Feb 21, 2017
@jkroepke jkroepke deleted the puppet4 branch February 21, 2017 00:17
@alexjfisher alexjfisher changed the title Replace validate_* functions with Puppet 4 data type validations BREAKING: Drop puppet 3 support. Replace validate_* functions with Puppet 4 data type validations Aug 24, 2017
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.

6 participants