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

Handle pkg_info(1) error message "Can't find" #6785

Conversation

sizeofvoid
Copy link
Contributor

SUMMARY

OpenBSD pkg_info(1) behavior change.

As we can see pkg_info behaves different between OpenBSD -current (>7.3) and OpenBSD <= 7.3.
It prints "Can't find inst:PKGNAME" if the package is not present. This has to be handled in the module otherwise we see

failed: [dev] (item=ranger) => {"ansible_loop_var": "item", "changed": false, "item": "ranger", "msg": "failed in get_package_state(): Can't find inst:ranger\n"}

Example pkg_info(1) call on OpenBSD 7.3 -stable

$ dmesg | head
OpenBSD 7.3 (RAMDISK_CD) #1063: Sat Mar 25 10:41:49 MDT 2023
    deraadt@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/RAMDISK_CD
$ pkg_info -Iq inst:abook
abook-0.6.1p3
triangle$ echo $?
0
$ pkg_info -Iq inst:NOTINSTALLED
$ echo $?
1

Example pkg_info(1) call on OpenBSD -current

$ dmesg | head
OpenBSD 7.3-current (GENERIC.MP) #1247: Sun Jun 18 09:42:58 MDT 2023
    deraadt@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
$ pkg_info -Iq inst:abook
abook-0.6.1p3
$ echo $?
0
$ pkg_info -Iq inst:NOTINSTALLED
Can't find inst:NOTINSTALLED
$ echo $?
1
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

openbsd_pkg

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) small_patch Hopefully easy to review labels Jun 26, 2023
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jun 26, 2023
@sizeofvoid sizeofvoid force-pushed the openbsd_pkg_pkg_info_handling branch from ace72aa to eb779ac Compare June 26, 2023 10:27
@ansibullbot

This comment was marked as outdated.

@sizeofvoid sizeofvoid force-pushed the openbsd_pkg_pkg_info_handling branch from eb779ac to 8ebe266 Compare June 26, 2023 10:46
@ansibullbot ansibullbot removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jun 26, 2023
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-6 labels Jun 26, 2023
Copy link
Collaborator

@felixfontein felixfontein 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 your contribution! Could you please add a changelog fragment? Thanks.

plugins/modules/openbsd_pkg.py Outdated Show resolved Hide resolved
@sizeofvoid sizeofvoid force-pushed the openbsd_pkg_pkg_info_handling branch 2 times, most recently from 1f92877 to 7ff7826 Compare June 27, 2023 05:37
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR and removed small_patch Hopefully easy to review labels Jun 27, 2023
@sizeofvoid sizeofvoid force-pushed the openbsd_pkg_pkg_info_handling branch from 7ff7826 to f0232e7 Compare June 27, 2023 05:46
@ansibullbot ansibullbot removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jun 27, 2023
@sizeofvoid sizeofvoid force-pushed the openbsd_pkg_pkg_info_handling branch from f0232e7 to 8286fd1 Compare June 27, 2023 06:05
@felixfontein
Copy link
Collaborator

Looks good to me, as far as I can tell. Will merge by the end of this week if nobody objects.

@sizeofvoid sizeofvoid force-pushed the openbsd_pkg_pkg_info_handling branch from 9e5df47 to 8286fd1 Compare June 27, 2023 06:32
@eest
Copy link
Contributor

eest commented Jun 27, 2023

Hello @sizeofvoid,

Thanks for a solid bug report and patch, this looks good to me :). The only thing I am thinking about is that in most cases in the module we use fairly strict regexes for matching output as in ^this is the complete output$ to not let future changes in output mistakenly pass the test where this ("Can't find inst:%s" % name) means it would also match I still Can't find inst:NOTINSTALLED what kind of case is this?.

Do you think it would be a good idea to go for a stricter regex match for this as well? I personally have preferred to be as strict as possible and have things fail rather than mistakenly work as things evolve, if that makes sense.

@sizeofvoid
Copy link
Contributor Author

Hello @sizeofvoid,

Do you think it would be a good idea to go for a stricter regex match for this as well? I personally have preferred to be as strict as possible and have things fail rather than mistakenly work as things evolve, if that makes sense.

Thanks @eest, I like the idea. I'll chance the current pull-request.

@sizeofvoid sizeofvoid force-pushed the openbsd_pkg_pkg_info_handling branch from 8286fd1 to d3c0cf8 Compare July 1, 2023 05:37
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jul 1, 2023
@sizeofvoid sizeofvoid force-pushed the openbsd_pkg_pkg_info_handling branch from d3c0cf8 to 0eef9c1 Compare July 1, 2023 05:54
@ansibullbot ansibullbot removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jul 1, 2023
@eest
Copy link
Contributor

eest commented Jul 1, 2023

This looks in line with what I had in mind, thanks! One more thing: since we are using the name variable as part of the regex we probably want to pass it through re.escape(). We have had problems in the past where package names include valid regex characters, see 56b5be0

Co-authored-by: Felix Fontein <felix@fontein.de>
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

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

LGTM

@eest
Copy link
Contributor

eest commented Jul 8, 2023

Thanks for your work on this @sizeofvoid! Also thanks to @felixfontein for the ever present support work for things like writing changelog fragments etc :)

LGTM

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Jul 8, 2023
@felixfontein felixfontein merged commit 704a301 into ansible-collections:main Jul 8, 2023
@patchback
Copy link

patchback bot commented Jul 8, 2023

Backport to stable-6: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-6/704a3019b74bafa9ebae6770bbf75e685a27a40d/pr-6785

Backported as #6892

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jul 8, 2023
* Handle pkg_info(1) error message "Can't find"

* Update plugins/modules/openbsd_pkg.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 704a301)
@patchback
Copy link

patchback bot commented Jul 8, 2023

Backport to stable-7: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-7/704a3019b74bafa9ebae6770bbf75e685a27a40d/pr-6785

Backported as #6893

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jul 8, 2023
* Handle pkg_info(1) error message "Can't find"

* Update plugins/modules/openbsd_pkg.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 704a301)
@felixfontein
Copy link
Collaborator

@sizeofvoid thanks for your contribution!
@eest thanks for reviewing and the kind words!
@russoz thanks for reviewing as well!

felixfontein pushed a commit that referenced this pull request Jul 8, 2023
…ge "Can't find" (#6892)

Handle pkg_info(1) error message "Can't find" (#6785)

* Handle pkg_info(1) error message "Can't find"

* Update plugins/modules/openbsd_pkg.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 704a301)

Co-authored-by: Rafael Sadowski <rafael@sizeofvoid.org>
felixfontein pushed a commit that referenced this pull request Jul 8, 2023
…ge "Can't find" (#6893)

Handle pkg_info(1) error message "Can't find" (#6785)

* Handle pkg_info(1) error message "Can't find"

* Update plugins/modules/openbsd_pkg.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 704a301)

Co-authored-by: Rafael Sadowski <rafael@sizeofvoid.org>
@sizeofvoid sizeofvoid deleted the openbsd_pkg_pkg_info_handling branch July 9, 2023 05:16
valeriopoggi pushed a commit to valeriopoggi/community.general that referenced this pull request Jul 17, 2023
* Handle pkg_info(1) error message "Can't find"

* Update plugins/modules/openbsd_pkg.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants