Skip to content

Do not crash at start on NetBSD and OpenBSD#68773

Open
khorben wants to merge 3 commits into
saltstack:masterfrom
khorben:khorben/netbsd-crashes
Open

Do not crash at start on NetBSD and OpenBSD#68773
khorben wants to merge 3 commits into
saltstack:masterfrom
khorben:khorben/netbsd-crashes

Conversation

@khorben

@khorben khorben commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR fixes two crashes when starting salt_master on NetBSD; one of the crashes is expected to affect OpenBSD as well.

What issues does this PR fix or reference?

The patch for salt/grains/core.py avoids accessing an undefined element
of the grains dictionary, on both NetBSD and OpenBSD. This matches the
corresponding code for FreeBSD.

The patch for salt/utils/network.py restricts the OS version test to the
part before "_" on NetBSD; this could raise an exception if py-packaging
wasn't aware of the suffix (e.g., "BETA" would work but "STABLE" not).

Previous Behavior

  File "/usr/pkg/lib/python3.12/site-packages/salt/loader/lazy.py", line 1302, in _run_as
    ret = _func_or_method(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/pkg/lib/python3.12/site-packages/salt/grains/core.py", line 2809, in os_data
    _osrelease_data(grains["os"], grains["osfullname"], grains["osrelease"])
                                  ~~~~~~^^^^^^^^^^^^^^
KeyError: 'osfullname'

And:

  File "/usr/pkg/lib/python3.12/site-packages/salt/utils/network.py", line 1102, in netbsd_interfaces
    if Version(os.uname()[2]) < Version("8.0"):
       ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/pkg/lib/python3.12/site-packages/packaging/version.py", line 202, in __init__
    raise InvalidVersion(f"Invalid version: {version!r}")
packaging.version.InvalidVersion: Invalid version: '10.1_STABLE'

New Behavior

Salt master starts as expected.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

@twangboy twangboy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we get a changelog and a test please

@twangboy

Copy link
Copy Markdown
Contributor

Consider opening this against 3006.x as the bug probably exists there.

Comment thread salt/grains/core.py
Comment on lines +2826 to 2829
grains["os_family"] = grains["osfullname"] = grains["os"] = grains["kernel"]
grains.update(_bsd_cpudata(grains))
grains["osrelease"] = grains["kernelrelease"].split("-")[0]
grains["osfullname"] = "{} {}".format(grains["kernel"], grains["osrelease"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand this change. osfullname is already here on line 2829.

khorben and others added 3 commits July 13, 2026 11:11
This avoids accessing an undefined element of the grains dictionary, on
both NetBSD and OpenBSD. This matches the corresponding code for
FreeBSD.

Tested on NetBSD/amd64.
This patch restricts the OS version test to the part before "_" on
NetBSD; this could raise an exception if py-packaging wasn't aware of
the suffix (e.g., "BETA" would work but "STABLE" not).

Tested on NetBSD/amd64.
Add changelog entry 68773 and unit tests covering:
- netbsd_interfaces() tolerating OS version strings with underscore
  suffixes (e.g. 10.1_STABLE) without raising InvalidVersion
- os_data() correctly setting osfullname on NetBSD and OpenBSD
Comment thread salt/grains/core.py
grains.update(_bsd_cpudata(grains))
elif grains["kernel"] in ("OpenBSD", "NetBSD"):
grains["os_family"] = grains["os"] = grains["kernel"]
grains["os_family"] = grains["osfullname"] = grains["os"] = grains["kernel"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you explain why you are setting grains["osfullname"] here when we immediately change it 3 lines below?

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

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants