Skip to content

ENT-8118: Added os_version_minor sys variable #5777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

victormlg
Copy link
Contributor

No description provided.

Copy link

Marking this PR as stale due to inactivity; it will be closed in 7 days.

@github-actions github-actions bot added the stale Pull requests with no recent activity label May 26, 2025
Copy link
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

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

Looks good 🚀 Would be nice if you could add an acceptance test. You can use os_version_major.cf as inspiration.

@github-actions github-actions bot removed the stale Pull requests with no recent activity label May 27, 2025
@victormlg victormlg force-pushed the os_version_minor branch 2 times, most recently from b01c5ad to 77e6a40 Compare June 10, 2025 14:40
@victormlg victormlg requested a review from larsewi June 10, 2025 15:06
@larsewi larsewi requested a review from jakub-nt June 11, 2025 07:16
Copy link
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

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

I think you will have to derive os_version_minor from somewhere else on Windows. We don't want it to be "Unknown" on supported platforms.

@victormlg
Copy link
Contributor Author

@cf-bottom jenkins, please

@cf-bottom
Copy link

@larsewi
Copy link
Contributor

larsewi commented Jun 24, 2025

Build for Windows (no tests)
Build Status
Packages here

@olehermanse olehermanse requested a review from larsewi June 24, 2025 13:50
@victormlg
Copy link
Contributor Author

I tested sys.os_version_minor on a win-2019-dev-v8 ami and got the following:

image

It looks like it is working. It's difficult to make sense of a "os version minor" on this type of machine. Here is the version of the OS that I got by running winver

image

@victormlg victormlg requested a review from olehermanse June 24, 2025 14:29
@olehermanse
Copy link
Member

That's okay, I guess. From your screenshot I would kind of expect the minor version to be 1809.

Copy link
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

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

Great work @victormlg 🚀 Only some smaller comments. Not sure what to do about Windows. Maybe $(sys.os_version_minor) -> Unknown is okey?

@olehermanse olehermanse requested a review from larsewi June 26, 2025 17:01
Copy link
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

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

Looks good 🚀 The fixes to the C code should be amended to the first commit though

@larsewi
Copy link
Contributor

larsewi commented Jun 27, 2025

@cf-bottom Jenkins with exotics please :)

@cf-bottom
Copy link

Copy link
Contributor

@larsewi larsewi left a comment

Choose a reason for hiding this comment

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

Acceptance test failed on redhat 7

FAIL (UNEXPECTED FAILURE) ./01_vars/01_basic/os_version_minor.cf

See log below

R: Version number extracted from class: centos_7_9
R: Defined classes: centos
R: Defined classes: feature_tls_1_0
R: Defined classes: GMT_Min31
R: Defined classes: ipv4_192_168
R: Defined classes: feature_copyfrom_restrict_keys
R: Defined classes: Lcycle_0
R: Defined classes: GMT_Yr2025
R: Defined classes: feature_def
R: Defined classes: Hr08_Q3
R: Defined classes: cfengine_3_27
R: Defined classes: feature_yaml
R: Defined classes: ipv4_192_168_121
R: Defined classes: June
R: Defined classes: error_mode
R: Defined classes: x86_64
R: Defined classes: warning_mode
R: Defined classes: net_iface_lo
R: Defined classes: GMT_Lcycle_0
R: Defined classes: ipv4_127_0
R: Defined classes: cfengine_3
R: Defined classes: GMT_Morning
R: Defined classes: feature_def_json_preparse
R: Defined classes: GMT_Friday
R: Defined classes: feature_host_specific_data_load
R: Defined classes: feature_host
R: Defined classes: GMT_Hr08
R: Defined classes: linux
R: Defined classes: 1_cpusocket
R: Defined classes: centos_7_x64_j2
R: Defined classes: GMT_Min30_35
R: Defined classes: redhat
R: Defined classes: DEBUG
R: Defined classes: systemd
R: Defined classes: GMT_June
R: Defined classes: compiled_on_linux_gnu
R: Defined classes: feature_host_specific_data
R: Defined classes: feature
R: Defined classes: cfengine
R: Defined classes: mac_52_54_00_0c_ef_5c
R: Defined classes: cfengine_3_27_0a_f77177768
R: Defined classes: 64_bit
R: Defined classes: linux_3_10_0_1127_el7_x86_64
R: Defined classes: notice_mode
R: Defined classes: feature_curl
R: Defined classes: feature_tls_1_3
R: Defined classes: linux_x86_64_3_10_0_1127_el7_x86_64__1_SMP_Tue_Mar_31_23_36_51_UTC_2020
R: Defined classes: feature_tls_1
R: Defined classes: agent
R: Defined classes: GMT_Day27
R: Defined classes: ipv4_192_168_121_34
R: Defined classes: 127_0_0_1
R: Defined classes: Friday
R: Defined classes: any
R: Defined classes: feature_copyfrom
R: Defined classes: feature_copyfrom_restrict
R: Defined classes: ipv4_gw_192_168_121_1
R: Defined classes: centos_7_9
R: Defined classes: centos_7
R: Defined classes: linux_x86_64_3_10_0_1127_el7_x86_64
R: Defined classes: ipv4_127_0_0_1
R: Defined classes: cfengine_3_27_0a
R: Defined classes: GMT_Hr8
R: Defined classes: net_iface_eth0
R: Defined classes: ipv4_192
R: Defined classes: feature_xml
R: Defined classes: 1_cpu
R: Defined classes: Day27
R: Defined classes: inform_mode
R: Defined classes: 192_168_121_34
R: Defined classes: linux_x86_64
R: Defined classes: Min30_35
R: Defined classes: ipv4_127_0_0
R: Defined classes: feature_def_json
R: Defined classes: feature_tls_1_1
R: Defined classes: feature_host_specific
R: Defined classes: Hr8
R: Defined classes: GMT_Q3
R: Defined classes: feature_pam
R: Defined classes: Morning
R: Defined classes: feature_tls
R: Defined classes: AUTO
R: Defined classes: community_edition
R: Defined classes: ipv4_127
R: Defined classes: Min31
R: Defined classes: Yr2025
R: Defined classes: Q3
R: Defined classes: GMT_Hr08_Q3
R: Defined classes: feature_tls_1_2
R: Defined classes: Hr08
R: /home/jenkins/workspace/testing-pr/label/PACKAGES_x86_64_linux_redhat_7/cfengine-3.27.0a.f77177768/tests/acceptance/./01_vars/01_basic/os_version_minor.cf Expected: 9
R: /home/jenkins/workspace/testing-pr/label/PACKAGES_x86_64_linux_redhat_7/cfengine-3.27.0a.f77177768/tests/acceptance/./01_vars/01_basic/os_version_minor.cf Found: Unknown
R: /home/jenkins/workspace/testing-pr/label/PACKAGES_x86_64_linux_redhat_7/cfengine-3.27.0a.f77177768/tests/acceptance/./01_vars/01_basic/os_version_minor.cf FAIL

