Patching a single function in a salt execution module

16 views
Skip to first unread message

Emond Papegaaij

unread,
May 2, 2022, 10:06:37 AM5/2/22
to Salt-users
Hi all,

During a migration from CentOS 7 to AlmaLinux 8, we are running into an issue with a bug in dnf on CentOS 7. The migration tool (leapp) requires dnf to be installed, but the dnf version on CentOS 7 has a bug in check-update. It incorrectly reports version locked packages. This clearly is a bug in dnf and fixed in a more recent version, which is not avaiable on CentOS 7. Salt is our only option of working around this issue.

I've followed the steps in this great guide: https://salt.tips/patching-salt-modules/ and copied the entire yumpkg.py to have pkg.list_upgrades exclude the packages returned from list_holds. This works like a charm, but I'd rather not copy a file of 3.5k lines of code to only change 2 lines in a single function. The author of the guide mentions it is possible to patch only a single function, but did not have the time to write a guide for this. So my question is: is this doable and how is it done?

Best regards,
Emond Papegaaij

Max Arnold

unread,
May 2, 2022, 11:36:25 AM5/2/22
to salt-...@googlegroups.com
Hey!

Did you try the self-patching method? https://salt.tips/patching-salt-modules/#self-patching  You can create a patch that only modifies those 2 lines and apply it using Salt itself.
Applying patches this way is much more succinct than overriding a single function. With that being said, here is an example of how to do the latter: https://github.com/saltstack/salt-jenkins/blob/develop/_modules/win_pkg.py#L36-L42


пн, 2 мая 2022 г. в 21:06, Emond Papegaaij <pape...@topicus.education>:
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/8967c40b-867a-46a3-8a71-a6fab3d0177en%40googlegroups.com.

Emond Papegaaij

unread,
May 2, 2022, 2:52:30 PM5/2/22
to Salt-users
Hi,

Thanks for the pointer. So if I understand it correctly, the code creates a new module and copies all functions from the old one to the new one, except for the function you want to change.

I've thought the self-patching solution, but replacing a function in the execution module gives me a bit more control on the life cycle of the patch. It keeps the patch and the original code completely separate. This also reduces the risk that the patch gets overwritten when, for example, salt is upgraded. I hope to only have this patch installed for a single release of our product.

Best regards,
Emond

Op maandag 2 mei 2022 om 17:36:25 UTC+2 schreef arnold...@gmail.com:
Reply all
Reply to author
Forward
0 new messages