Puppet 4.10.x version comparisons


Dominic Cleal <dominic@...>
 

Hello,

It looks like there will be a new Puppet 4.10.x release series soon,
which I think is going to cause a few issues in tests for modules and in
supporting projects, due to reaching minor version 10.

In quite a few projects there are constructs such as:

if Puppet.version.to_f >= 4.4

which will return false when `Puppet.version` is "4.10.0" (since
"4.10.0".to_f is 4.1, not four-point-ten).

These are mostly in tests, where specs might be constrained to
particular versions or expect different slightly results depending on
the version of Puppet. It's also possible that functions, types, or
providers occasionally have version constraints. Manifests are likely
safe as they should use the versioncmp() function, so this probably only
really affects module tests.

A safer way of comparing versions from Ruby is to use versioncmp too:

if Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0

Comparisons against 4.0, 3.x etc, or using `.to_i` are going to be
unaffected. It will only affect comparisons against later 4.x version
numbers.

I've opened a PR against rspec-puppet
(https://github.com/rodjek/rspec-puppet/pull/479) to fix some internal
checks and its own specs, and puppetlabs_spec_helper looks to be fine.

stdlib is an example of a module that has a lot of tests with affected
version comparisons:
https://github.com/puppetlabs/puppetlabs-stdlib/blob/db8c1fbb2394d93fe3156b17c840455f1b3e2c76/spec/functions/deprecation_spec.rb#L3

I'll continue trying to open PRs where I can find issues, but would
appreciate help to check modules to ensure it works on release.

Cheers,

--
Dominic Cleal
dominic@...


David Schmitt
 

Hi Dominic,

thanks for raising this issue early!

We'll be tracking this for our supported modules here: https://tickets.puppetlabs.com/browse/MODULES-4528


Cheers, David

On 14 March 2017 at 10:05, Dominic Cleal <dominic@...> wrote:
Hello,

It looks like there will be a new Puppet 4.10.x release series soon,
which I think is going to cause a few issues in tests for modules and in
supporting projects, due to reaching minor version 10.

In quite a few projects there are constructs such as:

  if Puppet.version.to_f >= 4.4

which will return false when `Puppet.version` is "4.10.0" (since
"4.10.0".to_f is 4.1, not four-point-ten).

These are mostly in tests, where specs might be constrained to
particular versions or expect different slightly results depending on
the version of Puppet. It's also possible that functions, types, or
providers occasionally have version constraints. Manifests are likely
safe as they should use the versioncmp() function, so this probably only
really affects module tests.

A safer way of comparing versions from Ruby is to use versioncmp too:

  if Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0

Comparisons against 4.0, 3.x etc, or using `.to_i` are going to be
unaffected. It will only affect comparisons against later 4.x version
numbers.

I've opened a PR against rspec-puppet
(https://github.com/rodjek/rspec-puppet/pull/479) to fix some internal
checks and its own specs, and puppetlabs_spec_helper looks to be fine.

stdlib is an example of a module that has a lot of tests with affected
version comparisons:
https://github.com/puppetlabs/puppetlabs-stdlib/blob/db8c1fbb2394d93fe3156b17c840455f1b3e2c76/spec/functions/deprecation_spec.rb#L3

I'll continue trying to open PRs where I can find issues, but would
appreciate help to check modules to ensure it works on release.

Cheers,

--
Dominic Cleal
dominic@...