distribution: add distribution_minor_version for Debian Distro (#74721)

* Added a fact about minor version details for Debian Distro

Fixes: #74481

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/77821/head
Abhijeet Kasurde 3 years ago committed by GitHub
parent 6230244537
commit 524d30b8b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- distribution - add distribution_minor_version for Debian Distro (https://github.com/ansible/ansible/issues/74481).

@ -14,7 +14,7 @@ import ansible.module_utils.compat.typing as t
from ansible.module_utils.common.sys_info import get_distribution, get_distribution_version, \ from ansible.module_utils.common.sys_info import get_distribution, get_distribution_version, \
get_distribution_codename get_distribution_codename
from ansible.module_utils.facts.utils import get_file_content from ansible.module_utils.facts.utils import get_file_content, get_file_lines
from ansible.module_utils.facts.collector import BaseFactCollector from ansible.module_utils.facts.collector import BaseFactCollector
@ -334,6 +334,12 @@ class DistributionFiles:
rc, out, err = self.module.run_command(cmd) rc, out, err = self.module.run_command(cmd)
if rc == 0: if rc == 0:
debian_facts['distribution_release'] = out.strip() debian_facts['distribution_release'] = out.strip()
debian_version_path = '/etc/debian_version'
distdata = get_file_lines(debian_version_path)
for line in distdata:
m = re.search(r'(\d+)\.(\d+)', line.strip())
if m:
debian_facts['distribution_minor_version'] = m.groups()[1]
elif 'Ubuntu' in data: elif 'Ubuntu' in data:
debian_facts['distribution'] = 'Ubuntu' debian_facts['distribution'] = 'Ubuntu'
# nothing else to do, Ubuntu gets correct info from python functions # nothing else to do, Ubuntu gets correct info from python functions

@ -27,7 +27,8 @@
}, },
"input": { "input": {
"/etc/os-release": "PRETTY_NAME=\"Debian GNU/Linux 10 (buster)\"\nNAME=\"Debian GNU/Linux\"\nVERSION_ID=\"10\"\nVERSION=\"10 (buster)\"\nVERSION_CODENAME=buster\nID=debian\nHOME_URL=\"https://www.debian.org/\"\nSUPPORT_URL=\"https://www.debian.org/support\"\nBUG_REPORT_URL=\"https://bugs.debian.org/\"\n", "/etc/os-release": "PRETTY_NAME=\"Debian GNU/Linux 10 (buster)\"\nNAME=\"Debian GNU/Linux\"\nVERSION_ID=\"10\"\nVERSION=\"10 (buster)\"\nVERSION_CODENAME=buster\nID=debian\nHOME_URL=\"https://www.debian.org/\"\nSUPPORT_URL=\"https://www.debian.org/support\"\nBUG_REPORT_URL=\"https://bugs.debian.org/\"\n",
"/usr/lib/os-release": "PRETTY_NAME=\"Debian GNU/Linux 10 (buster)\"\nNAME=\"Debian GNU/Linux\"\nVERSION_ID=\"10\"\nVERSION=\"10 (buster)\"\nVERSION_CODENAME=buster\nID=debian\nHOME_URL=\"https://www.debian.org/\"\nSUPPORT_URL=\"https://www.debian.org/support\"\nBUG_REPORT_URL=\"https://bugs.debian.org/\"\n" "/usr/lib/os-release": "PRETTY_NAME=\"Debian GNU/Linux 10 (buster)\"\nNAME=\"Debian GNU/Linux\"\nVERSION_ID=\"10\"\nVERSION=\"10 (buster)\"\nVERSION_CODENAME=buster\nID=debian\nHOME_URL=\"https://www.debian.org/\"\nSUPPORT_URL=\"https://www.debian.org/support\"\nBUG_REPORT_URL=\"https://bugs.debian.org/\"\n",
"/etc/debian_version": "10.7\n"
}, },
"platform.dist": ["debian", "10", "buster"], "platform.dist": ["debian", "10", "buster"],
"result": { "result": {
@ -35,6 +36,7 @@
"distribution_version": "10", "distribution_version": "10",
"distribution_release": "buster", "distribution_release": "buster",
"distribution_major_version": "10", "distribution_major_version": "10",
"distribution_minor_version": "7",
"os_family": "Debian" "os_family": "Debian"
} }
} }

@ -50,6 +50,13 @@ def test_distribution_version(am, mocker, testcase):
data = data.strip() data = data.strip()
return data return data
def mock_get_file_lines(fname, strip=True):
"""give fake lines if file exists, otherwise return empty list"""
data = mock_get_file_content(fname=fname, strip=strip)
if data:
return [data]
return []
def mock_get_uname(am, flags): def mock_get_uname(am, flags):
if '-v' in flags: if '-v' in flags:
return testcase.get('uname_v', None) return testcase.get('uname_v', None)
@ -115,6 +122,7 @@ def test_distribution_version(am, mocker, testcase):
return ret return ret
mocker.patch('ansible.module_utils.facts.system.distribution.get_file_content', mock_get_file_content) mocker.patch('ansible.module_utils.facts.system.distribution.get_file_content', mock_get_file_content)
mocker.patch('ansible.module_utils.facts.system.distribution.get_file_lines', mock_get_file_lines)
mocker.patch('ansible.module_utils.facts.system.distribution.get_uname', mock_get_uname) mocker.patch('ansible.module_utils.facts.system.distribution.get_uname', mock_get_uname)
mocker.patch('ansible.module_utils.facts.system.distribution._file_exists', mock_file_exists) mocker.patch('ansible.module_utils.facts.system.distribution._file_exists', mock_file_exists)
mocker.patch('ansible.module_utils.distro.name', mock_distro_name) mocker.patch('ansible.module_utils.distro.name', mock_distro_name)

Loading…
Cancel
Save