Skip to content

Fix distro fact handling for Flatcar#77635

Merged
bcoca merged 2 commits intoansible:develfrom
johananl:fix-flatcar-distro
Sep 7, 2022
Merged

Fix distro fact handling for Flatcar#77635
bcoca merged 2 commits intoansible:develfrom
johananl:fix-flatcar-distro

Conversation

@johananl
Copy link
Copy Markdown
Contributor

SUMMARY

The existence of the file /etc/flatcar/update.conf depends on bootstrap configuration typically provided by the user. For that reason this file is unsuitable for determining distro facts for Flatcar Container Linux. This PR switches to /etc/os-release as the file used for extracting distro facts for Flatcar.

Fixes #77537.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

distribution.py

NOTE: I'm having hard time figuring out how to test this change. There is test/units/module_utils/facts/system/distribution/fixtures/flatcar_2492.0.0.json but I couldn't get reliable results by executing the test which uses this fixture. Any help regarding how to test this change would be appreciated!

@ansibot ansibot added affects_2.14 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 25, 2022
if not data:
return False, flatcar_facts

version = re.search("VERSION=(.*)", data)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could even rely more on distro and reuse _distro.version() that already provides the VERSION_ID field, or?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, however distro inside parse_distribution_file_Flatcar() is a string, not an instance of LinuxDistribution. The version() method on LinuxDistribution is actually already used inside get_distribution_version() which gets invoked from _guess_distribution() which in turns runs before we try processing the dist file. The dist file parsing functions are overriding any facts guessed previously, and AFAICT are supposed to be the authoritative source for distro-specific facts.

Therefore, I think it's safer to explicitly set the relevant facts inside parse_distribution_file_Flatcar() and rely on guessed facts only as a fallback.

@johananl johananl force-pushed the fix-flatcar-distro branch 4 times, most recently from f64753e to f874b57 Compare April 26, 2022 13:42
@johananl
Copy link
Copy Markdown
Contributor Author

NOTE: I'm having hard time figuring out how to test this change. There is test/units/module_utils/facts/system/distribution/fixtures/flatcar_2492.0.0.json but I couldn't get reliable results by executing the test which uses this fixture. Any help regarding how to test this change would be appreciated!

I've updated the existing test fixture. The test seems to pass, however I'm not totally sure about the distro key here and whether it is correct.

@sivel
Copy link
Copy Markdown
Member

sivel commented Apr 26, 2022

The test seems to pass, however I'm not totally sure about the distro key here and whether it is correct.

That fixture can be generated by running hacking/tests/gen_distribution_version_testcase.py

@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Apr 26, 2022
The existence of the file /etc/flatcar/update.conf depends on
bootstrap configuration typically provided by the user. For that
reason this file is unsuitable for determining distro facts for
Flatcar Container Linux.

The distribution_release fact is meaningless in the case of Flatcar
since Flatcar doesn't have named releases. The distribution_version
fact, however, IS meaningful and should contain a number such as
"3139.2.0".

- Use /etc/os-release instead of /etc/flatcar/update.conf.
- Drop the distribution_release fact.
- Set the distribution_version fact.

Signed-off-by: Johanan Liebermann <jliebermann@microsoft.com>
@johananl johananl force-pushed the fix-flatcar-distro branch from f874b57 to 91b3bfc Compare April 26, 2022 16:17
@johananl
Copy link
Copy Markdown
Contributor Author

johananl commented Apr 26, 2022

The test seems to pass, however I'm not totally sure about the distro key here and whether it is correct.

That fixture can be generated by running hacking/tests/gen_distribution_version_testcase.py

Thanks @sivel. The generated output has result.distribution and result.os_family set to Flatcar Container Linux by Kinvolk though, which isn't what we want (see #77537) 😕
Generating the fixture and then setting these two keys to Flatcar manually seems to work well though.

Following is the full generated fixture, for the record:

