Refactor subscription-manager usage#107
Conversation
Before: when the input includes rpms, subscription-manager unregistration is done unconditionally in Run() while registration is done conditionally deeper in the call stack. This results in prefetch commands often logging "subscription-manager unregister command failed" in cases where registration was never done in the first place. Now: registration and unregistration happens in the same place, both only happen if registration should be done. The "unregistration failed" message is promoted to a warning, because it no longer occurs in expected scenarios. Signed-off-by: Adam Cmiel <acmiel@redhat.com>
Code Review by Qodo
1. Unneeded subman init fails
|
|
Manually tested the relevant scenarios with variations of: sudo env PATH=/home/acmiel/RedHat/Hermeto/hermeto/venv/bin:$PATH \
./konflux-build-cli prefetch-dependencies --input rpm --rhsm-activation-key activationkey.txt --rhsm-org org.txtPre-registration and unregistration still work as expected, stderr logging also works as expected |
Previously, when failing to read the RHSM activation key or org files, we would create a custom error with errors.New. This hides the root cause of the problem. Return the original ReadFile error instead, which already includes the file path and the reason why it couldn't be read. Signed-off-by: Adam Cmiel <acmiel@redhat.com>
There was a private captureLogOutput helper in two test packages already, and there will be a need for more. Extract it into the testutils package. Signed-off-by: Adam Cmiel <acmiel@redhat.com>
Previously, the prefetch command had private helpers for registering and unregistering with subscription-manager. They used CliExecutor directly instead of a dedicated subscription manager wrapper. This was not in line with how konflux-build-cli ususally does things, and made it impossible to mock subscription-manager in unit tests. In addition, the 'image build' command will also need to use subscription-manager in similar ways. Add a CLI wrapper for subscription-manager following the same pattern as other CLI wrappers. Assisted-by: Claude Signed-off-by: Adam Cmiel <acmiel@redhat.com>
0bc836d to
bfda7c0
Compare
|
Except for "Nil Register params panic", all of Qodo's concerns were valid (though two of them weren't problems introduced by these changes). Addressed the three relevant ones. With regards to "Nil Register params panic", it is technically true but it's a pattern used by all the CLI wrappers. |
Previously, we would completely hide the stderr when subscription-manager commands failed. Log the stderr to make debugging possible. Also return the underlying error from CliExecutor instead of making one with errors.New, for consistency with other CLI wrappers. Assisted-by: Claude Signed-off-by: Adam Cmiel <acmiel@redhat.com>
bfda7c0 to
ac466c3
Compare
See individual commits for more details. These are the changes necessary so that subscription-manager can also be used in other subcommands, not just prefetch. Plus a minor improvement to prefetch behavior.