Skip to content

Fix OS detection in DirectorStemcellOwner to read from system files#2640

Merged
rkoster merged 1 commit intocloudfoundry:mainfrom
s4heid:stemcell-owner
Dec 4, 2025
Merged

Fix OS detection in DirectorStemcellOwner to read from system files#2640
rkoster merged 1 commit intocloudfoundry:mainfrom
s4heid:stemcell-owner

Conversation

@s4heid
Copy link
Copy Markdown
Contributor

@s4heid s4heid commented Nov 12, 2025

What is this change about?

The DirectorStemcellOwner class was using regex parsing of uname output and hardcoded version-to-codename mappings, which was unmaintainable and failed for modern Ubuntu versions like Jammy.

This fix refactors the implementation to read OS information directly from system files:

  • Operating system name: /var/vcap/bosh/etc/operating_system (with fallback to /etc/os-release ID field)
  • Codename: /etc/os-release UBUNTU_CODENAME field

This approach is more reliable, requires no maintenance for new Ubuntu releases, and fixes the director info endpoint which was returning "-" instead of "ubuntu-jammy" for the Director Stemcell OS on Jammy-based stemcells.

Before (bosh env output):

  • Director Stemcell -/1.943

After (bosh env output):

  • Director Stemcell ubuntu-jammy/1.943

What tests have you run against this PR?

bundle exec rake spec:unit:director

How should this change be described in bosh release notes?

Fix parsing of Stemcell OS from system files

Does this PR introduce a breaking change?

No

The DirectorStemcellOwner class was using complex regex parsing of
uname output and hardcoded version-to-codename mappings, which was
unmaintainable and failed for modern Ubuntu versions like Jammy.

This fix refactors the implementation to read OS information directly
from system files:
- Operating system name: /var/vcap/bosh/etc/operating_system (with
  fallback to /etc/os-release ID field)
- Codename: /etc/os-release UBUNTU_CODENAME field

This approach is more reliable, requires no maintenance for new Ubuntu
releases, and fixes the director info endpoint which was returning "-"
instead of "ubuntu-jammy" for the Director Stemcell OS on Jammy-based
stemcells.

**Before (`bosh env` output):**

  * `Director Stemcell  -/1.943`

**After (`bosh env` output):**

  * `Director Stemcell  ubuntu-jammy/1.943`
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the DirectorStemcellOwner class to improve OS detection reliability by reading from system files instead of parsing uname output. This fixes the director info endpoint which was returning "-" instead of "ubuntu-jammy" for modern Ubuntu versions like Jammy.

Key Changes

  • Replaced regex parsing of uname output with direct file system reads from /var/vcap/bosh/etc/operating_system and /etc/os-release
  • Removed hardcoded version-to-codename mappings (14.04→trusty, 16.04→xenial, 18.04→bionic)
  • Added support for newer Ubuntu versions (Jammy, Noble) without code changes

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/bosh-director/lib/bosh/director/director_stemcell_owner.rb Replaced Etc.uname parsing with file-based OS detection using frozen path constants and new helper methods
src/bosh-director/spec/unit/bosh/director/director_stemcell_owner_spec.rb Updated test suite to mock file system interactions and added coverage for Jammy/Noble Ubuntu versions plus edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-project-automation github-project-automation bot moved this from Pending Review | Discussion to Pending Merge | Prioritized in Foundational Infrastructure Working Group Dec 3, 2025
@rkoster rkoster merged commit c4625ed into cloudfoundry:main Dec 4, 2025
14 checks passed
@github-project-automation github-project-automation bot moved this from Pending Merge | Prioritized to Done in Foundational Infrastructure Working Group Dec 4, 2025
@s4heid s4heid deleted the stemcell-owner branch December 4, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

5 participants