{
    "name": "Flatcar Container Linux by Kinvolk 3139.2.0",
    "distro": {
        "codename": "",
        "id": "flatcar",
        "name": "Flatcar Container Linux by Kinvolk",
        "version": "3139.2.0",
        "version_best": "3139.2.0",
        "lsb_release_info": {},
        "os_release_info": {
            "name": "Flatcar Container Linux by Kinvolk",
            "id": "flatcar",
            "id_like": "coreos",
            "version": "3139.2.0",
            "version_id": "3139.2.0",
            "build_id": "2022-04-05-1803",
            "pretty_name": "Flatcar Container Linux by Kinvolk 3139.2.0 (Oklo)",
            "ansi_color": "38;5;75",
            "home_url": "https://flatcar-linux.org/",
            "bug_report_url": "https://issues.flatcar-linux.org",
            "flatcar_board": "amd64-usr",
            "cpe_name": "cpe:2.3:o:flatcar-linux:flatcar_linux:3139.2.0:*:*:*:*:*:*:*"
        }
    },
    "input": {
        "/etc/os-release": "NAME=\"Flatcar Container Linux by Kinvolk\"\nID=flatcar\nID_LIKE=coreos\nVERSION=3139.2.0\nVERSION_ID=3139.2.0\nBUILD_ID=2022-04-05-1803\nPRETTY_NAME=\"Flatcar Container Linux by Kinvolk 3139.2.0 (Oklo)\"\nANSI_COLOR=\"38;5;75\"\nHOME_URL=\"https://flatcar-linux.org/\"\nBUG_REPORT_URL=\"https://issues.flatcar-linux.org\"\nFLATCAR_BOARD=\"amd64-usr\"\nCPE_NAME=\"cpe:2.3:o:flatcar-linux:flatcar_linux:3139.2.0:*:*:*:*:*:*:*\"\n",
        "/etc/lsb-release": "DISTRIB_ID=\"Flatcar Container Linux by Kinvolk\"\nDISTRIB_RELEASE=3139.2.0\nDISTRIB_CODENAME=\"Oklo\"\nDISTRIB_DESCRIPTION=\"Flatcar Container Linux by Kinvolk 3139.2.0 (Oklo)\"\n",
        "/usr/lib/os-release": "NAME=\"Flatcar Container Linux by Kinvolk\"\nID=flatcar\nID_LIKE=coreos\nVERSION=3139.2.0\nVERSION_ID=3139.2.0\nBUILD_ID=2022-04-05-1803\nPRETTY_NAME=\"Flatcar Container Linux by Kinvolk 3139.2.0 (Oklo)\"\nANSI_COLOR=\"38;5;75\"\nHOME_URL=\"https://flatcar-linux.org/\"\nBUG_REPORT_URL=\"https://issues.flatcar-linux.org\"\nFLATCAR_BOARD=\"amd64-usr\"\nCPE_NAME=\"cpe:2.3:o:flatcar-linux:flatcar_linux:3139.2.0:*:*:*:*:*:*:*\"\n"
    },
    "platform.dist": [
        "flatcar",
        "3139.2.0",
        ""
    ],
    "result": {
        "distribution": "Flatcar Container Linux by Kinvolk",
        "distribution_version": "3139.2.0",
        "distribution_release": "NA",
        "distribution_major_version": "3139",
        "os_family": "Flatcar Container Linux by Kinvolk"
    },
    "platform.release": "5.15.32-flatcar"
}

- Generate the fixture using gen_distribution_version_testcase.py.
- Override result.distribution and result.os_family manually as the
  generator script gives wrong values.
- Use a recent Flatcar version.

Signed-off-by: Johanan Liebermann <jliebermann@microsoft.com>
@johananl johananl force-pushed the fix-flatcar-distro branch from 91b3bfc to d461326 Compare April 27, 2022 12:02
@johananl
Copy link
Copy Markdown
Contributor Author

I've updated the fixture to be the output above, with the following manual overrides:

  • Set result.distribution to Flatcar.
  • Set result.os_family to Flatcar.

I hope that makes sense.

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 5, 2022
@s-hertel
Copy link
Copy Markdown
Contributor

s-hertel commented Sep 7, 2022

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Sep 7, 2022
@webknjaz
Copy link
Copy Markdown
Member

webknjaz commented Sep 7, 2022

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bcoca bcoca merged commit fbd8286 into ansible:devel Sep 7, 2022
@johananl johananl deleted the fix-flatcar-distro branch September 8, 2022 09:01
@ansible ansible locked and limited conversation to collaborators Sep 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

affects_2.14 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong OS family fact reported for Flatcar

7 participants