Correct pywinrm distribution name in HAS_WINRM detection (salt-cloud WinRM) - #69982
Open
fudianchn wants to merge 1 commit into
Open
Correct pywinrm distribution name in HAS_WINRM detection (salt-cloud WinRM)#69982fudianchn wants to merge 1 commit into
fudianchn wants to merge 1 commit into
Conversation
salt.utils.cloud looked up the distribution name "winrm" with
importlib.metadata.version(), but the PyPI package is distributed as
"pywinrm" (imported as `winrm`). version("winrm") raises
PackageNotFoundError, which the surrounding `except ImportError` swallows,
so HAS_WINRM is always False and salt-cloud WinRM deployments fail with
"WinRM requested but module winrm could not be imported" even when pywinrm
is installed (>= 0.3.0).
Use the correct "pywinrm" distribution name. The existing
test_winrm_pinnned_version already queries version("pywinrm").
Closes saltstack#69976
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
salt-cloudWindows deployments withuse_winrm: truealways fail witheven when
pywinrm(>= 0.3.0) is installed (#69976).Root cause is in the
HAS_WINRMdetection block ofsalt/utils/cloud.py:The PyPI package is distributed as
pywinrm(imported aswinrm).importlib.metadata.version("winrm")raisesPackageNotFoundError, which is a subclass ofImportError, so the surroundingexcept ImportError:swallows it andHAS_WINRMis leftFalseunconditionally.Fix
Use the correct distribution name:
Notably the existing
test_winrm_pinnned_versionalready queriesversion("pywinrm"), so the test suite was using the right name while the source wasn't.Verification
Reproduced the detection logic directly (Python 3.12,
pywinrm0.5.0 installed):Added a regression test (
test_has_winrm_detection_uses_pywinrm_distribution) that assertssalt.utils.cloud.HAS_WINRMisTruewhenpywinrmis installed (skips otherwise) — it fails with the old"winrm"lookup and passes after the fix.Closes #69976