Repository: saltstack/salt
Pull request: [master] fix to version.py 
### What does this PR do?
Fix to show the correct system version when running test.versions on OS X Mojave.  Added tests.

### What issues does this PR fix or reference?
Fixes: #57467 

### Merge requirements satisfied?
**[NOTICE] Bug fixes or features added to Salt require tests.**
<!-- Please review the [test documentation](https://docs.saltstack.com/en/master/topics/tutorials/writing_tests.html) for details on how to implement tests into Salt's test suite. -->
- [ ] Docs
- [ ] Changelog - https://docs.saltstack.com/en/master/topics/development/changelog.html
- [ ] Tests written/updated

### Commits signed with GPG?
Yes

Please review [Salt's Contributing Guide](https://docs.saltstack.com/en/master/topics/development/contributing.html) for best practices.

See GitHub's [page on GPG signing](https://help.github.com/articles/signing-commits-using-gpg/) for more information about signing commits with GPG.


Problem statement:
[BUG] [RC1 Sodium] Mac report wrong system version in 3001 RC
**Description**
Running `test.versions` reports `version: Darwin 18.2.0 ` should be `version: 10.14.3 x86_64`
This is on a 10.14 (Mojave) machine but see the same on 10.13 (High sierra) also.

```
    System Versions:
               dist: darwin 18.2.0 
             locale: UTF-8
            machine: x86_64
            release: 18.2.0
             system: Darwin
            version: Darwin 18.2.0 
```
I was expecting version to show
```
            version: 10.14.3 x86_64
```
not
```
            version: Darwin 18.2.0 
```
I am on a 10.14.3 machine
```
Mac-2:~ jenkins$ sw_vers -productVersion
10.14.3
```


**Versions Report**

```
    Salt Version:
               Salt: 3001rc1
     
    Dependency Versions:
               cffi: 1.12.2
           cherrypy: 17.4.1
           dateutil: 2.8.0
          docker-py: Not Installed
              gitdb: 2.0.6
          gitpython: 2.1.15
             Jinja2: 2.10.1
            libgit2: Not Installed
           M2Crypto: Not Installed
               Mako: 1.0.7
       msgpack-pure: Not Installed
     msgpack-python: 0.5.6
       mysql-python: Not Installed
          pycparser: 2.19
           pycrypto: Not Installed
       pycryptodome: 3.9.7
             pygit2: Not Installed
             Python: 3.7.4 (default, May 26 2020, 11:48:02)
       python-gnupg: 0.4.4
             PyYAML: 5.1.2
              PyZMQ: 18.0.1
              smmap: 3.0.4
            timelib: 0.2.4
            Tornado: 4.5.3
                ZMQ: 4.3.1
     
    System Versions:
               dist: darwin 18.2.0 
             locale: UTF-8
            machine: x86_64
            release: 18.2.0
             system: Darwin
            version: Darwin 18.2.0 
```

Hints from issue discussion:

Commit message: Fix to show the correct system version when running test.verions on OS X Mojave.  Added tests.

Patch to review:
diff --git a/salt/version.py b/salt/version.py
index 721a1324039a..5b16346e8a4c 100644
--- a/salt/version.py
+++ b/salt/version.py
@@ -678,7 +678,11 @@ def system_version():
         mac_ver = platform.mac_ver()
         win_ver = platform.win32_ver()
 
-        if lin_ver[0]:
+        # linux_distribution() will return a
+        # distribution on OS X, only return if
+        # we are sure we are running on Linux
+        # and mac_ver is empty.
+        if lin_ver[0] and not mac_ver[0]:
             return " ".join(lin_ver)
         elif mac_ver[0]:
             if isinstance(mac_ver[1], (tuple, list)) and "".join(mac_ver[1]):
diff --git a/tests/integration/modules/test_test.py b/tests/integration/modules/test_test.py
index 3b575534cd78..1e0150e5f0d3 100644
--- a/tests/integration/modules/test_test.py
+++ b/tests/integration/modules/test_test.py
@@ -2,13 +2,19 @@
 
 from __future__ import absolute_import, print_function, unicode_literals
 
+import logging
+import platform
+
 import pytest
 import salt.config
 import salt.version
+from distro import linux_distribution
 from tests.support.case import ModuleCase
 from tests.support.helpers import slowTest
 from tests.support.mixins import AdaptedConfigurationTestCaseMixin
 
+log = logging.getLogger(__name__)
+
 
 @pytest.mark.windows_whitelisted
 class TestModuleTest(ModuleCase, AdaptedConfigurationTestCaseMixin):
@@ -83,3 +89,35 @@ def test_outputter(self):
         test.outputter
         """
         self.assertEqual(self.run_function("test.outputter", ["text"]), "text")
+
+    @slowTest
+    def test_versions_version(self):
+        """
+        test.versions
+        """
+
+        # copied from salt/version.py
+        def _system_version():
+            """
+            Return host system version.
+            """
+
+            lin_ver = linux_distribution()
+            mac_ver = platform.mac_ver()
+            win_ver = platform.win32_ver()
+
+            if lin_ver[0] and not mac_ver[0]:
+                return " ".join(lin_ver)
+            elif mac_ver[0]:
+                if isinstance(mac_ver[1], (tuple, list)) and "".join(mac_ver[1]):
+                    return " ".join([mac_ver[0], ".".join(mac_ver[1]), mac_ver[2]])
+                else:
+                    return " ".join([mac_ver[0], mac_ver[2]])
+            elif win_ver[0]:
+                return " ".join(win_ver)
+            else:
+                return ""
+
+        versions = self.run_function("test.versions")
+        version = "version: {0}".format(_system_version())
+        self.assertIn(version, versions)


Code review comments:
diff_hunk: @@ -83,3 +89,35 @@ def test_outputter(self):
         test.outputter
         """
         self.assertEqual(self.run_function("test.outputter", ["text"]), "text")
+
+    @slowTest
+    def test_versions_version(self):
+        """
+        test.versions
+        """
+
+        # copied from salt/version.py
path: tests/integration/modules/test_test.py
text: @user1:
Shouldn't we instead refactor salt/version.py so we can test it, mocking it if necessary?