Fix incorrect oscodename grain on Ubuntu

Use the full content of /etc/os-release for the Ubuntu 16.04 (artful)
os_grains test case. This reveals a bug that 'oscodename' is not
correctly calculated if /etc/os-release provides PRETTY_NAME:

FAIL: test_ubuntu_os_grains (tests.unit.grains.test_core.CoreGrainsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/unit/grains/test_core.py", line 439, in test_ubuntu_os_grains
    self._run_ubuntu_os_grains_tests(_os_release_map)
  File "tests/unit/grains/test_core.py", line 446, in _run_ubuntu_os_grains_tests
    self._run_os_grains_tests(os_release_map)
  File "tests/unit/grains/test_core.py", line 262, in _run_os_grains_tests
    self.assertEqual(os_grains.get('oscodename'), os_release_map['oscodename'])
AssertionError: 'Ubuntu 16.04.3 LTS' != 'xenial'
- Ubuntu 16.04.3 LTS
+ xenial

fixes #34423 for Ubuntu
Signed-off-by: Benjamin Drung <benjamin.drung@profitbricks.com>
This commit is contained in:
Benjamin Drung 2018-02-21 15:15:44 +01:00
parent 7e62dc9fd2
commit 77d5356aba
3 changed files with 17 additions and 10 deletions

View file

@ -1423,7 +1423,9 @@ def os_data():
grains['lsb_distrib_id'] = os_release['NAME'].strip()
if 'VERSION_ID' in os_release:
grains['lsb_distrib_release'] = os_release['VERSION_ID']
if 'PRETTY_NAME' in os_release:
if 'VERSION_CODENAME' in os_release:
grains['lsb_distrib_codename'] = os_release['VERSION_CODENAME']
elif 'PRETTY_NAME' in os_release:
codename = os_release['PRETTY_NAME']
# https://github.com/saltstack/salt/issues/44108
if os_release['ID'] == 'debian':

View file

@ -0,0 +1,12 @@
# Taken from base-files 9.4ubuntu4.5
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

View file

@ -407,17 +407,10 @@ PATCHLEVEL = 3
@skipIf(not salt.utils.is_linux(), 'System is not Linux')
def test_ubuntu_os_grains(self):
'''
Test if OS grains are parsed correctly in Ubuntu Xenial Xerus
Test if OS grains are parsed correctly in Ubuntu 16.04 "Xenial Xerus"
'''
_os_release_map = {
'linux_distribution': ('Ubuntu', '16.04', 'xenial'),
'os_release_file': {
'NAME': 'Ubuntu',
'VERSION': '16.04.1 LTS (Xenial Xerus)',
'VERSION_ID': '16.04',
'PRETTY_NAME': '',
'ID': 'ubuntu',
},
'os': 'Ubuntu',
'os_family': 'Debian',
'oscodename': 'xenial',
@ -427,7 +420,7 @@ PATCHLEVEL = 3
'osmajorrelease': 16,
'osfinger': 'Ubuntu-16.04',
}
self._run_os_grains_tests(None, _os_release_map)
self._run_os_grains_tests("ubuntu-16.04", _os_release_map)
def test_docker_virtual(self):
'''