Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions salt/utils/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@
import importlib
import importlib.metadata

# Verify WinRM 0.3.0 or greater
# Verify WinRM 0.3.0 or greater. The PyPI distribution is "pywinrm"
# (imported as `winrm`); looking up "winrm" raises PackageNotFoundError
# (an ImportError subclass), leaving HAS_WINRM always False. See #69976.

version = importlib.metadata.version("winrm")
version = importlib.metadata.version("pywinrm")
if not salt.utils.versions.compare(version, ">=", WINRM_MIN_VER):
HAS_WINRM = False
else:
Expand Down
17 changes: 17 additions & 0 deletions tests/pytests/unit/utils/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,23 @@ def test_winrm_pinnned_version():
assert winrm_version >= "0.3.0"


def test_has_winrm_detection_uses_pywinrm_distribution():
"""
HAS_WINRM must be detected via the "pywinrm" distribution name (the PyPI
package), not "winrm". ``importlib.metadata.version("winrm")`` raises
``PackageNotFoundError`` (an ``ImportError`` subclass), which the surrounding
``except ImportError`` swallows, leaving ``HAS_WINRM`` always ``False`` and
breaking salt-cloud WinRM deployments. See #69976.
"""
import importlib.metadata

try:
importlib.metadata.version("pywinrm")
except importlib.metadata.PackageNotFoundError:
pytest.skip("pywinrm is not installed in this env.")
assert cloud.HAS_WINRM is True


def test_ssh_gateway_arguments_default_alive_args():
server_alive_interval = 60
server_alive_count_max = 3
Expand Down
Loading