[stable-2.10] Handle Slackware OS version strings containing a plus (“+”) (#68142) (#70717)

A couple of years ago Slackware -current began using a plus (“+”) at the end of the distribution version string to indicate a future version work-in-progress.

Rearrange distribution_files unit tests to easily support more tests
  - add conftest with common fixtures
  - use parametrize for testing multiple scenarios

* Add changelog
* Add unit tests for Slackware distribution parsing
* Use correct fixtures for Slackware
Data comes from /etc/slackware-version

Co-authored-by: Sam Doran <sdoran@redhat.com>
Co-authored-by: <Eduard Rozenberg <eduardr@pobox.com>>
(cherry picked from commit 566c5e6ce1)

Co-authored-by: Eduard Rozenberg <2648417+edrozenberg@users.noreply.github.com>

Co-authored-by: Eduard Rozenberg <2648417+edrozenberg@users.noreply.github.com>
pull/70790/head
Sam Doran 4 years ago committed by GitHub
parent a7f4c6a37f
commit 9b8a649f2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- facts - account for Slackware OS with ``+`` in the name (https://github.com/ansible/ansible/issues/38760)

@ -211,7 +211,7 @@ class DistributionFiles:
if 'Slackware' not in data: if 'Slackware' not in data:
return False, slackware_facts # TODO: remove return False, slackware_facts # TODO: remove
slackware_facts['distribution'] = name slackware_facts['distribution'] = name
version = re.findall(r'\w+[.]\w+', data) version = re.findall(r'\w+[.]\w+\+?', data)
if version: if version:
slackware_facts['distribution_version'] = version[0] slackware_facts['distribution_version'] = version[0]
return True, slackware_facts return True, slackware_facts

@ -0,0 +1,10 @@
NAME="Clear Linux OS"
VERSION=1
ID=clear-linux-os
ID_LIKE=clear-linux-os
VERSION_ID=28120
PRETTY_NAME="Clear Linux OS"
ANSI_COLOR="1;35"
HOME_URL="https://clearlinux.org"
SUPPORT_URL="https://clearlinux.org"
BUG_REPORT_URL="mailto:dev@lists.clearlinux.org"',

@ -0,0 +1,10 @@
NAME="Container Linux by CoreOS"
ID=coreos
VERSION=1911.5.0
VERSION_ID=1911.5.0
BUILD_ID=2018-12-15-2317
PRETTY_NAME="Container Linux by CoreOS 1911.5.0 (Rhyolite)"
ANSI_COLOR="38;5;75"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://issues.coreos.com"
COREOS_BOARD="amd64-usr"

@ -0,0 +1,12 @@
NAME="Linux Mint"
VERSION="19.1 (Tessa)"
ID=linuxmint
ID_LIKE=ubuntu
PRETTY_NAME="Linux Mint 19.1"
VERSION_ID="19.1"
HOME_URL="https://www.linuxmint.com/"
SUPPORT_URL="https://forums.ubuntu.com/"
BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/"
PRIVACY_POLICY_URL="https://www.linuxmint.com/"
VERSION_CODENAME=tessa
UBUNTU_CODENAME=bionic

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import pytest
from units.compat.mock import Mock
@pytest.fixture
def mock_module():
mock_module = Mock()
mock_module.params = {'gather_subset': ['all'],
'gather_timeout': 5,
'filter': '*'}
mock_module.get_bin_path = Mock(return_value=None)
return mock_module

@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import pytest
from ansible.module_utils.facts.system.distribution import DistributionFiles
@pytest.fixture
def test_input():
return {
'name': 'Clearlinux',
'path': '/usr/lib/os-release',
'collected_facts': None,
}
def test_parse_distribution_file_clear_linux(mock_module, test_input):
test_input['data'] = open(os.path.join(os.path.dirname(__file__), '../../fixtures/distribution_files/ClearLinux')).read()
result = (
True,
{
'distribution': 'Clear Linux OS',
'distribution_major_version': '28120',
'distribution_release': 'clear-linux-os',
'distribution_version': '28120'
}
)
distribution = DistributionFiles(module=mock_module())
assert result == distribution.parse_distribution_file_ClearLinux(**test_input)
@pytest.mark.parametrize('distro_file', ('CoreOS', 'LinuxMint'))
def test_parse_distribution_file_clear_linux_no_match(mock_module, distro_file, test_input):
"""
Test against data from Linux Mint and CoreOS to ensure we do not get a reported
match from parse_distribution_file_ClearLinux()
"""
test_input['data'] = open(os.path.join(os.path.dirname(__file__), '../../fixtures/distribution_files', distro_file)).read()
result = (False, {})
distribution = DistributionFiles(module=mock_module())
assert result == distribution.parse_distribution_file_ClearLinux(**test_input)

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import pytest
from ansible.module_utils.facts.system.distribution import DistributionFiles
@pytest.mark.parametrize(
('distro_file', 'expected_version'),
(
('Slackware', '14.1'),
('SlackwareCurrent', '14.2+'),
)
)
def test_parse_distribution_file_slackware(mock_module, distro_file, expected_version):
test_input = {
'name': 'Slackware',
'data': open(os.path.join(os.path.dirname(__file__), '../../fixtures/distribution_files', distro_file)).read(),
'path': '/etc/os-release',
'collected_facts': None,
}
result = (
True,
{
'distribution': 'Slackware',
'distribution_version': expected_version
}
)
distribution = DistributionFiles(module=mock_module())
assert result == distribution.parse_distribution_file_Slackware(**test_input)
Loading…
Cancel
Save