@victormlg
Copy link
Contributor Author

@cf-bottom Jenkins with exotics please :)

@cf-bottom
Copy link

@victormlg
Copy link
Contributor Author

@cf-bottom Jenkins with exotics please :)

@cf-bottom
Copy link

@victormlg victormlg force-pushed the os_version_minor branch 4 times, most recently from 2987a78 to 4e33700 Compare July 8, 2025 11:14
@victormlg
Copy link
Contributor Author

@cf-bottom Jenkins with exotics please :)

@cf-bottom
Copy link

@victormlg victormlg force-pushed the os_version_minor branch 3 times, most recently from 61ad8c2 to 6a55210 Compare July 14, 2025 12:46
@victormlg
Copy link
Contributor Author

@cf-bottom Jenkins with exotics please :)

@cf-bottom
Copy link

@victormlg victormlg requested a review from larsewi July 14, 2025 16:53
Ticket: ENT-8118
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Signed-off-by: Victor Moene <victor.moene@northern.tech>
@victormlg
Copy link
Contributor Author

@cf-bottom Jenkins with exotics please :)

@cf-bottom
Copy link

Comment on lines +37 to +39
any::
"os_class"
string => nth(classesmatching("$(class_regex)"), "0");
Copy link
Member

Choose a reason for hiding this comment

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

Reading this, my first reaction is that it feels a bit too complicated and advanced, I would expect something like:

  classes:
    ubuntu_20_04|ubuntu_22_04|ubuntu_24_04::
      "ok"
        if => strcmp("$(sys.os_version_minor)", "4");
      "not_ok"
        if => not(strcmp("$(sys.os_version_minor)", "4"));

    debian_12_11::
      "ok"
        if => strcmp("$(sys.os_version_minor)", "11");
      "not_ok"
        if => not(strcmp("$(sys.os_version_minor)", "11"));

  reports:
    ok.!not_ok::
      "Pass";

    !ok|not_ok::
      "Fail";

That's much easier to read, and gives me more confidence that the test is actually working correctly. However, it will be hard, impossible even, to cover all platforms like this, especially future ones. So maybe a combination would be good? One test which is dynamic and uses regex and covers everything, and one which is stupid and simple and "bulletproof" but doesn't cover all possible platforms?

@@ -2506,6 +2608,7 @@ static int Linux_Misc_Version(EvalContext *ctx)
nt_static_assert((sizeof(version)) > 255);
sscanf(sp + strlen("DISTRIB_RELEASE="), "%255[^\n]", version);
CanonifyNameInPlace(version);
SysOSVersionMinorPutFromVersion(ctx, "", version, "source=agent, derived-from=/etc/lsb_release");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
SysOSVersionMinorPutFromVersion(ctx, "", version, "source=agent, derived-from=/etc/lsb_release");
SysOSVersionMinorPutFromVersion(ctx, "", version, "source=agent, derived-from-file=/etc/lsb_release");

Copy link
Member

@olehermanse olehermanse left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants