Skip to content

(CLOUD_1505) validate functions #99

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

Merged
merged 1 commit into from
Jan 10, 2018
Merged

(CLOUD_1505) validate functions #99

merged 1 commit into from
Jan 10, 2018

Conversation

sheenaajay
Copy link
Contributor

@sheenaajay sheenaajay commented Jan 4, 2018

Request to review the changes for replacing validate functions with datatypes and assert_type function.
Following jobs are running clean
bundle exec rake test
bundle exec rake spec
bundle exec rake acceptance

@@ -73,7 +73,7 @@
$local_user_strip = regsubst($local_user, '-', '', 'G')

$_pass_hash = $pass_hash ? {
Undef => pw_hash("${title}${auth_environment}${auth_cmd}${local_user}", 'SHA-512', $local_user_strip),
'Undef' => pw_hash("${title}${auth_environment}${auth_cmd}${local_user}", 'SHA-512', $local_user_strip),
Copy link
Contributor

Choose a reason for hiding this comment

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

@sheenaajay have you run this through travis without the qoutes? The PR to remove them was valid and needs to as is.

Copy link
Contributor

@davejrt davejrt left a comment

Choose a reason for hiding this comment

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

Can we look further into the quotes around undef and make sure it's not something with your local test environment?

if $icc != undef {
validate_bool($icc)
if $version {
assert_type(String[1], $version)

Choose a reason for hiding this comment

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

Not 100% sure, but I think you can put this check in the type declaration itself, like - Optional[String[1]] $version - Will save you the extra couple of lines of the assert type here :)

fail('This module only works on Debian or Red Hat based systems or on Archlinux as on Gentoo.')
}
}
assert_type(Boolean, $manage_kernel)

Choose a reason for hiding this comment

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

When you define the params at the top with the Data Type it's pretty much the same as doing an assert type on the param - If it comes through as anything other than the specified Data Type it'd fail further up at the param definition, so you can take all these assert types out!

validate_string($tls_cacert)
validate_string($tls_cert)
validate_string($tls_key)
assert_type(String[1], $tls_cacert)

Choose a reason for hiding this comment

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

Again, if it makes sense, I'd remove these assert types and add the string lower limit to the data type - Optional[String[1]] $tls_cacert

) {
include docker::params

validate_re($ensure, '^(present|absent)$')
assert_type(Pattern[/^present$|^absent$/], $ensure)

Choose a reason for hiding this comment

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

You can use Pattern[] as a data type! So you could remove this line and have the definition further up as -
Optional[Pattern[/^present$|^absent$/]] $ensure - https://puppet.com/docs/puppet/5.3/lang_data_abstract.html#pattern

manifests/run.pp Outdated
validate_re($memory_limit, '^[\d]*(b|k|m|g)$')
validate_re($ensure, '^(present|absent)')
if $image {
assert_type(Pattern[/^[\S]*$/], $image)

Choose a reason for hiding this comment

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

As above - I'd consider moving the params here to data type Pattern to be able to remove the assert_types here.

Copy link

@HelenCampbell HelenCampbell left a comment

Choose a reason for hiding this comment

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

There's a few little things you could clean up around your new data types and the assert_types, aside from that this is looking really good!

@sheenaajay
Copy link
Contributor Author

@davejrt Thanks alot Dave.Will check the local environment and reexecute the unit testcases.Travis jobs are running clean.

@sheenaajay
Copy link
Contributor Author

@HelenCampbell Thanks alot for the review.

@sheenaajay sheenaajay closed this Jan 10, 2018
@sheenaajay sheenaajay reopened this Jan 10, 2018
@sheenaajay
Copy link
Contributor Author

@davejrt @HelenCampbell Thanks for the reviews.All comments are incorporated.

Optional[Pattern[/^present$|^absent$/]] $ensure = 'present',
Optional[String] $version = $docker::params::compose_version,
Optional[String] $install_path = $docker::params::compose_install_path,
Optional[Pattern[/^(https?:\/\/)?([^:^@]+:[^:^@]+@|)([\da-z\.-]+)\.([\da-z\.]{2,6})(:[\d])?([\/\w \.-]*)*\/?$/]] $proxy = undef

Choose a reason for hiding this comment

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

I have to scroll to see what the parameter names are, maybe a custom type alias is a good idea here

Choose a reason for hiding this comment

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

Same comment for every large data 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.

@jeefberkey Thank you for the valuable comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeefberkey The large data types are not repeating alot to create a data type.So will specify the assert_type function for all large data types outside the variable declaration area so keep it short.

@davejrt
Copy link
Contributor

davejrt commented Jan 10, 2018

LGTM

@davejrt davejrt merged commit 10241bd into puppetlabs:master Jan 10, 2018
@davejrt davejrt mentioned this pull request Jan 10, 2018
@esalberg
Copy link
Contributor

esalberg commented Feb 5, 2018

We are having issues upgrading past this commit as well due to dm_use_deferred_deletion and dm_use_deferred_removal being set to String instead of Boolean. Perhaps it was set to String because the default was set to 'undef' (converted to false)? My concern is that while the String update breaks our config, I don't know if other installations might be affected the other way (although lint doesn't like a quoted true/false, so I'm assuming most probably used booleans by default).

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.

7 participants