From 4d8e89204beb56af9a9a47b3eb4b88edf25aead7 Mon Sep 17 00:00:00 2001
From: Benjamin Drung <benjamin.drung@cloud.ionos.com>
Date: Thu, 30 Jan 2020 18:21:08 +0100
Subject: Support distro.linux_distribution

Salt fails on Python 3.8:

```
======================================================================
ERROR: unit.grains.test_core (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: unit.grains.test_core
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "tests/unit/grains/test_core.py", line 37, in <module>
    import salt.grains.core as core
  File "salt/grains/core.py", line 40, in <module>
    from platform import _supported_dists
ImportError: cannot import name '_supported_dists' from 'platform' (/usr/lib/python3.8/platform.py)
```

So only try to import `_supported_dists` from `platform` for Python <=
3.7. Otherwise rely on the external `distro` module to  not need any
special handling.

Addresses parts of #55835
Forwarded: https://github.com/saltstack/salt/pull/56031
Signed-off-by: Benjamin Drung <benjamin.drung@cloud.ionos.com>
---
 salt/grains/core.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/salt/grains/core.py b/salt/grains/core.py
index 9b244def9c..0b5f3ae9a8 100644
--- a/salt/grains/core.py
+++ b/salt/grains/core.py
@@ -35,20 +35,20 @@ except ImportError:
 __proxyenabled__ = ['*']
 __FQDN__ = None
 
-# Extend the default list of supported distros. This will be used for the
-# /etc/DISTRO-release checking that is part of linux_distribution()
-from platform import _supported_dists
-_supported_dists += ('arch', 'mageia', 'meego', 'vmware', 'bluewhite64',
-                     'slamd64', 'ovs', 'system', 'mint', 'oracle', 'void')
-
 # linux_distribution deprecated in py3.7
 try:
     from platform import linux_distribution as _deprecated_linux_distribution
 
+    # Extend the default list of supported distros. This will be used for the
+    # /etc/DISTRO-release checking that is part of linux_distribution()
+    from platform import _supported_dists
+    _supported_dists += ('arch', 'mageia', 'meego', 'vmware', 'bluewhite64',
+                         'slamd64', 'ovs', 'system', 'mint', 'oracle', 'void')
+
     def linux_distribution(**kwargs):
         with warnings.catch_warnings():
             warnings.simplefilter("ignore")
-            return _deprecated_linux_distribution(**kwargs)
+            return _deprecated_linux_distribution(supported_dists=_supported_dists, **kwargs)
 except ImportError:
     from distro import linux_distribution
 
@@ -1939,7 +1939,7 @@ def os_data():
         )
         (osname, osrelease, oscodename) = \
             [x.strip('"').strip("'") for x in
-             linux_distribution(supported_dists=_supported_dists)]
+             linux_distribution()]
         # Try to assign these three names based on the lsb info, they tend to
         # be more accurate than what python gets from /etc/DISTRO-release.
         # It's worth noting that Ubuntu has patched their Python distribution
-- 
2.20.1

