diff options
author | Abhijeet Kasurde <akasurde@redhat.com> | 2020-07-21 23:17:11 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-21 13:47:11 -0400 |
commit | 4f96f9826c38e008112a45599a3550dc3cc98b07 (patch) | |
tree | 825b9efc71e2f0ba0c39f3f78f96174cb6bf8c14 | |
parent | 1e0d83524c09cac889b6e961a6db71773ae28003 (diff) | |
download | ansible-4f96f9826c38e008112a45599a3550dc3cc98b07.tar.gz |
distribution: Add support for DragonFly (#70748)
partially fixes #43739
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
6 files changed, 80 insertions, 3 deletions
diff --git a/changelogs/fragments/43739_dragonflybsd_disto.yml b/changelogs/fragments/43739_dragonflybsd_disto.yml new file mode 100644 index 0000000000..6cd9976c16 --- /dev/null +++ b/changelogs/fragments/43739_dragonflybsd_disto.yml @@ -0,0 +1,2 @@ +minor_changes: +- distribution - add support for DragonFly distribution (https://github.com/ansible/ansible/issues/43739). diff --git a/hacking/tests/gen_distribution_version_testcase.py b/hacking/tests/gen_distribution_version_testcase.py index 39c0a2fc2c..a1573bfc52 100755 --- a/hacking/tests/gen_distribution_version_testcase.py +++ b/hacking/tests/gen_distribution_version_testcase.py @@ -12,9 +12,10 @@ This assumes a working ansible version in the path. from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import json import os.path +import platform import subprocess -import json import sys from ansible.module_utils import distro @@ -91,4 +92,12 @@ output = { 'result': ansible_facts, } +system = platform.system() +if system != 'Linux': + output['platform.system'] = system + +release = platform.release() +if release: + output['platform.release'] = release + print(json.dumps(output, indent=4)) diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py index ab401b14dc..8ad69ec079 100644 --- a/lib/ansible/module_utils/facts/system/distribution.py +++ b/lib/ansible/module_utils/facts/system/distribution.py @@ -506,7 +506,8 @@ class Distribution(object): 'HP-UX': ['HPUX'], 'Darwin': ['MacOSX'], 'FreeBSD': ['FreeBSD', 'TrueOS'], - 'ClearLinux': ['Clear Linux OS', 'Clear Linux Mix']} + 'ClearLinux': ['Clear Linux OS', 'Clear Linux Mix'], + 'DragonFly': ['DragonflyBSD', 'DragonFlyBSD', 'Gentoo/DragonflyBSD', 'Gentoo/DragonFlyBSD']} OS_FAMILY = {} for family, names in OS_FAMILY_MAP.items(): @@ -604,7 +605,15 @@ class Distribution(object): return openbsd_facts def get_distribution_DragonFly(self): - return {} + dragonfly_facts = { + 'distribution_release': platform.release() + } + rc, out, dummy = self.module.run_command("/sbin/sysctl -n kern.version") + match = re.search(r'v(\d+)\.(\d+)\.(\d+)-(RELEASE|STABLE|CURRENT).*', out) + if match: + dragonfly_facts['distribution_major_version'] = match.group(1) + dragonfly_facts['distribution_version'] = '%s.%s.%s' % match.groups()[:3] + return dragonfly_facts def get_distribution_NetBSD(self): netbsd_facts = {} diff --git a/test/units/module_utils/facts/system/distribution/fixtures/dragonfly_5.2.2.json b/test/units/module_utils/facts/system/distribution/fixtures/dragonfly_5.2.2.json new file mode 100644 index 0000000000..5b99a48247 --- /dev/null +++ b/test/units/module_utils/facts/system/distribution/fixtures/dragonfly_5.2.2.json @@ -0,0 +1,25 @@ +{ + "name": "DragonFly v5.2.0-RELEASE #3", + "input": {}, + "platform.system": "DragonFly", + "platform.release": "5.2-RELEASE", + "command_output": { + "/sbin/sysctl -n kern.version": "DragonFly v5.2.0-RELEASE #1: Mon Apr 9 00:17:53 EDT 2018\nroot@www.shiningsilence.com:/usr/obj/home/justin/release/5_2/sys/X86_64_GENERIC" + }, + "distro": { + "codename": "", + "id": "dragonfly", + "name": "DragonFly", + "version": "5.2", + "version_best": "", + "os_release_info": {}, + "lsb_release_info": {} + }, + "result": { + "distribution": "DragonFly", + "distribution_major_version": "5", + "distribution_release": "5.2-RELEASE", + "os_family": "DragonFly", + "distribution_version": "5.2.0" + } +}
\ No newline at end of file diff --git a/test/units/module_utils/facts/system/distribution/fixtures/dragonfly_5.6.2.json b/test/units/module_utils/facts/system/distribution/fixtures/dragonfly_5.6.2.json new file mode 100644 index 0000000000..90ec6201aa --- /dev/null +++ b/test/units/module_utils/facts/system/distribution/fixtures/dragonfly_5.6.2.json @@ -0,0 +1,25 @@ +{ + "name": "DragonFly v5.6.2-RELEASE #3", + "input": {}, + "platform.system": "DragonFly", + "platform.release": "5.6-RELEASE", + "command_output": { + "/sbin/sysctl -n kern.version": "DragonFly v5.6.2-RELEASE #3: Sat Aug 10 10:28:36 EDT 2019\nroot@www.shiningsilence.com:/usr/obj/home/justin/release/5_6/sys/X86_64_GENERIC" + }, + "distro": { + "codename": "", + "id": "dragonfly", + "name": "DragonFly", + "version": "5.2", + "version_best": "", + "os_release_info": {}, + "lsb_release_info": {} + }, + "result": { + "distribution": "DragonFly", + "distribution_major_version": "5", + "distribution_release": "5.6-RELEASE", + "os_family": "DragonFly", + "distribution_version": "5.6.2" + } +}
\ No newline at end of file diff --git a/test/units/module_utils/facts/system/distribution/test_distribution_version.py b/test/units/module_utils/facts/system/distribution/test_distribution_version.py index 091ec8ad3c..161ca728f6 100644 --- a/test/units/module_utils/facts/system/distribution/test_distribution_version.py +++ b/test/units/module_utils/facts/system/distribution/test_distribution_version.py @@ -108,6 +108,12 @@ def test_distribution_version(am, mocker, testcase): return True return False + def mock_run_command_output(v, command): + ret = (0, '', '') + if 'command_output' in testcase: + ret = (0, testcase['command_output'].get(command, ''), '') + 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_uname', mock_get_uname) mocker.patch('ansible.module_utils.facts.system.distribution._file_exists', mock_file_exists) @@ -125,6 +131,7 @@ def test_distribution_version(am, mocker, testcase): mocker.patch('platform.system', mock_platform_system) mocker.patch('platform.release', mock_platform_release) mocker.patch('platform.version', mock_platform_version) + mocker.patch('ansible.module_utils.basic.AnsibleModule.run_command', mock_run_command_output) real_open = builtins.open mocker.patch.object(builtins, 'open', new=mock_open) |