Skip to content

Make ensure_packages work with ensure => present #1300

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
Apr 23, 2023

Conversation

alexjfisher
Copy link
Collaborator

This unbreaks the breaking change made in #1196

Also refactored to create a separate dispatch method for the case when packages is a Hash, and having that call the main ensure_packages method. This simplifies the code by only ever calling ensure_resource instead of calling ensure_resources for hashes.

Defaulting default_attributes to an empty hash instead of nil in the method signatures further simplifies the code.

Fixes #1252

@alexjfisher alexjfisher requested a review from a team as a code owner March 13, 2023 13:05
@puppet-community-rangefinder
Copy link

ensure_packages is a function

Breaking changes to this file MAY impact these 551 modules (near match):

This module is declared in 318 of 580 indexed public Puppetfiles.


These results were generated with Rangefinder, a tool that helps predict the downstream impact of breaking changes to elements used in Puppet modules. You can run this on the command line to get a full report.

Exact matches are those that we can positively identify via namespace and the declaring modules' metadata. Non-namespaced items, such as Puppet 3.x functions, will always be reported as near matches only.

tuxmea
tuxmea previously approved these changes Mar 13, 2023
@MindTooth
Copy link

I hate to bump stuff, but just got hit by this. And is somewhat starting to break stuff. 😭 Are we any closing in getting this merged and perhaps release a new patch version that includes it?

Again, sorry for the bump. 🥺

bastelfreak
bastelfreak previously approved these changes Apr 11, 2023
@binford2k
Copy link
Contributor

@Sharpie do you have thoughts on this?

private

def default_ensure(package_name)
if call_function('defined_with_params', "Package[#{package_name}]", { 'ensure' => 'present' })
Copy link
Collaborator

Choose a reason for hiding this comment

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

The root cause of many problems is that defined_with_params doesn't understand this bit: https://github.com/puppetlabs/puppet/blob/523d881ecdee777d7bec46cea5b26fd6621f558c/lib/puppet/type/package.rb#L113-L114

I was thinking about this too and wondering about teaching defined_with_params about aliasvalue. Though I really wonder how you'd implement that, given a lot of those mechanics are private APIs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, I did try and figure out a more generic solution, but also figured the less I touch, the less chance of subtly breaking anything!

This is effectively my 2nd PR on the way to fixing this issue. The first one was a while back and turned the function into a modern API version.

Whilst I'm not super happy with the hackiness of this solution, as a whole with the refactoring in this PR combined with the work done when moving from the old API I think the final result is still a lot nicer than what we originally had.

The breaking change in 8.0.0 has been a blocker for several people in upgrading stdlib, so hopefully this is a good enough fix and can be merged.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also ran into it myself, so I think this would be good start.

Copy link
Contributor

Choose a reason for hiding this comment

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

I drilled into this for a bit and got closer, but not completely there. I got stuck trying to figure out how to get a list of known aliases and couldn't get there in this context. What I'd like to do is update this check,

found_match = (res_is_undef && value_is_undef) || (res[key] == value)

to do something smarter, like res[key].aliases.include? value instead of the straight equality check it does now.

In other contexts, I can get a list of aliases using Puppet::Parameter::Value.aliases but I can't quite get there from here yet.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@binford2k that's exactly what my line of thought was, except I gave up on figuring out the .aliases bit. As I said: those parts look like private APIs.

@CLAassistant
Copy link

CLAassistant commented Apr 19, 2023

CLA assistant check
All committers have signed the CLA.

@alexjfisher alexjfisher dismissed stale reviews from bastelfreak and tuxmea via a30e8b1 April 20, 2023 11:17
@alexjfisher alexjfisher force-pushed the ensure_packages_improvements branch from cd6ec5f to a30e8b1 Compare April 20, 2023 11:17
b4ldr
b4ldr previously approved these changes Apr 20, 2023
@alexjfisher alexjfisher requested a review from bastelfreak April 20, 2023 12:58
@alexjfisher
Copy link
Collaborator Author

Rebased. Build failure doesn't look related.

bastelfreak
bastelfreak previously approved these changes Apr 20, 2023
@alexjfisher
Copy link
Collaborator Author

Test failures are because of the changes to fqdn_rand in Puppet 7.23.0. #1294 needs fixing up and merging. I'm happy with either approached discussed.

This unbreaks the breaking change made in puppetlabs#1196

Also refactored to create a separate dispatch method for the case when
`packages` is a `Hash`, and having that call the main `ensure_packages`
method. This simplifies the code by only ever calling `ensure_resource`
instead of calling `ensure_resources` for hashes.

Defaulting `default_attributes` to an empty hash instead of `nil` in the
method signatures further simplifies the code.

Fixes puppetlabs#1252
@alexjfisher alexjfisher dismissed stale reviews from bastelfreak and b4ldr via 837f988 April 21, 2023 17:13
@alexjfisher alexjfisher force-pushed the ensure_packages_improvements branch from a30e8b1 to 837f988 Compare April 21, 2023 17:13
@ekohl ekohl merged commit 441b6b3 into puppetlabs:main Apr 23, 2023
@alexjfisher alexjfisher deleted the ensure_packages_improvements branch April 24, 2023 08:17
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.

ensure_package existing resource detection