summaryrefslogtreecommitdiffstats
path: root/test/units/module_utils
diff options
context:
space:
mode:
authorAnatoly Pugachev <matorola@gmail.com>2019-01-24 02:33:32 +0100
committerBrian Coca <bcoca@users.noreply.github.com>2019-01-24 02:33:32 +0100
commitfe8412128b843003d4e25d1976635708286f2e04 (patch)
tree6f65b0310edf7c651e44518d99433af6c017159b /test/units/module_utils
parentDoc fragments to plugins (#50172) (diff)
downloadansible-fe8412128b843003d4e25d1976635708286f2e04.tar.xz
ansible-fe8412128b843003d4e25d1976635708286f2e04.zip
facts: solaris: introduce distribution_major version detection for Solaris (#43978)
* facts: solaris: introduce distribution_major version detection for Solaris Currently, there's no distribution_major in facts module on Solaris OS. Use "uname -r" output to report major version. Before the patch we get this on Solaris 11.3 : $ ansible -o solaris11 -m setup -a filter=ansible_distribution_major_version solaris11 | SUCCESS => {"ansible_facts": {}, "changed": false} and after this patch, output is the following: $ ansible -o solaris11 -m setup -a filter=ansible_distribution_major_version solaris11 | SUCCESS => {"ansible_facts": {"ansible_distribution_major_version": "11"}, "changed": false} Tested with Solaris 11.3 and Solaris 10 (both are x86_64 VMs) Includes patch for test/units. Fixes #18197 * Try to fix test unit * should work now... * fixes for W291 (trailing whitespace) and E265 (block comment) * mock uname_release for solaris 10 and solaris 11 * facts: solaris: introduce distribution_major version detection for Solaris Currently, there's no distribution_major in facts module on Solaris OS. Use "uname -r" output to report major version. Before the patch we get this on Solaris 11.3 : $ ansible -o solaris11 -m setup -a filter=ansible_distribution_major_version solaris11 | SUCCESS => {"ansible_facts": {}, "changed": false} and after this patch, output is the following: $ ansible -o solaris11 -m setup -a filter=ansible_distribution_major_version solaris11 | SUCCESS => {"ansible_facts": {"ansible_distribution_major_version": "11"}, "changed": false} Tested with Solaris 11.3 and Solaris 10 (both are x86_64 VMs) Includes patch for test/units. Fixes #18197 * Try to fix test unit * should work now... * fixes for W291 (trailing whitespace) and E265 (block comment) * mock uname_release for solaris 10 and solaris 11 * typo uname_v -> uname_r * rebase * fix pep8 E302: 2 blank lines * remove int() cast to match test case * use single function for uname_r and uname_v * add solaris 11.4 OS to distribution test unit * fix pep8 sanity - E231 missing whitespace * distribution_major_version variable strip newline * mocker test function for mock_get_uname with parameters instead of two different functions * failed to make one fuction with test unit, revert to use 2 different functions * try to use single get_uname function * fix pep8: E703
Diffstat (limited to 'test/units/module_utils')
-rw-r--r--test/units/module_utils/test_distribution_version.py46
1 files changed, 41 insertions, 5 deletions
diff --git a/test/units/module_utils/test_distribution_version.py b/test/units/module_utils/test_distribution_version.py
index 025806d168..d88f7733dc 100644
--- a/test/units/module_utils/test_distribution_version.py
+++ b/test/units/module_utils/test_distribution_version.py
@@ -844,10 +844,12 @@ DISTRIB_DESCRIPTION="CoreOS 976.0.0 (Coeur Rouge)"
{
"name": "Solaris 10",
"uname_v": "Generic_141445-09",
+ "uname_r": "5.10",
"result": {
"distribution_release": "Solaris 10 10/09 s10x_u8wos_08a X86",
"distribution": "Solaris",
"os_family": "Solaris",
+ "distribution_major_version": "10",
"distribution_version": "10"
},
"platform.dist": [
@@ -865,10 +867,12 @@ DISTRIB_DESCRIPTION="CoreOS 976.0.0 (Coeur Rouge)"
{
"name": "Solaris 11",
"uname_v": "11.0",
+ "uname_r": "5.11",
"result": {
"distribution_release": "Oracle Solaris 11 11/11 X86",
"distribution": "Solaris",
"os_family": "Solaris",
+ "distribution_major_version": "11",
"distribution_version": "11"
},
"platform.dist": [
@@ -884,6 +888,7 @@ DISTRIB_DESCRIPTION="CoreOS 976.0.0 (Coeur Rouge)"
},
{
"name": "Solaris 11.3",
+ "uname_r": "5.11",
"platform.dist": [
"",
"",
@@ -891,8 +896,8 @@ DISTRIB_DESCRIPTION="CoreOS 976.0.0 (Coeur Rouge)"
],
"input": {
"/etc/release": (
- " Oracle Solaris 11.3 X86\n Copyright (c) 1983, 2015, Oracle and/or its affiliates. "
- "All rights reserved.\n Assembled 06 October 2015\n"
+ " Oracle Solaris 11.3 X86\n Copyright (c) 1983, 2018, Oracle and/or its affiliates. "
+ "All rights reserved.\n Assembled 09 May 2018\n"
)
},
"platform.system": "SunOS",
@@ -900,11 +905,36 @@ DISTRIB_DESCRIPTION="CoreOS 976.0.0 (Coeur Rouge)"
"distribution_release": "Oracle Solaris 11.3 X86",
"distribution": "Solaris",
"os_family": "Solaris",
+ "distribution_major_version": "11",
"distribution_version": "11.3"
}
},
{
+ "name": "Solaris 11.4",
+ "uname_r": "5.11",
+ "platform.dist": [
+ "",
+ "",
+ ""
+ ],
+ "input": {
+ "/etc/release": (
+ " Oracle Solaris 11.4 SPARC\n Copyright (c) 1983, 2018, Oracle and/or its affiliates."
+ " All rights reserved.\n Assembled 14 September 2018\n"
+ )
+ },
+ "platform.system": "SunOS",
+ "result": {
+ "distribution_release": "Oracle Solaris 11.4 SPARC",
+ "distribution": "Solaris",
+ "os_family": "Solaris",
+ "distribution_major_version": "11",
+ "distribution_version": "11.4"
+ }
+ },
+ {
"name": "Solaris 10",
+ "uname_r": "5.10",
"platform.dist": [
"",
"",
@@ -919,6 +949,7 @@ DISTRIB_DESCRIPTION="CoreOS 976.0.0 (Coeur Rouge)"
"distribution_release": "Oracle Solaris 10 1/13 s10x_u11wos_24a X86",
"distribution": "Solaris",
"os_family": "Solaris",
+ "distribution_major_version": "10",
"distribution_version": "10"
}
},
@@ -1109,8 +1140,13 @@ def test_distribution_version(am, mocker, testcase):
data = data.strip()
return data
- def mock_get_uname_version(am):
- return testcase.get('uname_v', None)
+ def mock_get_uname(am, flags):
+ if '-v' in flags:
+ return testcase.get('uname_v', None)
+ elif '-r' in flags:
+ return testcase.get('uname_r', None)
+ else:
+ return None
def mock_file_exists(fname, allow_empty=False):
if fname not in testcase['input']:
@@ -1152,7 +1188,7 @@ def test_distribution_version(am, mocker, testcase):
return False
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_version', mock_get_uname_version)
+ 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.distro.name', mock_distro_name)
mocker.patch('ansible.module_utils.distro.id', mock_distro_name)