distribution: Add support for DragonFly (#70748)
partially fixes #43739 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
1e0d83524c
commit
4f96f9826c
6 changed files with 81 additions and 4 deletions
2
changelogs/fragments/43739_dragonflybsd_disto.yml
Normal file
2
changelogs/fragments/43739_dragonflybsd_disto.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- distribution - add support for DragonFly distribution (https://github.com/ansible/ansible/issues/43739).
|
|
@ -12,9 +12,10 @@ This assumes a working ansible version in the path.
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os.path
|
||||
import subprocess
|
||||
import json
|
||||
import os.path
|
||||
import platform
|
||||
import subprocess
|
||||
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))
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue