mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Dist version fix for Red Hat and more tests (#15663)
* add tests for centos6, rhel6 and rhel7 * gen_distribution_version_testcase with python2.6 * remove unused imports * fix redhat/vmware/... parsing * add centos7 test case
This commit is contained in:
parent
6f4f8e6e79
commit
1d6608e84f
3 changed files with 156 additions and 80 deletions
|
@ -22,9 +22,6 @@ import sys
|
|||
|
||||
# to work around basic.py reading stdin
|
||||
import json
|
||||
from io import BytesIO, StringIO
|
||||
from ansible.compat.six import PY3
|
||||
from ansible.utils.unicode import to_bytes
|
||||
|
||||
from units.mock.procenv import swap_stdin_and_argv
|
||||
|
||||
|
@ -38,6 +35,82 @@ from ansible.compat.tests.mock import patch
|
|||
# to generate the testcase data, you can use the script gen_distribution_version_testcase.py in hacking/tests
|
||||
TESTSETS = [
|
||||
{
|
||||
"platform.dist": [
|
||||
"centos",
|
||||
"7.2.1511",
|
||||
"Core"
|
||||
],
|
||||
"input": {
|
||||
"/etc/redhat-release": "CentOS Linux release 7.2.1511 (Core) \n",
|
||||
"/etc/os-release": "NAME=\"CentOS Linux\"\nVERSION=\"7 (Core)\"\nID=\"centos\"\nID_LIKE=\"rhel fedora\"\nVERSION_ID=\"7\"\nPRETTY_NAME=\"CentOS Linux 7 (Core)\"\nANSI_COLOR=\"0;31\"\nCPE_NAME=\"cpe:/o:centos:centos:7\"\nHOME_URL=\"https://www.centos.org/\"\nBUG_REPORT_URL=\"https://bugs.centos.org/\"\n\nCENTOS_MANTISBT_PROJECT=\"CentOS-7\"\nCENTOS_MANTISBT_PROJECT_VERSION=\"7\"\nREDHAT_SUPPORT_PRODUCT=\"centos\"\nREDHAT_SUPPORT_PRODUCT_VERSION=\"7\"\n\n",
|
||||
"/etc/system-release": "CentOS Linux release 7.2.1511 (Core) \n"
|
||||
},
|
||||
"name": "CentOS 7.2.1511",
|
||||
"result": {
|
||||
"distribution_release": "Core",
|
||||
"distribution": "CentOS",
|
||||
"distribution_major_version": "7",
|
||||
"distribution_version": "7.2.1511"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "CentOS 6.7",
|
||||
"platform.dist": [
|
||||
"centos",
|
||||
"6.7",
|
||||
"Final"
|
||||
],
|
||||
"input": {
|
||||
"/etc/redhat-release": "CentOS release 6.7 (Final)\n",
|
||||
"/etc/lsb-release": "LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch\n",
|
||||
"/etc/system-release": "CentOS release 6.7 (Final)\n"
|
||||
},
|
||||
"result": {
|
||||
"distribution_release": "Final",
|
||||
"distribution": "CentOS",
|
||||
"distribution_major_version": "6",
|
||||
"distribution_version": "6.7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "RedHat 7.2",
|
||||
"platform.dist": [
|
||||
"redhat",
|
||||
"7.2",
|
||||
"Maipo"
|
||||
],
|
||||
"input": {
|
||||
"/etc/redhat-release": "Red Hat Enterprise Linux Server release 7.2 (Maipo)\n",
|
||||
"/etc/os-release": "NAME=\"Red Hat Enterprise Linux Server\"\nVERSION=\"7.2 (Maipo)\"\nID=\"rhel\"\nID_LIKE=\"fedora\"\nVERSION_ID=\"7.2\"\nPRETTY_NAME=\"Red Hat Enterprise Linux Server 7.2 (Maipo)\"\nANSI_COLOR=\"0;31\"\nCPE_NAME=\"cpe:/o:redhat:enterprise_linux:7.2:GA:server\"\nHOME_URL=\"https://www.redhat.com/\"\nBUG_REPORT_URL=\"https://bugzilla.redhat.com/\"\n\nREDHAT_BUGZILLA_PRODUCT=\"Red Hat Enterprise Linux 7\"\nREDHAT_BUGZILLA_PRODUCT_VERSION=7.2\nREDHAT_SUPPORT_PRODUCT=\"Red Hat Enterprise Linux\"\nREDHAT_SUPPORT_PRODUCT_VERSION=\"7.2\"\n",
|
||||
"/etc/system-release": "Red Hat Enterprise Linux Server release 7.2 (Maipo)\n"
|
||||
},
|
||||
"result": {
|
||||
"distribution_release": "Maipo",
|
||||
"distribution": "RedHat",
|
||||
"distribution_major_version": "7",
|
||||
"distribution_version": "7.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "RedHat 6.7",
|
||||
"platform.dist": [
|
||||
"redhat",
|
||||
"6.7",
|
||||
"Santiago"
|
||||
],
|
||||
"input": {
|
||||
"/etc/redhat-release": "Red Hat Enterprise Linux Server release 6.7 (Santiago)\n",
|
||||
"/etc/lsb-release": "LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch\n",
|
||||
"/etc/system-release": "Red Hat Enterprise Linux Server release 6.7 (Santiago)\n"
|
||||
},
|
||||
"result": {
|
||||
"distribution_release": "Santiago",
|
||||
"distribution": "RedHat",
|
||||
"distribution_major_version": "6",
|
||||
"distribution_version": "6.7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name" : "openSUSE Leap 42.1",
|
||||
"input": {
|
||||
"/etc/os-release":
|
||||
|
@ -339,7 +412,7 @@ def test_distribution_version():
|
|||
|
||||
def _test_one_distribution(facts, module, testcase):
|
||||
"""run the test on one distribution testcase
|
||||
|
||||
|
||||
* prepare some mock functions to get the testdata in
|
||||
* run Facts()
|
||||
* compare with the expected output
|
||||
|
@ -373,7 +446,7 @@ def _test_one_distribution(facts, module, testcase):
|
|||
@patch('platform.system', lambda: 'Linux')
|
||||
def get_facts(testcase):
|
||||
return facts.Facts(module).populate()
|
||||
|
||||
|
||||
generated_facts = get_facts(testcase)
|
||||
|
||||
# testcase['result'] has a list of variables and values it expects Facts() to set
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue